diff --git a/pom.xml b/pom.xml
index e5a963e..dea98a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -296,7 +296,7 @@
runtime
-
+
org.reflections
reflections
@@ -406,7 +406,7 @@
jersey-test-framework-provider-grizzly2
test
-
+
org.gcube.contentmanagement
@@ -419,13 +419,15 @@
storage-manager-wrapper
[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)
-
+
+
- com.amazonaws
- aws-java-sdk
- 1.11.163
+ io.minio
+ minio
+ 8.3.3
+
${project.artifactId}
diff --git a/src/main/java/org/gcube/data/access/storagehub/Constants.java b/src/main/java/org/gcube/data/access/storagehub/Constants.java
index 1b7515e..7aa6af2 100644
--- a/src/main/java/org/gcube/data/access/storagehub/Constants.java
+++ b/src/main/java/org/gcube/data/access/storagehub/Constants.java
@@ -36,4 +36,5 @@ public class Constants {
public static final List WRITE_PROTECTED_FOLDER = Arrays.asList(Constants.OLD_VRE_FOLDER_PARENT_NAME, Constants.TRASH_ROOT_FOLDER_NAME);
public static final List PROTECTED_FOLDER = Arrays.asList(Constants.WORKSPACE_ROOT_FOLDER_NAME, Constants.OLD_VRE_FOLDER_PARENT_NAME, Constants.TRASH_ROOT_FOLDER_NAME);
+
}
diff --git a/src/main/java/org/gcube/data/access/storagehub/Utils.java b/src/main/java/org/gcube/data/access/storagehub/Utils.java
index 75cfe55..f7550a2 100644
--- a/src/main/java/org/gcube/data/access/storagehub/Utils.java
+++ b/src/main/java/org/gcube/data/access/storagehub/Utils.java
@@ -349,11 +349,10 @@ public class Utils {
}
public static void setContentFromMetaInfo(AbstractFileItem item, MetaInfo contentInfo) {
- item.getContent().setManagedBy(contentInfo.getManagedBy());
item.getContent().setSize(contentInfo.getSize());
item.getContent().setRemotePath(contentInfo.getRemotePath());
item.getContent().setSize(contentInfo.getSize());
- item.getContent().setStorageId(contentInfo.getStorageId());
+ item.getContent().setPayloadBackend(contentInfo.getPayloadBackend());
}
}
diff --git a/src/main/java/org/gcube/data/access/storagehub/handlers/CompressHandler.java b/src/main/java/org/gcube/data/access/storagehub/handlers/CompressHandler.java
index c5c52c6..df6ab80 100644
--- a/src/main/java/org/gcube/data/access/storagehub/handlers/CompressHandler.java
+++ b/src/main/java/org/gcube/data/access/storagehub/handlers/CompressHandler.java
@@ -77,9 +77,9 @@ public class CompressHandler {
try {
AbstractFileItem fileItem = (AbstractFileItem)item;
- StorageBackendFactory sbf = storageBackendHandler.get(fileItem.getContent().getManagedBy());
+ StorageBackendFactory sbf = storageBackendHandler.get(fileItem.getContent().getPayloadBackend());
- StorageBackend sb = sbf.create(null);
+ StorageBackend sb = sbf.create(fileItem.getContent().getPayloadBackend());
InputStream streamToWrite = sb.download(fileItem.getContent());
if (streamToWrite == null){
diff --git a/src/main/java/org/gcube/data/access/storagehub/handlers/TrashHandler.java b/src/main/java/org/gcube/data/access/storagehub/handlers/TrashHandler.java
index 12ce727..5847ca9 100644
--- a/src/main/java/org/gcube/data/access/storagehub/handlers/TrashHandler.java
+++ b/src/main/java/org/gcube/data/access/storagehub/handlers/TrashHandler.java
@@ -111,9 +111,9 @@ public class TrashHandler {
try {
- StorageBackendFactory sbf = storageBackendHandler.get(item.getContent().getManagedBy());
+ StorageBackendFactory sbf = storageBackendHandler.get(item.getContent().getPayloadBackend());
- StorageBackend sb = sbf.create(null);
+ StorageBackend sb = sbf.create(item.getContent().getPayloadBackend());
contentSet.add(new ContentPair(item.getContent(), sb));
diff --git a/src/main/java/org/gcube/data/access/storagehub/handlers/items/Item2NodeConverter.java b/src/main/java/org/gcube/data/access/storagehub/handlers/items/Item2NodeConverter.java
index 35bd301..154da54 100644
--- a/src/main/java/org/gcube/data/access/storagehub/handlers/items/Item2NodeConverter.java
+++ b/src/main/java/org/gcube/data/access/storagehub/handlers/items/Item2NodeConverter.java
@@ -82,7 +82,6 @@ public class Item2NodeConverter {
logger.debug("error setting value",e);
}
-
}
}
return newNode;
@@ -94,7 +93,7 @@ public class Item2NodeConverter {
}
private void iterateItemNodeAttributeFields(Object object, Node parentNode, String nodeName) throws Exception{
-
+
AttributeRootNode attributeRootNode = object.getClass().getAnnotation(AttributeRootNode.class);
Node newNode;
@@ -145,6 +144,21 @@ public class Item2NodeConverter {
iterateItemNodeAttributeFields(obj,newNode, field.getName()+(i++));
}
+ } else if (field.isAnnotationPresent(NodeAttribute.class)){
+
+ NodeAttribute nodeAttribute = field.getAnnotation(NodeAttribute.class);
+ if (nodeAttribute.isReadOnly()) continue;
+ String subNodeName = nodeAttribute.value();
+ logger.trace("retrieving field node "+field.getName());
+ field.setAccessible(true);
+ try{
+ Object obj = field.get(object);
+ if (obj!=null)
+ iterateItemNodeAttributeFields(obj, newNode, subNodeName);
+ } catch (Exception e ) {
+ logger.debug("error setting value",e);
+ }
+
}
}
}
@@ -197,22 +211,9 @@ public class Item2NodeConverter {
node.setProperty(NodeProperty.LAST_MODIFIED_BY.toString(), item.getLastModifiedBy());
node.setProperty(NodeProperty.LAST_ACTION.toString(), action.name());
- for (Field field : retrieveAllFields(item.getContent().getClass())){
- if (field.isAnnotationPresent(Attribute.class)){
- Attribute attribute = field.getAnnotation(Attribute.class);
- if (attribute.isReadOnly()) continue;
- field.setAccessible(true);
- try{
- //Class> returnType = field.getType();
- Values values = getObjectValue(field.getType(), field.get(item.getContent()));
- if (values.isMulti()) contentNode.setProperty(attribute.value(), values.getValues() );
- else contentNode.setProperty(attribute.value(), values.getValue());
-
- } catch (Exception e ) {
- logger.debug("error setting value for attribute "+attribute.value(),e);
- }
- }
- }
+
+ replaceContentFieldIterator(contentNode, item.getContent().getClass(),item.getContent());
+
} catch (RepositoryException e) {
logger.error("error writing repository",e);
@@ -220,7 +221,41 @@ public class Item2NodeConverter {
}
}
+
+ //VALID ONLY FOR CONTENT
+ private void replaceContentFieldIterator(Node node, Class> clazz, Object instance) {
+ for (Field field : retrieveAllFields(clazz)){
+ if (field.isAnnotationPresent(Attribute.class)){
+ Attribute attribute = field.getAnnotation(Attribute.class);
+ if (attribute.isReadOnly()) continue;
+ field.setAccessible(true);
+ try{
+ //Class> returnType = field.getType();
+ Values values = getObjectValue(field.getType(), field.get(instance));
+ if (values.isMulti()) node.setProperty(attribute.value(), values.getValues() );
+ else node.setProperty(attribute.value(), values.getValue());
+ } catch (Exception e ) {
+ logger.debug("error setting value for attribute "+attribute.value(),e);
+ }
+ } else if (field.isAnnotationPresent(NodeAttribute.class)){
+ NodeAttribute nodeAttribute = field.getAnnotation(NodeAttribute.class);
+ if (nodeAttribute.isReadOnly()) continue;
+ String subNodeName = nodeAttribute.value();
+ logger.trace("retrieving field node "+field.getName());
+ field.setAccessible(true);
+ try{
+ Object obj = field.get(instance);
+ if (obj!=null)
+ iterateItemNodeAttributeFields(obj, node, subNodeName);
+ } catch (Exception e ) {
+ logger.debug("error setting value",e);
+ }
+ }
+ }
+ }
+
+
public void updateHidden(Node node, Boolean hidden,String login) throws RepositoryException {
Utils.setPropertyOnChangeNode(node, login, ItemAction.UPDATED);
node.setProperty(NodeProperty.HIDDEN.toString(), hidden);
diff --git a/src/main/java/org/gcube/data/access/storagehub/handlers/items/ItemHandler.java b/src/main/java/org/gcube/data/access/storagehub/handlers/items/ItemHandler.java
index c091136..91cad81 100644
--- a/src/main/java/org/gcube/data/access/storagehub/handlers/items/ItemHandler.java
+++ b/src/main/java/org/gcube/data/access/storagehub/handlers/items/ItemHandler.java
@@ -56,6 +56,7 @@ import org.gcube.data.access.storagehub.handlers.items.builders.FolderCreationPa
import org.gcube.data.access.storagehub.handlers.items.builders.GCubeItemCreationParameters;
import org.gcube.data.access.storagehub.handlers.items.builders.URLCreationParameters;
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -141,7 +142,7 @@ public class ItemHandler {
}
private Node create(FileCreationParameters params, Node destination) throws Exception{
- Node newNode = createFileItemInternally(params.getSession(), destination, params.getStream(), params.getName(), params.getDescription(), params.getUser(), true);
+ Node newNode = createFileItemInternally(params.getSession(), destination, params.getStream(), params.getName(), params.getDescription(), params.getFileDetails(), params.getUser(), true);
params.getSession().save();
versionHandler.checkinContentNode(newNode);
log.info("file with id {} correctly created",newNode.getIdentifier());
@@ -190,13 +191,13 @@ public class ItemHandler {
log.debug("creating file with entire path {}, name {}, parentPath {} ", entirePath, name, parentPath);
Node fileNode = null;
if (parentPath.isEmpty())
- fileNode = createFileItemInternally(params.getSession(), parentDirectoryNode, input, name, "", params.getUser(), false);
+ fileNode = createFileItemInternally(params.getSession(), parentDirectoryNode, input, name, "", params.getFileDetails(), params.getUser(), false);
else {
Node parentNode = directoryNodeMap.get(parentPath);
if (parentNode ==null)
parentNode = createPath(parentPath, directoryNodeMap, parentDirectoryNode, params.getSession(), params.getUser());
- fileNode = createFileItemInternally(params.getSession(), parentNode, input, name, "", params.getUser(), false);
+ fileNode = createFileItemInternally(params.getSession(), parentNode, input, name, "",params.getFileDetails(), params.getUser(), false);
}
fileNodes.add(fileNode);
}catch(Exception e) {
@@ -246,17 +247,15 @@ public class ItemHandler {
return newNode;
}
- private Node createFileItemInternally(Session ses, Node destinationNode, InputStream stream, String name, String description, String login, boolean withLock) throws RepositoryException, StorageHubException{
+ private Node createFileItemInternally(Session ses, Node destinationNode, InputStream stream, String name, String description, FormDataContentDisposition fileDetails, String login, boolean withLock) throws RepositoryException, StorageHubException{
- log.debug("UPLOAD: starting preparing file");
+ log.trace("UPLOAD: starting preparing file");
Node newNode;
FolderItem destinationItem = node2Item.getItem(destinationNode, Excludes.ALL);
- StorageBackendFactory sbf = storageBackendHandler.get(destinationItem.getBackend().getStorageName());
-
- //TODO: add metadata taken from content node
- StorageBackend sb = sbf.create(destinationItem.getBackend().getParameters());
+ StorageBackendFactory sbf = storageBackendHandler.get(destinationItem.getBackend());
+ StorageBackend sb = sbf.create(destinationItem.getBackend());
String relativePath = destinationNode.getPath();
@@ -268,7 +267,7 @@ public class ItemHandler {
newNode = ses.getNode(newNodePath);
authChecker.checkWriteAuthorizationControl(ses, login, newNode.getIdentifier(), false);
- AbstractFileItem item = fillItemWithContent(stream, sb, name, description, relativePath,login);
+ AbstractFileItem item = fillItemWithContent(stream, sb, name, description, fileDetails, relativePath,login);
if (withLock) {
try {
@@ -289,7 +288,7 @@ public class ItemHandler {
}
else {
authChecker.checkWriteAuthorizationControl(ses, login, destinationNode.getIdentifier(), true);
- AbstractFileItem item = fillItemWithContent(stream, sb, name, description, relativePath, login);
+ AbstractFileItem item = fillItemWithContent(stream, sb, name, description, fileDetails, relativePath, login);
if (withLock) {
try {
log.debug("trying to acquire lock");
@@ -314,16 +313,16 @@ public class ItemHandler {
- private AbstractFileItem fillItemWithContent(InputStream stream, StorageBackend storageBackend, String name, String description, String relPath, String login) throws BackendGenericError{
- log.debug("UPLOAD: filling content");
- ContentHandler handler = getContentHandler(stream, storageBackend, name, relPath, login);
+ private AbstractFileItem fillItemWithContent(InputStream stream, StorageBackend storageBackend, String name, String description, FormDataContentDisposition fileDetails, String relPath, String login) throws BackendGenericError{
+ log.trace("UPLOAD: filling content");
+ ContentHandler handler = getContentHandler(stream, storageBackend, name, fileDetails, relPath, login);
AbstractFileItem item =handler.buildItem(name, description, login);
return item ;
}
- private ContentHandler getContentHandler(InputStream stream, StorageBackend storageBackend, String name, String relPath, String login) throws BackendGenericError {
+ private ContentHandler getContentHandler(InputStream stream, StorageBackend storageBackend, String name, FormDataContentDisposition fileDetails, String relPath, String login) throws BackendGenericError {
- log.debug("UPLOAD: handling content");
+ log.trace("UPLOAD: handling content");
final MultipleOutputStream mos;
try{
@@ -354,7 +353,7 @@ public class ItemHandler {
is1.reset();
handler.initiliseSpecificContent(is1, name, mimeType);
- log.debug("UPLOAD: reading the mimetype - finished in {}",System.currentTimeMillis()-start);
+ log.trace("UPLOAD: reading the mimetype - finished in {}",System.currentTimeMillis()-start);
} catch (Throwable e) {
log.error("error retrieving mimeType",e);
throw new RuntimeException(e);
@@ -370,7 +369,11 @@ public class ItemHandler {
public MetaInfo call() throws Exception {
try(InputStream is1 = mos.get()){
log.debug("UPLOAD: upload on - start");
- MetaInfo info = storageBackend.upload(is1, relPath, name);
+ MetaInfo info;
+ if (fileDetails !=null && fileDetails.getSize()>0)
+ info = storageBackend.upload(is1, relPath, name, fileDetails.getSize());
+ else
+ info = storageBackend.upload(is1, relPath, name);
log.debug("UPLOAD: upload on storage - stop");
return info;
}catch (Throwable e) {
@@ -385,18 +388,20 @@ public class ItemHandler {
Future uploaderF = executor.submit(AuthorizedTasks.bind(uploader));
long start = System.currentTimeMillis();
- log.debug("UPLOAD: writing the stream - start");
+ log.trace("UPLOAD: writing the stream - start");
try {
mos.startWriting();
ContentHandler handler = detectorF.get();
MetaInfo info = uploaderF.get();
- log.debug("UPLOAD: writing the stream - finished in {}",System.currentTimeMillis()-start);
+ log.trace("UPLOAD: writing the stream - finished in {}",System.currentTimeMillis()-start);
handler.getContent().setData(NodeConstants.CONTENT_NAME);
handler.getContent().setStorageId(info.getStorageId());
handler.getContent().setSize(info.getSize());
- handler.getContent().setRemotePath(info.getRemotePath());
- handler.getContent().setManagedBy(info.getManagedBy());
+ handler.getContent().setRemotePath(info.getRemotePath());
+
+ handler.getContent().setPayloadBackend(info.getPayloadBackend());
+ log.trace("UPLOAD: content payload seta as {} ", handler.getContent().getPayloadBackend());
return handler;
}catch (Exception e) {
throw new BackendGenericError(e);
diff --git a/src/main/java/org/gcube/data/access/storagehub/handlers/items/Node2ItemConverter.java b/src/main/java/org/gcube/data/access/storagehub/handlers/items/Node2ItemConverter.java
index 24683c0..bad0e8b 100644
--- a/src/main/java/org/gcube/data/access/storagehub/handlers/items/Node2ItemConverter.java
+++ b/src/main/java/org/gcube/data/access/storagehub/handlers/items/Node2ItemConverter.java
@@ -83,7 +83,7 @@ public class Node2ItemConverter {
setGenericFields(node.getFrozenNode(), Content.class, null, content);
return content;
}
-
+
public Message getMessageItem(Node node) throws RepositoryException{
if (!(node.getPrimaryNodeType().getName().equals("nthl:itemSentRequest")
|| node.getPrimaryNodeType().getName().equals("nthl:itemSentRequestSH")))
@@ -95,7 +95,7 @@ public class Node2ItemConverter {
}catch (Throwable e) {
msg.setWithAttachments(false);
}
-
+
setRootItemCommonFields(node, Collections.emptyList(), Message.class, msg);
return msg;
}
@@ -129,7 +129,7 @@ public class Node2ItemConverter {
item.setExternalManaged(false);
}
-
+
item.setLocked(node.isLocked());
setRootItemCommonFields(node, excludes, classToHandle, item);
@@ -137,7 +137,7 @@ public class Node2ItemConverter {
return item;
}
-
+
private boolean hasTypedParent(Node node, Class parentType) throws BackendGenericError, RepositoryException{
if(node==null) return false;
@@ -146,16 +146,16 @@ public class Node2ItemConverter {
private void setRootItemCommonFields(Node node, List excludes, Class classToHandle, T instance) throws RepositoryException{
-
+
try{
instance.setParentId(node.getParent().getIdentifier());
instance.setParentPath(node.getParent().getPath());
}catch (Throwable e) {
logger.trace("Root node doesn't have a parent");
}
-
+
instance.setRelatedNode(node);
-
+
instance.setId(node.getIdentifier());
instance.setName(Text.unescapeIllegalJcrChars(node.getName()));
@@ -166,7 +166,7 @@ public class Node2ItemConverter {
setGenericFields(node, classToHandle, excludes, instance);
}
-
+
private void setGenericFields(Node node, Class classToHandle,List excludes, T instance){
for (Field field : retrieveAllFields(classToHandle)){
if (field.isAnnotationPresent(Attribute.class)){
@@ -192,7 +192,7 @@ public class Node2ItemConverter {
}
}
}
-
+
private T iterateNodeAttributeFields(Class clazz, Node node) throws Exception{
T obj = clazz.newInstance();
for (Field field : retrieveAllFields(clazz)){
@@ -200,84 +200,113 @@ public class Node2ItemConverter {
setAttributeFieldCheckingDefault(field, obj, node);
} else if (field.isAnnotationPresent(MapAttribute.class)){
logger.trace("found field {} of type annotated as MapAttribute in class {} and node name {}", field.getName(), clazz.getName(), node.getName());
- field.setAccessible(true);
- String exclude = field.getAnnotation(MapAttribute.class).excludeStartWith();
- Map mapToset = new HashMap();
- PropertyIterator iterator = node.getProperties();
- if (iterator!=null) {
- while (iterator.hasNext()){
- Property prop = iterator.nextProperty();
- if (!exclude.isEmpty() && prop.getName().startsWith(exclude)) continue;
- try{
- logger.trace("adding {} in the map",prop.getName());
-
- mapToset.put(prop.getName(), getPropertyValue(prop));
- }catch(PathNotFoundException e){
- logger.warn("the property {} is not mapped",prop.getName());
- } catch (Exception e ) {
- logger.debug("error setting value {}",e.getMessage());
- }
- }
- }
- field.set(obj, mapToset);
+ setMapAttribute(field, obj, node);
} else if (field.isAnnotationPresent(ListNodes.class)){
logger.trace("found field {} of type annotated as ListNodes in class {} on node {}", field.getName(), clazz.getName(), node.getName());
+ setListNode(field, obj, node);
+ } else if (field.isAnnotationPresent(NodeAttribute.class)){
+ logger.debug("found field {} of type annotated as NodeAttribute in class {} on node {}", field.getName(), clazz.getName(), node.getName());
+ String fieldNodeName = field.getAnnotation(NodeAttribute.class).value();
+ //for now it excludes only first level node
+ //if (excludes!=null && excludes.contains(fieldNodeName)) continue;
+ //for now it excludes only first level node
+ logger.info("retrieving field node {} on field {}", fieldNodeName, field.getName());
field.setAccessible(true);
- String exclude = field.getAnnotation(ListNodes.class).excludeTypeStartWith();
- String include = field.getAnnotation(ListNodes.class).includeTypeStartWith();
-
- Class listType = field.getAnnotation(ListNodes.class).listClass();
-
- Map subTypesMap = Collections.emptyMap();
-
- if (!typeToSubtypeMap.containsKey(listType)) {
-
- Configuration config = new ConfigurationBuilder().forPackages(listType.getPackage().getName());
- Reflections reflections = new Reflections(config);
- Set subTypes = reflections.getSubTypesOf(listType);
-
-
- if (subTypes.size()>0) {
- subTypesMap = new HashMap<>();
- for (Class subtype: subTypes)
- if (subtype.isAnnotationPresent(AttributeRootNode.class)) {
- AttributeRootNode attributeRootNode = (AttributeRootNode)subtype.getAnnotation(AttributeRootNode.class);
- subTypesMap.put(attributeRootNode.value(), subtype);
- }
- } else logger.trace("no subtypes found for {}",listType.getName());
-
- typeToSubtypeMap.put(listType, subTypesMap);
-
- } else {
- logger.info("subtypes already found in cache");
- subTypesMap = typeToSubtypeMap.get(listType);
+ try{
+ Node fieldNode = node.getNode(fieldNodeName);
+ logger.info("looking in node {} searched with {}",fieldNode.getName(),fieldNodeName);
+ field.set(obj, iterateNodeAttributeFields(field.getType(), fieldNode));
+ }catch(PathNotFoundException e){
+ logger.warn("the current node dosn't contain {} node",fieldNodeName);
+ } catch (Exception e ) {
+ logger.warn("error setting value",e);
}
- List