Improving lib
This commit is contained in:
parent
b8dfefd4d9
commit
525dfddd52
|
@ -1,12 +1,44 @@
|
|||
package org.gcube.storagehub;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.storagehub.model.Metadata;
|
||||
|
||||
public interface MetadataMatcher {
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class MetadataMatcher {
|
||||
|
||||
public static final String GENERATING_APPLICATION_NAME = "Generating Application Name";
|
||||
public static final String GENERATING_APPLICATION_METADATA_VERSION = "Generating Application Version";
|
||||
public static final String GENERATING_METADATA_NAME = "Generating Metadata Name";
|
||||
public static final String GENERATING_METADATA_VERSION = "Generating Metadata Version";
|
||||
|
||||
public boolean check(Metadata metadata);
|
||||
protected final String metadataName;
|
||||
protected final String metadataVersion;
|
||||
protected final String id;
|
||||
|
||||
protected MetadataMatcher(String metadataName, String metadataVersion, String id) {
|
||||
this.metadataName = metadataName;
|
||||
this.metadataVersion = metadataVersion;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public abstract boolean check(Metadata metadata);
|
||||
|
||||
protected Map<String,Object> getBaseMetadataMap() {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put(MetadataMatcher.GENERATING_METADATA_NAME, metadataName);
|
||||
map.put(MetadataMatcher.GENERATING_METADATA_VERSION, metadataVersion);
|
||||
return map;
|
||||
}
|
||||
|
||||
protected abstract Map<String,Object> getSpecificMetadataMap();
|
||||
|
||||
public Metadata getMetadata() {
|
||||
Map<String, Object> map = getBaseMetadataMap();
|
||||
map.putAll(getSpecificMetadataMap());
|
||||
Metadata metadata = new Metadata(map);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class StorageHubManagement {
|
|||
storageHubClient = new StorageHubClient();
|
||||
}
|
||||
|
||||
public void setCheckMetadata(MetadataMatcher checkMetadata) {
|
||||
public void setMetadataMatcher(MetadataMatcher checkMetadata) {
|
||||
this.metadataMatcher = checkMetadata;
|
||||
}
|
||||
|
||||
|
@ -174,15 +174,15 @@ public class StorageHubManagement {
|
|||
recursiveList(folderContainer, 1);
|
||||
}
|
||||
|
||||
public URL persistFile(InputStream inputStream, String fileName, String mimeType, Metadata metadata)
|
||||
public URL persistFile(InputStream inputStream, String fileName, String mimeType)
|
||||
throws Exception {
|
||||
this.mimeType = mimeType;
|
||||
FolderContainer destinationFolder = getDestinationFolder(mimeType);
|
||||
persitedFile = destinationFolder.uploadFile(inputStream, fileName,
|
||||
"This file has been created to ensure persistence");
|
||||
|
||||
if(metadata != null) {
|
||||
persitedFile.setMetadata(metadata);
|
||||
if(metadataMatcher != null) {
|
||||
persitedFile.setMetadata(metadataMatcher.getMetadata());
|
||||
}
|
||||
|
||||
URL finalURL = persitedFile.getPublicLink();
|
||||
|
@ -202,19 +202,16 @@ public class StorageHubManagement {
|
|||
}
|
||||
}
|
||||
}
|
||||
return this.persitedFile;
|
||||
logger.warn("Unable to find file with mimetype {} and name {} in the expected folder (i.e. id:{}, path:{})",
|
||||
mimeType, filename, destinationFolder.getId(), destinationFolder.get().getPath());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void removePersistedFile(String filename, String mimeType) throws Exception {
|
||||
getPersistedFile(filename, mimeType);
|
||||
removePersistedFile(this.persitedFile);
|
||||
}
|
||||
|
||||
public void removePersistedFile(FileContainer fileContainer) throws Exception {
|
||||
if(fileContainer !=null) {
|
||||
fileContainer.delete();
|
||||
persitedFile = getPersistedFile(filename, mimeType);
|
||||
if(persitedFile !=null) {
|
||||
persitedFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -46,13 +46,13 @@ public class StorageHubManagementTest extends ContextTest {
|
|||
*/
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Ignore
|
||||
@Test
|
||||
public void listFolders() throws Exception {
|
||||
List<String> contexts = new ArrayList<>();
|
||||
// contexts.add(GCUBE);
|
||||
// contexts.add(DEVSEC);
|
||||
// contexts.add(DEVVRE);
|
||||
contexts.add(DEVVRE);
|
||||
// contexts.add(DEVNEXT);
|
||||
// contexts.add(NEXTNEXT);
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class StorageHubManagementTest extends ContextTest {
|
|||
if(name.compareTo(".catalogue")==0 || name.compareTo("service-account-gcat")==0 || name.compareTo("service-account-grsf-publisher")==0) {
|
||||
logger.info("Catalogue folder found");
|
||||
storageHubManagement.tree((FolderContainer) itemContainer);
|
||||
// if(false) {
|
||||
// if(name.compareTo("service-account-grsf-publisher")==0) {
|
||||
// itemContainer.delete();
|
||||
// }
|
||||
}else {
|
||||
|
|
Loading…
Reference in New Issue