Changed the way to get all relations

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@141565 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-01-13 16:06:57 +00:00
parent b853a799f9
commit f5b33d67c1
3 changed files with 124 additions and 50 deletions

View File

@ -227,6 +227,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
throw new ResourceRegistryException("Invalid type " + erType throw new ResourceRegistryException("Invalid type " + erType
+ " provided"); + " provided");
} }
if (jsonNode != null) { if (jsonNode != null) {
checkERMatch(); checkERMatch();
} }
@ -252,13 +253,15 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
} }
protected void checkERMatch() throws ResourceRegistryException { protected void checkERMatch() throws ResourceRegistryException {
String type = getClassProperty(jsonNode); if(jsonNode!=null){
if (type != null && type.compareTo(erType) != 0) { String type = getClassProperty(jsonNode);
String error = String if (type != null && type.compareTo(erType) != 0) {
.format("Declared resourceType does not match with json representation %s!=%s", String error = String
erType, type); .format("Declared resourceType does not match with json representation %s!=%s",
logger.trace(error); erType, type);
throw new ResourceRegistryException(error); logger.trace(error);
throw new ResourceRegistryException(error);
}
} }
try { try {

View File

@ -543,7 +543,7 @@ public abstract class RelationManagement<R extends Relation> extends
Vertex vertex = (Vertex) entityManagement.getElement(); Vertex vertex = (Vertex) entityManagement.getElement();
List<JSONObject> list = new ArrayList<>(); List<JSONObject> list = new ArrayList<>();
Iterable<Edge> edges = vertex.getEdges(Direction.BOTH, erType); Iterable<Edge> edges = vertex.getEdges(direction, erType);
list.addAll(serializeEdges(edges, !polymorphic)); list.addAll(serializeEdges(edges, !polymorphic));
return serializeJSONObjectList(list); return serializeJSONObjectList(list);

View File

@ -6,7 +6,6 @@ package org.gcube.informationsystem.resourceregistry.er;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -415,7 +414,6 @@ public class ERManagementTest extends ScopedTest {
} }
@SuppressWarnings("rawtypes")
@Test @Test
public void testGetAll() throws Exception{ public void testGetAll() throws Exception{
Map<String, List<Resource>> resources = new HashMap<>(); Map<String, List<Resource>> resources = new HashMap<>();
@ -468,14 +466,14 @@ public class ERManagementTest extends ScopedTest {
json = isRelatedToManagement.all(true); json = isRelatedToManagement.all(true);
List<IsRelatedTo> isRelatedToList = Entities.unmarshalList(IsRelatedTo.class, json); List<Resource> resourcesList = Entities.unmarshalList(Resource.class, json);
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, isRelatedToList.size(), isRelatedToList); logger.debug("{} are {} : {} ", IsRelatedTo.NAME, resourcesList.size(), resourcesList);
Assert.assertTrue(isRelatedToList.size()==MAX); Assert.assertTrue(resourcesList.size()==MAX);
json = isRelatedToManagement.all(false); json = isRelatedToManagement.all(false);
isRelatedToList = Entities.unmarshalList(IsRelatedTo.class, json); resourcesList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(isRelatedToList.size()==0); Assert.assertTrue(resourcesList.size()==0);
@ -485,12 +483,12 @@ public class ERManagementTest extends ScopedTest {
ConsistsOfManagement consistsOfManagement = (ConsistsOfManagement) ERManagement.getERManagement(ConsistsOf.NAME); ConsistsOfManagement consistsOfManagement = (ConsistsOfManagement) ERManagement.getERManagement(ConsistsOf.NAME);
json = consistsOfManagement.all(true); json = consistsOfManagement.all(true);
List<ConsistsOf> consistsOfPolimorphicList = Entities.unmarshalList(ConsistsOf.class, json); List<Resource> consistsOfPolimorphicList = Entities.unmarshalList(Resource.class, json);
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfPolimorphicList.size(), consistsOfPolimorphicList); logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfPolimorphicList.size(), consistsOfPolimorphicList);
json = consistsOfManagement.all(false); json = consistsOfManagement.all(false);
List<ConsistsOf> consistsOfNonPolimorphicList = Entities.unmarshalList(ConsistsOf.class, json); List<Resource> consistsOfNonPolimorphicList = Entities.unmarshalList(Resource.class, json);
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfNonPolimorphicList.size(), consistsOfNonPolimorphicList); logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfNonPolimorphicList.size(), consistsOfNonPolimorphicList);
Assert.assertTrue(consistsOfPolimorphicList.size()>=consistsOfNonPolimorphicList.size()); Assert.assertTrue(consistsOfPolimorphicList.size()>=consistsOfNonPolimorphicList.size());
@ -515,59 +513,132 @@ public class ERManagementTest extends ScopedTest {
Map<String, Resource> map = createHostingNodeAndEService(); Map<String, Resource> map = createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME); EService eService = (EService) map.get(EService.NAME);
UUID eServiceUUID = eService.getHeader().getUUID();
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME); HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement(); IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setElementType(IsRelatedTo.NAME); isRelatedToManagement.setElementType(IsRelatedTo.NAME);
/* EService */
String json = isRelatedToManagement.allFrom(eServiceUUID, Direction.BOTH, true);
List<Resource> resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==1);
Resource sourceResource = resourceList.get(0);
Resource targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
String json = isRelatedToManagement.allFrom(eService.getHeader().getUUID(), Direction.BOTH, true);
@SuppressWarnings("rawtypes")
List<IsRelatedTo> isRelatedToList = Entities.unmarshalList(IsRelatedTo.class, json);
Assert.assertTrue(isRelatedToList.size()==1);
Assert.assertTrue(isRelatedToList.get(0).getSource().getHeader().getUUID().compareTo(hostingNode.getHeader().getUUID())==0);
json = isRelatedToManagement.allFrom(eService.getHeader().getUUID(), Direction.IN, true); json = isRelatedToManagement.allFrom(eServiceUUID, Direction.IN, true);
isRelatedToList = Entities.unmarshalList(IsRelatedTo.class, json); resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(isRelatedToList.size()==1); Assert.assertTrue(resourceList.size()==1);
Assert.assertTrue(isRelatedToList.get(0).getSource().getHeader().getUUID().compareTo(hostingNode.getHeader().getUUID())==0); sourceResource = resourceList.get(0);
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
json = isRelatedToManagement.allFrom(eService.getHeader().getUUID(), Direction.OUT, true);
isRelatedToList = Entities.unmarshalList(IsRelatedTo.class, json); json = isRelatedToManagement.allFrom(eServiceUUID, Direction.OUT, true);
Assert.assertTrue(isRelatedToList.size()==0); resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = isRelatedToManagement.allFrom(eServiceUUID, Direction.BOTH, false);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = isRelatedToManagement.allFrom(eServiceUUID, Direction.IN, false);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = isRelatedToManagement.allFrom(eServiceUUID, Direction.OUT, false);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
/* END EService */
json = isRelatedToManagement.allFrom(eService.getHeader().getUUID(), Direction.BOTH, false); /* Hosting Node */
Assert.assertTrue(isRelatedToList.size()==0); json = isRelatedToManagement.allFrom(hostingNodeUUID, Direction.BOTH, true);
json = isRelatedToManagement.allFrom(eService.getHeader().getUUID(), Direction.IN, false); resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(isRelatedToList.size()==0); Assert.assertTrue(resourceList.size()==1);
json = isRelatedToManagement.allFrom(eService.getHeader().getUUID(), Direction.OUT, false); sourceResource = resourceList.get(0);
Assert.assertTrue(isRelatedToList.size()==0); targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
json = isRelatedToManagement.allFrom(hostingNodeUUID, Direction.IN, true);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = isRelatedToManagement.allFrom(hostingNodeUUID, Direction.OUT, true);
json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.BOTH, true); resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(isRelatedToList.size()==1); Assert.assertTrue(resourceList.size()==1);
Assert.assertTrue(isRelatedToList.get(0).getTarget().getHeader().getUUID().compareTo(eService.getHeader().getUUID())==0); sourceResource = resourceList.get(0);
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.IN, true); Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
Assert.assertTrue(isRelatedToList.size()==0); Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.OUT, true);
Assert.assertTrue(isRelatedToList.size()==1);
Assert.assertTrue(isRelatedToList.get(0).getTarget().getHeader().getUUID().compareTo(eService.getHeader().getUUID())==0);
json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.BOTH, false); json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.BOTH, false);
Assert.assertTrue(isRelatedToList.size()==0); resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.IN, false); json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.IN, false);
Assert.assertTrue(isRelatedToList.size()==0); resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.OUT, false); json = isRelatedToManagement.allFrom(hostingNode.getHeader().getUUID(), Direction.OUT, false);
Assert.assertTrue(isRelatedToList.size()==0); resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
/* END HostingNode */
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(ConsistsOf.NAME);
Facet identificationFacet = eService.getIdentificationFacets().get(0);
UUID identificationFacetUUID = identificationFacet.getHeader().getUUID();
/* SoftwareFacet of Eservice */
json = consistsOfManagement.allFrom(identificationFacetUUID, Direction.BOTH, true);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==1);
sourceResource = resourceList.get(0);
Facet targetIdentificationFacet = sourceResource.getIdentificationFacets().get(0);
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID)==0);
json = consistsOfManagement.allFrom(identificationFacetUUID, Direction.IN, true);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==1);
sourceResource = resourceList.get(0);
targetIdentificationFacet = sourceResource.getIdentificationFacets().get(0);
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(eServiceUUID)==0);
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID)==0);
json = consistsOfManagement.allFrom(identificationFacetUUID, Direction.OUT, true);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = consistsOfManagement.allFrom(identificationFacetUUID, Direction.BOTH, false);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = consistsOfManagement.allFrom(identificationFacetUUID, Direction.IN, false);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
json = consistsOfManagement.allFrom(identificationFacetUUID, Direction.OUT, false);
resourceList = Entities.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size()==0);
/* END SoftwareFacet of Eservice */