Refs #10238: Refactor Context Port Type
Task-Url: https://support.d4science.org/issues/10238 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158615 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6edb78bdfd
commit
99d0e8e04f
|
@ -35,32 +35,22 @@ public class ERManagementUtility {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(EntityManagement.class);
|
||||
/*
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ERManagement getERManagement(AccessType querableType)
|
||||
throws ResourceRegistryException {
|
||||
switch (querableType) {
|
||||
case FACET:
|
||||
return new FacetManagement();
|
||||
|
||||
case RESOURCE:
|
||||
return new ResourceManagement();
|
||||
|
||||
case IS_RELATED_TO:
|
||||
return new IsRelatedToManagement();
|
||||
|
||||
case CONSISTS_OF:
|
||||
return new ConsistsOfManagement();
|
||||
|
||||
default:
|
||||
throw new ResourceRegistryException(String.format(
|
||||
"%s is not querable", querableType.toString()));
|
||||
}
|
||||
}
|
||||
*/
|
||||
* @SuppressWarnings("rawtypes") public static ERManagement
|
||||
* getERManagement(AccessType querableType) throws ResourceRegistryException {
|
||||
* switch (querableType) { case FACET: return new FacetManagement();
|
||||
*
|
||||
* case RESOURCE: return new ResourceManagement();
|
||||
*
|
||||
* case IS_RELATED_TO: return new IsRelatedToManagement();
|
||||
*
|
||||
* case CONSISTS_OF: return new ConsistsOfManagement();
|
||||
*
|
||||
* default: throw new ResourceRegistryException(String.format(
|
||||
* "%s is not querable", querableType.toString())); } }
|
||||
*/
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ERManagement getERManagement(String type)
|
||||
throws ResourceRegistryException {
|
||||
public static ERManagement getERManagement(String type) throws ResourceRegistryException {
|
||||
|
||||
OClass oClass = SchemaManagementImpl.getTypeSchema(type, null);
|
||||
ERManagement erManagement = null;
|
||||
|
@ -76,8 +66,7 @@ public class ERManagementUtility {
|
|||
}
|
||||
|
||||
if (erManagement == null) {
|
||||
throw new ResourceRegistryException(String.format(
|
||||
"%s is not querable", type.toString()));
|
||||
throw new ResourceRegistryException(String.format("%s is not querable", type.toString()));
|
||||
}
|
||||
|
||||
erManagement.setElementType(type);
|
||||
|
@ -85,24 +74,21 @@ public class ERManagementUtility {
|
|||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static ERManagement getERManagement(OrientGraph orientGraph,
|
||||
Element element) throws ResourceRegistryException {
|
||||
private static ERManagement getERManagement(OrientGraph orientGraph, Element element)
|
||||
throws ResourceRegistryException {
|
||||
if (element instanceof Vertex) {
|
||||
return getEntityManagement(orientGraph,
|
||||
(Vertex) element);
|
||||
return getEntityManagement(orientGraph, (Vertex) element);
|
||||
} else if (element instanceof Edge) {
|
||||
return getRelationManagement(orientGraph,
|
||||
(Edge) element);
|
||||
return getRelationManagement(orientGraph, (Edge) element);
|
||||
}
|
||||
throw new ResourceRegistryException(String.format(
|
||||
"%s is not a %s nor a %s", element.getClass().getSimpleName(),
|
||||
throw new ResourceRegistryException(String.format("%s is not a %s nor a %s", element.getClass().getSimpleName(),
|
||||
Entity.NAME, Relation.NAME));
|
||||
}
|
||||
|
||||
public static Element getAnyElementByUUID(UUID uuid) throws ERNotFoundException, ResourceRegistryException {
|
||||
try{
|
||||
try {
|
||||
return Utility.getElementByUUIDAsAdmin(null, uuid, Vertex.class);
|
||||
}catch (ERNotFoundException e) {
|
||||
} catch (ERNotFoundException e) {
|
||||
return Utility.getElementByUUIDAsAdmin(null, uuid, Edge.class);
|
||||
} catch (ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
@ -111,11 +97,11 @@ public class ERManagementUtility {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static Element getAnyElementByUUID(OrientGraph orientGraph, UUID uuid) throws ERNotFoundException, ResourceRegistryException {
|
||||
try{
|
||||
private static Element getAnyElementByUUID(OrientGraph orientGraph, UUID uuid)
|
||||
throws ERNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
return Utility.getElementByUUID(orientGraph, null, uuid, Vertex.class);
|
||||
}catch (ERNotFoundException e) {
|
||||
} catch (ERNotFoundException e) {
|
||||
return Utility.getElementByUUID(orientGraph, null, uuid, Edge.class);
|
||||
} catch (ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
@ -125,37 +111,39 @@ public class ERManagementUtility {
|
|||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ERManagement getERManagementFromUUID(OrientGraph orientGraph,
|
||||
UUID uuid) throws ResourceRegistryException {
|
||||
public static ERManagement getERManagementFromUUID(OrientGraph orientGraph, UUID uuid)
|
||||
throws ResourceRegistryException {
|
||||
Element element;
|
||||
try {
|
||||
element = getAnyElementByUUID(orientGraph, uuid);
|
||||
return getERManagement(orientGraph, element);
|
||||
} catch (Exception e) {
|
||||
throw new ResourceRegistryException(String.format(
|
||||
"%s does not belong to an %s nor to a %s",
|
||||
uuid.toString(), Entity.NAME, Relation.NAME));
|
||||
throw new ResourceRegistryException(String.format("%s does not belong to an %s nor to a %s",
|
||||
uuid.toString(), Entity.NAME, Relation.NAME));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static EntityManagement getEntityManagement(OrientGraph orientGraph,
|
||||
Vertex vertex) throws ResourceRegistryException {
|
||||
public static EntityManagement getEntityManagement(OrientGraph orientGraph, Vertex vertex)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
if(orientGraph==null){
|
||||
throw new ResourceRegistryException(OrientGraph.class.getSimpleName() + "instance is null. This is really strage please contact the administrator.");
|
||||
if (orientGraph == null) {
|
||||
throw new ResourceRegistryException(OrientGraph.class.getSimpleName()
|
||||
+ "instance is null. This is really strage please contact the administrator.");
|
||||
}
|
||||
|
||||
if(vertex==null){
|
||||
throw new ResourceRegistryException(Vertex.class.getSimpleName() + "instance is null. This is really strage please contact the administrator.");
|
||||
if (vertex == null) {
|
||||
throw new ResourceRegistryException(Vertex.class.getSimpleName()
|
||||
+ "instance is null. This is really strage please contact the administrator.");
|
||||
}
|
||||
|
||||
OrientVertexType orientVertexType = null;
|
||||
try {
|
||||
orientVertexType = ((OrientVertex) vertex).getType();
|
||||
}catch (Exception e) {
|
||||
String error = String.format("Unable to detect type of %s. This is really strage please contact the administrator.", vertex.toString());
|
||||
} catch (Exception e) {
|
||||
String error = String.format(
|
||||
"Unable to detect type of %s. This is really strage please contact the administrator.",
|
||||
vertex.toString());
|
||||
logger.error(error, e);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
@ -166,10 +154,8 @@ public class ERManagementUtility {
|
|||
} else if (orientVertexType.isSubClassOf(Facet.NAME)) {
|
||||
entityManagement = new FacetManagement(orientGraph);
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. "
|
||||
+ "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.", vertex, Resource.NAME,
|
||||
Facet.NAME);
|
||||
String error = String.format("{%s is not a %s nor a %s. " + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.", vertex, Resource.NAME, Facet.NAME);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
entityManagement.setElement(vertex);
|
||||
|
|
|
@ -66,7 +66,7 @@ public abstract class EntityManagement<E extends Entity> extends
|
|||
String id = edge.getId().toString();
|
||||
RelationManagement relationManagement = relationManagements.get(id);
|
||||
if(relationManagement==null) {
|
||||
relationManagement = RelationManagement.getRelationManagement(orientGraph, edge);
|
||||
relationManagement = ERManagementUtility.getRelationManagement(orientGraph, edge);
|
||||
}
|
||||
return relationManagement;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
|
||||
for (Edge edge : edges) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
RelationManagement relationManagement = RelationManagement.getRelationManagement(orientGraph, edge);
|
||||
RelationManagement relationManagement = ERManagementUtility.getRelationManagement(orientGraph, edge);
|
||||
relationManagement.setSourceEntityManagement(this);
|
||||
|
||||
if (relationManagement instanceof ConsistsOfManagement) {
|
||||
|
|
|
@ -21,8 +21,6 @@ import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveCo
|
|||
import org.gcube.informationsystem.model.entity.Entity;
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.relation.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
|
@ -44,7 +42,6 @@ import com.tinkerpop.blueprints.Edge;
|
|||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
/**
|
||||
|
@ -162,6 +159,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
String id = source.getId().toString();
|
||||
|
||||
JSONObject sourceResource = visitedSourceResources.get(id);
|
||||
|
||||
if (sourceResource == null) {
|
||||
ResourceManagement resourceManagement = (ResourceManagement) ERManagementUtility
|
||||
.getEntityManagement(orientGraph, source);
|
||||
|
@ -307,17 +305,16 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
|
||||
|
||||
/*
|
||||
public void setSourceUUID(UUID sourceUUID) throws ResourceRegistryException {
|
||||
this.sourceEntityManagemen = newSourceEntityManagement();
|
||||
this.sourceEntityManagemen.setUUID(sourceUUID);
|
||||
}
|
||||
|
||||
public void setTargetUUID(UUID targetUUID) throws ResourceRegistryException {
|
||||
this.targetEntityManagemen = newTargetEntityManagement();
|
||||
this.targetEntityManagemen.setUUID(targetUUID);
|
||||
|
||||
}
|
||||
*/
|
||||
* public void setSourceUUID(UUID sourceUUID) throws ResourceRegistryException {
|
||||
* this.sourceEntityManagemen = newSourceEntityManagement();
|
||||
* this.sourceEntityManagemen.setUUID(sourceUUID); }
|
||||
*
|
||||
* public void setTargetUUID(UUID targetUUID) throws ResourceRegistryException {
|
||||
* this.targetEntityManagemen = newTargetEntityManagement();
|
||||
* this.targetEntityManagemen.setUUID(targetUUID);
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected Edge reallyUpdate() throws ResourceRegistryException {
|
||||
|
@ -372,22 +369,22 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
}
|
||||
|
||||
switch (addConstraint) {
|
||||
case propagate:
|
||||
/*
|
||||
* The relation must be added only in the case the target vertex must be added.
|
||||
* Otherwise we have a relation which point to an entity outside of the context.
|
||||
*/
|
||||
getTargetEntityManagemen().internalAddToContext();
|
||||
case propagate:
|
||||
/*
|
||||
* The relation must be added only in the case the target vertex must be added.
|
||||
* Otherwise we have a relation which point to an entity outside of the context.
|
||||
*/
|
||||
getTargetEntityManagemen().internalAddToContext();
|
||||
|
||||
ContextUtility.addToActualContext(orientGraph, getElement());
|
||||
ContextUtility.addToActualContext(orientGraph, getElement());
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case unpropagate:
|
||||
break;
|
||||
case unpropagate:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -409,17 +406,12 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
}
|
||||
|
||||
/*
|
||||
protected boolean removeFromContextTargetVertex(Vertex target) throws ResourceRegistryException {
|
||||
EntityManagement entityManagement = EntityManagement.getEntityManagement(orientGraph, target);
|
||||
if (entityManagement != null) {
|
||||
entityManagement.internalRemoveFromContext();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
* protected boolean removeFromContextTargetVertex(Vertex target) throws
|
||||
* ResourceRegistryException { EntityManagement entityManagement =
|
||||
* EntityManagement.getEntityManagement(orientGraph, target); if
|
||||
* (entityManagement != null) { entityManagement.internalRemoveFromContext();
|
||||
* return true; } else { return false; } }
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected boolean reallyRemoveFromContext() throws ContextException, ResourceRegistryException {
|
||||
|
@ -458,81 +450,50 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
ContextUtility.removeFromActualContext(orientGraph, element);
|
||||
|
||||
switch (removeConstraint) {
|
||||
case cascade:
|
||||
getTargetEntityManagemen().internalRemoveFromContext();
|
||||
break;
|
||||
case cascade:
|
||||
getTargetEntityManagemen().internalRemoveFromContext();
|
||||
break;
|
||||
|
||||
case cascadeWhenOrphan:
|
||||
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
|
||||
case cascadeWhenOrphan:
|
||||
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
|
||||
|
||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
int count = 0;
|
||||
OrientEdge edge = null;
|
||||
while (iterator.hasNext()) {
|
||||
edge = (OrientEdge) iterator.next();
|
||||
OrientEdge thisOrientEdge = (OrientEdge) getElement();
|
||||
if (edge.compareTo(thisOrientEdge) != 0) {
|
||||
if (thisOrientEdge.getOutVertex().compareTo(edge.getOutVertex()) != 0) {
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* else{ ContextUtility.removeFromActualContext(orientGraph, edge); }
|
||||
*/
|
||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
int count = 0;
|
||||
OrientEdge edge = null;
|
||||
while (iterator.hasNext()) {
|
||||
edge = (OrientEdge) iterator.next();
|
||||
OrientEdge thisOrientEdge = (OrientEdge) getElement();
|
||||
if (edge.compareTo(thisOrientEdge) != 0) {
|
||||
if (thisOrientEdge.getOutVertex().compareTo(edge.getOutVertex()) != 0) {
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* else{ ContextUtility.removeFromActualContext(orientGraph, edge); }
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
logger.trace(
|
||||
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from current context.",
|
||||
element, target, edge, removeConstraint);
|
||||
} else {
|
||||
getTargetEntityManagemen().internalRemoveFromContext();
|
||||
}
|
||||
break;
|
||||
if (count > 0) {
|
||||
logger.trace(
|
||||
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from current context.",
|
||||
element, target, edge, removeConstraint);
|
||||
} else {
|
||||
getTargetEntityManagemen().internalRemoveFromContext();
|
||||
}
|
||||
break;
|
||||
|
||||
case keep:
|
||||
break;
|
||||
case keep:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static RelationManagement getRelationManagement(OrientGraph orientGraph, Edge edge)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
if (orientGraph == null) {
|
||||
throw new ResourceRegistryException(OrientGraph.class.getSimpleName()
|
||||
+ "instance is null. This is really strage please contact the administrator.");
|
||||
}
|
||||
|
||||
if (edge == null) {
|
||||
throw new ResourceRegistryException(Edge.class.getSimpleName()
|
||||
+ "instance is null. This is really strage please contact the administrator.");
|
||||
}
|
||||
|
||||
OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
|
||||
RelationManagement relationManagement = null;
|
||||
if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(orientGraph);
|
||||
} else if (orientEdgeType.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(orientGraph);
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. " + "This is really strange ad should not occur. "
|
||||
+ "Please Investigate it.", edge, ConsistsOf.NAME, IsRelatedTo.NAME);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
relationManagement.setElement(edge);
|
||||
return relationManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
|
||||
|
@ -567,26 +528,26 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
element.remove();
|
||||
|
||||
switch (removeConstraint) {
|
||||
case cascade:
|
||||
case cascade:
|
||||
getTargetEntityManagemen().internalDelete();
|
||||
break;
|
||||
|
||||
case cascadeWhenOrphan:
|
||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
|
||||
target, removeConstraint);
|
||||
} else {
|
||||
getTargetEntityManagemen().internalDelete();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case cascadeWhenOrphan:
|
||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
|
||||
target, removeConstraint);
|
||||
} else {
|
||||
getTargetEntityManagemen().internalDelete();
|
||||
}
|
||||
break;
|
||||
case keep:
|
||||
break;
|
||||
|
||||
case keep:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -631,7 +592,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
if (postFilterPolymorphic && edge.getLabel().compareTo(erType) != 0) {
|
||||
continue;
|
||||
}
|
||||
RelationManagement relationManagement = getRelationManagement(orientGraph, edge);
|
||||
RelationManagement relationManagement = ERManagementUtility.getRelationManagement(orientGraph, edge);
|
||||
visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);
|
||||
}
|
||||
return visitedSourceResources.values();
|
||||
|
|
Loading…
Reference in New Issue