Fixing type management
This commit is contained in:
parent
0efb8f5e08
commit
bf24fe07c4
|
@ -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<BaseType,OType> BASE_TYPE_TO_OTYPE;
|
||||||
|
|
||||||
|
protected static final Map<OType,BaseType> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.properties.PropertyTypeDefinitionManagement;
|
||||||
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.OrientDBType;
|
import org.gcube.informationsystem.types.PropertyTypeName;
|
||||||
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.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||||
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
||||||
|
@ -381,7 +382,7 @@ public class SchemaManagement {
|
||||||
if(propertyDefinitions!=null) {
|
if(propertyDefinitions!=null) {
|
||||||
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
|
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
|
||||||
|
|
||||||
OType oType = OType.getById(propertyDefinition.getType().byteValue());
|
PropertyTypeName propertyTypeName = ((PropertyDefinitionImpl) propertyDefinition).getPropertyTypeName();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Types update is not allowed,
|
* Types update is not allowed,
|
||||||
|
@ -390,11 +391,11 @@ public class SchemaManagement {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if(!typeList.contains(type.getName())) {
|
if(!typeList.contains(type.getName())) {
|
||||||
switch(oType) {
|
switch(propertyTypeName.getBaseType()) {
|
||||||
case EMBEDDEDLIST:
|
case LIST:
|
||||||
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST
|
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST
|
||||||
+ " 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 SET:
|
||||||
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET
|
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET
|
||||||
+ " 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:
|
||||||
|
@ -402,6 +403,8 @@ public class SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OType oType = OrientDBTypeMapping.getOTypeByBaseType(propertyTypeName.getBaseType());
|
||||||
|
|
||||||
OProperty op = oClass.createProperty(propertyDefinition.getName(), oType);
|
OProperty op = oClass.createProperty(propertyDefinition.getName(), oType);
|
||||||
op.setDescription(propertyDefinition.getDescription());
|
op.setDescription(propertyDefinition.getDescription());
|
||||||
|
|
||||||
|
@ -418,8 +421,10 @@ public class SchemaManagement {
|
||||||
op.setReadonly(propertyDefinition.isReadonly());
|
op.setReadonly(propertyDefinition.isReadonly());
|
||||||
op.setRegexp(propertyDefinition.getRegexp());
|
op.setRegexp(propertyDefinition.getRegexp());
|
||||||
|
|
||||||
if(propertyDefinition.getLinkedClass() != null) {
|
if(propertyTypeName.getGenericBaseType() != null) {
|
||||||
OClass linkedClass = getOClass(oSchema, propertyDefinition.getLinkedClass());
|
OType linkedType =
|
||||||
|
OClass linkedClass = getOClass(oSchema, propertyTypeName.getGenericBaseType().toString());
|
||||||
|
|
||||||
if(linkedClass == null) {
|
if(linkedClass == null) {
|
||||||
logger.trace("class {} not found in schema", propertyDefinition.getLinkedClass());
|
logger.trace("class {} not found in schema", propertyDefinition.getLinkedClass());
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
|
Loading…
Reference in New Issue