From 6bc15e3164c046c3c80189d97dbc98c23da9e54b Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 8 Nov 2019 13:14:56 +0100 Subject: [PATCH] fixed type definitions creation --- .../EntityTypeDefinitionManagement.java | 123 +++++++++--------- .../PropertyTypeDefinitionManagement.java | 47 +++---- .../RelationTypeDefinitionManagement.java | 87 ++++++++----- 3 files changed, 136 insertions(+), 121 deletions(-) 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 cc34cb3..e831369 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 @@ -2,8 +2,6 @@ package org.gcube.informationsystem.resourceregistry.instances.type.entities; import java.util.HashMap; -import javax.ws.rs.NotAcceptableException; - import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; @@ -50,6 +48,15 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement()); - if(resultSet == null || !resultSet.hasNext()) { String error = String.format("No %s with name %s was found", elementType, getName()); logger.info(error); @@ -139,8 +178,7 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement { @Override protected OElement reallyCreate() throws AlreadyPresentException, ResourceRegistryException { logger.debug("Going to create {} for {}", PropertyTypeDefinition.NAME, getName()); - - try { - this.element = new ODocument(elementType); - - ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys); - - logger.debug("Created {} is {}", PropertyTypeDefinition.NAME, Utility.toJsonString(element, true)); - - return element; - } catch(ResourceRegistryException e) { - throw e; - } catch(Exception e) { - logger.trace("Error while creating {} for {} ({}) using {}", OElement.class.getSimpleName(), - accessType.getName(), elementType, jsonNode, e); - throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e.getCause()); - } + return createElement(); } @Override protected OElement reallyUpdate() throws NotFoundException, ResourceRegistryException { - logger.debug("Going to update {} for {}", EntityTypeDefinition.NAME, getName()); + logger.debug("Going to update {} for {}", PropertyTypeDefinition.NAME, getName()); OElement propertyTypeDefinition = getElement(); propertyTypeDefinition = (OElement) ERManagement.updateProperties(oClass, propertyTypeDefinition, jsonNode, ignoreKeys, ignoreStartWithKeys); @@ -180,6 +165,24 @@ public class PropertyTypeDefinitionManagement extends ERManagement { } } + protected OElement createElement() throws AlreadyPresentException, ResourceRegistryException { + try { + this.element = new ODocument(elementType); + + ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys); + + logger.debug("Created {} is {}", PropertyTypeDefinition.NAME, Utility.toJsonString(element, true)); + + return element; + } catch(ResourceRegistryException e) { + throw e; + } catch(Exception e) { + logger.trace("Error while creating {} for {} ({}) using {}", OElement.class.getSimpleName(), + accessType.getName(), elementType, jsonNode, e); + throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e.getCause()); + } + } + @Override public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException { throw new UnsupportedOperationException(); @@ -202,14 +205,14 @@ public class PropertyTypeDefinitionManagement extends ERManagement { return new SchemaNotFoundException(e.getMessage(), e.getCause()); } - @Override - protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) { - throw new UnsupportedOperationException(); - } - @Override protected AlreadyPresentException getSpecificERAlreadyPresentException(String message) { return new SchemaAlreadyPresentException(message); } + @Override + protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) { + throw new UnsupportedOperationException(); + } + } 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 ffc27f3..361e0b1 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 @@ -9,6 +9,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAn import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment; @@ -27,8 +28,8 @@ 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 { +public class RelationTypeDefinitionManagement + extends BaseRelationManagement { protected String name; @@ -42,6 +43,15 @@ public class RelationTypeDefinitionManagement extends getWorkingContext(); } + @Override + protected SecurityContext getWorkingContext() throws ResourceRegistryException { + if(workingContext == null) { + this.workingContext = ContextUtility.getInstance() + .getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID); + } + return workingContext; + } + public void setName(String name) { this.name = name; } @@ -59,18 +69,9 @@ public class RelationTypeDefinitionManagement extends return name; } - @Override - protected SecurityContext getWorkingContext() throws ResourceRegistryException { - if(workingContext == null) { - this.workingContext = ContextUtility.getInstance() - .getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID); - } - return workingContext; - } - @Override protected OEdge reallyCreate() throws ResourceRegistryException { - + logger.debug("Going to create {} for {}", RelationTypeDefinition.NAME, getName()); if(sourceEntityManagement == null) { if(!jsonNode.has(Relation.SOURCE_PROPERTY)) { @@ -109,6 +110,23 @@ public class RelationTypeDefinitionManagement extends return element; } + @Override + protected OEdge reallyUpdate() throws NotFoundException, ResourceRegistryException { + logger.debug("Going to update {} for {}", RelationTypeDefinition.NAME, getName()); + OEdge relationTypeDefinition = getElement(); + relationTypeDefinition = (OEdge) ERManagement.updateProperties(oClass, relationTypeDefinition, jsonNode, + ignoreKeys, ignoreStartWithKeys); + return relationTypeDefinition; + + } + + @Override + protected boolean reallyDelete() throws RelationNotFoundException, ResourceRegistryException { + logger.debug("Going to remove {} for {}", RelationTypeDefinition.NAME, getName()); + getElement().delete(); + return true; + } + @Override public OEdge getElement() throws NotFoundException, ResourceRegistryException { if(element == null) { @@ -137,12 +155,11 @@ public class RelationTypeDefinitionManagement extends throw new NotFoundException("null name does not allow to retrieve the Element"); } - String select = "SELECT FROM " + elementType + " WHERE " + RelationTypeDefinition.NAME_PROPERTY - + " = \"" + getName() + "\""; + String select = "SELECT FROM " + elementType + " WHERE " + RelationTypeDefinition.NAME_PROPERTY + " = \"" + + getName() + "\""; OResultSet resultSet = oDatabaseDocument.query(select, new HashMap<>()); - if(resultSet == null || !resultSet.hasNext()) { String error = String.format("No %s with name %s was found", elementType, getName()); logger.info(error); @@ -170,25 +187,8 @@ public class RelationTypeDefinitionManagement extends } @Override - protected EntityTypeDefinitionManagement newSourceEntityManagement() - throws ResourceRegistryException { - return new EntityTypeDefinitionManagement(oDatabaseDocument); - } - - @Override - protected EntityTypeDefinitionManagement newTargetEntityManagement() - throws ResourceRegistryException { - return new EntityTypeDefinitionManagement(oDatabaseDocument); - } - - @Override - protected NotFoundException getSpecificElementNotFoundException(NotFoundException e) { - return new SchemaNotFoundException(e.getMessage(), e.getCause()); - } - - @Override - protected AlreadyPresentException getSpecificERAlreadyPresentException(String message) { - return new SchemaAlreadyPresentException(message); + public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException { + throw new UnsupportedOperationException(); } @Override @@ -203,14 +203,29 @@ public class RelationTypeDefinitionManagement extends throw new UnsupportedOperationException(); } + @Override + protected NotFoundException getSpecificElementNotFoundException(NotFoundException e) { + return new SchemaNotFoundException(e.getMessage(), e.getCause()); + } + + @Override + protected AlreadyPresentException getSpecificERAlreadyPresentException(String message) { + return new SchemaAlreadyPresentException(message); + } + @Override protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) { throw new UnsupportedOperationException(); } @Override - public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException { - throw new UnsupportedOperationException(); + protected EntityTypeDefinitionManagement newSourceEntityManagement() throws ResourceRegistryException { + return new EntityTypeDefinitionManagement(oDatabaseDocument); + } + + @Override + protected EntityTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException { + return new EntityTypeDefinitionManagement(oDatabaseDocument); } }