diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/OrientDBTypeMapping.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/OrientDBTypeMapping.java new file mode 100644 index 0000000..122b81d --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/OrientDBTypeMapping.java @@ -0,0 +1,56 @@ +package org.gcube.informationsystem.resourceregistry.types; + +import java.util.HashMap; +import java.util.Map; + +import org.gcube.informationsystem.types.PropertyTypeName.BaseType; + +import com.orientechnologies.orient.core.metadata.schema.OType; + +/** + * @author Luca Frosini (ISTI - CNR) + * Create a mapping between OrientDB {@link OType} + * https://orientdb.gitbooks.io/orientdb-manual/content/orientdb.wiki/Types.html + * and {@link BaseType} + */ +public class OrientDBTypeMapping { + + protected static final Map BASE_TYPE_TO_OTYPE; + + protected static final Map OTYPE_TO_BASE_TYPE; + + + static { + BASE_TYPE_TO_OTYPE = new HashMap<>(); + + BASE_TYPE_TO_OTYPE.put(BaseType.BOOLEAN, OType.BOOLEAN); + BASE_TYPE_TO_OTYPE.put(BaseType.INTEGER, OType.INTEGER); + BASE_TYPE_TO_OTYPE.put(BaseType.SHORT, OType.SHORT); + BASE_TYPE_TO_OTYPE.put(BaseType.LONG, OType.LONG); + BASE_TYPE_TO_OTYPE.put(BaseType.FLOAT, OType.FLOAT); + BASE_TYPE_TO_OTYPE.put(BaseType.DOUBLE, OType.DOUBLE); + BASE_TYPE_TO_OTYPE.put(BaseType.DATE, OType.DATETIME); + BASE_TYPE_TO_OTYPE.put(BaseType.STRING, OType.STRING); + BASE_TYPE_TO_OTYPE.put(BaseType.BINARY, OType.BINARY); + BASE_TYPE_TO_OTYPE.put(BaseType.BYTE, OType.BYTE); + BASE_TYPE_TO_OTYPE.put(BaseType.PROPERTY, OType.EMBEDDED); + BASE_TYPE_TO_OTYPE.put(BaseType.LIST, OType.EMBEDDEDLIST); + BASE_TYPE_TO_OTYPE.put(BaseType.SET, OType.EMBEDDEDSET); + BASE_TYPE_TO_OTYPE.put(BaseType.MAP, OType.EMBEDDEDMAP); + + OTYPE_TO_BASE_TYPE = new HashMap<>(); + for(BaseType baseType : BASE_TYPE_TO_OTYPE.keySet()) { + OTYPE_TO_BASE_TYPE.put(BASE_TYPE_TO_OTYPE.get(baseType), baseType); + } + + } + + public static OType getOTypeByBaseType(final BaseType baseType) { + return BASE_TYPE_TO_OTYPE.get(baseType); + } + + public static BaseType getBaseTypeByOType(final OType oType) { + return OTYPE_TO_BASE_TYPE.get(oType); + } + +} 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 d57bfc8..a402dd3 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java @@ -38,8 +38,9 @@ import org.gcube.informationsystem.resourceregistry.types.entities.ResourceTypeD import org.gcube.informationsystem.resourceregistry.types.properties.PropertyTypeDefinitionManagement; import org.gcube.informationsystem.resourceregistry.types.relations.ConsistsOfTypeDefinitionManagement; import org.gcube.informationsystem.resourceregistry.types.relations.IsRelatedToTypeDefinitionManagement; -import org.gcube.informationsystem.types.OrientDBType; +import org.gcube.informationsystem.types.PropertyTypeName; import org.gcube.informationsystem.types.TypeMapper; +import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl; import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.types.reference.entities.EntityType; import org.gcube.informationsystem.types.reference.entities.FacetType; @@ -381,7 +382,7 @@ public class SchemaManagement { if(propertyDefinitions!=null) { for(PropertyDefinition propertyDefinition : propertyDefinitions) { - OType oType = OType.getById(propertyDefinition.getType().byteValue()); + PropertyTypeName propertyTypeName = ((PropertyDefinitionImpl) propertyDefinition).getPropertyTypeName(); /* * Types update is not allowed, @@ -390,11 +391,11 @@ public class SchemaManagement { * */ if(!typeList.contains(type.getName())) { - switch(oType) { - case EMBEDDEDLIST: + switch(propertyTypeName.getBaseType()) { + case LIST: throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354"); - case EMBEDDEDSET: + case SET: throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354"); default: @@ -402,6 +403,8 @@ public class SchemaManagement { } } + OType oType = OrientDBTypeMapping.getOTypeByBaseType(propertyTypeName.getBaseType()); + OProperty op = oClass.createProperty(propertyDefinition.getName(), oType); op.setDescription(propertyDefinition.getDescription()); @@ -418,8 +421,10 @@ public class SchemaManagement { op.setReadonly(propertyDefinition.isReadonly()); op.setRegexp(propertyDefinition.getRegexp()); - if(propertyDefinition.getLinkedClass() != null) { - OClass linkedClass = getOClass(oSchema, propertyDefinition.getLinkedClass()); + 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(