fixed type definitions creation
This commit is contained in:
parent
f8427ea85b
commit
6bc15e3164
|
@ -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<EntityT
|
|||
getWorkingContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if(workingContext == null) {
|
||||
workingContext = ContextUtility.getInstance()
|
||||
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
||||
}
|
||||
return workingContext;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -67,6 +74,39 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
|
|||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
return serializeSelfOnly();
|
||||
// For Resources Definition include mandatory and suggested IsRelatedTo and ConsistsOf
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
logger.debug("Going to create {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
return createVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to update {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
OVertex entityTypeDefinition = getElement();
|
||||
entityTypeDefinition = (OVertex) ERManagement.updateProperties(oClass, entityTypeDefinition, jsonNode,
|
||||
ignoreKeys, ignoreStartWithKeys);
|
||||
return entityTypeDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
getElement().delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OVertex getElement() throws NotFoundException, ResourceRegistryException {
|
||||
if(element == null) {
|
||||
|
@ -95,12 +135,11 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
|
|||
throw new NotFoundException("null name does not allow to retrieve the Element");
|
||||
}
|
||||
|
||||
String select = "SELECT FROM " + elementType + " WHERE " + EntityTypeDefinition.NAME_PROPERTY
|
||||
+ " = \"" + getName() + "\"";
|
||||
String select = "SELECT FROM " + elementType + " WHERE " + EntityTypeDefinition.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);
|
||||
|
@ -139,8 +178,7 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
|
|||
|
||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
logger.info("Created {} is {}", OVertex.class.getSimpleName(),
|
||||
Utility.toJsonString(element, true));
|
||||
logger.info("Created {} is {}", OVertex.class.getSimpleName(), Utility.toJsonString(element, true));
|
||||
|
||||
return element;
|
||||
} catch(ResourceRegistryException e) {
|
||||
|
@ -153,12 +191,20 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if(workingContext == null) {
|
||||
workingContext = ContextUtility.getInstance()
|
||||
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
||||
}
|
||||
return workingContext;
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -166,62 +212,13 @@ public class EntityTypeDefinitionManagement extends BaseEntityManagement<EntityT
|
|||
return new SchemaNotFoundException(e.getMessage(), e.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new NotAcceptableException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
||||
return new SchemaAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
return serializeSelfOnly();
|
||||
// For Resources Definition include mandatory and suggested IsRelatedTo and ConsistsOf
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
logger.debug("Going to create {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
return createVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to update {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
OVertex entityTypeDefinition = getElement();
|
||||
entityTypeDefinition = (OVertex) ERManagement.updateProperties(oClass, entityTypeDefinition, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
return entityTypeDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
getElement().delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,27 +87,12 @@ public class PropertyTypeDefinitionManagement extends ERManagement<OElement> {
|
|||
@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<OElement> {
|
|||
}
|
||||
}
|
||||
|
||||
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<OElement> {
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<EntityTypeDefinitionManagement,EntityTypeDefinitionManagement> {
|
||||
public class RelationTypeDefinitionManagement
|
||||
extends BaseRelationManagement<EntityTypeDefinitionManagement,EntityTypeDefinitionManagement> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue