From 1ccefd44e2c1c2c335512555f8b013da1ba2f88f Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 20 Jan 2021 15:11:51 +0100 Subject: [PATCH] Ported SchemaManagement to the new way to define the type of a property --- .../types/SchemaManagement.java | 83 +++++++++++-------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java index a402dd3..c270302 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java @@ -39,6 +39,7 @@ import org.gcube.informationsystem.resourceregistry.types.properties.PropertyTyp import org.gcube.informationsystem.resourceregistry.types.relations.ConsistsOfTypeDefinitionManagement; import org.gcube.informationsystem.resourceregistry.types.relations.IsRelatedToTypeDefinitionManagement; import org.gcube.informationsystem.types.PropertyTypeName; +import org.gcube.informationsystem.types.PropertyTypeName.BaseType; import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl; import org.gcube.informationsystem.types.reference.Type; @@ -393,10 +394,10 @@ public class SchemaManagement { if(!typeList.contains(type.getName())) { switch(propertyTypeName.getBaseType()) { case LIST: - throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST + throw new UnsupportedDataTypeException(OType.EMBEDDEDLIST + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354"); case SET: - throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET + throw new UnsupportedDataTypeException(OType.EMBEDDEDSET + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354"); default: break; @@ -421,23 +422,27 @@ public class SchemaManagement { op.setReadonly(propertyDefinition.isReadonly()); op.setRegexp(propertyDefinition.getRegexp()); - if(propertyTypeName.getGenericBaseType() != null) { - OType linkedType = - OClass linkedClass = getOClass(oSchema, propertyTypeName.getGenericBaseType().toString()); - - if(linkedClass == null) { - logger.trace("class {} not found in schema", propertyDefinition.getLinkedClass()); - throw new Exception( - "class " + propertyDefinition.getLinkedClass() + " not found in schema"); + if(propertyTypeName.getGenericBaseType()!=null) { + if(propertyTypeName.getGenericBaseType().ordinal() >= BaseType.PROPERTY.ordinal()) { + if(propertyTypeName.getGenericBaseType()!=null) { + OType linkedOType = OrientDBTypeMapping.getOTypeByBaseType(propertyTypeName.getGenericBaseType()); + op.setLinkedType(OType.getById(Integer.valueOf(linkedOType.ordinal()).byteValue())); + }else if(propertyTypeName.getGenericClassName()!=null){ + + OClass linkedClass = getOClass(oSchema, propertyTypeName.getGenericClassName()); + + if(linkedClass == null) { + logger.trace("Class {} not found.", propertyTypeName.getGenericClassName()); + throw new Exception("Class " + propertyTypeName.getGenericClassName() + " not found."); + } + + if(linkedClass.isEdgeType() || linkedClass.isVertexType()) { + throw new Exception("A PropertyType cannot be an Entity type or a Relation type"); + } + + op.setLinkedClass(linkedClass); + } } - - if(linkedClass.isEdgeType() || linkedClass.isVertexType()) { - throw new Exception("A Property Field cannot be an Entity or a Relation"); - } - - op.setLinkedClass(linkedClass); - } else if(propertyDefinition.getLinkedType() != null) { - op.setLinkedType(OType.getById(propertyDefinition.getLinkedType().byteValue())); } } } @@ -572,7 +577,8 @@ public class SchemaManagement { continue; } - OType oType = OType.getById(newPropertyDefinition.getType().byteValue()); + PropertyTypeName newPropertyTypeName = ((PropertyDefinitionImpl) newPropertyDefinition).getPropertyTypeName(); + OType oType = OrientDBTypeMapping.getOTypeByBaseType(newPropertyTypeName.getBaseType()); /* * Excluding EMBEDDEDLIST and EMBEDDEDSET @@ -582,10 +588,10 @@ public class SchemaManagement { if(!typeList.contains(newTypeDefinition.getName())) { switch(oType) { case EMBEDDEDLIST: - throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST + throw new UnsupportedDataTypeException(OType.EMBEDDEDLIST + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354"); case EMBEDDEDSET: - throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET + throw new UnsupportedDataTypeException(OType.EMBEDDEDSET + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354"); default: break; @@ -615,22 +621,29 @@ public class SchemaManagement { op.setReadonly(newPropertyDefinition.isReadonly()); op.setRegexp(newPropertyDefinition.getRegexp()); - if(newPropertyDefinition.getLinkedClass() != null) { - OClass linkedClass = getOClass(oSchema, newPropertyDefinition.getLinkedClass()); - if(linkedClass == null) { - logger.trace("class {} not found in schema", newPropertyDefinition.getLinkedClass()); - throw new Exception( - "class " + newPropertyDefinition.getLinkedClass() + " not found in schema"); + if(newPropertyTypeName.getGenericBaseType()!=null) { + if(newPropertyTypeName.getGenericBaseType().ordinal() >= BaseType.PROPERTY.ordinal()) { + if(newPropertyTypeName.getGenericBaseType()!=null) { + OType linkedOType = OrientDBTypeMapping.getOTypeByBaseType(newPropertyTypeName.getGenericBaseType()); + op.setLinkedType(OType.getById(Integer.valueOf(linkedOType.ordinal()).byteValue())); + }else if(newPropertyTypeName.getGenericClassName()!=null){ + + OClass linkedClass = getOClass(oSchema, newPropertyTypeName.getGenericClassName()); + + if(linkedClass == null) { + logger.trace("Class {} not found.", newPropertyTypeName.getGenericClassName()); + throw new Exception("Class " + newPropertyTypeName.getGenericClassName() + " not found."); + } + + if(linkedClass.isEdgeType() || linkedClass.isVertexType()) { + throw new Exception("A PropertyType cannot be an Entity type or a Relation type"); + } + + op.setLinkedClass(linkedClass); + } } - - if(linkedClass.isEdgeType() || linkedClass.isVertexType()) { - throw new Exception("A Property Field cannot be an Entity or a Relation"); - } - - op.setLinkedClass(linkedClass); - } else if(newPropertyDefinition.getLinkedType() != null) { - op.setLinkedType(OType.getById(newPropertyDefinition.getLinkedType().byteValue())); } + } }