Added code (and commented) to return also target Resource on Resource marshalling.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@135176 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-12-01 16:17:03 +00:00
parent 78213468eb
commit 6d0d99f0a8
3 changed files with 66 additions and 19 deletions

View File

@ -21,7 +21,7 @@ import org.gcube.informationsystem.impl.utils.Entities;
import org.gcube.informationsystem.model.embedded.Embedded;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.embedded.RelationProperty;
import org.gcube.informationsystem.model.embedded.RelationProperty.ReferentiaIntegrity;
import org.gcube.informationsystem.model.embedded.RelationProperty.ReferentialIntegrity;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
@ -61,6 +61,7 @@ import com.tinkerpop.blueprints.Element;
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;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
@ -1169,33 +1170,43 @@ public class EntityManagementImpl implements EntityManagement {
true);
JSONArray consistsOfArray = new JSONArray();
/*
JSONArray isRelatedToArray = new JSONArray();
*/
Iterable<Edge> edges = vertex.getEdges(Direction.OUT);
for (Edge edge : edges) {
String edgeType = edge.getLabel();
try {
SchemaManagementImpl.getTypeSchema(orientGraph, edgeType,
ConsistsOf.NAME);
} catch (SchemaNotFoundException e) {
// This not an ConsistsOf Edge. it will be skipped
continue;
}
OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
JSONObject jsonObjectEdge = Utility.toJsonObject((OrientEdge) edge,
true);
Vertex facetVertex = edge.getVertex(Direction.IN);
Vertex targetVertex = edge.getVertex(Direction.IN);
jsonObjectEdge.put(Relation.TARGET_PROPERTY,
Utility.toJsonObject((OrientVertex) facetVertex, true));
Utility.toJsonObject((OrientVertex) targetVertex, true));
if(orientEdgeType.isSubClassOf(ConsistsOf.NAME)){
consistsOfArray.put(jsonObjectEdge);
}
/*
else if(orientEdgeType.isSubClassOf(IsRelatedTo.NAME)){
isRelatedToArray.put(jsonObjectEdge);
}
*/
}
jsonObject.put(lowerCaseFirstCharacter(ConsistsOf.NAME),
consistsOfArray);
/*
jsonObject.put(lowerCaseFirstCharacter(IsRelatedTo.NAME),
isRelatedToArray);
*/
return jsonObject.toString();
}
@ -1390,8 +1401,8 @@ public class EntityManagementImpl implements EntityManagement {
//+ rid
+ ") "
+ "WHERE ("
+ Relation.RELATION_PROPERTY + "." + RelationProperty.REFERENTIAL_INTEGRITY + " = '" + ReferentiaIntegrity.onDeleteCascade.toString() + "' OR ("
+ Relation.RELATION_PROPERTY + "." + RelationProperty.REFERENTIAL_INTEGRITY + " = '" + ReferentiaIntegrity.onDeleteCascadeWhenOrphan.toString() + "' AND "
+ Relation.RELATION_PROPERTY + "." + RelationProperty.REFERENTIAL_INTEGRITY + " = '" + ReferentialIntegrity.onDeleteCascade.toString() + "' OR ("
+ Relation.RELATION_PROPERTY + "." + RelationProperty.REFERENTIAL_INTEGRITY + " = '" + ReferentialIntegrity.onDeleteCascadeWhenOrphan.toString() + "' AND "
+ "inV().inE().size()=1"
+ ")"
+ ")";
@ -1436,6 +1447,7 @@ public class EntityManagementImpl implements EntityManagement {
OrientEdge relation = iterator.next();
ODocument oDocument = relation.getInVertex().getRecord();
oDocument.delete();
relation.remove();
}
}

View File

@ -0,0 +1,35 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.resources.impl;
import java.util.UUID;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class ReferentialIntegrityTest {
protected EntityManagementImpl entityManagementImpl;
@Before
public void before(){
ScopeProvider.instance.set("/gcube/devNext");
}
public ReferentialIntegrityTest() {
entityManagementImpl = new EntityManagementImpl();
}
@Test
public void test() throws Exception{
}
}

View File

@ -132,7 +132,7 @@ public class SmartgearResourcesTest {
networkingFacet.setAdditionalProperty("Port", 8080);
RelationProperty relationProperty = new RelationPropertyImpl();
relationProperty.setReferentialIntegrity(RelationProperty.ReferentiaIntegrity.onDeleteCascadeWhenOrphan);
relationProperty.setReferentialIntegrity(RelationProperty.ReferentialIntegrity.onDeleteCascadeWhenOrphan);
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedBy =
new IsIdentifiedByImpl<>(hostingNode, networkingFacet, relationProperty);