Fixed types creation to support resource schema definition.

This commit is contained in:
Luca Frosini 2020-01-20 10:29:56 +01:00
parent 72f2ee3e15
commit a825fe51af
14 changed files with 83 additions and 44 deletions

View File

@ -18,13 +18,12 @@ 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.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Property;
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;
@ -32,8 +31,11 @@ import org.gcube.informationsystem.resourceregistry.security.SecurityContext.Per
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.entities.FacetTypeDefinition;
import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition;
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.RelationTypeDefinition;
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
@ -226,11 +228,15 @@ public class DatabaseEnvironment {
List<Class<? extends ISManageable>> definitionToBeCreated = new ArrayList<>();
definitionToBeCreated.add(BaseProperty.class);
definitionToBeCreated.add(Property.class);
definitionToBeCreated.add(Header.class);
definitionToBeCreated.add(PropertyDefinition.class);
definitionToBeCreated.add(PropertyTypeDefinition.class);
definitionToBeCreated.add(ResourceEntryDefinition.class);
definitionToBeCreated.add(BaseEntity.class);
definitionToBeCreated.add(EntityTypeDefinition.class);
definitionToBeCreated.add(FacetTypeDefinition.class);
definitionToBeCreated.add(ResourceTypeDefinition.class);
definitionToBeCreated.add(BaseRelation.class);
definitionToBeCreated.add(RelationTypeDefinition.class);
@ -247,6 +253,7 @@ public class DatabaseEnvironment {
}
}
/*
for(Class<? extends ISManageable> clz : definitionToBeCreated) {
ERManagement<? extends OElement> erManagement = null;
@ -254,6 +261,9 @@ public class DatabaseEnvironment {
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();
}
@ -261,6 +271,17 @@ public class DatabaseEnvironment {
erManagement.setJson(TypeBinder.serializeType(clz));
erManagement.create();
}
*/
List<Class<? extends ISManageable>> schemaToBeCreated = new ArrayList<>();
schemaToBeCreated.add(Property.class);
schemaToBeCreated.add(Header.class);
for(Class<? extends ISManageable> clz : schemaToBeCreated) {
ERManagement<? extends OElement> erManagement = new PropertyTypeDefinitionManagement();
erManagement.setJson(TypeBinder.serializeType(clz));
erManagement.create();
}
List<Package> packages = new ArrayList<Package>();

View File

