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@158632 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-11-17 16:34:29 +00:00
parent 008f621677
commit 2d7805b132
4 changed files with 50 additions and 55 deletions

View File

@ -59,7 +59,6 @@ import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientElement;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import com.tinkerpop.blueprints.util.StringFactory;
/**
@ -115,7 +114,6 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
this.ignoreStartWithKeys.add(AT);
this.ignoreStartWithKeys.add(UNDERSCORE);
}
protected ERManagement(AccessType accessType, OrientGraph orientGraph) {
@ -274,7 +272,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
reallyUpdate();
HeaderUtility.updateModifiedByAndLastUpdate(element);
((OrientVertex) element).save();
((OrientElement) element).save();
return element;
}catch (ResourceRegistryException e) {
@ -306,8 +304,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
public boolean internalAddToContext() throws ContextException, ResourceRegistryException {
try {
boolean ret = reallyAddToContext();
HeaderUtility.updateModifiedByAndLastUpdate(getElement());
((OrientElement) getElement()).save();
HeaderUtility.updateModifiedByAndLastUpdate(element);
((OrientElement) element).save();
return ret && true;
}catch (ResourceRegistryException e) {
throw e;
@ -323,7 +321,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
try {
boolean ret = reallyRemoveFromContext();
HeaderUtility.updateModifiedByAndLastUpdate(element);
((OrientVertex) element).save();
((OrientElement) element).save();
return ret && true;
}catch (ResourceRegistryException e) {
throw e;

View File

@ -193,15 +193,15 @@ public abstract class EntityManagement<E extends Entity> extends
protected boolean reallyRemoveFromContext() throws ContextException,
ResourceRegistryException {
ContextUtility.removeFromActualContext(orientGraph, getElement());
Iterable<Edge> edges = element.getEdges(Direction.OUT);
Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
for (Edge edge : edges) {
@SuppressWarnings("rawtypes")
RelationManagement relationManagement = getRelationManagement(edge);
relationManagement.internalRemoveFromContext();
}
ContextUtility.removeFromActualContext(orientGraph, getElement());
return true;
}

View File

@ -1,6 +1,3 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.er.entity;
import java.util.Iterator;

View File

@ -53,8 +53,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
protected final Class<? extends Entity> targetEntityClass;
private S sourceEntityManagemen;
private T targetEntityManagemen;
private S sourceEntityManagement;
private T targetEntityManagement;
protected RelationManagement(AccessType accessType) {
super(accessType);
@ -81,8 +81,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
break;
}
sourceEntityManagemen = null;
targetEntityManagemen = null;
sourceEntityManagement = null;
targetEntityManagement = null;
}
@ -92,31 +92,31 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
}
@SuppressWarnings("unchecked")
protected S getSourceEntityManagemen() throws ResourceRegistryException {
if (sourceEntityManagemen == null) {
protected S getSourceEntityManagement() throws ResourceRegistryException {
if (sourceEntityManagement == null) {
Vertex source = getElement().getVertex(Direction.OUT);
sourceEntityManagemen = newSourceEntityManagement();
sourceEntityManagemen.setElement(source);
sourceEntityManagement = newSourceEntityManagement();
sourceEntityManagement.setElement(source);
}
return sourceEntityManagemen;
return sourceEntityManagement;
}
@SuppressWarnings("unchecked")
public T getTargetEntityManagemen() throws ResourceRegistryException {
if (targetEntityManagemen == null) {
public T getTargetEntityManagement() throws ResourceRegistryException {
if (targetEntityManagement == null) {
Vertex target = getElement().getVertex(Direction.IN);
targetEntityManagemen = newTargetEntityManagement();
targetEntityManagemen.setElement(target);
targetEntityManagement = newTargetEntityManagement();
targetEntityManagement.setElement(target);
}
return targetEntityManagemen;
return targetEntityManagement;
}
public void setSourceEntityManagement(S sourceEntityManagement) {
this.sourceEntityManagemen = sourceEntityManagement;
this.sourceEntityManagement = sourceEntityManagement;
}
public void setTargetEntityManagement(T targetEntityManagement) {
this.targetEntityManagemen = targetEntityManagement;
this.targetEntityManagement = targetEntityManagement;
}
@Override
@ -134,11 +134,11 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
try {
if (includeSource) {
relation.put(Relation.SOURCE_PROPERTY, getSourceEntityManagemen().serializeSelfOnly());
relation.put(Relation.SOURCE_PROPERTY, getSourceEntityManagement().serializeSelfOnly());
}
if (includeTarget) {
relation.put(Relation.TARGET_PROPERTY, getTargetEntityManagemen().serializeAsJson());
relation.put(Relation.TARGET_PROPERTY, getTargetEntityManagement().serializeAsJson());
}
} catch (ResourceRegistryException e) {
@ -196,7 +196,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
@Override
protected Edge reallyCreate() throws ResourceRegistryException {
if (sourceEntityManagemen == null) {
if (sourceEntityManagement == null) {
if (!jsonNode.has(Relation.SOURCE_PROPERTY)) {
throw new ResourceRegistryException("Error while creating relation. No source definition found");
@ -205,34 +205,34 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
UUID sourceUUID = org.gcube.informationsystem.impl.utils.Utility
.getUUIDFromJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
sourceEntityManagemen = newSourceEntityManagement();
sourceEntityManagemen.setUUID(sourceUUID);
sourceEntityManagement = newSourceEntityManagement();
sourceEntityManagement.setUUID(sourceUUID);
}
if (targetEntityManagemen == null) {
targetEntityManagemen = newTargetEntityManagement();
if (targetEntityManagement == null) {
targetEntityManagement = newTargetEntityManagement();
if (!jsonNode.has(Relation.TARGET_PROPERTY)) {
throw new ResourceRegistryException("Error while creating " + erType + ". No target definition found");
}
try {
targetEntityManagemen.setJSON(jsonNode.get(Relation.TARGET_PROPERTY));
targetEntityManagement.setJSON(jsonNode.get(Relation.TARGET_PROPERTY));
} catch (SchemaException e) {
StringWriter errorMessage = new StringWriter();
errorMessage.append("A ");
errorMessage.append(erType);
errorMessage.append(" can be only created beetween ");
errorMessage.append(sourceEntityManagemen.getAccessType().getName());
errorMessage.append(sourceEntityManagement.getAccessType().getName());
errorMessage.append(" and ");
errorMessage.append(targetEntityManagemen.getAccessType().getName());
errorMessage.append(targetEntityManagement.getAccessType().getName());
throw new ResourceRegistryException(errorMessage.toString(), e);
}
try {
targetEntityManagemen.getElement();
targetEntityManagement.getElement();
} catch (Exception e) {
targetEntityManagemen.internalCreate();
targetEntityManagement.internalCreate();
}
}
@ -277,11 +277,11 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
*/
// end of if-else to be revisited
logger.trace("Creating {} beetween {} -> {}", erType, getSourceEntityManagemen().serialize(),
getTargetEntityManagemen().serialize());
logger.trace("Creating {} beetween {} -> {}", erType, getSourceEntityManagement().serialize(),
getTargetEntityManagement().serialize());
Vertex source = (Vertex) getSourceEntityManagemen().getElement();
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
Vertex source = (Vertex) getSourceEntityManagement().getElement();
Vertex target = (Vertex) getTargetEntityManagement().getElement();
element = orientGraph.addEdge(null, source, target, erType);
@ -374,7 +374,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
* 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();
getTargetEntityManagement().internalAddToContext();
ContextUtility.addToActualContext(orientGraph, getElement());
@ -395,10 +395,10 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
getElement();
/* Adding source to Context */
getSourceEntityManagemen().internalAddToContext();
getSourceEntityManagement().internalAddToContext();
/* Adding target to Context */
getTargetEntityManagemen().internalAddToContext();
getTargetEntityManagement().internalAddToContext();
ContextUtility.addToActualContext(orientGraph, getElement());
@ -451,11 +451,11 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
switch (removeConstraint) {
case cascade:
getTargetEntityManagemen().internalRemoveFromContext();
getTargetEntityManagement().internalRemoveFromContext();
break;
case cascadeWhenOrphan:
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
Vertex target = (Vertex) getTargetEntityManagement().getElement();
Iterable<Edge> iterable = target.getEdges(Direction.IN);
Iterator<Edge> iterator = iterable.iterator();
@ -480,7 +480,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from current context.",
element, target, edge, removeConstraint);
} else {
getTargetEntityManagemen().internalRemoveFromContext();
getTargetEntityManagement().internalRemoveFromContext();
}
break;
@ -524,12 +524,12 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true), removeConstraint);
}
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
Vertex target = (Vertex) getTargetEntityManagement().getElement();
element.remove();
switch (removeConstraint) {
case cascade:
getTargetEntityManagemen().internalDelete();
getTargetEntityManagement().internalDelete();
break;
case cascadeWhenOrphan:
@ -539,7 +539,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
target, removeConstraint);
} else {
getTargetEntityManagemen().internalDelete();
getTargetEntityManagement().internalDelete();
}
break;
@ -558,8 +558,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
try {
orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.WRITER, forceAdmin);
getSourceEntityManagemen().setUUID(sourceUUID);
getTargetEntityManagemen().setUUID(targetUUID);
getSourceEntityManagement().setUUID(sourceUUID);
getTargetEntityManagement().setUUID(targetUUID);
element = reallyCreate();