Fixed types creations
This commit is contained in:
parent
a825fe51af
commit
ecc047889e
|
@ -36,6 +36,8 @@ import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefiniti
|
|||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.properties.ResourceEntryDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.ConsistsOfTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.IsRelatedToTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
|
||||
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
|
||||
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
|
||||
|
@ -239,6 +241,8 @@ public class DatabaseEnvironment {
|
|||
definitionToBeCreated.add(ResourceTypeDefinition.class);
|
||||
definitionToBeCreated.add(BaseRelation.class);
|
||||
definitionToBeCreated.add(RelationTypeDefinition.class);
|
||||
definitionToBeCreated.add(IsRelatedToTypeDefinition.class);
|
||||
definitionToBeCreated.add(ConsistsOfTypeDefinition.class);
|
||||
|
||||
SchemaAction schemaAction = new SchemaActionImpl();
|
||||
|
||||
|
@ -253,27 +257,6 @@ public class DatabaseEnvironment {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for(Class<? extends ISManageable> clz : definitionToBeCreated) {
|
||||
ERManagement<? extends OElement> erManagement = null;
|
||||
|
||||
if(BaseProperty.class.isAssignableFrom(clz)) {
|
||||
erManagement = new PropertyTypeDefinitionManagement();
|
||||
} else if(BaseEntity.class.isAssignableFrom(clz)) {
|
||||
erManagement = new EntityTypeDefinitionManagement();
|
||||
if(ResourceTypeDefinition.class.isAssignableFrom(clz)) {
|
||||
erManagement.setElementType(ResourceTypeDefinition.NAME);
|
||||
}
|
||||
} else if(BaseRelation.class.isAssignableFrom(clz)) {
|
||||
erManagement = new RelationTypeDefinitionManagement();
|
||||
}
|
||||
|
||||
erManagement.setJson(TypeBinder.serializeType(clz));
|
||||
erManagement.create();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
List<Class<? extends ISManageable>> schemaToBeCreated = new ArrayList<>();
|
||||
schemaToBeCreated.add(Property.class);
|
||||
schemaToBeCreated.add(Header.class);
|
||||
|
@ -301,7 +284,6 @@ public class DatabaseEnvironment {
|
|||
packages.addAll(registrationProvider.getPackagesToRegister());
|
||||
}
|
||||
|
||||
|
||||
ISMDiscovery.manageISM(schemaAction, packages);
|
||||
|
||||
}
|
||||
|
|
|
@ -6,14 +6,12 @@ package org.gcube.informationsystem.resourceregistry.instances.type;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.activation.UnsupportedDataTypeException;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
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;
|
||||
|
@ -21,6 +19,8 @@ import org.gcube.informationsystem.model.reference.entities.Entity;
|
|||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaCreationException;
|
||||
|
@ -28,14 +28,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.EntityTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.FacetTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.ResourceTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.properties.PropertyTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.relations.RelationTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.relations.ConsistsOfTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.relations.IsRelatedToTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.types.Type;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.gcube.informationsystem.types.reference.PropertyCapableTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetTypeDefinition;
|
||||
|
@ -43,24 +44,20 @@ import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefiniti
|
|||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.properties.ResourceEntryDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.ConsistsOfTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.IsRelatedToTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
|
||||
import org.slf4j.Logger;
|
||||
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.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.exception.OSchemaException;
|
||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClassImpl;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OProperty;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -79,7 +76,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
/*
|
||||
private static TypeDefinition getOClassTypeDefinition(OClass oClass) throws SchemaException {
|
||||
try {
|
||||
ODocument oDocument = ((OClassImpl) oClass).toStream();
|
||||
|
@ -87,11 +84,13 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode node = (ObjectNode) mapper.readTree(json);
|
||||
|
||||
if(oClass.isSubClassOf(BaseProperty.NAME)) {
|
||||
if(oClass.isSubClassOf(Property.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)) {
|
||||
} else if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
node.put(ISManageable.CLASS_PROPERTY, ResourceTypeDefinition.NAME);
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
node.put(ISManageable.CLASS_PROPERTY, FacetTypeDefinition.NAME);
|
||||
} else if(oClass.isSubClassOf(Relation.NAME)) {
|
||||
node.put(ISManageable.CLASS_PROPERTY, RelationTypeDefinition.NAME);
|
||||
}
|
||||
|
||||
|
@ -112,22 +111,27 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
throw new SchemaException(e);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException {
|
||||
try {
|
||||
ERManagement<? extends OElement> erManagement = null;
|
||||
|
||||
if(oClass.isSubClassOf(BaseProperty.NAME)) {
|
||||
if(oClass.isSubClassOf(Property.NAME)) {
|
||||
erManagement = new PropertyTypeDefinitionManagement();
|
||||
((PropertyTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(BaseEntity.NAME)) {
|
||||
erManagement = new EntityTypeDefinitionManagement();
|
||||
((EntityTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(BaseRelation.NAME)) {
|
||||
erManagement = new RelationTypeDefinitionManagement();
|
||||
((RelationTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
}
|
||||
} else if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
erManagement = new ResourceTypeDefinitionManagement();
|
||||
((ResourceTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
erManagement = new FacetTypeDefinitionManagement();
|
||||
((FacetTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
erManagement = new IsRelatedToTypeDefinitionManagement();
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
erManagement = new ConsistsOfTypeDefinitionManagement();
|
||||
|
||||
}
|
||||
String ret = erManagement.read();
|
||||
return TypeBinder.deserializeTypeDefinition(ret);
|
||||
} catch(Exception e) {
|
||||
|
@ -181,7 +185,6 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
|
||||
private static Set<String> baseTypes;
|
||||
public static Set<String> typeDefinitionTypes;
|
||||
// public static Set<String> skipTypeDefinitionCreation;
|
||||
|
||||
static {
|
||||
baseTypes = new HashSet<String>();
|
||||
|
@ -194,15 +197,10 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
typeDefinitionTypes.add(ResourceEntryDefinition.NAME);
|
||||
typeDefinitionTypes.add(EntityTypeDefinition.NAME);
|
||||
typeDefinitionTypes.add(ResourceTypeDefinition.NAME);
|
||||
typeDefinitionTypes.add(FacetTypeDefinition.NAME);
|
||||
typeDefinitionTypes.add(RelationTypeDefinition.NAME);
|
||||
|
||||
/*
|
||||
skipTypeDefinitionCreation = new HashSet<String>();
|
||||
skipTypeDefinitionCreation.addAll(baseTypes);
|
||||
skipTypeDefinitionCreation.add(PropertyDefinition.NAME);
|
||||
skipTypeDefinitionCreation.add(Property.NAME);
|
||||
skipTypeDefinitionCreation.add(Header.NAME);
|
||||
*/
|
||||
typeDefinitionTypes.add(IsRelatedToTypeDefinition.NAME);
|
||||
typeDefinitionTypes.add(ConsistsOfTypeDefinition.NAME);
|
||||
}
|
||||
|
||||
protected void registerTypeSchema(TypeDefinition typeDefinition, AccessType baseType)
|
||||
|
@ -266,11 +264,10 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
oClass.setSuperClasses(oSuperclasses);
|
||||
}
|
||||
|
||||
if(typeDefinition instanceof PropertyCapableTypeDefinition) {
|
||||
if(!(typeDefinition instanceof ResourceTypeDefinition)) {
|
||||
// A Resource cannot contains any properties.
|
||||
//
|
||||
|
||||
Set<PropertyDefinition> propertyDefinitions = ((PropertyCapableTypeDefinition) typeDefinition).getProperties();
|
||||
Set<PropertyDefinition> propertyDefinitions = typeDefinition.getProperties();
|
||||
|
||||
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
|
||||
|
||||
|
@ -400,15 +397,14 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
|
||||
ERManagement<? extends OElement> erManagement = null;
|
||||
|
||||
if(Entity.class.isAssignableFrom(accessType.getTypeClass())) {
|
||||
erManagement = new EntityTypeDefinitionManagement();
|
||||
if(Resource.class.isAssignableFrom(accessType.getTypeClass())) {
|
||||
((EntityTypeDefinitionManagement) erManagement).setElementTypeRaw(ResourceTypeDefinition.NAME);
|
||||
erManagement = new ResourceTypeDefinitionManagement();
|
||||
}else if(Facet.class.isAssignableFrom(accessType.getTypeClass())) {
|
||||
((EntityTypeDefinitionManagement) erManagement).setElementTypeRaw(FacetTypeDefinition.NAME);
|
||||
}
|
||||
} else if(Relation.class.isAssignableFrom(accessType.getTypeClass())) {
|
||||
erManagement = new RelationTypeDefinitionManagement();
|
||||
erManagement = new FacetTypeDefinitionManagement();
|
||||
} else if(IsRelatedTo.class.isAssignableFrom(accessType.getTypeClass())) {
|
||||
erManagement = new IsRelatedToTypeDefinitionManagement();
|
||||
} else if(ConsistsOf.class.isAssignableFrom(accessType.getTypeClass())) {
|
||||
erManagement = new ConsistsOfTypeDefinitionManagement();
|
||||
} else if(Property.class.isAssignableFrom(accessType.getTypeClass())) {
|
||||
erManagement = new PropertyTypeDefinitionManagement();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.entities.Base
|
|||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -27,28 +28,23 @@ import com.orientechnologies.orient.core.record.OVertex;
|
|||
import com.orientechnologies.orient.core.sql.executor.OResult;
|
||||
import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
||||
|
||||
public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityTypeDefinition> {
|
||||
public abstract class EntityTypeDefinitionManagement<E extends EntityTypeDefinition> extends BaseEntityManagement<E> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(EntityTypeDefinitionManagement.class);
|
||||
|
||||
protected String name;
|
||||
|
||||
public EntityTypeDefinitionManagement() {
|
||||
protected EntityTypeDefinitionManagement(Class<E> clz) {
|
||||
super(AccessType.ENTITY_TYPE_DEFINITION);
|
||||
this.elementType = EntityTypeDefinition.NAME;
|
||||
|
||||
this.elementType = TypeBinder.getType(clz);
|
||||
}
|
||||
|
||||
public EntityTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
protected EntityTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument, Class<E> clz) throws ResourceRegistryException {
|
||||
this(clz);
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
setWorkingContext(securityContext);
|
||||
}
|
||||
|
||||
public void setElementTypeRaw(String elementType) throws ResourceRegistryException {
|
||||
this.elementType = elementType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if(workingContext == null) {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.type.entities;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetTypeDefinition;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
public class FacetTypeDefinitionManagement extends EntityTypeDefinitionManagement<FacetTypeDefinition> {
|
||||
|
||||
public FacetTypeDefinitionManagement() {
|
||||
super(FacetTypeDefinition.class);
|
||||
}
|
||||
|
||||
public FacetTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
super(securityContext, oDatabaseDocument, FacetTypeDefinition.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.type.entities;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
public class ResourceTypeDefinitionManagement extends EntityTypeDefinitionManagement<ResourceTypeDefinition> {
|
||||
|
||||
public ResourceTypeDefinitionManagement() {
|
||||
super(ResourceTypeDefinition.class);
|
||||
}
|
||||
|
||||
public ResourceTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
super(securityContext, oDatabaseDocument, ResourceTypeDefinition.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.type.relations;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.FacetTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.ConsistsOfTypeDefinition;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
public class ConsistsOfTypeDefinitionManagement
|
||||
extends RelationTypeDefinitionManagement<FacetTypeDefinitionManagement,FacetTypeDefinition> {
|
||||
|
||||
public ConsistsOfTypeDefinitionManagement() {
|
||||
super(FacetTypeDefinition.class);
|
||||
this.elementType = ConsistsOfTypeDefinition.NAME;
|
||||
}
|
||||
|
||||
public ConsistsOfTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument)
|
||||
throws ResourceRegistryException {
|
||||
super(securityContext, oDatabaseDocument, FacetTypeDefinition.class);
|
||||
this.elementType = ConsistsOfTypeDefinition.NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FacetTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new FacetTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.type.relations;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.ResourceTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.IsRelatedToTypeDefinition;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
public class IsRelatedToTypeDefinitionManagement
|
||||
extends RelationTypeDefinitionManagement<ResourceTypeDefinitionManagement,ResourceTypeDefinition> {
|
||||
|
||||
public IsRelatedToTypeDefinitionManagement() {
|
||||
super(ResourceTypeDefinition.class);
|
||||
this.elementType = IsRelatedToTypeDefinition.NAME;
|
||||
}
|
||||
|
||||
public IsRelatedToTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument)
|
||||
throws ResourceRegistryException {
|
||||
super(securityContext, oDatabaseDocument, ResourceTypeDefinition.class);
|
||||
this.elementType = IsRelatedToTypeDefinition.NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,9 +17,11 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
|||
import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.EntityTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.ResourceTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
@ -28,18 +30,18 @@ import com.orientechnologies.orient.core.record.OVertex;
|
|||
import com.orientechnologies.orient.core.sql.executor.OResult;
|
||||
import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
||||
|
||||
public class RelationTypeDefinitionManagement
|
||||
extends BaseRelationManagement<EntityTypeDefinitionManagement,EntityTypeDefinitionManagement> {
|
||||
public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefinitionManagement<TT>, TT extends EntityTypeDefinition>
|
||||
extends BaseRelationManagement<ResourceTypeDefinitionManagement, T> {
|
||||
|
||||
protected String name;
|
||||
|
||||
public RelationTypeDefinitionManagement() {
|
||||
super(AccessType.RELATION_TYPE_DEFINITION, EntityTypeDefinition.class, EntityTypeDefinition.class);
|
||||
public RelationTypeDefinitionManagement(Class<TT> clz) {
|
||||
super(AccessType.RELATION_TYPE_DEFINITION, ResourceTypeDefinition.class, clz);
|
||||
this.elementType = RelationTypeDefinition.NAME;
|
||||
}
|
||||
|
||||
public RelationTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
public RelationTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument, Class<TT> clz) throws ResourceRegistryException {
|
||||
this(clz);
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
setWorkingContext(securityContext);
|
||||
}
|
||||
|
@ -74,28 +76,24 @@ public class RelationTypeDefinitionManagement
|
|||
protected OEdge reallyCreate() throws ResourceRegistryException {
|
||||
logger.debug("Going to create {} for {}", RelationTypeDefinition.NAME, getName());
|
||||
if(sourceEntityManagement == null) {
|
||||
|
||||
if(!jsonNode.has(Relation.SOURCE_PROPERTY)) {
|
||||
throw new ResourceRegistryException("Error while creating relation. No source definition found");
|
||||
}
|
||||
|
||||
sourceEntityManagement = newSourceEntityManagement();
|
||||
sourceEntityManagement.setElementType(EntityTypeDefinition.NAME);
|
||||
// sourceEntityManagement.setElementType(EntityTypeDefinition.NAME);
|
||||
sourceEntityManagement.setJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
||||
}
|
||||
|
||||
if(targetEntityManagement == null) {
|
||||
targetEntityManagement = newTargetEntityManagement();
|
||||
|
||||
if(!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error while creating " + elementType + ". No target definition found");
|
||||
}
|
||||
|
||||
targetEntityManagement = newTargetEntityManagement();
|
||||
targetEntityManagement.setElementType(EntityTypeDefinition.NAME);
|
||||
// targetEntityManagement.setElementType(EntityTypeDefinition.NAME);
|
||||
targetEntityManagement.setJsonNode(jsonNode.get(Relation.TARGET_PROPERTY));
|
||||
|
||||
}
|
||||
|
||||
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serialize(),
|
||||
|
@ -220,13 +218,8 @@ public class RelationTypeDefinitionManagement
|
|||
}
|
||||
|
||||
@Override
|
||||
protected EntityTypeDefinitionManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new EntityTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new EntityTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument);
|
||||
protected ResourceTypeDefinitionManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -211,13 +211,17 @@ public class SchemaManagementImplTest {
|
|||
|
||||
}
|
||||
|
||||
@Test(expected=SchemaAlreadyPresentException.class)
|
||||
@Test
|
||||
public void createRelationTypeDefinitionType() throws Exception {
|
||||
RelationTypeDefinition relationTypeDefinition = new RelationTypeDefinitionImpl((Class<? extends BaseRelation<?,?>>) RelationTypeDefinition.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
RelationTypeDefinition<EntityTypeDefinition, EntityTypeDefinition> relationTypeDefinition = new RelationTypeDefinitionImpl<EntityTypeDefinition, EntityTypeDefinition>((Class<? extends BaseRelation<?,?>>) RelationTypeDefinition.class);
|
||||
|
||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||
((SchemaManagementImpl) schemaManagement).setTypeName(RelationTypeDefinition.NAME);
|
||||
String ret = schemaManagement.create(ISMapper.marshal(relationTypeDefinition), AccessType.BASE_RELATION);
|
||||
|
||||
String ret = ISMapper.marshal(relationTypeDefinition);
|
||||
|
||||
//String ret = schemaManagement.create(ISMapper.marshal(relationTypeDefinition), AccessType.BASE_RELATION);
|
||||
|
||||
logger.debug(ret);
|
||||
|
||||
|
|
Loading…
Reference in New Issue