-
Notifications
You must be signed in to change notification settings - Fork 3
Story/vspc 204 #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Story/vspc 204 #308
Changes from 24 commits
0783f6d
d1b15cc
e1cda05
d68de99
9e509e2
70907bb
0d2e771
78c5003
1a6da12
7a71f63
737dad5
0a24c03
ef2ee5a
0c3e206
3caf863
b7d9442
34496eb
e74fe71
e280828
dff8c3d
e1bf075
3adad85
3a86887
d2a9a14
3926ce1
7d8fb37
9f521c3
88c9b87
c7c6df4
0847669
4896d85
1f2c46d
4702909
3cc5781
60bc618
1f4b4fd
da355c1
2a6ce84
1c52717
0bdf246
9fe3a25
342f195
0b8538e
f8cce1c
b6f9027
fbfca18
510692d
9f390e4
8152349
7ae7346
d84796c
40a83b6
4e716bf
ccb6a35
cec7445
effb3a5
b7ab2e7
8c64978
24fbc07
72abc69
1f05362
eeacaea
bcde954
d00e77b
bd85667
38ee8a9
3d23f6d
e391b62
c3e29aa
0a1add5
9c1b8ed
4c2fa90
eb029f3
7c9b5ba
aad9e14
ab92dad
80d3796
b19a2b6
8ba400d
52a24b3
92b0062
b0a44ad
f777e53
d61e650
7f3ce57
b35db5b
7b232cc
35a495c
d9b3deb
44bbd99
298e3d9
6dc1fc0
2357602
0134549
4cf5d37
70d45f3
966c169
38794fa
d3b7e10
1091f71
d270fc0
57bac32
be69f61
b5ce14d
502cbb9
e12f6f0
e7857e9
7d6b9f0
246caf4
2635356
9da2084
26e30c8
fa22d8c
a3afc68
6b93127
2d28775
2a4149b
de3303d
fd94f74
74b3372
9ebe4ce
e42f6fe
229ba5f
8ba9281
e42eac9
e269bb1
504ff0b
27c94a7
334ff22
27bcf6b
3d19a1e
79210a4
93b1aa9
d665d9e
a205132
5f1b1cc
41d73db
4256d9e
2fa6b8c
937227c
d7c3f76
f1407a2
c66eac7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package edu.asu.diging.vspace.core.data; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
|
||
import edu.asu.diging.vspace.core.model.impl.ExhibitionDownload; | ||
|
||
public interface ExhibitionDownloadRepository extends PagingAndSortingRepository<ExhibitionDownload, String> { | ||
|
||
List<ExhibitionDownload> findAllByOrderByCreationDateDesc(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package edu.asu.diging.vspace.core.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Exhibition Download folder Not Found") | ||
|
||
public class ExhibitionDownloadNotFoundException extends Exception{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ExhibitionDownloadNotFoundException(String id) { | ||
super("Exhibition download folder with id " + id + " not found"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,16 @@ | |
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URLConnection; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.stream.Stream; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.stereotype.Component; | ||
|
@@ -20,20 +29,23 @@ | |
@Component | ||
@PropertySource({"classpath:config.properties", "${appConfigFile:classpath:}/app.properties"}) | ||
public class StorageEngine implements IStorageEngine { | ||
jdamerow marked this conversation as resolved.
Show resolved
Hide resolved
jdamerow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@Value("${uploads_path}") | ||
private String path; | ||
|
||
/* (non-Javadoc) | ||
* @see edu.asu.diging.vspace.core.file.impl.IStorageEngine#storeFile(byte[], java.lang.String, java.lang.String) | ||
*/ | ||
@Override | ||
public String storeFile(byte[] fileContent, String filename, String directory) throws FileStorageException { | ||
File parent = new File(path + File.separator + directory); | ||
if (!parent.exists()) { | ||
parent.mkdir(); | ||
} | ||
File file = new File(parent.getAbsolutePath() + File.separator + filename); | ||
* @see edu.asu.diging.vspace.core.file.impl.IStorageEngine#storeFile(byte[], java.lang.String, java.lang.String) | ||
*/ | ||
@Override | ||
public String storeFile(byte[] fileContent, String filename, String directory, String path) throws FileStorageException { | ||
|
||
File parent = new File(path + (directory!= null ? File.separator + directory : "" )); | ||
if (!parent.exists()) { | ||
parent.mkdir(); | ||
} | ||
File file = new File(parent.getAbsolutePath() + File.separator + filename); | ||
|
||
|
||
BufferedOutputStream stream; | ||
try { | ||
stream = new BufferedOutputStream(new FileOutputStream(file)); | ||
|
@@ -48,7 +60,8 @@ public String storeFile(byte[] fileContent, String filename, String directory) t | |
} | ||
|
||
return directory; | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public byte[] getImageContent(String directory, String filename) throws IOException { | ||
|
@@ -89,4 +102,77 @@ public boolean renameImage(IVSImage image, String newFileName) { | |
File renamedFile = new File(path + File.separator + image.getId() + File.separator + newFileName); | ||
return currentFile.renameTo(renamedFile); | ||
} | ||
|
||
|
||
|
||
|
||
public String createFolder(String folderName, String path ) { | ||
File folder = new File(path + File.separator + folderName); | ||
if (!folder.exists()) { | ||
folder.mkdir(); | ||
} | ||
|
||
return folder.getAbsolutePath(); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Converts the given folder into a zip folder and returna byte array. | ||
* | ||
* @param folderPath | ||
* @return | ||
* @throws IOException | ||
*/ | ||
public byte[] generateZipFolder(String folderPath) throws IOException { | ||
jdamerow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Path zipFile = Paths.get(folderPath); | ||
|
||
try ( | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream); | ||
ZipOutputStream responseZipStream = new ZipOutputStream(bufferedOutputStream); | ||
|
||
Stream<Path> paths = Files.walk(zipFile)) { | ||
paths | ||
.filter(path -> !Files.isDirectory(path)) | ||
.forEach(path -> { | ||
ZipEntry zipEntry = new ZipEntry(zipFile.relativize(path).toString()); | ||
try { | ||
responseZipStream.putNextEntry(zipEntry); | ||
Files.copy(path, responseZipStream); | ||
responseZipStream.closeEntry(); | ||
|
||
} catch (IOException e) { | ||
System.err.println(e); | ||
|
||
} | ||
}); | ||
IOUtils.close(responseZipStream); | ||
IOUtils.close(bufferedOutputStream); | ||
IOUtils.close(byteArrayOutputStream); | ||
|
||
|
||
return byteArrayOutputStream.toByteArray(); | ||
|
||
} catch (IOException e) { | ||
throw new IOException(e); | ||
|
||
} | ||
|
||
} | ||
jdamerow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
|
||
/** | ||
* Copies given image to imagesFolderPath | ||
* | ||
* @param image | ||
* @param imagesFolderPath | ||
*/ | ||
public void copyImageToFolder(IVSImage image, String imagesFolderPath) { | ||
try { | ||
byte[] byteArray = getImageContent(image.getId(), image.getFilename()); | ||
storeFile(byteArray, image.getFilename(),image.getId(), imagesFolderPath ); | ||
|
||
} catch (IOException | FileStorageException e) { | ||
logger.error("Could not copy images" , e); | ||
} | ||
} | ||
jdamerow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package edu.asu.diging.vspace.core.model; | ||
|
||
public interface IExhibitionDownload { | ||
|
||
} | ||
jdamerow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package edu.asu.diging.vspace.core.model.impl; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.annotations.GenericGenerator; | ||
import org.hibernate.annotations.Parameter; | ||
|
||
import edu.asu.diging.vspace.core.model.IExhibitionDownload; | ||
|
||
@Entity | ||
public class ExhibitionDownload extends VSpaceElement implements IExhibitionDownload{ | ||
|
||
@Id | ||
@GeneratedValue(generator = "exhibit_download_id_generator") | ||
@GenericGenerator(name = "exhibit_download_id_generator", parameters = @Parameter(name = "prefix", value = "EXHDWNLD"), strategy = "edu.asu.diging.vspace.core.data.IdGenerator") | ||
private String id; | ||
|
||
private String folderPath; | ||
|
||
private String folderName; | ||
|
||
|
||
public ExhibitionDownload() { | ||
super(); | ||
} | ||
|
||
public ExhibitionDownload(String folderPath, String folderName) { | ||
|
||
super(); | ||
this.folderPath = folderPath; | ||
this.folderName = folderName; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return this.id; } | ||
|
||
@Override | ||
public void setId(String id) { | ||
this.id = id; | ||
|
||
} | ||
|
||
public String getFolderPath() { | ||
return folderPath; | ||
} | ||
|
||
public void setFolderPath(String folderPath) { | ||
this.folderPath = folderPath; | ||
} | ||
|
||
|
||
public String getFolderName() { | ||
return folderName; | ||
} | ||
|
||
public void setFolderName(String folderName) { | ||
this.folderName = folderName; | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect capitalization, should be "Exhibition download folder not found". Also, is the Exhibition download not found or the folder?
And also, let's loose the empty line after the annotation (line 7)