diff --git a/pom.xml b/pom.xml index 1c1eb4d..80f22d3 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,6 @@ org.apache.maven.plugins maven-resources-plugin - 2.6 copy-profile diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java index f6da9f0..b9f0648 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java @@ -116,7 +116,6 @@ public class DatabaseIntializator { entityRegistrationAction.manageEmbeddedClass(Embedded.class); entityRegistrationAction.manageEmbeddedClass(ValueSchema.class); erDiscovery.manageDiscoveredERTypes(entityRegistrationAction); - } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java index 002da26..3bc3b15 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java @@ -722,7 +722,7 @@ public abstract class ERManagement { if(key.compareTo(ER.HEADER_PROPERTY)==0){ // Keep the header - HeaderOrient headerOrient = (HeaderOrient) object; + HeaderOrient headerOrient = HeaderUtility.getHeaderOrient((ODocument) object); JSONObject headerObject = new JSONObject(headerOrient.toJSON("class")); properties.put(ER.HEADER_PROPERTY, headerObject); continue; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java index 290118b..c7dc4a4 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java @@ -12,6 +12,7 @@ import java.util.UUID; import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.authorization.library.provider.ClientInfo; import org.gcube.common.authorization.library.utils.Caller; +import org.gcube.informationsystem.impl.utils.Entities; import org.gcube.informationsystem.model.embedded.Header; import org.gcube.informationsystem.model.entity.Entity; import org.gcube.informationsystem.model.entity.Resource; @@ -22,6 +23,7 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; +import com.orientechnologies.orient.core.record.impl.ODocument; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Element; import com.tinkerpop.blueprints.Vertex; @@ -93,6 +95,24 @@ public class HeaderUtility { return null; } + public static HeaderOrient getHeaderOrient(ODocument oDocument) throws ResourceRegistryException{ + if (oDocument instanceof HeaderOrient) { + return (HeaderOrient) oDocument; + }else{ + try { + HeaderOrient headerOrient = new HeaderOrient(); + Header header = Entities.unmarshal(Header.class, oDocument.toJSON()); + headerOrient.setUUID(header.getUUID()); + headerOrient.setCreator(header.getCreator()); + headerOrient.setCreationTime(header.getCreationTime()); + headerOrient.setLastUpdateTime(header.getLastUpdateTime()); + return headerOrient; + } catch (Exception e) { + throw new ResourceRegistryException("Unable to recreate Header. This should not occur. Please contact Administrator."); + } + } + } + public static Header addHeader(Vertex vertex, UUID uuid) { Header header = createHeader(uuid); vertex.setProperty(Entity.HEADER_PROPERTY, header); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java index 1f97d60..c1132ac 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java @@ -11,6 +11,7 @@ import java.util.UUID; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.gcube.informationsystem.impl.utils.Entities; +import org.gcube.informationsystem.model.embedded.Embedded; import org.gcube.informationsystem.model.embedded.Header; import org.gcube.informationsystem.model.entity.Entity; import org.gcube.informationsystem.model.relation.Relation; @@ -127,16 +128,16 @@ public class Utility { } - public static T getEmbedded(Class clz, Element element, String property) + public static E getEmbedded(Class clz, Element element, String property) throws ResourceRegistryException { try { ODocument oDocument = element.getProperty(property); - T t = Entities.unmarshal(clz, oDocument.toJSON()); - return t; - } catch (Exception e) { + E e = Entities.unmarshal(clz, oDocument.toJSON()); + return e; + } catch (Exception ex) { String error = String.format("Error while getting %s from %s", property, toJsonString(element, true)); - throw new ResourceRegistryException(error, e); + throw new ResourceRegistryException(error, ex); } }