Removed OLD query parameter in prepared query API

This commit is contained in:
Luca Frosini 2021-07-07 12:01:47 +02:00
parent 67eb336c96
commit 6770823e29
4 changed files with 42 additions and 41 deletions

View File

@ -524,8 +524,13 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
*/ */
} }
/*
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction, public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException { boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
*/
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
ArrayNode arrayNode = objectMapper.createArrayNode(); ArrayNode arrayNode = objectMapper.createArrayNode();
@ -651,6 +656,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
continue; continue;
} }
/*
JsonNode jsonNode; JsonNode jsonNode;
if(includeRelationInResult) { if(includeRelationInResult) {
RelationManagement<?,?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), RelationManagement<?,?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
@ -659,8 +665,10 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
}else { }else {
jsonNode = entityManagement.serializeAsJsonNode(); jsonNode = entityManagement.serializeAsJsonNode();
} }
*/
JsonNode node = entityManagement.serializeAsJsonNode();
arrayNode.add(jsonNode); arrayNode.add(node);
} catch(ResourceRegistryException e) { } catch(ResourceRegistryException e) {
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
@ -782,8 +790,12 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
} }
} }
/*
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction, public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException { boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
*/
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try { try {
@ -844,7 +856,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
break; break;
} }
return reallyQuery(relationType, referenceType, referenceUUID, direction, polymorphic, constraint, includeRelationInResult); // return reallyQuery(relationType, referenceType, referenceUUID, direction, polymorphic, constraint, includeRelationInResult);
return reallyQuery(relationType, referenceType, referenceUUID, direction, polymorphic, constraint);
} catch(ResourceRegistryException e) { } catch(ResourceRegistryException e) {
throw e; throw e;

View File

@ -284,7 +284,7 @@ public class Access extends BaseRest {
@QueryParam(AccessPath._REFERENCE_PARAM) String reference, @QueryParam(AccessPath._REFERENCE_PARAM) String reference,
@QueryParam(AccessPath._POLYMORPHIC_PARAM) @DefaultValue("false") Boolean polymorphic, @QueryParam(AccessPath._POLYMORPHIC_PARAM) @DefaultValue("false") Boolean polymorphic,
@QueryParam(AccessPath._DIRECTION_PARAM) @DefaultValue("out") String direction, @QueryParam(AccessPath._DIRECTION_PARAM) @DefaultValue("out") String direction,
@QueryParam(AccessPath._INCLUDE_RELATION_PARAM) @DefaultValue("false") Boolean includeRelation, /*@QueryParam(AccessPath._INCLUDE_RELATION_PARAM) @DefaultValue("false") Boolean includeRelation,*/
@Context UriInfo uriInfo) throws ResourceRegistryException { @Context UriInfo uriInfo) throws ResourceRegistryException {
logger.info("Requested {} instances having a(n) {} ({}={}} with {} ({}={}. Complete Request is {})", resourcetype, relationType, logger.info("Requested {} instances having a(n) {} ({}={}} with {} ({}={}. Complete Request is {})", resourcetype, relationType,
@ -315,9 +315,11 @@ public class Access extends BaseRest {
case AccessPath._REFERENCE_PARAM: case AccessPath._REFERENCE_PARAM:
break; break;
/*
case AccessPath._INCLUDE_RELATION_PARAM: case AccessPath._INCLUDE_RELATION_PARAM:
break; break;
*/
case "gcube-token": case "gcube-token":
break; break;
@ -346,7 +348,7 @@ public class Access extends BaseRest {
} }
return ((ResourceManagement) erManagement).query(relationType, referenceType, refereceUUID, directionEnum, return ((ResourceManagement) erManagement).query(relationType, referenceType, refereceUUID, directionEnum,
polymorphic, constraint, includeRelation); polymorphic, constraint); /*, includeRelation*/
} }
String error = String.format("%s is not a %s type", resourcetype, Resource.NAME); String error = String.format("%s is not a %s type", resourcetype, Resource.NAME);

View File

@ -157,7 +157,7 @@ public class MultiContextTest extends ERManagementTest {
// resourceManagement.setUUID(resourceUUID); // resourceManagement.setUUID(resourceUUID);
String ret = resourceManagement.query(IsRelatedTo.NAME, resourceType, resourceUUID, oDirection, true, String ret = resourceManagement.query(IsRelatedTo.NAME, resourceType, resourceUUID, oDirection, true,
new HashMap<>(), true); new HashMap<>());
List<IsRelatedTo> isRelatedToList = ElementMapper.unmarshalList(IsRelatedTo.class, ret); List<IsRelatedTo> isRelatedToList = ElementMapper.unmarshalList(IsRelatedTo.class, ret);
return isRelatedToList; return isRelatedToList;
} }

View File

@ -166,72 +166,62 @@ public class QueryTest extends ERManagementTest {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Service.NAME); resourceManagement.setElementType(Service.NAME);
boolean includeRelation = false;
/* Getting Hosting Node */ /* Getting Hosting Node */
String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, true, String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, true,
null, includeRelation); null);
List<Resource> resourceList = ElementMapper.unmarshalList(Resource.class, json); List<Resource> resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
Resource resource = resourceList.get(0); Resource resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0); Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, true, null, json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, true, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0); resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0); Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, true, null, json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, true, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, false, null, json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, false, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, false, null, json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, false, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, false, null, json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, false, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
/* END Getting Hosting Node */ /* END Getting Hosting Node */
/* Getting EService */ /* Getting EService */
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, true, json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, true,
null, includeRelation); null);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID) == 0); Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID) == 0);
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, true, null, json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, true, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, true, null, json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, true, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID) == 0); Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID) == 0);
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, false, json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, false,
null, includeRelation); null);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, false, json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, false,
null, includeRelation); null);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, false, null, json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, false, null);
includeRelation);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
/* END Getting HostingNode */ /* END Getting HostingNode */
@ -242,13 +232,13 @@ public class QueryTest extends ERManagementTest {
/* EService --ConsistsOf--> SoftwareFacet */ /* EService --ConsistsOf--> SoftwareFacet */
try { try {
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID,
ODirection.BOTH, true, null, includeRelation); ODirection.BOTH, true, null);
} catch (InvalidQueryException e) { } catch (InvalidQueryException e) {
// Ok expected // Ok expected
} }
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT,
true, null, includeRelation); true, null);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0); resource = resourceList.get(0);
@ -258,7 +248,7 @@ public class QueryTest extends ERManagementTest {
try { try {
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN,
true, null, includeRelation); true, null);
throw new Exception("Expected InvalidQueryException"); throw new Exception("Expected InvalidQueryException");
} catch (InvalidQueryException e) { } catch (InvalidQueryException e) {
// Ok expected // Ok expected
@ -266,20 +256,20 @@ public class QueryTest extends ERManagementTest {
try { try {
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID,
ODirection.BOTH, false, null, includeRelation); ODirection.BOTH, false, null);
throw new Exception("Expected InvalidQueryException"); throw new Exception("Expected InvalidQueryException");
} catch (InvalidQueryException e) { } catch (InvalidQueryException e) {
// Ok expected // Ok expected
} }
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT,
false, null, includeRelation); false, null);
resourceList = ElementMapper.unmarshalList(Resource.class, json); resourceList = ElementMapper.unmarshalList(Resource.class, json);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
try { try {
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN,
false, null, includeRelation); false, null);
throw new Exception("Expected InvalidQueryException"); throw new Exception("Expected InvalidQueryException");
} catch (InvalidQueryException e) { } catch (InvalidQueryException e) {
// Ok expected // Ok expected
@ -307,13 +297,11 @@ public class QueryTest extends ERManagementTest {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ElementManagement erManagement = ElementManagementUtility.getERManagement(type); ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
boolean includeRelation = false;
if (erManagement instanceof ResourceManagement) { if (erManagement instanceof ResourceManagement) {
boolean[] booleans = new boolean[] {true, false}; boolean[] booleans = new boolean[] {true, false};
for(boolean bool : booleans) { for(boolean bool : booleans) {
String ret = ((ResourceManagement) erManagement).query(relationType, facetType, null, ODirection.OUT, bool, constraint, includeRelation); String ret = ((ResourceManagement) erManagement).query(relationType, facetType, null, ODirection.OUT, bool, constraint);
logger.debug("Result of query for {}polymorphic {} --{}--> {} with constaint {} is {}", bool ? "" : "NOT ", logger.debug("Result of query for {}polymorphic {} --{}--> {} with constaint {} is {}", bool ? "" : "NOT ",
type, relationType, facetType, constraint, ret); type, relationType, facetType, constraint, ret);
} }
@ -389,8 +377,6 @@ public class QueryTest extends ERManagementTest {
Configuration expected = createdConfigurations.get(i); Configuration expected = createdConfigurations.get(i);
UUID expectedUUID = expected.getHeader().getUUID(); UUID expectedUUID = expected.getHeader().getUUID();
boolean includeRelation = false;
for(Boolean polymorphic : polymorphics) { for(Boolean polymorphic : polymorphics) {
@ -404,7 +390,7 @@ public class QueryTest extends ERManagementTest {
resourceType, relationType, referenceType, constraint); resourceType, relationType, referenceType, constraint);
String ret = resourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, String ret = resourceManagement.query(relationType, referenceType, refereceUUID, directionEnum,
polymorphic, constraint, includeRelation); polymorphic, constraint);
List<Configuration> list = ElementMapper.unmarshalList(Configuration.class, ret); List<Configuration> list = ElementMapper.unmarshalList(Configuration.class, ret);
Assert.assertTrue(list.size()==expectedSize); Assert.assertTrue(list.size()==expectedSize);
@ -430,7 +416,7 @@ public class QueryTest extends ERManagementTest {
parentResourceType, relationType, referenceType, constraint); parentResourceType, relationType, referenceType, constraint);
String retPolimorphic = parentResourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, String retPolimorphic = parentResourceManagement.query(relationType, referenceType, refereceUUID, directionEnum,
polymorphic, constraint, includeRelation); polymorphic, constraint);
List<ConfigurationTemplate> listPolimorphic = ElementMapper.unmarshalList(ConfigurationTemplate.class, retPolimorphic); List<ConfigurationTemplate> listPolimorphic = ElementMapper.unmarshalList(ConfigurationTemplate.class, retPolimorphic);
Assert.assertTrue(listPolimorphic.size()==expectedSize); Assert.assertTrue(listPolimorphic.size()==expectedSize);