From f2cf0a4f1792e53973d6f7c67e868b0c1b28db49 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Mon, 20 Nov 2023 16:27:57 +0100 Subject: [PATCH] Implementing projection --- .../queries/json/base/JsonQueryERElement.java | 32 +++++++++----- .../base/relations/JsonQueryConsistsOf.java | 44 ++++++++++++------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/JsonQueryERElement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/JsonQueryERElement.java index 0840d09..0933276 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/JsonQueryERElement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/JsonQueryERElement.java @@ -247,13 +247,19 @@ public abstract class JsonQueryERElement { while(iterator.hasNext()) { String fieldName = iterator.next(); - if(first) { - first = false; - }else { + JsonNode node = objectNode.get(fieldName); + StringBuffer evBuffer = evaluateNode(node, fieldName, fieldNamePrefix); + + if(!first) { stringBuffer.append(queryLogicalOperator.getLogicalOperator()); } - JsonNode node = objectNode.get(fieldName); - stringBuffer.append(evaluateNode(node, fieldName, fieldNamePrefix)); + + if(evBuffer!=null && evBuffer.length()>0) { + if(first) { + first = false; + } + stringBuffer.append(evBuffer); + } } } @@ -262,13 +268,19 @@ public abstract class JsonQueryERElement { Iterator iterator = arrayNode.iterator(); boolean first = true; while(iterator.hasNext()) { - if(first) { - first = false; - }else { + JsonNode node = iterator.next(); + StringBuffer evBuffer = evaluateNode(node, null, fieldNamePrefix); + + if(!first) { stringBuffer.append(queryLogicalOperator.getLogicalOperator()); } - JsonNode node = iterator.next(); - stringBuffer.append(evaluateNode(node, null, fieldNamePrefix)); + + if(evBuffer!=null && evBuffer.length()>0) { + if(first) { + first = false; + } + stringBuffer.append(evBuffer); + } } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryConsistsOf.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryConsistsOf.java index c449946..6dd75a8 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryConsistsOf.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/relations/JsonQueryConsistsOf.java @@ -141,6 +141,25 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { @Override protected StringBuffer getSpecificMatchQuery(List childrenBreadcrumb) throws SchemaException, ResourceRegistryException { + + + StringBuffer newBuffer = new StringBuffer(); + if(jsonNode.has(ConsistsOf.TARGET_PROPERTY)) { + --size; + JsonNode facetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY); + JsonQueryFacet jsonQueryFacet = new JsonQueryFacet(facetJsonNode); + jsonQueryFacet.setTraverseBack(true); + newBuffer = jsonQueryFacet.createMatchQuery(newBuffer); + } + + if(jsonNode.has(ConsistsOf.SOURCE_PROPERTY)) { + --size; + JsonNode resourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY); + JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode); + jsonQueryResource.setTraverseBack(true); + newBuffer = jsonQueryResource.createMatchQuery(newBuffer); + } + StringBuffer buffer = new StringBuffer(); if(!entryPoint) { @@ -149,24 +168,19 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { buffer.append("E('"); buffer.append(type); buffer.append("'"); + + if(size>0) { + alias = getAlias(true); + buffer.append("{ where: ($matched."); + buffer.append(alias); + buffer.append(" == $currentMatch)"); + buffer.append(addConstraints(jsonNode, null, alias)); + buffer.append("}\n"); + } } - if(jsonNode.has(ConsistsOf.TARGET_PROPERTY)) { - --size; - JsonNode facetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY); - JsonQueryFacet jsonQueryFacet = new JsonQueryFacet(facetJsonNode); - jsonQueryFacet.setTraverseBack(true); - buffer = jsonQueryFacet.createMatchQuery(buffer); - } - - if(jsonNode.has(ConsistsOf.SOURCE_PROPERTY)) { - --size; - JsonNode resourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY); - JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode); - jsonQueryResource.setTraverseBack(true); - buffer = jsonQueryResource.createMatchQuery(buffer); - } + buffer.append(newBuffer); if(traverseBack) { buffer.append("\n\t");