From a134a93f0280deb696c6327d3b6134a35aa4ffce Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 7 Dec 2022 22:58:13 +0100 Subject: [PATCH] Fixed IsRelatedTo Query management --- .../base/relations/JsonQueryIsRelatedTo.java | 10 +++--- .../queries/JsonQueryTest.java | 2 +- src/test/resources/queries/query9.json | 36 +++++++++++++++++++ src/test/resources/queries/query9.query | 1 + 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/test/resources/queries/query9.json create mode 100644 src/test/resources/queries/query9.query diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryIsRelatedTo.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryIsRelatedTo.java index a6e00bf..a800e6c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryIsRelatedTo.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryIsRelatedTo.java @@ -1,7 +1,6 @@ package org.gcube.informationsystem.resourceregistry.queries.json.base.relations; import org.gcube.com.fasterxml.jackson.databind.JsonNode; -import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; @@ -109,7 +108,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { stringBuffer = jsonQueryResource.analize(stringBuffer); StringBuffer buffer = new StringBuffer(); - if(!entryPoint) { + if(requestedResourceType!=null) { buffer.append("TRAVERSE "); buffer.append(direction.opposite().name().toLowerCase()); buffer.append("V(\""); @@ -123,7 +122,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { buffer.append("\") FROM ( "); buffer.append(stringBuffer); buffer.append(")"); - if(!entryPoint) { + if(requestedResourceType!=null) { buffer.append(")"); } stringBuffer = buffer; @@ -136,17 +135,16 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { jsonQueryResource.setEntryPoint(false); stringBuffer = jsonQueryResource.analize(stringBuffer); + boolean entryPointOldValue = entryPoint; // It is no more and entry point for the function traverseThisEdge entryPoint = false; stringBuffer = traverseThisEdge(stringBuffer); // Restoring entryPoint indication - entryPoint = true; + entryPoint = entryPointOldValue; } return stringBuffer; } - - } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java index 246a89c..1499476 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java @@ -66,7 +66,7 @@ public class JsonQueryTest extends ContextTest { @Test public void testSingleCreateQuery() throws Exception { File queriesDirectory = getQueriesDirectory(); - File jsonQueryFile = new File(queriesDirectory, "query8.json"); + File jsonQueryFile = new File(queriesDirectory, "query9.json"); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(jsonQueryFile); logger.info("Going to test the following JSON query {}", jsonNode.toString()); diff --git a/src/test/resources/queries/query9.json b/src/test/resources/queries/query9.json new file mode 100644 index 0000000..5ee9d9b --- /dev/null +++ b/src/test/resources/queries/query9.json @@ -0,0 +1,36 @@ +{ + "@class": "SimpleFacet", + "_in": { + "@class": "ConsistsOf", + "source": { + "@class": "Configuration", + "consistsOf": [ + { + "@class": "IsIdentifiedBy", + "target": { + "@class": "IdentifierFacet", + "value": "gcat-configuration" + } + } + ], + "isRelatedTo": [ + { + "@class": "IsCustomizedBy", + "source": { + "@class": "VirtualService", + "consistsOf": [ + { + "@class": "IsIdentifiedBy", + "target": { + "@class": "SoftwareFacet", + "group": "org.gcube.data-catalogue", + "name": "catalogue-virtual-service" + } + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/src/test/resources/queries/query9.query b/src/test/resources/queries/query9.query new file mode 100644 index 0000000..b723d4b --- /dev/null +++ b/src/test/resources/queries/query9.query @@ -0,0 +1 @@ +SELECT FROM ( TRAVERSE inV("SimpleFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("Configuration") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("IdentifierFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE inV("Configuration") FROM ( TRAVERSE outE("IsCustomizedBy") FROM ( TRAVERSE outV("VirtualService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("VirtualService") FROM ( SELECT FROM IsCustomizedBy)))) WHERE group = "org.gcube.data-catalogue" AND name = "catalogue-virtual-service"))))))) WHERE value = "gcat-configuration"))))) \ No newline at end of file