@ -20,8 +20,8 @@ import javax.activation.UnsupportedDataTypeException;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -182,16 +182,16 @@ public abstract class ERManagement<El extends OElement> {
return oClass;
}
public void setElementType(String erType) throws ResourceRegistryException {
public void setElementType(String elementType) throws ResourceRegistryException {
if(this.elementType == null) {
if(erType == null || erType.compareTo("") == 0) {
erType = accessType.getName();
if(elementType == null || elementType.compareTo("") == 0) {
elementType = accessType.getName();
}
this.elementType = erType;
this.elementType = elementType;
} else {
if(elementType.compareTo(erType) != 0) {
if(elementType.compareTo(elementType) != 0) {
throw new ResourceRegistryException(
"Provided type " + erType + " does not match with the one already known " + this.accessType);
"Provided type " + elementType + " does not match with the one already known " + this.accessType);
}
}

View File

@ -6,9 +6,9 @@ import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;

View File

@ -5,9 +5,9 @@ import java.util.Iterator;
import java.util.UUID;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;

View File

@ -8,10 +8,10 @@ import java.util.UUID;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.properties.Header;
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.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;

View File

@ -16,9 +16,9 @@ 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.properties.Header;
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.Relation;
@ -35,10 +35,14 @@ import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContex
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;
import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition;
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.RelationTypeDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -91,12 +95,14 @@ public class SchemaManagementImpl implements SchemaManagement {
node.put(ISManageable.CLASS_PROPERTY, RelationTypeDefinition.NAME);
}
ArrayNode arrayNode = (ArrayNode) node.get(TypeDefinition.PROPERTIES_PROPERTY);
if(!oClass.isSubClassOf(Resource.NAME)) {
ArrayNode arrayNode = (ArrayNode) node.get(PropertyCapableTypeDefinition.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);
@ -175,7 +181,7 @@ public class SchemaManagementImpl implements SchemaManagement {
private static Set<String> baseTypes;
public static Set<String> typeDefinitionTypes;
public static Set<String> skipTypeDefinitionCreation;
// public static Set<String> skipTypeDefinitionCreation;
static {
baseTypes = new HashSet<String>();
@ -185,13 +191,18 @@ public class SchemaManagementImpl implements SchemaManagement {
typeDefinitionTypes = new HashSet<String>();
typeDefinitionTypes.add(PropertyTypeDefinition.NAME);
typeDefinitionTypes.add(ResourceEntryDefinition.NAME);
typeDefinitionTypes.add(EntityTypeDefinition.NAME);
typeDefinitionTypes.add(ResourceTypeDefinition.NAME);
typeDefinitionTypes.add(RelationTypeDefinition.NAME);
/*
skipTypeDefinitionCreation = new HashSet<String>();
skipTypeDefinitionCreation.addAll(baseTypes);
skipTypeDefinitionCreation.add(Header.NAME);
skipTypeDefinitionCreation.add(PropertyDefinition.NAME);
skipTypeDefinitionCreation.add(Property.NAME);
skipTypeDefinitionCreation.add(Header.NAME);
*/
}
protected void registerTypeSchema(TypeDefinition typeDefinition, AccessType baseType)
@ -255,12 +266,12 @@ public class SchemaManagementImpl implements SchemaManagement {
oClass.setSuperClasses(oSuperclasses);
}
Set<PropertyDefinition> propertyDefinitions = typeDefinition.getProperties();
if(Resource.class.isAssignableFrom(baseType.getTypeClass())) {
if(propertyDefinitions != null && propertyDefinitions.size() > 0) {
throw new SchemaCreationException("A Resource cannot contains any properties.");
}
} else {
if(typeDefinition instanceof PropertyCapableTypeDefinition) {
// A Resource cannot contains any properties.
//
Set<PropertyDefinition> propertyDefinitions = ((PropertyCapableTypeDefinition) typeDefinition).getProperties();
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
OType oType = OType.getById(propertyDefinition.getType().byteValue());
@ -370,7 +381,6 @@ public class SchemaManagementImpl implements SchemaManagement {
oDatabaseDocument.close();
}
}
}
@Override
@ -390,17 +400,21 @@ public class SchemaManagementImpl implements SchemaManagement {
ERManagement<? extends OElement> erManagement = null;
if(BaseEntity.class.isAssignableFrom(accessType.getTypeClass())) {
if(Entity.class.isAssignableFrom(accessType.getTypeClass())) {
erManagement = new EntityTypeDefinitionManagement();
} else if(BaseRelation.class.isAssignableFrom(accessType.getTypeClass())) {
if(Resource.class.isAssignableFrom(accessType.getTypeClass())) {
((EntityTypeDefinitionManagement) erManagement).setElementTypeRaw(ResourceTypeDefinition.NAME);
}else if(Facet.class.isAssignableFrom(accessType.getTypeClass())) {
((EntityTypeDefinitionManagement) erManagement).setElementTypeRaw(FacetTypeDefinition.NAME);
}
} else if(Relation.class.isAssignableFrom(accessType.getTypeClass())) {
erManagement = new RelationTypeDefinitionManagement();
} else if(BaseProperty.class.isAssignableFrom(accessType.getTypeClass())) {
} else if(Property.class.isAssignableFrom(accessType.getTypeClass())) {
erManagement = new PropertyTypeDefinitionManagement();
}
String ret = null;
if(!typeDefinitionTypes.contains(typeDefinition.getName())
&& !skipTypeDefinitionCreation.contains(typeDefinition.getName())) {
if(erManagement!=null) {
erManagement.setJson(jsonSchema);
ret = erManagement.create();
}else {

View File

@ -45,6 +45,10 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
setWorkingContext(securityContext);
}
public void setElementTypeRaw(String elementType) throws ResourceRegistryException {
this.elementType = elementType;
}
@Override
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
if(workingContext == null) {
@ -84,13 +88,13 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
@Override
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
logger.debug("Going to create {} for {}", EntityTypeDefinition.NAME, getName());
logger.debug("Going to create {} for {}", this.elementType, getName());
return createVertex();
}
@Override
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
logger.debug("Going to update {} for {}", EntityTypeDefinition.NAME, getName());
logger.debug("Going to update {} for {}", this.elementType, getName());
OVertex entityTypeDefinition = getElement();
entityTypeDefinition = (OVertex) ERManagement.updateProperties(oClass, entityTypeDefinition, jsonNode,
ignoreKeys, ignoreStartWithKeys);
@ -99,7 +103,7 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
@Override
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
logger.debug("Going to remove {} for {}", EntityTypeDefinition.NAME, getName());
logger.debug("Going to remove {} for {}", this.elementType, getName());
getElement().delete();
return true;
}

View File

@ -3,7 +3,7 @@ package org.gcube.informationsystem.resourceregistry.utils;
import java.util.Date;
import java.util.UUID;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Header;
import com.orientechnologies.orient.core.record.impl.ODocument;

View File

@ -10,7 +10,7 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.utils.ISMapper;
import org.slf4j.Logger;

View File

@ -5,8 +5,8 @@ import java.util.UUID;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;

View File

@ -4,10 +4,10 @@ import java.io.IOException;
import java.util.List;
import java.util.UUID;
import org.gcube.informationsystem.base.impl.properties.HeaderImpl;
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;

View File

@ -16,8 +16,8 @@ import java.util.Map;
import java.util.UUID;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.informationsystem.base.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;

View File

@ -22,12 +22,12 @@ import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gcube.informationsystem.base.impl.properties.HeaderImpl;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;

View File

@ -8,13 +8,13 @@ import java.util.List;
import org.gcube.informationsystem.base.reference.AccessType;
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;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;