diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index 1b3ac0a..9fb1bc0 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -4,13 +4,13 @@
-
+
uses
uses
-
+
uses
diff --git a/pom.xml b/pom.xml
index 9ec454b..b1d9e02 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
org.gcube.information-system
resource-registry
- 1.0.0-SNAPSHOT
+ 1.1.0-SNAPSHOT
Resource Registry
Resource Registry
war
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/EntityManagementImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/EntityManagementImpl.java
index b372b12..7e502f5 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/EntityManagementImpl.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/EntityManagementImpl.java
@@ -4,13 +4,21 @@
package org.gcube.informationsystem.resourceregistry.resources.impl;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.gcube.informationsystem.impl.utils.Entities;
+import org.gcube.informationsystem.model.embedded.Embedded;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
+import org.gcube.informationsystem.model.orientdb.impl.embedded.Header;
import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.model.relation.IsRelatedTo;
import org.gcube.informationsystem.model.relation.Relation;
@@ -26,9 +34,12 @@ import org.gcube.informationsystem.resourceregistry.resources.utils.Utility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
@@ -94,15 +105,261 @@ public class EntityManagementImpl implements EntityManagement {
}
- public String createVertexEntity(String entityType,
- Class extends Entity> entity, String jsonRepresentation)
- throws ResourceRegistryException {
- OrientGraph orientGraph = null;
+ private static String lowerCaseFirstCharacter(String string) {
+ return string.substring(0, 1).toLowerCase() + string.substring(1);
+ }
+ private static String getClassProperty(JsonNode jsonNode) {
+ if (jsonNode.has(Entities.CLASS_PROPERTY)) {
+ return jsonNode.get(Entities.CLASS_PROPERTY).asText();
+ }
+ return null;
+ }
+
+ private static Header getHeader(JsonNode jsonNode)
+ throws JsonParseException, JsonMappingException, IOException {
+ if (jsonNode.has(Resource.HEADER_PROPERTY)) {
+ JsonNode header = jsonNode.get(Resource.HEADER_PROPERTY);
+ if (header.isNull()) {
+ return null;
+ }
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.readValue(header.toString(), Header.class);
+ }
+ return null;
+ }
+
+ private static Entity checkTypeAndGetHeader(JsonNode jsonNode) throws ResourceRegistryException {
+ if(jsonNode.has(Entities.CLASS_PROPERTY)){
+ // Complex type
+ String type = getClassProperty(jsonNode);
+
+
+ SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
+ try {
+ schemaManagement.getTypeSchema(type, Embedded.NAME);
+ } catch (SchemaNotFoundException e) {
+ throw e;
+ }
+ boolean validType = false;
+ boolean notEmbedded = false;
+
+
+
+ // Header can be ignored or managed. Actually is managed.
+ if(validType && notEmbedded){
+ Header header = null;
+ try {
+ header = getHeader(jsonNode);
+ } catch (Exception e){
+ logger.warn("An invalid Header has been provided. An embedded object cannot have an Header. It will be ignored.");
+ //throw new ResourceRegistryException("An embedded object cannot have an Header");
+ }
+
+ if(header!=null){
+ logger.warn("An embedded object cannot have an Header. It will be ignored.");
+ //throw new ResourceRegistryException("An embedded object cannot have an Header");
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public static Object getObejctFromElement(JsonNode value) throws ResourceRegistryException {
+ JsonNodeType jsonNodeType = value.getNodeType();
+ switch (jsonNodeType) {
+ case OBJECT:
+ // TODO
+ checkTypeAndGetHeader(value);
+ return null;
+
+ case ARRAY:
+ List