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
+ " provided");
}
if (jsonNode != null) {
checkERMatch();
}
@ -252,6 +253,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
}
protected void checkERMatch() throws ResourceRegistryException {
if(jsonNode!=null){
String type = getClassProperty(jsonNode);
if (type != null && type.compareTo(erType) != 0) {
String error = String
@ -260,6 +262,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
logger.trace(error);
throw new ResourceRegistryException(error);
}
}
try {
SchemaManagementImpl.getTypeSchema(erType, baseType);

View File

@ -543,7 +543,7 @@ public abstract class RelationManagement<R extends Relation> extends
Vertex vertex = (Vertex) entityManagement.getElement();
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));
return serializeJSONObjectList(list);

View File

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