Ported SchemaManagement to the new way to define the type of a property

This commit is contained in:
Luca Frosini 2021-01-20 15:11:51 +01:00
parent bf24fe07c4
commit 1ccefd44e2
1 changed files with 48 additions and 35 deletions

View File

@ -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.ConsistsOfTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.relations.IsRelatedToTypeDefinitionManagement; import org.gcube.informationsystem.resourceregistry.types.relations.IsRelatedToTypeDefinitionManagement;
import org.gcube.informationsystem.types.PropertyTypeName; import org.gcube.informationsystem.types.PropertyTypeName;
import org.gcube.informationsystem.types.PropertyTypeName.BaseType;
import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl; import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.types.reference.Type;
@ -393,10 +394,10 @@ public class SchemaManagement {
if(!typeList.contains(type.getName())) { if(!typeList.contains(type.getName())) {
switch(propertyTypeName.getBaseType()) { switch(propertyTypeName.getBaseType()) {
case LIST: 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"); + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
case SET: 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"); + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
default: default:
break; break;
@ -421,23 +422,27 @@ public class SchemaManagement {
op.setReadonly(propertyDefinition.isReadonly()); op.setReadonly(propertyDefinition.isReadonly());
op.setRegexp(propertyDefinition.getRegexp()); op.setRegexp(propertyDefinition.getRegexp());
if(propertyTypeName.getGenericBaseType() != null) { if(propertyTypeName.getGenericBaseType()!=null) {
OType linkedType = if(propertyTypeName.getGenericBaseType().ordinal() >= BaseType.PROPERTY.ordinal()) {
OClass linkedClass = getOClass(oSchema, propertyTypeName.getGenericBaseType().toString()); if(propertyTypeName.getGenericBaseType()!=null) {
OType linkedOType = OrientDBTypeMapping.getOTypeByBaseType(propertyTypeName.getGenericBaseType());
if(linkedClass == null) { op.setLinkedType(OType.getById(Integer.valueOf(linkedOType.ordinal()).byteValue()));
logger.trace("class {} not found in schema", propertyDefinition.getLinkedClass()); }else if(propertyTypeName.getGenericClassName()!=null){
throw new Exception(
"class " + propertyDefinition.getLinkedClass() + " not found in schema"); 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; continue;
} }
OType oType = OType.getById(newPropertyDefinition.getType().byteValue()); PropertyTypeName newPropertyTypeName = ((PropertyDefinitionImpl) newPropertyDefinition).getPropertyTypeName();
OType oType = OrientDBTypeMapping.getOTypeByBaseType(newPropertyTypeName.getBaseType());
/* /*
* Excluding EMBEDDEDLIST and EMBEDDEDSET * Excluding EMBEDDEDLIST and EMBEDDEDSET
@ -582,10 +588,10 @@ public class SchemaManagement {
if(!typeList.contains(newTypeDefinition.getName())) { if(!typeList.contains(newTypeDefinition.getName())) {
switch(oType) { switch(oType) {
case EMBEDDEDLIST: 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"); + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
case EMBEDDEDSET: 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"); + " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
default: default:
break; break;
@ -615,22 +621,29 @@ public class SchemaManagement {
op.setReadonly(newPropertyDefinition.isReadonly()); op.setReadonly(newPropertyDefinition.isReadonly());
op.setRegexp(newPropertyDefinition.getRegexp()); op.setRegexp(newPropertyDefinition.getRegexp());
if(newPropertyDefinition.getLinkedClass() != null) { if(newPropertyTypeName.getGenericBaseType()!=null) {
OClass linkedClass = getOClass(oSchema, newPropertyDefinition.getLinkedClass()); if(newPropertyTypeName.getGenericBaseType().ordinal() >= BaseType.PROPERTY.ordinal()) {
if(linkedClass == null) { if(newPropertyTypeName.getGenericBaseType()!=null) {
logger.trace("class {} not found in schema", newPropertyDefinition.getLinkedClass()); OType linkedOType = OrientDBTypeMapping.getOTypeByBaseType(newPropertyTypeName.getGenericBaseType());
throw new Exception( op.setLinkedType(OType.getById(Integer.valueOf(linkedOType.ordinal()).byteValue()));
"class " + newPropertyDefinition.getLinkedClass() + " not found in schema"); }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()));
} }
} }
} }