Improving lib
This commit is contained in:
parent
b8dfefd4d9
commit
525dfddd52
|
@ -1,12 +1,44 @@
|
||||||
package org.gcube.storagehub;
|
package org.gcube.storagehub;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
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_METADATA_NAME = "Generating Metadata Name";
|
||||||
public static final String GENERATING_APPLICATION_METADATA_VERSION = "Generating Application Version";
|
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();
|
storageHubClient = new StorageHubClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCheckMetadata(MetadataMatcher checkMetadata) {
|
public void setMetadataMatcher(MetadataMatcher checkMetadata) {
|
||||||
this.metadataMatcher = checkMetadata;
|
this.metadataMatcher = checkMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,15 +174,15 @@ public class StorageHubManagement {
|
||||||
recursiveList(folderContainer, 1);
|
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 {
|
throws Exception {
|
||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
FolderContainer destinationFolder = getDestinationFolder(mimeType);
|
FolderContainer destinationFolder = getDestinationFolder(mimeType);
|
||||||
persitedFile = destinationFolder.uploadFile(inputStream, fileName,
|
persitedFile = destinationFolder.uploadFile(inputStream, fileName,
|
||||||
"This file has been created to ensure persistence");
|
"This file has been created to ensure persistence");
|
||||||
|
|
||||||
if(metadata != null) {
|
if(metadataMatcher != null) {
|
||||||
persitedFile.setMetadata(metadata);
|
persitedFile.setMetadata(metadataMatcher.getMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
URL finalURL = persitedFile.getPublicLink();
|
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 {
|
public void removePersistedFile(String filename, String mimeType) throws Exception {
|
||||||
getPersistedFile(filename, mimeType);
|
persitedFile = getPersistedFile(filename, mimeType);
|
||||||
removePersistedFile(this.persitedFile);
|
if(persitedFile !=null) {
|
||||||
}
|
persitedFile.delete();
|
||||||
|
|
||||||
public void removePersistedFile(FileContainer fileContainer) throws Exception {
|
|
||||||
if(fileContainer !=null) {
|
|
||||||
fileContainer.delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,13 +46,13 @@ public class StorageHubManagementTest extends ContextTest {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
// @Ignore
|
||||||
@Test
|
@Test
|
||||||
public void listFolders() throws Exception {
|
public void listFolders() throws Exception {
|
||||||
List<String> contexts = new ArrayList<>();
|
List<String> contexts = new ArrayList<>();
|
||||||
// contexts.add(GCUBE);
|
// contexts.add(GCUBE);
|
||||||
// contexts.add(DEVSEC);
|
// contexts.add(DEVSEC);
|
||||||
// contexts.add(DEVVRE);
|
contexts.add(DEVVRE);
|
||||||
// contexts.add(DEVNEXT);
|
// contexts.add(DEVNEXT);
|
||||||
// contexts.add(NEXTNEXT);
|
// 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) {
|
if(name.compareTo(".catalogue")==0 || name.compareTo("service-account-gcat")==0 || name.compareTo("service-account-grsf-publisher")==0) {
|
||||||
logger.info("Catalogue folder found");
|
logger.info("Catalogue folder found");
|
||||||
storageHubManagement.tree((FolderContainer) itemContainer);
|
storageHubManagement.tree((FolderContainer) itemContainer);
|
||||||
// if(false) {
|
// if(name.compareTo("service-account-grsf-publisher")==0) {
|
||||||
// itemContainer.delete();
|
// itemContainer.delete();
|
||||||
// }
|
// }
|
||||||
}else {
|
}else {
|
||||||
|
|
Loading…
Reference in New Issue