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:
Luca Frosini 2017-11-17 15:04:15 +00:00
parent 6edb78bdfd
commit 99d0e8e04f
4 changed files with 154 additions and 207 deletions

View File

@ -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,17 +74,14 @@ 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));
}
@ -111,8 +97,8 @@ public class ERManagementUtility {
}
}
private static Element getAnyElementByUUID(OrientGraph orientGraph, UUID uuid) throws ERNotFoundException, ResourceRegistryException {
private static Element getAnyElementByUUID(OrientGraph orientGraph, UUID uuid)
throws ERNotFoundException, ResourceRegistryException {
try {
return Utility.getElementByUUID(orientGraph, null, uuid, Vertex.class);
} catch (ERNotFoundException 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",
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.");
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.");
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());
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);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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,16 +305,15 @@ 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
@ -409,18 +406,13 @@ 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 {
getElement();
@ -502,37 +494,6 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
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,
@ -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();