diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java index ad2699c..eb731ff 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java @@ -6,22 +6,37 @@ import java.net.URL; import java.security.Key; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.ServiceLoader; +import java.util.Set; import java.util.UUID; 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.ISManageable; +import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.base.reference.properties.BaseProperty; +import org.gcube.informationsystem.base.reference.properties.Header; +import org.gcube.informationsystem.base.reference.relations.BaseRelation; +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.properties.PropertyTypeDefinitionManagement; +import org.gcube.informationsystem.resourceregistry.instances.type.relations.RelationTypeDefinitionManagement; import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext; import org.gcube.informationsystem.resourceregistry.security.ContextSecurityContext; import org.gcube.informationsystem.resourceregistry.security.SchemaSecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.types.TypeBinder; 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.PropertyTypeDefinition; +import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import org.gcube.informationsystem.utils.discovery.ISMDiscovery; import org.gcube.informationsystem.utils.discovery.RegistrationProvider; import org.gcube.informationsystem.utils.discovery.SchemaAction; @@ -43,10 +58,12 @@ import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.metadata.security.ORole; import com.orientechnologies.orient.core.metadata.security.OSecurity; import com.orientechnologies.orient.core.metadata.security.OUser; +import com.orientechnologies.orient.core.record.OElement; /** * @author Luca Frosini (ISTI - CNR) */ +@SuppressWarnings("unchecked") public class DatabaseEnvironment { private static Logger logger = LoggerFactory.getLogger(DatabaseEnvironment.class); @@ -208,6 +225,39 @@ public class DatabaseEnvironment { schemaSecurityContext.create(); + SchemaAction schemaAction = new SchemaActionImpl(); + schemaAction.managePropertyClass(BaseProperty.class); + schemaAction.managePropertyClass(Header.class); + schemaAction.managePropertyClass(PropertyDefinition.class); + schemaAction.managePropertyClass(PropertyTypeDefinition.class); + schemaAction.manageEntityClass(BaseEntity.class); + schemaAction.manageEntityClass(EntityTypeDefinition.class); + schemaAction.manageRelationClass(BaseRelation.class); + schemaAction.manageRelationClass(RelationTypeDefinition.class); + + + Set> definitionToBeCreated = new HashSet<>(); + definitionToBeCreated.add(BaseProperty.class); + definitionToBeCreated.add(Header.class); + definitionToBeCreated.add(BaseEntity.class); + definitionToBeCreated.add(BaseRelation.class); + + for(Class clz : definitionToBeCreated) { + ERManagement erManagement = null; + + if(BaseEntity.class.isAssignableFrom(clz)) { + erManagement = new EntityTypeDefinitionManagement(); + } else if(BaseRelation.class.isAssignableFrom(clz)) { + erManagement = new RelationTypeDefinitionManagement(); + } else if(BaseProperty.class.isAssignableFrom(clz)) { + erManagement = new PropertyTypeDefinitionManagement(); + } + + erManagement.setJson(TypeBinder.serializeType(clz)); + erManagement.create(); + } + + List packages = new ArrayList(); Class tdClz = TypeDefinition.class; @@ -225,7 +275,7 @@ public class DatabaseEnvironment { packages.addAll(registrationProvider.getPackagesToRegister()); } - SchemaAction schemaAction = new SchemaActionImpl(); + ISMDiscovery.manageISM(schemaAction, packages); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/SchemaActionImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/SchemaActionImpl.java index 0275012..bc05bb5 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/SchemaActionImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/SchemaActionImpl.java @@ -4,15 +4,11 @@ import org.gcube.informationsystem.base.reference.AccessType; 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.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.instances.type.SchemaManagement; import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl; import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.utils.discovery.SchemaAction; @@ -26,17 +22,12 @@ public class SchemaActionImpl implements SchemaAction { private static Logger logger = LoggerFactory.getLogger(SchemaActionImpl.class); - protected SchemaManagement schemaManagement; - - public SchemaActionImpl() { - this.schemaManagement = new SchemaManagementImpl(); - } - @Override public > void manageRelationClass(Class r) throws Exception { try { - ((SchemaManagementImpl) schemaManagement).setTypeName(TypeBinder.getType(r)); + SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); + schemaManagement.setTypeName(TypeBinder.getType(r)); String json = TypeBinder.serializeType(r); logger.trace(json); if(ConsistsOf.class.isAssignableFrom(r)) { @@ -49,8 +40,7 @@ public class SchemaActionImpl implements SchemaAction { } catch(SchemaAlreadyPresentException sape) { logger.warn("{} already exists. It will be ignored", TypeBinder.getType(r)); } catch(Exception ex) { - logger.error("Error creating schema for {} type {} : {}", Relation.NAME, r.getSimpleName(), - ex.getMessage()); + logger.error("Error creating schema for {} {}: {}", BaseRelation.NAME, r.getSimpleName(), ex.getMessage()); throw ex; } } @@ -58,7 +48,8 @@ public class SchemaActionImpl implements SchemaAction { @Override public void manageEntityClass(Class e) throws Exception { try { - ((SchemaManagementImpl) schemaManagement).setTypeName(TypeBinder.getType(e)); + SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); + schemaManagement.setTypeName(TypeBinder.getType(e)); String json = TypeBinder.serializeType(e); logger.trace(json); if(Facet.class.isAssignableFrom(e)) { @@ -71,23 +62,23 @@ public class SchemaActionImpl implements SchemaAction { } catch(SchemaAlreadyPresentException sape) { logger.warn("{} already exists. It will be ignored", TypeBinder.getType(e)); } catch(Exception ex) { - logger.error("Error creating schema for {} type {} : {}", Entity.NAME, e.getSimpleName(), ex.getMessage()); + logger.error("Error creating schema for {} {}: {}", BaseEntity.NAME, e.getSimpleName(), ex.getMessage()); throw ex; } } @Override - public

void managePropertyClass(Class

e) throws Exception { + public

void managePropertyClass(Class

p) throws Exception { try { - ((SchemaManagementImpl) schemaManagement).setTypeName(TypeBinder.getType(e)); - String json = TypeBinder.serializeType(e); + SchemaManagementImpl schemaManagement = new SchemaManagementImpl(); + schemaManagement.setTypeName(TypeBinder.getType(p)); + String json = TypeBinder.serializeType(p); logger.trace(json); schemaManagement.create(json, AccessType.BASE_PROPERTY); } catch(SchemaAlreadyPresentException sape) { - logger.warn("{} already exists. It will be ignored", TypeBinder.getType(e)); + logger.warn("{} already exists. It will be ignored", TypeBinder.getType(p)); } catch(Exception ex) { - logger.error("Error creating schema for {} type {} : {}", Property.NAME, e.getSimpleName(), - ex.getMessage()); + logger.error("Error creating schema for {} {}: {}", BaseProperty.NAME, p.getSimpleName(), ex.getMessage()); throw ex; } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagement.java index 416ac36..f050b92 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagement.java @@ -31,7 +31,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment; import org.gcube.informationsystem.resourceregistry.instances.base.properties.BasePropertyManagement; import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; -import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl; import org.gcube.informationsystem.resourceregistry.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.utils.HeaderOrient; @@ -177,7 +176,7 @@ public abstract class ERManagement { if(element != null) { oClass = getOClass(element); } else { - oClass = SchemaManagementImpl.getTypeSchema(elementType, accessType); + oClass = ERManagementUtility.getTypeSchema(elementType, accessType); } } return oClass; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagementUtility.java index 9abd14a..6d9556d 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ERManagementUtility.java @@ -12,20 +12,26 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; +import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.RelationManagement; -import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl; +import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.utils.Utility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.orientechnologies.orient.core.db.document.ODatabaseDocument; +import com.orientechnologies.orient.core.metadata.OMetadata; import com.orientechnologies.orient.core.metadata.schema.OClass; +import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.record.OEdge; import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.record.OVertex; @@ -39,7 +45,7 @@ public class ERManagementUtility { public static AccessType getBaseAccessType(String type) throws ResourceRegistryException { - OClass oClass = SchemaManagementImpl.getTypeSchema(type, null); + OClass oClass = ERManagementUtility.getTypeSchema(type, null); if(oClass.isSubClassOf(Resource.NAME)) { return AccessType.RESOURCE; @@ -61,7 +67,7 @@ public class ERManagementUtility { @SuppressWarnings("rawtypes") public static ERManagement getERManagement(String type) throws ResourceRegistryException { - OClass oClass = SchemaManagementImpl.getTypeSchema(type, null); + OClass oClass = ERManagementUtility.getTypeSchema(type, null); ERManagement erManagement = null; if(oClass.isSubClassOf(Resource.NAME)) { @@ -199,4 +205,85 @@ public class ERManagementUtility { return relationManagement; } + public static OClass getTypeSchema(ODatabaseDocument oDatabaseDocument, String type, AccessType accessType) + throws SchemaException, SchemaNotFoundException { + OMetadata oMetadata = oDatabaseDocument.getMetadata(); + OSchema oSchema = oMetadata.getSchema(); + return getTypeSchema(oSchema, type, accessType); + } + + public static OClass getTypeSchema(OSchema oSchema, String type, AccessType accessType) + throws SchemaException, SchemaNotFoundException { + try { + OClass oClass = oSchema.getClass(type); + if(oClass == null) { + throw new SchemaNotFoundException(type + " was not registered"); + } + if(accessType != null && type.compareTo(accessType.getName()) != 0) { + if(!oClass.isSubClassOf(accessType.getName())) { + throw new SchemaException(type + " is not a " + accessType.getName()); + } + } + return oClass; + } catch(SchemaNotFoundException snfe) { + throw snfe; + } catch(Exception e) { + throw new SchemaException(e.getMessage()); + } + } + + public static OClass getTypeSchema(String type, AccessType accessType) + throws SchemaException, ResourceRegistryException { + ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); + ODatabaseDocument oDatabaseDocument = null; + try { + logger.debug("Getting {} Type {} schema", accessType != null ? accessType.getName() : "", type); + AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); + return getTypeSchema(oDatabaseDocument, type, accessType); + } catch(ResourceRegistryException e) { + throw e; + } catch(Exception e) { + throw new ResourceRegistryException(e); + } finally { + if(oDatabaseDocument != null) { + oDatabaseDocument.close(); + } + + if(current!=null) { + current.activateOnCurrentThread(); + } + } + + /* + try { + ExecutorService es = Executors.newSingleThreadExecutor(); + Future result = es.submit(new Callable() { + public OClass call() throws Exception { + ODatabaseDocument oDatabaseDocument = null; + try { + logger.debug("Getting {} Type {} schema", accessType != null ? accessType.getName() : "", type); + + AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); + oDatabaseDocument.activateOnCurrentThread(); + return getTypeSchema(oDatabaseDocument, type, accessType); + } catch(ResourceRegistryException e) { + throw e; + } catch(Exception e) { + throw new ResourceRegistryException(e); + } finally { + if(oDatabaseDocument != null) { + oDatabaseDocument.close(); + } + } + } + }); + return result.get(); + } catch(Exception e) { + throw new ResourceRegistryException(e); + } + */ + } + } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/BaseEntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/BaseEntityManagement.java index 9162bbf..7d02f67 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/BaseEntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/BaseEntityManagement.java @@ -50,9 +50,9 @@ public abstract class BaseEntityManagement extends ERManag } - protected BaseEntityManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument orientGraph) { + protected BaseEntityManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument oDatabaseDocument) { this(accessType); - this.oDatabaseDocument = orientGraph; + this.oDatabaseDocument = oDatabaseDocument; setWorkingContext(workingContext); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/BasePropertyManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/BasePropertyManagement.java index e58de31..c48dd08 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/BasePropertyManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/BasePropertyManagement.java @@ -14,7 +14,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment; import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement; -import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl; +import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility; import org.gcube.informationsystem.resourceregistry.utils.EncryptedOrient; import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility; import org.slf4j.Logger; @@ -56,7 +56,7 @@ public class BasePropertyManagement { OClass oClass = null; try { - oClass = SchemaManagementImpl.getTypeSchema(type, AccessType.BASE_PROPERTY); + oClass = ERManagementUtility.getTypeSchema(type, AccessType.BASE_PROPERTY); } catch(SchemaNotFoundException e) { throw e; } @@ -125,7 +125,7 @@ public class BasePropertyManagement { return jsonNode; } - OClass oClass = SchemaManagementImpl.getTypeSchema(type, AccessType.BASE_PROPERTY); + OClass oClass = ERManagementUtility.getTypeSchema(type, AccessType.BASE_PROPERTY); /* * In case it is an Encrypted type the value is encrypted with the DB Key diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java index 6b1c5a2..cb7b460 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java @@ -22,7 +22,6 @@ import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.model.reference.relations.Relation; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaCreationException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; @@ -68,7 +67,7 @@ public class SchemaManagementImpl implements SchemaManagement { protected String typeName; - protected static OClass getOClass(OSchema oSchema, String type) throws SchemaException { + protected OClass getOClass(OSchema oSchema, String type) throws SchemaException { return oSchema.getClass(type); } @@ -76,87 +75,6 @@ public class SchemaManagementImpl implements SchemaManagement { this.typeName = typeName; } - public static OClass getTypeSchema(ODatabaseDocument oDatabaseDocument, String type, AccessType accessType) - throws SchemaException, SchemaNotFoundException { - OMetadata oMetadata = oDatabaseDocument.getMetadata(); - OSchema oSchema = oMetadata.getSchema(); - return getTypeSchema(oSchema, type, accessType); - } - - public static OClass getTypeSchema(OSchema oSchema, String type, AccessType accessType) - throws SchemaException, SchemaNotFoundException { - try { - OClass oClass = oSchema.getClass(type); - if(oClass == null) { - throw new SchemaNotFoundException(type + " was not registered"); - } - if(accessType != null && type.compareTo(accessType.getName()) != 0) { - if(!oClass.isSubClassOf(accessType.getName())) { - throw new SchemaException(type + " is not a " + accessType.getName()); - } - } - return oClass; - } catch(SchemaNotFoundException snfe) { - throw snfe; - } catch(Exception e) { - throw new SchemaException(e.getMessage()); - } - } - - public static OClass getTypeSchema(String type, AccessType accessType) - throws SchemaException, ResourceRegistryException { - ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); - ODatabaseDocument oDatabaseDocument = null; - try { - logger.debug("Getting {} Type {} schema", accessType != null ? accessType.getName() : "", type); - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); - return getTypeSchema(oDatabaseDocument, type, accessType); - } catch(ResourceRegistryException e) { - throw e; - } catch(Exception e) { - throw new ResourceRegistryException(e); - } finally { - if(oDatabaseDocument != null) { - oDatabaseDocument.close(); - } - - if(current!=null) { - current.activateOnCurrentThread(); - } - } - - /* - try { - ExecutorService es = Executors.newSingleThreadExecutor(); - Future result = es.submit(new Callable() { - public OClass call() throws Exception { - ODatabaseDocument oDatabaseDocument = null; - try { - logger.debug("Getting {} Type {} schema", accessType != null ? accessType.getName() : "", type); - - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); - oDatabaseDocument.activateOnCurrentThread(); - return getTypeSchema(oDatabaseDocument, type, accessType); - } catch(ResourceRegistryException e) { - throw e; - } catch(Exception e) { - throw new ResourceRegistryException(e); - } finally { - if(oDatabaseDocument != null) { - oDatabaseDocument.close(); - } - } - } - }); - return result.get(); - } catch(Exception e) { - throw new ResourceRegistryException(e); - } - */ - } - @SuppressWarnings("unused") private static TypeDefinition getOClassTypeDefinition(OClass oClass) throws SchemaException { try { @@ -189,7 +107,7 @@ public class SchemaManagementImpl implements SchemaManagement { } } - private static TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException { + private TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException { try { ERManagement erManagement = null; @@ -211,7 +129,7 @@ public class SchemaManagementImpl implements SchemaManagement { } } - protected static String getTypeDefinitionAsString(OClass oClass) throws SchemaException { + protected String getTypeDefinitionAsString(OClass oClass) throws SchemaException { try { TypeDefinition typeDefinition = getTypeDefinition(oClass); return TypeBinder.serializeTypeDefinition(typeDefinition); @@ -256,8 +174,8 @@ public class SchemaManagementImpl implements SchemaManagement { } private static Set baseTypes; - private static Set typeDefinitionTypes; - private static Set skipTypeDefinitionCreation; + public static Set typeDefinitionTypes; + public static Set skipTypeDefinitionCreation; static { baseTypes = new HashSet(); @@ -272,10 +190,8 @@ public class SchemaManagementImpl implements SchemaManagement { skipTypeDefinitionCreation = new HashSet(); skipTypeDefinitionCreation.addAll(baseTypes); - skipTypeDefinitionCreation.addAll(typeDefinitionTypes); skipTypeDefinitionCreation.add(Header.NAME); skipTypeDefinitionCreation.add(PropertyDefinition.NAME); - } protected void registerTypeSchema(TypeDefinition typeDefinition, AccessType baseType) @@ -406,7 +322,6 @@ public class SchemaManagementImpl implements SchemaManagement { oDatabaseDocument.commit(); logger.info("{} {} registered successfully", baseType.getName(), typeDefinition.getName()); - } catch(Exception e) { oSchema.dropClass(typeDefinition.getName()); throw e; @@ -433,7 +348,7 @@ public class SchemaManagementImpl implements SchemaManagement { OMetadata oMetadata = oDatabaseDocument.getMetadata(); OSchema oSchema = oMetadata.getSchema(); - OClass baseOClass = getTypeSchema(oSchema, type, null); + OClass baseOClass = oSchema.getClass(type); List typeDefinitions = new ArrayList<>(); typeDefinitions.add(getTypeDefinition(baseOClass)); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/entities/EntityTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/entities/EntityTypeDefinitionManagement.java index e831369..984856c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/entities/EntityTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/entities/EntityTypeDefinitionManagement.java @@ -33,19 +33,16 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement { protected String name; - private void init() { + public PropertyTypeDefinitionManagement() { + super(AccessType.PROPERTY_TYPE_DEFINITION); this.elementType = PropertyTypeDefinition.NAME; } - public PropertyTypeDefinitionManagement() { - super(AccessType.PROPERTY_TYPE_DEFINITION); - init(); - } - - public PropertyTypeDefinitionManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException { + public PropertyTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException { this(); this.oDatabaseDocument = oDatabaseDocument; - getWorkingContext(); + setWorkingContext(securityContext); } @Override diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/relations/RelationTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/relations/RelationTypeDefinitionManagement.java index 361e0b1..cb22852 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/relations/RelationTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/relations/RelationTypeDefinitionManagement.java @@ -35,12 +35,13 @@ public class RelationTypeDefinitionManagement public RelationTypeDefinitionManagement() { super(AccessType.RELATION_TYPE_DEFINITION, EntityTypeDefinition.class, EntityTypeDefinition.class); + this.elementType = RelationTypeDefinition.NAME; } - public RelationTypeDefinitionManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException { + public RelationTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException { this(); this.oDatabaseDocument = oDatabaseDocument; - getWorkingContext(); + setWorkingContext(securityContext); } @Override @@ -220,12 +221,12 @@ public class RelationTypeDefinitionManagement @Override protected EntityTypeDefinitionManagement newSourceEntityManagement() throws ResourceRegistryException { - return new EntityTypeDefinitionManagement(oDatabaseDocument); + return new EntityTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument); } @Override protected EntityTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException { - return new EntityTypeDefinitionManagement(oDatabaseDocument); + return new EntityTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument); } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java index 2c04906..836cf6e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/Utility.java @@ -144,5 +144,5 @@ public class Utility { Header header = HeaderUtility.getHeader(element); return header.getUUID(); } - + } \ No newline at end of file diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/schema/SchemaManagementImplTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/type/SchemaManagementImplTest.java similarity index 89% rename from src/test/java/org/gcube/informationsystem/resourceregistry/schema/SchemaManagementImplTest.java rename to src/test/java/org/gcube/informationsystem/resourceregistry/type/SchemaManagementImplTest.java index d160d36..85bb21a 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/schema/SchemaManagementImplTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/type/SchemaManagementImplTest.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.informationsystem.resourceregistry.schema; +package org.gcube.informationsystem.resourceregistry.type; import java.util.List; @@ -10,6 +10,7 @@ import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.base.reference.properties.Header; import org.gcube.informationsystem.base.reference.relations.BaseRelation; +import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; @@ -167,6 +168,18 @@ public class SchemaManagementImplTest { } + @Test + public void createContextType() throws Exception { + EntityTypeDefinition entityTypeDefinition = new EntityTypeDefinitionImpl(Context.class); + + SchemaManagement schemaManagement = new SchemaManagementImpl(); + ((SchemaManagementImpl) schemaManagement).setTypeName(Context.NAME); + String ret = schemaManagement.create(ISMapper.marshal(entityTypeDefinition), AccessType.BASE_ENTITY); + + logger.debug(ret); + + } + @Test public void createFacetType() throws Exception { EntityTypeDefinition entityTypeDefinition = new EntityTypeDefinitionImpl(AccessPointFacet.class); @@ -199,6 +212,18 @@ public class SchemaManagementImplTest { } + @Test + public void createRelationTypeDefinitionType() throws Exception { + RelationTypeDefinition relationTypeDefinition = new RelationTypeDefinitionImpl((Class>) RelationTypeDefinition.class); + + SchemaManagement schemaManagement = new SchemaManagementImpl(); + ((SchemaManagementImpl) schemaManagement).setTypeName(RelationTypeDefinition.NAME); + String ret = schemaManagement.create(ISMapper.marshal(relationTypeDefinition), AccessType.BASE_RELATION); + + logger.debug(ret); + + } + @Test public void createIsRelatedToType() throws Exception { @SuppressWarnings("unchecked")