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:
parent
008f621677
commit
2d7805b132
|
@ -59,7 +59,6 @@ import com.tinkerpop.blueprints.Element;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
|
||||||
import com.tinkerpop.blueprints.util.StringFactory;
|
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(AT);
|
||||||
this.ignoreStartWithKeys.add(UNDERSCORE);
|
this.ignoreStartWithKeys.add(UNDERSCORE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ERManagement(AccessType accessType, OrientGraph orientGraph) {
|
protected ERManagement(AccessType accessType, OrientGraph orientGraph) {
|
||||||
|
@ -274,7 +272,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
reallyUpdate();
|
reallyUpdate();
|
||||||
|
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
((OrientVertex) element).save();
|
((OrientElement) element).save();
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
|
@ -306,8 +304,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
public boolean internalAddToContext() throws ContextException, ResourceRegistryException {
|
public boolean internalAddToContext() throws ContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
boolean ret = reallyAddToContext();
|
boolean ret = reallyAddToContext();
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(getElement());
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
((OrientElement) getElement()).save();
|
((OrientElement) element).save();
|
||||||
return ret && true;
|
return ret && true;
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -323,7 +321,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
try {
|
try {
|
||||||
boolean ret = reallyRemoveFromContext();
|
boolean ret = reallyRemoveFromContext();
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
((OrientVertex) element).save();
|
((OrientElement) element).save();
|
||||||
return ret && true;
|
return ret && true;
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -193,9 +193,7 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
protected boolean reallyRemoveFromContext() throws ContextException,
|
protected boolean reallyRemoveFromContext() throws ContextException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
|
|
||||||
ContextUtility.removeFromActualContext(orientGraph, getElement());
|
Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
|
||||||
|
|
||||||
Iterable<Edge> edges = element.getEdges(Direction.OUT);
|
|
||||||
|
|
||||||
for (Edge edge : edges) {
|
for (Edge edge : edges) {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -203,6 +201,8 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
relationManagement.internalRemoveFromContext();
|
relationManagement.internalRemoveFromContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContextUtility.removeFromActualContext(orientGraph, getElement());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.informationsystem.resourceregistry.er.entity;
|
package org.gcube.informationsystem.resourceregistry.er.entity;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
|
@ -53,8 +53,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
protected final Class<? extends Entity> targetEntityClass;
|
protected final Class<? extends Entity> targetEntityClass;
|
||||||
|
|
||||||
private S sourceEntityManagemen;
|
private S sourceEntityManagement;
|
||||||
private T targetEntityManagemen;
|
private T targetEntityManagement;
|
||||||
|
|
||||||
protected RelationManagement(AccessType accessType) {
|
protected RelationManagement(AccessType accessType) {
|
||||||
super(accessType);
|
super(accessType);
|
||||||
|
@ -81,8 +81,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceEntityManagemen = null;
|
sourceEntityManagement = null;
|
||||||
targetEntityManagemen = null;
|
targetEntityManagement = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,31 +92,31 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected S getSourceEntityManagemen() throws ResourceRegistryException {
|
protected S getSourceEntityManagement() throws ResourceRegistryException {
|
||||||
if (sourceEntityManagemen == null) {
|
if (sourceEntityManagement == null) {
|
||||||
Vertex source = getElement().getVertex(Direction.OUT);
|
Vertex source = getElement().getVertex(Direction.OUT);
|
||||||
sourceEntityManagemen = newSourceEntityManagement();
|
sourceEntityManagement = newSourceEntityManagement();
|
||||||
sourceEntityManagemen.setElement(source);
|
sourceEntityManagement.setElement(source);
|
||||||
}
|
}
|
||||||
return sourceEntityManagemen;
|
return sourceEntityManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public T getTargetEntityManagemen() throws ResourceRegistryException {
|
public T getTargetEntityManagement() throws ResourceRegistryException {
|
||||||
if (targetEntityManagemen == null) {
|
if (targetEntityManagement == null) {
|
||||||
Vertex target = getElement().getVertex(Direction.IN);
|
Vertex target = getElement().getVertex(Direction.IN);
|
||||||
targetEntityManagemen = newTargetEntityManagement();
|
targetEntityManagement = newTargetEntityManagement();
|
||||||
targetEntityManagemen.setElement(target);
|
targetEntityManagement.setElement(target);
|
||||||
}
|
}
|
||||||
return targetEntityManagemen;
|
return targetEntityManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSourceEntityManagement(S sourceEntityManagement) {
|
public void setSourceEntityManagement(S sourceEntityManagement) {
|
||||||
this.sourceEntityManagemen = sourceEntityManagement;
|
this.sourceEntityManagement = sourceEntityManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTargetEntityManagement(T targetEntityManagement) {
|
public void setTargetEntityManagement(T targetEntityManagement) {
|
||||||
this.targetEntityManagemen = targetEntityManagement;
|
this.targetEntityManagement = targetEntityManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -134,11 +134,11 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (includeSource) {
|
if (includeSource) {
|
||||||
relation.put(Relation.SOURCE_PROPERTY, getSourceEntityManagemen().serializeSelfOnly());
|
relation.put(Relation.SOURCE_PROPERTY, getSourceEntityManagement().serializeSelfOnly());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeTarget) {
|
if (includeTarget) {
|
||||||
relation.put(Relation.TARGET_PROPERTY, getTargetEntityManagemen().serializeAsJson());
|
relation.put(Relation.TARGET_PROPERTY, getTargetEntityManagement().serializeAsJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
|
@ -196,7 +196,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
@Override
|
@Override
|
||||||
protected Edge reallyCreate() throws ResourceRegistryException {
|
protected Edge reallyCreate() throws ResourceRegistryException {
|
||||||
|
|
||||||
if (sourceEntityManagemen == null) {
|
if (sourceEntityManagement == null) {
|
||||||
|
|
||||||
if (!jsonNode.has(Relation.SOURCE_PROPERTY)) {
|
if (!jsonNode.has(Relation.SOURCE_PROPERTY)) {
|
||||||
throw new ResourceRegistryException("Error while creating relation. No source definition found");
|
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
|
UUID sourceUUID = org.gcube.informationsystem.impl.utils.Utility
|
||||||
.getUUIDFromJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
.getUUIDFromJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
||||||
|
|
||||||
sourceEntityManagemen = newSourceEntityManagement();
|
sourceEntityManagement = newSourceEntityManagement();
|
||||||
sourceEntityManagemen.setUUID(sourceUUID);
|
sourceEntityManagement.setUUID(sourceUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetEntityManagemen == null) {
|
if (targetEntityManagement == null) {
|
||||||
targetEntityManagemen = newTargetEntityManagement();
|
targetEntityManagement = newTargetEntityManagement();
|
||||||
|
|
||||||
if (!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
if (!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
||||||
throw new ResourceRegistryException("Error while creating " + erType + ". No target definition found");
|
throw new ResourceRegistryException("Error while creating " + erType + ". No target definition found");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
targetEntityManagemen.setJSON(jsonNode.get(Relation.TARGET_PROPERTY));
|
targetEntityManagement.setJSON(jsonNode.get(Relation.TARGET_PROPERTY));
|
||||||
} catch (SchemaException e) {
|
} catch (SchemaException e) {
|
||||||
StringWriter errorMessage = new StringWriter();
|
StringWriter errorMessage = new StringWriter();
|
||||||
errorMessage.append("A ");
|
errorMessage.append("A ");
|
||||||
errorMessage.append(erType);
|
errorMessage.append(erType);
|
||||||
errorMessage.append(" can be only created beetween ");
|
errorMessage.append(" can be only created beetween ");
|
||||||
errorMessage.append(sourceEntityManagemen.getAccessType().getName());
|
errorMessage.append(sourceEntityManagement.getAccessType().getName());
|
||||||
errorMessage.append(" and ");
|
errorMessage.append(" and ");
|
||||||
errorMessage.append(targetEntityManagemen.getAccessType().getName());
|
errorMessage.append(targetEntityManagement.getAccessType().getName());
|
||||||
throw new ResourceRegistryException(errorMessage.toString(), e);
|
throw new ResourceRegistryException(errorMessage.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
targetEntityManagemen.getElement();
|
targetEntityManagement.getElement();
|
||||||
} catch (Exception e) {
|
} 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
|
// end of if-else to be revisited
|
||||||
|
|
||||||
logger.trace("Creating {} beetween {} -> {}", erType, getSourceEntityManagemen().serialize(),
|
logger.trace("Creating {} beetween {} -> {}", erType, getSourceEntityManagement().serialize(),
|
||||||
getTargetEntityManagemen().serialize());
|
getTargetEntityManagement().serialize());
|
||||||
|
|
||||||
Vertex source = (Vertex) getSourceEntityManagemen().getElement();
|
Vertex source = (Vertex) getSourceEntityManagement().getElement();
|
||||||
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
|
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||||
|
|
||||||
element = orientGraph.addEdge(null, source, target, erType);
|
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.
|
* 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.
|
* Otherwise we have a relation which point to an entity outside of the context.
|
||||||
*/
|
*/
|
||||||
getTargetEntityManagemen().internalAddToContext();
|
getTargetEntityManagement().internalAddToContext();
|
||||||
|
|
||||||
ContextUtility.addToActualContext(orientGraph, getElement());
|
ContextUtility.addToActualContext(orientGraph, getElement());
|
||||||
|
|
||||||
|
@ -395,10 +395,10 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
/* Adding source to Context */
|
/* Adding source to Context */
|
||||||
getSourceEntityManagemen().internalAddToContext();
|
getSourceEntityManagement().internalAddToContext();
|
||||||
|
|
||||||
/* Adding target to Context */
|
/* Adding target to Context */
|
||||||
getTargetEntityManagemen().internalAddToContext();
|
getTargetEntityManagement().internalAddToContext();
|
||||||
|
|
||||||
ContextUtility.addToActualContext(orientGraph, getElement());
|
ContextUtility.addToActualContext(orientGraph, getElement());
|
||||||
|
|
||||||
|
@ -451,11 +451,11 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
switch (removeConstraint) {
|
switch (removeConstraint) {
|
||||||
case cascade:
|
case cascade:
|
||||||
getTargetEntityManagemen().internalRemoveFromContext();
|
getTargetEntityManagement().internalRemoveFromContext();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cascadeWhenOrphan:
|
case cascadeWhenOrphan:
|
||||||
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
|
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||||
|
|
||||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||||
Iterator<Edge> iterator = iterable.iterator();
|
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.",
|
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from current context.",
|
||||||
element, target, edge, removeConstraint);
|
element, target, edge, removeConstraint);
|
||||||
} else {
|
} else {
|
||||||
getTargetEntityManagemen().internalRemoveFromContext();
|
getTargetEntityManagement().internalRemoveFromContext();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -524,12 +524,12 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true), removeConstraint);
|
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true), removeConstraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex target = (Vertex) getTargetEntityManagemen().getElement();
|
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||||
element.remove();
|
element.remove();
|
||||||
|
|
||||||
switch (removeConstraint) {
|
switch (removeConstraint) {
|
||||||
case cascade:
|
case cascade:
|
||||||
getTargetEntityManagemen().internalDelete();
|
getTargetEntityManagement().internalDelete();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cascadeWhenOrphan:
|
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,
|
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
|
||||||
target, removeConstraint);
|
target, removeConstraint);
|
||||||
} else {
|
} else {
|
||||||
getTargetEntityManagemen().internalDelete();
|
getTargetEntityManagement().internalDelete();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -558,8 +558,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
try {
|
try {
|
||||||
orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.WRITER, forceAdmin);
|
orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.WRITER, forceAdmin);
|
||||||
|
|
||||||
getSourceEntityManagemen().setUUID(sourceUUID);
|
getSourceEntityManagement().setUUID(sourceUUID);
|
||||||
getTargetEntityManagemen().setUUID(targetUUID);
|
getTargetEntityManagement().setUUID(targetUUID);
|
||||||
|
|
||||||
element = reallyCreate();
|
element = reallyCreate();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue