Fixing resource-registry due to model redesign
This commit is contained in:
parent
10e5feb9d9
commit
495cba3145
|
@ -4,19 +4,26 @@ import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.common.encryption.SymmetricKey;
|
import org.gcube.common.encryption.SymmetricKey;
|
||||||
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.base.reference.ISConstants;
|
import org.gcube.informationsystem.base.reference.ISConstants;
|
||||||
|
import org.gcube.informationsystem.base.reference.ISManageable;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.security.ContextSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.context.security.ContextSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.security.SchemaSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.context.security.SchemaSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||||
|
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
||||||
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
|
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
|
||||||
|
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
|
||||||
import org.gcube.informationsystem.utils.discovery.SchemaAction;
|
import org.gcube.informationsystem.utils.discovery.SchemaAction;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -202,8 +209,27 @@ public class DatabaseEnvironment {
|
||||||
|
|
||||||
schemaSecurityContext.create();
|
schemaSecurityContext.create();
|
||||||
|
|
||||||
|
|
||||||
|
List<Package> packages = new ArrayList<Package>();
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
Class<TypeDefinition> tdClz = TypeDefinition.class;
|
||||||
|
packages.add(tdClz.getPackage());
|
||||||
|
|
||||||
|
AccessType[] accessTypes = AccessType.values();
|
||||||
|
for(AccessType accessType : accessTypes) {
|
||||||
|
Class<ISManageable> clz = accessType.getTypeClass();
|
||||||
|
packages.add(clz.getPackage());
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader
|
||||||
|
.load(RegistrationProvider.class);
|
||||||
|
for(RegistrationProvider registrationProvider : regsitrationProviders) {
|
||||||
|
packages.addAll(registrationProvider.getPackagesToRegister());
|
||||||
|
}
|
||||||
|
|
||||||
SchemaAction schemaAction = new SchemaActionImpl();
|
SchemaAction schemaAction = new SchemaActionImpl();
|
||||||
ISMDiscovery.manageISM(schemaAction);
|
ISMDiscovery.manageISM(schemaAction, packages);
|
||||||
|
|
||||||
}
|
}
|
||||||
logger.info("Database Connection has been properly initialized");
|
logger.info("Database Connection has been properly initialized");
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class SchemaActionImpl implements SchemaAction {
|
||||||
} else if(IsRelatedTo.class.isAssignableFrom(r)) {
|
} else if(IsRelatedTo.class.isAssignableFrom(r)) {
|
||||||
schemaManagement.create(json, AccessType.IS_RELATED_TO);
|
schemaManagement.create(json, AccessType.IS_RELATED_TO);
|
||||||
} else {
|
} else {
|
||||||
schemaManagement.create(json, AccessType.RELATION);
|
schemaManagement.create(json, AccessType.BASE_RELATION);
|
||||||
}
|
}
|
||||||
} catch(SchemaAlreadyPresentException sape) {
|
} catch(SchemaAlreadyPresentException sape) {
|
||||||
logger.warn("{} already exists. It will be ignored", TypeBinder.getType(r));
|
logger.warn("{} already exists. It will be ignored", TypeBinder.getType(r));
|
||||||
|
@ -66,7 +66,7 @@ public class SchemaActionImpl implements SchemaAction {
|
||||||
} else if(Resource.class.isAssignableFrom(e)) {
|
} else if(Resource.class.isAssignableFrom(e)) {
|
||||||
schemaManagement.create(json, AccessType.RESOURCE);
|
schemaManagement.create(json, AccessType.RESOURCE);
|
||||||
} else {
|
} else {
|
||||||
schemaManagement.create(json, AccessType.ENTITY);
|
schemaManagement.create(json, AccessType.BASE_ENTITY);
|
||||||
}
|
}
|
||||||
} catch(SchemaAlreadyPresentException sape) {
|
} catch(SchemaAlreadyPresentException sape) {
|
||||||
logger.warn("{} already exists. It will be ignored", TypeBinder.getType(e));
|
logger.warn("{} already exists. It will be ignored", TypeBinder.getType(e));
|
||||||
|
@ -82,7 +82,7 @@ public class SchemaActionImpl implements SchemaAction {
|
||||||
((SchemaManagementImpl) schemaManagement).setTypeName(TypeBinder.getType(e));
|
((SchemaManagementImpl) schemaManagement).setTypeName(TypeBinder.getType(e));
|
||||||
String json = TypeBinder.serializeType(e);
|
String json = TypeBinder.serializeType(e);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
schemaManagement.create(json, AccessType.PROPERTY);
|
schemaManagement.create(json, AccessType.BASE_PROPERTY);
|
||||||
} catch(SchemaAlreadyPresentException sape) {
|
} catch(SchemaAlreadyPresentException sape) {
|
||||||
logger.warn("{} already exists. It will be ignored", TypeBinder.getType(e));
|
logger.warn("{} already exists. It will be ignored", TypeBinder.getType(e));
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ public class SchemaManager {
|
||||||
AccessType accessType = null;
|
AccessType accessType = null;
|
||||||
String firstGotType = null;
|
String firstGotType = null;
|
||||||
try {
|
try {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Set<String> superClasses = TypeBinder.deserializeTypeDefinition(json).getSuperClasses();
|
Set<String> superClasses = TypeBinder.deserializeTypeDefinition(json).getSuperClasses();
|
||||||
if(superClasses.size()==0) {
|
if(superClasses.size()==0) {
|
||||||
throw new ResourceRegistryException("No superclasses defined");
|
throw new ResourceRegistryException("No superclasses defined");
|
||||||
|
|
|
@ -3,9 +3,9 @@ package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
|
||||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||||
|
@ -63,13 +63,13 @@ public class SchemaContextManagement implements SchemaManagement {
|
||||||
orientGraph = adminSecurityContext.getGraph(PermissionMode.WRITER);
|
orientGraph = adminSecurityContext.getGraph(PermissionMode.WRITER);
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
TypeDefinition<? extends TypeDefinition> typeDefinition = TypeBinder.deserializeTypeDefinition(json);
|
TypeDefinition typeDefinition = TypeBinder.deserializeTypeDefinition(json);
|
||||||
|
|
||||||
if(Entity.class.isAssignableFrom(baseType.getTypeClass())) {
|
if(BaseEntity.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
OrientVertex orientVertex = orientGraph.addVertex("class:" + typeDefinition.getName());
|
OrientVertex orientVertex = orientGraph.addVertex("class:" + typeDefinition.getName());
|
||||||
orientVertex.setProperty(SCHEMA, json);
|
orientVertex.setProperty(SCHEMA, json);
|
||||||
orientVertex.save();
|
orientVertex.save();
|
||||||
} else if(Relation.class.isAssignableFrom(baseType.getTypeClass())) {
|
} else if(BaseRelation.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
String sourceClass = ((RelationTypeDefinition) typeDefinition).getSourceType();
|
String sourceClass = ((RelationTypeDefinition) typeDefinition).getSourceType();
|
||||||
Vertex source = getVertex(orientGraph, sourceClass);
|
Vertex source = getVertex(orientGraph, sourceClass);
|
||||||
|
@ -82,7 +82,7 @@ public class SchemaContextManagement implements SchemaManagement {
|
||||||
orientEdge.setProperty(SCHEMA, json);
|
orientEdge.setProperty(SCHEMA, json);
|
||||||
orientEdge.save();
|
orientEdge.save();
|
||||||
|
|
||||||
} else if(Property.class.isAssignableFrom(baseType.getTypeClass())) {
|
} else if(BaseProperty.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
ODocument doc = new ODocument(typeDefinition.getName());
|
ODocument doc = new ODocument(typeDefinition.getName());
|
||||||
doc.field(SCHEMA, json);
|
doc.field(SCHEMA, json);
|
||||||
doc.save();
|
doc.save();
|
||||||
|
|
|
@ -5,6 +5,7 @@ package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
@ -16,6 +17,9 @@ import javax.activation.UnsupportedDataTypeException;
|
||||||
|
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.base.reference.ISManageable;
|
import org.gcube.informationsystem.base.reference.ISManageable;
|
||||||
|
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
||||||
|
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
|
||||||
|
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||||
|
@ -28,12 +32,20 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||||
|
import org.gcube.informationsystem.types.Type;
|
||||||
import org.gcube.informationsystem.types.TypeBinder;
|
import org.gcube.informationsystem.types.TypeBinder;
|
||||||
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
||||||
|
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||||
|
import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition;
|
||||||
|
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.orientechnologies.orient.core.db.ODatabaseSession;
|
import com.orientechnologies.orient.core.db.ODatabaseSession;
|
||||||
import com.orientechnologies.orient.core.exception.OSchemaException;
|
import com.orientechnologies.orient.core.exception.OSchemaException;
|
||||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||||
|
@ -127,28 +139,54 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static <ISM extends ISManageable> TypeDefinition<ISM> getTypeDefinition(OClass oClass) throws SchemaException {
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected static TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException {
|
||||||
|
// TODO OrientSerilizatoin is not acceptable anymore since TypeDefiniton introduction
|
||||||
|
|
||||||
ODocument oDocument = ((OClassImpl) oClass).toStream();
|
ODocument oDocument = ((OClassImpl) oClass).toStream();
|
||||||
String json = oDocument.toJSON();
|
String json = oDocument.toJSON();
|
||||||
try {
|
try {
|
||||||
return TypeBinder.deserializeTypeDefinition(json);
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
ObjectNode node = (ObjectNode) mapper.readTree(json);
|
||||||
|
|
||||||
|
if(oClass.isSubClassOf(BaseProperty.NAME)) {
|
||||||
|
node.put(ISManageable.CLASS_PROPERTY, PropertyTypeDefinition.NAME);
|
||||||
|
} else if(oClass.isSubClassOf(BaseEntity.NAME)) {
|
||||||
|
node.put(ISManageable.CLASS_PROPERTY, EntityTypeDefinition.NAME);
|
||||||
|
} else if(oClass.isSubClassOf(BaseRelation.NAME)) {
|
||||||
|
node.put(ISManageable.CLASS_PROPERTY, RelationTypeDefinition.NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ArrayNode arrayNode = (ArrayNode) node.get(TypeDefinition.PROPERTIES_PROPERTY);
|
||||||
|
Iterator<JsonNode> iterator = arrayNode.iterator();
|
||||||
|
while(iterator.hasNext()) {
|
||||||
|
ObjectNode propertyNode = (ObjectNode) iterator.next();
|
||||||
|
propertyNode.put(ISManageable.CLASS_PROPERTY, PropertyDefinition.NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
String managedJson = mapper.writeValueAsString(node);
|
||||||
|
logger.trace("{} -> {}", json, managedJson);
|
||||||
|
|
||||||
|
return TypeBinder.deserializeTypeDefinition(managedJson);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new SchemaException(e);
|
throw new SchemaException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static <ISM extends ISManageable> String getTypeDefinitionAsString(OClass oClass) throws SchemaException {
|
@SuppressWarnings({"rawtypes"})
|
||||||
|
protected static String getTypeDefinitionAsString(OClass oClass) throws SchemaException {
|
||||||
try {
|
try {
|
||||||
TypeDefinition<ISM> typeDefinition = getTypeDefinition(oClass);
|
TypeDefinition typeDefinition = getTypeDefinition(oClass);
|
||||||
return TypeBinder.serializeTypeDefinition(typeDefinition);
|
return TypeBinder.serializeTypeDefinition(typeDefinition);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new SchemaException(e);
|
throw new SchemaException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <ISM extends ISManageable> List<OClass> getSuperclassesAndCheckCompliancy(ODatabaseSession oDatabaseSession,
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
TypeDefinition<ISM> typeDefinition, String baseType) throws SchemaException {
|
protected List<OClass> getSuperclassesAndCheckCompliancy(ODatabaseSession oDatabaseSession,
|
||||||
|
TypeDefinition typeDefinition, String baseType) throws SchemaException {
|
||||||
|
|
||||||
Set<String> superClasses = typeDefinition.getSuperClasses();
|
Set<String> superClasses = typeDefinition.getSuperClasses();
|
||||||
if(baseType != null) {
|
if(baseType != null) {
|
||||||
|
@ -182,15 +220,35 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
return oSuperclasses;
|
return oSuperclasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<String> baseTypes;
|
||||||
|
private static List<String> typeDefinitionTypes;
|
||||||
|
|
||||||
|
static {
|
||||||
|
baseTypes = new ArrayList<String>();
|
||||||
|
baseTypes.add(BaseProperty.NAME);
|
||||||
|
baseTypes.add(BaseEntity.NAME);
|
||||||
|
baseTypes.add(BaseRelation.NAME);
|
||||||
|
|
||||||
|
typeDefinitionTypes = new ArrayList<String>();
|
||||||
|
typeDefinitionTypes.add(PropertyTypeDefinition.NAME);
|
||||||
|
typeDefinitionTypes.add(EntityTypeDefinition.NAME);
|
||||||
|
typeDefinitionTypes.add(RelationTypeDefinition.NAME);
|
||||||
|
}
|
||||||
|
|
||||||
protected String registerTypeSchema(String jsonSchema, AccessType baseType) throws SchemaException {
|
protected String registerTypeSchema(String jsonSchema, AccessType baseType) throws SchemaException {
|
||||||
|
|
||||||
ODatabaseSession oDatabaseSession = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
logger.info("Trying to register {} {}", baseType.getName(), jsonSchema);
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
TypeDefinition<? extends TypeDefinition> typeDefinition = TypeBinder.deserializeTypeDefinition(jsonSchema);
|
TypeDefinition typeDefinition = null;
|
||||||
|
try {
|
||||||
|
typeDefinition = TypeBinder.deserializeTypeDefinition(jsonSchema);
|
||||||
|
logger.info("Trying to register {} {} : {}", baseType.getName(), typeDefinition.getName(), jsonSchema);
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.error("Error while trying to register {} {}", baseType.getName(), jsonSchema);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(typeName.compareTo(typeDefinition.getName())!=0) {
|
if(typeName.compareTo(typeDefinition.getName())!=0) {
|
||||||
String error = String.format("Provided type name path argument %s does not match with the type name in the definition %S. Please be coherent.", typeName, typeDefinition.getName());
|
String error = String.format("Provided type name path argument %s does not match with the type name in the definition %S. Please be coherent.", typeName, typeDefinition.getName());
|
||||||
|
@ -206,9 +264,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
OClass oClass = null;
|
OClass oClass = null;
|
||||||
|
|
||||||
if(Entity.class.isAssignableFrom(baseType.getTypeClass())) {
|
if(BaseEntity.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
oClass = oDatabaseSession.createVertexClass(typeDefinition.getName());
|
oClass = oDatabaseSession.createVertexClass(typeDefinition.getName());
|
||||||
} else if(Relation.class.isAssignableFrom(baseType.getTypeClass())) {
|
} else if(BaseRelation.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
oClass = oDatabaseSession.createEdgeClass(typeDefinition.getName());
|
oClass = oDatabaseSession.createEdgeClass(typeDefinition.getName());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -217,7 +275,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
* typeDefinition.getInBaseType();
|
* typeDefinition.getInBaseType();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
} else if(Property.class.isAssignableFrom(baseType.getTypeClass())) {
|
} else if(BaseProperty.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
oClass = oSchema.createClass(typeDefinition.getName());
|
oClass = oSchema.createClass(typeDefinition.getName());
|
||||||
} else {
|
} else {
|
||||||
String error = String.format("Allowed superclass are %s, %s, %s, or any subclasses of them.",
|
String error = String.format("Allowed superclass are %s, %s, %s, or any subclasses of them.",
|
||||||
|
@ -247,31 +305,41 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
typeDefinition.getName());
|
typeDefinition.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeDefinition.getName().compareTo(Property.NAME) != 0) {
|
if(! baseTypes.contains(typeDefinition.getName())) {
|
||||||
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(oDatabaseSession, typeDefinition,
|
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(oDatabaseSession, typeDefinition,
|
||||||
baseType.getName());
|
baseType.getName());
|
||||||
oClass.setSuperClasses(oSuperclasses);
|
oClass.setSuperClasses(oSuperclasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Resource.class.isAssignableFrom(baseType.getTypeClass())) {
|
@SuppressWarnings("unchecked")
|
||||||
Set<PropertyDefinition> propertyDefinitions = typeDefinition.getProperties();
|
Set<PropertyDefinition> propertyDefinitions = typeDefinition.getProperties();
|
||||||
|
if(Resource.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
if(propertyDefinitions != null && propertyDefinitions.size() > 0) {
|
if(propertyDefinitions != null && propertyDefinitions.size() > 0) {
|
||||||
throw new SchemaCreationException("A Resource cannot contains any properties.");
|
throw new SchemaCreationException("A Resource cannot contains any properties.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(PropertyDefinition propertyDefinition : typeDefinition.getProperties()) {
|
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
|
||||||
|
|
||||||
OType oType = OType.getById(propertyDefinition.getType().byteValue());
|
OType oType = OType.getById(propertyDefinition.getType().byteValue());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types update is not allowed,
|
||||||
|
* hence bug https://github.com/orientechnologies/orientdb/issues/7354 cannot occur
|
||||||
|
* Excluding the check from types used for type definition
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if(!typeDefinitionTypes.contains(typeDefinition.getName())) {
|
||||||
switch(oType) {
|
switch(oType) {
|
||||||
case EMBEDDEDLIST:
|
case EMBEDDEDLIST:
|
||||||
throw new UnsupportedDataTypeException(oType.name()
|
throw new UnsupportedDataTypeException(Type.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 EMBEDDEDSET:
|
||||||
throw new UnsupportedDataTypeException(oType.name()
|
throw new UnsupportedDataTypeException(Type.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:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OProperty op = oClass.createProperty(propertyDefinition.getName(), oType);
|
OProperty op = oClass.createProperty(propertyDefinition.getName(), oType);
|
||||||
op.setDescription(propertyDefinition.getDescription());
|
op.setDescription(propertyDefinition.getDescription());
|
||||||
|
@ -342,6 +410,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected <ISM extends ISManageable> String getSchema(String type, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
protected <ISM extends ISManageable> String getSchema(String type, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
||||||
ODatabaseSession oDatabaseSession = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -49,15 +49,21 @@ public class ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
|
// PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
|
||||||
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "preprod";
|
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
|
||||||
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
||||||
|
|
||||||
|
|
||||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||||
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "devNext";
|
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
||||||
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
|
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
|
||||||
|
|
||||||
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
|
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setContextByName(DEFAULT_TEST_SCOPE);
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class DiscoveryTest {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append("[");
|
stringBuilder.append("[");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Class<Resource> resource : resourceDiscovery.getDiscovered()) {
|
for (Class<? extends Resource> resource : resourceDiscovery.getDiscovered()) {
|
||||||
if(first) {
|
if(first) {
|
||||||
first = false;
|
first = false;
|
||||||
}else {
|
}else {
|
||||||
|
|
|
@ -60,7 +60,8 @@ public class SchemaManagementImplTest {
|
||||||
public void getFacetSchema() throws Exception {
|
public void getFacetSchema() throws Exception {
|
||||||
String json = new SchemaManagementImpl().read(ContactFacet.NAME, false);
|
String json = new SchemaManagementImpl().read(ContactFacet.NAME, false);
|
||||||
logger.info(json);
|
logger.info(json);
|
||||||
List<TypeDefinition<ContactFacet>> typeDefinitions = TypeBinder.deserializeTypeDefinitions(json);
|
@SuppressWarnings("rawtypes")
|
||||||
|
List<TypeDefinition> typeDefinitions = TypeBinder.deserializeTypeDefinitions(json);
|
||||||
logger.info("{}", typeDefinitions);
|
logger.info("{}", typeDefinitions);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue