Added the possibility of retrieving a persisted file
This commit is contained in:
parent
c1ba3fb85e
commit
4d0921b139
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.data-publishing</groupId>
|
||||
<artifactId>storagehub-application-persistence</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>1.3.1-SNAPSHOT</version>
|
||||
<name>StorageHub Application Persistence</name>
|
||||
<description>
|
||||
This library allows any application to persist in its workspace home any
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ApplicationMode {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void end() {
|
||||
public synchronized void end() {
|
||||
if(originalToken!=null) {
|
||||
try {
|
||||
ContextUtility.setContext(originalToken);
|
||||
|
|
|
@ -37,7 +37,7 @@ public class StorageHubManagement {
|
|||
|
||||
protected final StorageHubClient storageHubClient;
|
||||
|
||||
protected FileContainer createdFile;
|
||||
protected FileContainer persitedFile;
|
||||
protected String mimeType;
|
||||
|
||||
public StorageHubManagement() {
|
||||
|
@ -52,8 +52,8 @@ public class StorageHubManagement {
|
|||
return mimeType;
|
||||
}
|
||||
|
||||
public FileContainer getCreatedFile() {
|
||||
return createdFile;
|
||||
public FileContainer getPersistedFile() {
|
||||
return persitedFile;
|
||||
}
|
||||
|
||||
protected void recursiveList(FolderContainer folder, int level) throws StorageHubException {
|
||||
|
@ -216,29 +216,39 @@ public class StorageHubManagement {
|
|||
throws Exception {
|
||||
this.mimeType = mimeType;
|
||||
FolderContainer destinationFolder = getDestinationFolder(mimeType);
|
||||
createdFile = destinationFolder.uploadFile(inputStream, fileName,
|
||||
persitedFile = destinationFolder.uploadFile(inputStream, fileName,
|
||||
"This file has been created to ensure persistence");
|
||||
|
||||
if(metadata != null) {
|
||||
createdFile.setMetadata(metadata);
|
||||
persitedFile.setMetadata(metadata);
|
||||
}
|
||||
|
||||
URL finalURL = createdFile.getPublicLink();
|
||||
URL finalURL = persitedFile.getPublicLink();
|
||||
logger.debug("File persistence has been ensured. The file is available at {}", finalURL);
|
||||
return finalURL;
|
||||
}
|
||||
|
||||
public void removePersistedFile(String filename, String mimeType) throws Exception {
|
||||
public FileContainer getPersistedFile(String filename, String mimeType) throws Exception {
|
||||
FolderContainer destinationFolder = getDestinationFolder(mimeType);
|
||||
ListResolver listResolver = destinationFolder.findByName(filename);
|
||||
List<ItemContainer<? extends Item>> itemContainers = listResolver.withMetadata().getContainers();
|
||||
for(ItemContainer<? extends Item> itemContainer : itemContainers) {
|
||||
if(itemContainer.getType()==ContainerType.FILE) {
|
||||
if(isPersistedFile((FileContainer) itemContainer, filename)) {
|
||||
itemContainer.delete();
|
||||
this.persitedFile = (FileContainer) itemContainer;
|
||||
return this.persitedFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.persitedFile;
|
||||
}
|
||||
|
||||
|
||||
public void removePersistedFile(String filename, String mimeType) throws Exception {
|
||||
getPersistedFile(filename, mimeType);
|
||||
if(this.persitedFile !=null) {
|
||||
this.persitedFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue