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 3d33f5d..9126599 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 @@ -62,8 +62,6 @@ import com.tinkerpop.blueprints.impls.orient.OrientVertex; */ public class EntityManagementImpl implements EntityManagement { - // TODO This Class is too long please refactoring is needed - private static Logger logger = LoggerFactory .getLogger(EntityManagementImpl.class); @@ -102,9 +100,8 @@ public class EntityManagementImpl implements EntityManagement { String classProperty = getClassProperty(jsonNode); - SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); try { - schemaManagement.getTypeSchema(classProperty, classProperty); + SchemaManagementImpl.getTypeSchema(classProperty, classProperty); } catch (SchemaNotFoundException e) { throw e; } @@ -159,9 +156,8 @@ public class EntityManagementImpl implements EntityManagement { String classProperty = getClassProperty(jsonNode); if (relationType.compareTo(classProperty) != 0) { - SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); try { - schemaManagement.getTypeSchema(relationType, classProperty); + SchemaManagementImpl.getTypeSchema(relationType, classProperty); } catch (SchemaNotFoundException e) { throw e; } @@ -194,9 +190,8 @@ public class EntityManagementImpl implements EntityManagement { // Complex type String type = getClassProperty(jsonNode); - SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); try { - schemaManagement.getTypeSchema(type, Embedded.NAME); + SchemaManagementImpl.getTypeSchema(type, Embedded.NAME); } catch (SchemaNotFoundException e) { throw e; } @@ -451,9 +446,8 @@ public class EntityManagementImpl implements EntityManagement { try { - SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); try { - schemaManagement.getTypeSchema(entityType, + SchemaManagementImpl.getTypeSchema(entityType, entity.getSimpleName()); } catch (SchemaNotFoundException e) { throw e; @@ -605,9 +599,8 @@ public class EntityManagementImpl implements EntityManagement { + " Type cannot be empty or null"); } - SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); try { - schemaManagement.getTypeSchema(relationType, + SchemaManagementImpl.getTypeSchema(relationType, relationBaseClass.getSimpleName()); } catch (SchemaNotFoundException e) { throw e; @@ -694,9 +687,8 @@ public class EntityManagementImpl implements EntityManagement { + " Type cannot be empty or null"); } - SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); try { - schemaManagement.getTypeSchema(relationType, + SchemaManagementImpl.getTypeSchema(relationType, relationClass.getSimpleName()); } catch (SchemaNotFoundException e) { throw e; @@ -1104,8 +1096,7 @@ public class EntityManagementImpl implements EntityManagement { String edgeType = edge.getLabel(); try { - SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); - schemaManagement.getTypeSchema(edgeType, ConsistsOf.NAME); + SchemaManagementImpl.getTypeSchema(edgeType, ConsistsOf.NAME); JSONObject jsonObjectEdge = Utility.toJsonObject( (OrientEdge) edge, true); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/SchemaManagementImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/SchemaManagementImpl.java index 0fdf654..fc61321 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/SchemaManagementImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/resources/impl/SchemaManagementImpl.java @@ -33,6 +33,7 @@ import com.orientechnologies.orient.core.metadata.schema.OProperty; import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.record.impl.ODocument; +import com.tinkerpop.blueprints.impls.orient.OrientElementType; import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; @@ -55,7 +56,7 @@ public class SchemaManagementImpl implements SchemaManagement { return oSchema.getClass(entityType); } - protected OClass getTypeSchema(String type, String baseType) + protected static OClass getTypeSchema(String type, String baseType) throws SchemaNotFoundException { OrientGraphFactory orientGraphFactory = SecurityContextMapper .getSecurityContextFactory( @@ -90,7 +91,7 @@ public class SchemaManagementImpl implements SchemaManagement { } } - protected static String serializeOClass(OClass oClass) { + protected static String serializeOClass(OClass oClass) throws SchemaException { ODocument oDocument = ((OClassImpl) oClass).toStream(); String json = oDocument.toJSON(); logger.trace("Requested type serialization is {}", json); @@ -234,7 +235,12 @@ public class SchemaManagementImpl implements SchemaManagement { } } - String ret = serializeOClass(oClass); + OClass toBeSerializedOClass = oClass; + if(oClass instanceof OrientElementType){ + toBeSerializedOClass = getEntityOClass(orientGraphNoTx, typeDefinition.getName()); + } + + String ret = serializeOClass(toBeSerializedOClass); logger.info("{} type registered successfully: {}", baseType, jsonSchema); return ret;