Refs #11288: Made resource-registry more RESTful
Task-Url: https://support.d4science.org/issues/11288 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@168993 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
047f1a678d
commit
cba560a6e8
|
@ -46,7 +46,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
private void init() {
|
||||
this.ignoreStartWithKeys.add(Context.PARENT_PROPERTY);
|
||||
this.ignoreStartWithKeys.add(Context.CHILDREN_PROPERTY);
|
||||
this.erType = Context.NAME;
|
||||
this.elementType = Context.NAME;
|
||||
}
|
||||
|
||||
public ContextManagement() {
|
||||
|
@ -384,7 +384,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Iterable<Vertex> iterable = orientGraph.getVerticesOfClass(erType, polymorphic);
|
||||
Iterable<Vertex> iterable = orientGraph.getVerticesOfClass(elementType, polymorphic);
|
||||
for(Vertex vertex : iterable) {
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setElement(vertex);
|
||||
|
|
|
@ -80,7 +80,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
protected UUID uuid;
|
||||
protected JsonNode jsonNode;
|
||||
protected OClass oClass;
|
||||
protected String erType;
|
||||
protected String elementType;
|
||||
|
||||
protected El element;
|
||||
protected boolean reload;
|
||||
|
@ -159,14 +159,14 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
String type = orientElement.getRecord().getClassName();
|
||||
oClass = oSchema.getClass(type);
|
||||
} else {
|
||||
oClass = SchemaManagementImpl.getTypeSchema(erType, accessType);
|
||||
oClass = SchemaManagementImpl.getTypeSchema(elementType, accessType);
|
||||
}
|
||||
}
|
||||
return oClass;
|
||||
}
|
||||
|
||||
public void setElementType(String erType) throws ResourceRegistryException {
|
||||
this.erType = erType;
|
||||
this.elementType = erType;
|
||||
if(erType == null || erType.compareTo("") == 0) {
|
||||
erType = accessType.getName();
|
||||
}
|
||||
|
@ -175,6 +175,11 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
}
|
||||
}
|
||||
|
||||
public String getElementType() {
|
||||
return elementType;
|
||||
}
|
||||
|
||||
|
||||
protected void checkJSON() throws ResourceRegistryException {
|
||||
if(uuid == null) {
|
||||
try {
|
||||
|
@ -185,8 +190,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
checkUUIDMatch();
|
||||
}
|
||||
|
||||
if(this.erType == null) {
|
||||
this.erType = getClassProperty(jsonNode);
|
||||
if(this.elementType == null) {
|
||||
this.elementType = getClassProperty(jsonNode);
|
||||
getOClass();
|
||||
} else {
|
||||
checkERMatch();
|
||||
|
@ -196,9 +201,9 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
protected void checkERMatch() throws ResourceRegistryException {
|
||||
if(jsonNode != null) {
|
||||
String type = getClassProperty(jsonNode);
|
||||
if(type != null && type.compareTo(erType) != 0) {
|
||||
if(type != null && type.compareTo(elementType) != 0) {
|
||||
String error = String.format("Requested type does not match with json representation %s!=%s",
|
||||
erType, type);
|
||||
elementType, type);
|
||||
logger.trace(error);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
@ -219,7 +224,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
if(resourceUUID.compareTo(uuid) != 0) {
|
||||
String error = String.format(
|
||||
"UUID provided in header (%s) differs from the one (%s) used to identify the %s instance",
|
||||
resourceUUID.toString(), uuid.toString(), erType);
|
||||
resourceUUID.toString(), uuid.toString(), elementType);
|
||||
throw new ResourceRegistryException(error);
|
||||
|
||||
}
|
||||
|
@ -259,7 +264,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException("Error Creating " + erType + " with " + jsonNode, e);
|
||||
throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,7 +282,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException("Error Updating " + erType + " with " + jsonNode, e);
|
||||
throw new ResourceRegistryException("Error Updating " + elementType + " with " + jsonNode, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,7 +312,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException("Error Adding " + erType + " to " + targetSecurityContext.toString(), e.getCause());
|
||||
throw new ResourceRegistryException("Error Adding " + elementType + " to " + targetSecurityContext.toString(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,7 +327,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException("Error Removing " + erType + " from " + targetSecurityContext.toString(), e.getCause());
|
||||
throw new ResourceRegistryException("Error Removing " + elementType + " from " + targetSecurityContext.toString(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,6 +337,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
}
|
||||
this.element = element;
|
||||
this.uuid = HeaderUtility.getHeader(element).getUUID();
|
||||
this.elementType = ((OrientElement) element).getLabel();
|
||||
}
|
||||
|
||||
protected abstract NotFoundException getSpecificElementNotFoundException(NotFoundException e);
|
||||
|
@ -348,8 +354,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
} catch(NotFoundException e) {
|
||||
try {
|
||||
retrieveElementFromAnyContext();
|
||||
throw getSpecificERAvailableInAnotherContextException(erType == null ? accessType.getName()
|
||||
: erType + " with UUID " + uuid + " is available in another "
|
||||
throw getSpecificERAvailableInAnotherContextException(elementType == null ? accessType.getName()
|
||||
: elementType + " with UUID " + uuid + " is available in another "
|
||||
+ Context.class.getSimpleName());
|
||||
} catch(AvailableInAnotherContextException e1) {
|
||||
throw e1;
|
||||
|
@ -375,7 +381,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
if(uuid == null) {
|
||||
throw new NotFoundException("null UUID does not allow to retrieve the Element");
|
||||
}
|
||||
return Utility.getElementByUUID(orientGraph, erType == null ? accessType.getName() : erType, uuid,
|
||||
return Utility.getElementByUUID(orientGraph, elementType == null ? accessType.getName() : elementType, uuid,
|
||||
elementClass);
|
||||
} catch(NotFoundException e) {
|
||||
throw getSpecificElementNotFoundException(e);
|
||||
|
@ -388,7 +394,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
|
||||
public El retrieveElementFromAnyContext() throws NotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
return Utility.getElementByUUIDAsAdmin(erType == null ? accessType.getName() : erType, uuid, elementClass);
|
||||
return Utility.getElementByUUIDAsAdmin(elementType == null ? accessType.getName() : elementType, uuid, elementClass);
|
||||
} catch(NotFoundException e) {
|
||||
throw getSpecificElementNotFoundException(e);
|
||||
} catch(ResourceRegistryException e) {
|
||||
|
@ -581,17 +587,17 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
boolean added = internalAddToContext(targetSecurityContext);
|
||||
|
||||
orientGraph.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", erType, uuid, contextUUID);
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return added;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", erType, uuid, contextUUID);
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", erType, uuid, contextUUID, e);
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID, e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -604,7 +610,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
}
|
||||
|
||||
public boolean removeFromContext(UUID contextUUID) throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", erType, uuid, contextUUID);
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
try {
|
||||
|
||||
|
@ -617,17 +623,17 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
boolean removed = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
orientGraph.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", erType, uuid, contextUUID);
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return removed;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", erType, uuid, contextUUID);
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", erType, uuid, contextUUID, e);
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID, e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -124,24 +126,24 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
protected Vertex createVertex() throws EntityAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
logger.trace("Going to create {} for {} ({}) using {}", Vertex.class.getSimpleName(), accessType.getName(),
|
||||
erType, jsonNode);
|
||||
elementType, jsonNode);
|
||||
|
||||
try {
|
||||
|
||||
if(oClass.isAbstract()) {
|
||||
String error = String.format(
|
||||
"Trying to create an instance of %s of type %s which is abstract. The operation will be aborted.",
|
||||
accessType.getName(), erType);
|
||||
accessType.getName(), elementType);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
Vertex vertexEntity = orientGraph.addVertex("class:" + erType);
|
||||
Vertex vertexEntity = orientGraph.addVertex("class:" + elementType);
|
||||
|
||||
try {
|
||||
if(uuid != null) {
|
||||
Vertex v = getElement();
|
||||
if(v != null) {
|
||||
String error = String.format("A %s with UUID %s already exist", erType, uuid.toString());
|
||||
String error = String.format("A %s with UUID %s already exist", elementType, uuid.toString());
|
||||
throw getSpecificERAlreadyPresentException(error);
|
||||
}
|
||||
}
|
||||
|
@ -176,8 +178,8 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.trace("Error while creating {} for {} ({}) using {}", Vertex.class.getSimpleName(),
|
||||
accessType.getName(), erType, jsonNode, e);
|
||||
throw new ResourceRegistryException("Error Creating " + erType + " with " + jsonNode, e.getCause());
|
||||
accessType.getName(), elementType, jsonNode, e);
|
||||
throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +220,7 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Iterable<Vertex> iterable = orientGraph.getVerticesOfClass(erType, polymorphic);
|
||||
Iterable<Vertex> iterable = orientGraph.getVerticesOfClass(elementType, polymorphic);
|
||||
for(Vertex vertex : iterable) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
EntityManagement entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
|
@ -234,10 +236,103 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
public String reallyQuery(String relationType, String referenceType, Direction direction, boolean polymorphic,
|
||||
Map<String,String> constraint) throws ResourceRegistryException {
|
||||
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, Direction direction,
|
||||
boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
Iterable<Vertex> references = null;
|
||||
|
||||
if(referenceUUID != null) {
|
||||
Element element = ERManagementUtility.getAnyElementByUUID(referenceUUID);
|
||||
if(element instanceof Vertex) {
|
||||
@SuppressWarnings("unchecked")
|
||||
EntityManagement<Entity> entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, (Vertex) element);
|
||||
|
||||
OrientVertexType orientVertexType = ((OrientVertex) element).getType();
|
||||
|
||||
String elementType = entityManagement.getElementType();
|
||||
if(elementType.compareTo(referenceType) != 0) {
|
||||
if(polymorphic && orientVertexType.isSubClassOf(referenceType)) {
|
||||
// OK
|
||||
} else {
|
||||
String error = String.format("Referenced instace with UUID %s is not a %s", referenceUUID,
|
||||
referenceType);
|
||||
throw new InvalidQueryException(error);
|
||||
}
|
||||
}
|
||||
|
||||
List<Vertex> vertexes = new ArrayList<>();
|
||||
vertexes.add((Vertex) element);
|
||||
references = vertexes;
|
||||
|
||||
} else {
|
||||
String error = String.format("Referenced instace with UUID %s is not an %s", referenceUUID, Entity.NAME);
|
||||
throw new InvalidQueryException(error);
|
||||
}
|
||||
|
||||
} else {
|
||||
references = orientGraph.getVerticesOfClass(referenceType, polymorphic);
|
||||
}
|
||||
|
||||
for(Vertex v : references) {
|
||||
List<Direction> directions = new ArrayList<>();
|
||||
if(direction==Direction.BOTH) {
|
||||
directions.add(Direction.IN);
|
||||
directions.add(Direction.OUT);
|
||||
}else {
|
||||
directions.add(direction);
|
||||
}
|
||||
|
||||
for(Direction d : directions) {
|
||||
|
||||
Iterable<Edge> edges = v.getEdges(d.opposite(), relationType);
|
||||
for(Edge edge : edges) {
|
||||
Vertex vertex = ((OrientEdge) edge).getVertex(d);
|
||||
OrientVertex orientVertex = (OrientVertex) vertex;
|
||||
|
||||
if(((OrientVertex) v).getIdentity().compareTo(orientVertex.getIdentity()) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(elementType.compareTo(orientVertex.getLabel()) != 0) {
|
||||
OrientVertexType orientVertexType = orientVertex.getType();
|
||||
|
||||
if(polymorphic && orientVertexType.isSubClassOf(elementType)) {
|
||||
// OK
|
||||
} else {
|
||||
// excluding from results
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
EntityManagement entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, vertex);
|
||||
try {
|
||||
if(entityManagement.getUUID().compareTo(referenceUUID) == 0) {
|
||||
continue;
|
||||
}
|
||||
JSONObject jsonObject = entityManagement.serializeAsJson();
|
||||
jsonArray.put(jsonObject);
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
public String reallyQueryTraversal(String relationType, String referenceType, UUID referenceUUID,
|
||||
Direction direction, boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
if(referenceUUID != null) {
|
||||
constraint.put(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY, referenceUUID.toString());
|
||||
}
|
||||
|
||||
// TODO check types
|
||||
|
||||
/*
|
||||
|
@ -254,7 +349,7 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
selectStringBuilder.append("'), ");
|
||||
selectStringBuilder.append(direction.opposite().name().toLowerCase());
|
||||
selectStringBuilder.append("V('");
|
||||
selectStringBuilder.append(erType);
|
||||
selectStringBuilder.append(elementType);
|
||||
selectStringBuilder.append("') FROM (SELECT FROM ");
|
||||
selectStringBuilder.append(referenceType);
|
||||
boolean first = true;
|
||||
|
@ -276,7 +371,7 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
|
||||
if(!polymorphic) {
|
||||
selectStringBuilder.append(" WHERE @class='");
|
||||
selectStringBuilder.append(erType);
|
||||
selectStringBuilder.append(elementType);
|
||||
selectStringBuilder.append("'");
|
||||
}
|
||||
|
||||
|
@ -303,8 +398,8 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
if(orientVertexType.getName().compareTo(erType) != 0) {
|
||||
if(!orientVertexType.isSubClassOf(erType)) {
|
||||
if(orientVertexType.getName().compareTo(elementType) != 0) {
|
||||
if(!orientVertexType.isSubClassOf(elementType)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -317,6 +412,12 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
EntityManagement entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, vertex);
|
||||
try {
|
||||
if(constraint.containsKey(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY)) {
|
||||
String uuid = constraint.get(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY);
|
||||
if(entityManagement.getUUID().compareTo(UUID.fromString(uuid)) == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = entityManagement.serializeAsJson();
|
||||
jsonArray.put(jsonObject);
|
||||
} catch(ResourceRegistryException e) {
|
||||
|
@ -334,13 +435,13 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
|
||||
AccessType relationAccessType = ERManagementUtility.getBaseAccessType(relationType);
|
||||
if(relationAccessType != AccessType.IS_RELATED_TO || relationAccessType != AccessType.CONSISTS_OF) {
|
||||
if(relationAccessType != AccessType.IS_RELATED_TO && relationAccessType != AccessType.CONSISTS_OF) {
|
||||
String error = String.format("%s must be a relation type", relationType);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
AccessType referenceAccessType = ERManagementUtility.getBaseAccessType(referenceType);
|
||||
if(referenceAccessType != AccessType.RESOURCE || relationAccessType != AccessType.FACET) {
|
||||
if(referenceAccessType != AccessType.RESOURCE && referenceAccessType != AccessType.FACET) {
|
||||
String error = String.format("%s must be a en entity type", referenceType);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
@ -356,7 +457,7 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
|
||||
if(direction != Direction.OUT) {
|
||||
String error = String.format("%s can only goes %s from %s.", relationType,
|
||||
Direction.OUT.name(), erType);
|
||||
Direction.OUT.name(), elementType);
|
||||
throw new InvalidQueryException(error);
|
||||
} else {
|
||||
if(referenceAccessType != AccessType.FACET) {
|
||||
|
@ -372,8 +473,8 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
case FACET:
|
||||
if(relationAccessType != AccessType.CONSISTS_OF || direction != Direction.IN
|
||||
|| referenceAccessType != AccessType.RESOURCE) {
|
||||
String error = String.format("%s can only has %s %s from a %s.", erType, Direction.IN.name(),
|
||||
ConsistsOf.NAME, Resource.NAME);
|
||||
String error = String.format("%s can only has %s %s from a %s.", elementType,
|
||||
Direction.IN.name(), ConsistsOf.NAME, Resource.NAME);
|
||||
throw new InvalidQueryException(error);
|
||||
}
|
||||
|
||||
|
@ -383,11 +484,7 @@ public abstract class EntityManagement<E extends Entity> extends ERManagement<E,
|
|||
break;
|
||||
}
|
||||
|
||||
if(referenceUUID != null) {
|
||||
constraint.put(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY, referenceUUID.toString());
|
||||
}
|
||||
|
||||
return reallyQuery(relationType, referenceType, direction, polymorphic, constraint);
|
||||
return reallyQuery(relationType, referenceType, referenceUUID, direction, polymorphic, constraint);
|
||||
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
|
|
@ -222,7 +222,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
targetEntityManagement = newTargetEntityManagement();
|
||||
|
||||
if(!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
||||
throw new ResourceRegistryException("Error while creating " + erType + ". No target definition found");
|
||||
throw new ResourceRegistryException("Error while creating " + elementType + ". No target definition found");
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -230,7 +230,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
} catch(SchemaException e) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
errorMessage.append("A ");
|
||||
errorMessage.append(erType);
|
||||
errorMessage.append(elementType);
|
||||
errorMessage.append(" can be only created beetween ");
|
||||
errorMessage.append(sourceEntityManagement.getAccessType().getName());
|
||||
errorMessage.append(" and ");
|
||||
|
@ -245,17 +245,17 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
}
|
||||
}
|
||||
|
||||
logger.trace("Creating {} beetween {} -> {}", erType, getSourceEntityManagement().serialize(),
|
||||
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serialize(),
|
||||
getTargetEntityManagement().serialize());
|
||||
|
||||
Vertex source = (Vertex) getSourceEntityManagement().getElement();
|
||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||
|
||||
element = orientGraph.addEdge(null, source, target, erType);
|
||||
element = orientGraph.addEdge(null, source, target, elementType);
|
||||
|
||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
logger.info("{} successfully created", erType);
|
||||
logger.info("{} successfully created", elementType);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
@Override
|
||||
protected Edge reallyUpdate() throws ResourceRegistryException {
|
||||
|
||||
logger.debug("Trying to update {} : {}", erType, jsonNode);
|
||||
logger.debug("Trying to update {} : {}", elementType, jsonNode);
|
||||
|
||||
Edge edge = getElement();
|
||||
ERManagement.updateProperties(oClass, edge, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
@ -281,7 +281,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
}
|
||||
}
|
||||
|
||||
logger.info("{} {} successfully updated", erType, jsonNode);
|
||||
logger.info("{} {} successfully updated", elementType, jsonNode);
|
||||
|
||||
return edge;
|
||||
|
||||
|
@ -488,7 +488,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
throws ResourceRegistryException {
|
||||
Map<String,JSONObject> visitedSourceResources = new HashMap<>();
|
||||
for(Edge edge : edges) {
|
||||
if(postFilterPolymorphic && edge.getLabel().compareTo(erType) != 0) {
|
||||
if(postFilterPolymorphic && edge.getLabel().compareTo(elementType) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -506,7 +506,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
Iterable<Edge> edges = orientGraph.getEdgesOfClass(erType, polymorphic);
|
||||
Iterable<Edge> edges = orientGraph.getEdgesOfClass(elementType, polymorphic);
|
||||
Collection<JSONObject> collection = serializeEdges(edges, false);
|
||||
return serializeJSONObjectList(collection);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public class SharingManagement {
|
|||
protected void setCalledMethod(HTTPMETHOD httpMethod, String type) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(SharingPath.SHARING_PATH_PART);
|
||||
list.add(SharingPath.CONTEXTS_PATH_PART);
|
||||
list.add("{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}");
|
||||
list.add(type);
|
||||
list.add("{" + AccessPath.UUID_PATH_PARAM + "}");
|
||||
|
@ -48,8 +49,8 @@ public class SharingManagement {
|
|||
*
|
||||
*/
|
||||
@PUT
|
||||
@Path("/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}" + "/" + AccessPath.TYPE_PATH_PARAM + "/{"
|
||||
+ AccessPath.UUID_PATH_PARAM + "}")
|
||||
@Path("/" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}" + "/"
|
||||
+ AccessPath.TYPE_PATH_PARAM + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
||||
@Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public boolean add(@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||
|
@ -88,8 +89,8 @@ public class SharingManagement {
|
|||
*
|
||||
*/
|
||||
@DELETE
|
||||
@Path("/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}" + "/" + AccessPath.TYPE_PATH_PARAM + "/{"
|
||||
+ AccessPath.UUID_PATH_PARAM + "}")
|
||||
@Path("/" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}" + "/"
|
||||
+ AccessPath.TYPE_PATH_PARAM + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
||||
@Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public boolean remove(@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||
|
|
|
@ -638,24 +638,21 @@ public class ERManagementTest extends ScopedTest {
|
|||
String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.BOTH, true, null);
|
||||
List<Resource> resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
Resource sourceResource = resourceList.get(0);
|
||||
Resource targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
|
||||
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
|
||||
Resource resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.OUT, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
sourceResource = resourceList.get(0);
|
||||
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
|
||||
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.IN, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.BOTH, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
@ -677,24 +674,22 @@ public class ERManagementTest extends ScopedTest {
|
|||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.OUT, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.IN, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID)==0);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.IN, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.BOTH, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.BOTH, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.OUT, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.OUT, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.IN, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.IN, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
/* END Getting HostingNode */
|
||||
|
@ -713,9 +708,9 @@ public class ERManagementTest extends ScopedTest {
|
|||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.OUT, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
sourceResource = resourceList.get(0);
|
||||
Facet targetIdentificationFacet = sourceResource.getIdentificationFacets().get(0);
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
|
||||
resource = resourceList.get(0);
|
||||
Facet targetIdentificationFacet = resource.getIdentificationFacets().get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID)==0);
|
||||
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID)==0);
|
||||
|
||||
try {
|
||||
|
@ -726,17 +721,17 @@ public class ERManagementTest extends ScopedTest {
|
|||
|
||||
|
||||
try {
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.BOTH, true, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.BOTH, false, null);
|
||||
}catch(InvalidQueryException e) {
|
||||
// Ok expected
|
||||
}
|
||||
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.OUT, true, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.OUT, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
try {
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.IN, true, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.IN, false, null);
|
||||
}catch(InvalidQueryException e) {
|
||||
// Ok expected
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue