From 46cb4f0975557045eff6c952de8e262088530b2c Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Thu, 16 Nov 2023 14:29:32 +0100 Subject: [PATCH] Added methods to create match query --- .../resourceregistry/queries/json/JsonQuery.java | 2 +- .../queries/json/base/JsonQueryERElement.java | 7 ++++++- .../queries/json/base/entities/JsonQueryFacet.java | 8 ++++++-- .../json/base/entities/JsonQueryResource.java | 11 ++++++++--- .../json/base/relations/JsonQueryConsistsOf.java | 14 +++++++++----- .../json/base/relations/JsonQueryIsRelatedTo.java | 12 ++++++++---- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java index 65c5836..5aa9768 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java @@ -100,7 +100,7 @@ public class JsonQuery { public StringBuffer createQuery() throws SchemaException, InvalidQueryException, ResourceRegistryException { entryPoint = getJsonQueryERElement(jsonQuery); entryPoint.setEntryPoint(true); - return entryPoint.analize(new StringBuffer()); + return entryPoint.createQuery(new StringBuffer()); } public String query() throws InvalidQueryException, ResourceRegistryException { 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 ed37194..90ad721 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 @@ -99,8 +99,13 @@ public abstract class JsonQueryERElement { this.traverseBack = traverseBack; } - public abstract StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException, SchemaException, ResourceRegistryException; + public StringBuffer createQuery(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException, SchemaException, ResourceRegistryException { + return createTraversalQuery(stringBuffer); + } + protected abstract StringBuffer createTraversalQuery(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException, SchemaException, ResourceRegistryException; + + protected abstract StringBuffer createMatchQuery(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException, SchemaException, ResourceRegistryException; protected StringBuffer addConstraints(JsonNode jsonNode, LogicalOperator queryLogicalOperator, String fieldNamePrefix) throws InvalidQueryException { StringBuffer stringBuffer = new StringBuffer(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryFacet.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryFacet.java index 5d021d5..81ca0a9 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryFacet.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryFacet.java @@ -22,7 +22,7 @@ public class JsonQueryFacet extends JsonQueryEntity { } @Override - public StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + public StringBuffer createTraversalQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { StringBuffer newBuffer = new StringBuffer(); int size = jsonNode.size(); @@ -36,7 +36,7 @@ public class JsonQueryFacet extends JsonQueryEntity { JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfNode); jsonQueryConsistsOf.setTraverseBack(traverseBackLocal); jsonQueryConsistsOf.setDirection(Direction.OUT); - stringBuffer = jsonQueryConsistsOf.analize(stringBuffer); + stringBuffer = jsonQueryConsistsOf.createTraversalQuery(stringBuffer); traverseBackLocal = true; /* Need to substract 1 from size otherwise @@ -88,5 +88,9 @@ public class JsonQueryFacet extends JsonQueryEntity { return newBuffer; } + @Override + public StringBuffer createMatchQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + return null; + } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryResource.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryResource.java index 004591e..1b6467a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryResource.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/base/entities/JsonQueryResource.java @@ -56,7 +56,7 @@ public class JsonQueryResource extends JsonQueryEntity { } @Override - public StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + public StringBuffer createTraversalQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { boolean wrapInnerQuery = false; @@ -83,7 +83,7 @@ public class JsonQueryResource extends JsonQueryEntity { jsonQueryIsRelatedTo.setRequestedResourceType(type); jsonQueryIsRelatedTo.setDirectionByJson(); jsonQueryIsRelatedTo.setTraverseBack( (!(!traverseBack) && i==0) ); - stringBuffer = jsonQueryIsRelatedTo.analize(stringBuffer); + stringBuffer = jsonQueryIsRelatedTo.createTraversalQuery(stringBuffer); } wrapInnerQuery = true; } @@ -97,7 +97,7 @@ public class JsonQueryResource extends JsonQueryEntity { jsonQueryConsistsOf.setRequestedResourceType(type); jsonQueryConsistsOf.setDirection(Direction.IN); jsonQueryConsistsOf.setTraverseBack(!((!traverseBack) && !wrapInnerQuery && i==0)); - stringBuffer = jsonQueryConsistsOf.analize(stringBuffer); + stringBuffer = jsonQueryConsistsOf.createTraversalQuery(stringBuffer); } wrapInnerQuery = true; // Must be set after the cycle and not before } @@ -114,4 +114,9 @@ public class JsonQueryResource extends JsonQueryEntity { return stringBuffer; } + @Override + public StringBuffer createMatchQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + return null; + } + } 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 caf3f51..0111cfd 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 @@ -77,7 +77,7 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { } @Override - public StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + public StringBuffer createTraversalQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { boolean wrapInnerQuery = false; @@ -99,7 +99,7 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { JsonNode facetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY); JsonQueryFacet jsonQueryFacet = new JsonQueryFacet(facetJsonNode); jsonQueryFacet.setTraverseBack(!((!traverseBack) && !wrapInnerQuery)); - stringBuffer = jsonQueryFacet.analize(stringBuffer); + stringBuffer = jsonQueryFacet.createTraversalQuery(stringBuffer); wrapInnerQuery = true; } @@ -108,7 +108,7 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { JsonNode resourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY); JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode); jsonQueryResource.setTraverseBack(!((!traverseBack) && !wrapInnerQuery)); - stringBuffer = jsonQueryResource.analize(stringBuffer); + stringBuffer = jsonQueryResource.createTraversalQuery(stringBuffer); wrapInnerQuery = true; } @@ -132,8 +132,12 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { stringBuffer = traverseBackToCallerResource(stringBuffer); } - return stringBuffer; - } + + @Override + public StringBuffer createMatchQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + return null; + } + } 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 b23783d..a1f2e9c 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 @@ -113,7 +113,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { } @Override - public StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + public StringBuffer createTraversalQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { if(!entryPoint && direction==null) { throw new InternalServerErrorException("Caller Resource must invoke setDirectionByJson() first. This is a server bug. Please contact the administator. "); @@ -143,7 +143,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { wrapDirection = Direction.OUT; jsonQueryResource.setDirection(Direction.OUT); jsonQueryResource.setTraverseBack(!((!traverseBack) && !wrapInnerQuery)); - stringBuffer = jsonQueryResource.analize(stringBuffer); + stringBuffer = jsonQueryResource.createTraversalQuery(stringBuffer); wrapInnerQuery = true; } @@ -166,7 +166,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { wrapDirection = Direction.IN; jsonQueryResource.setDirection(Direction.IN); jsonQueryResource.setTraverseBack(!((!traverseBack) && !wrapInnerQuery)); - stringBuffer = jsonQueryResource.analize(stringBuffer); + stringBuffer = jsonQueryResource.createTraversalQuery(stringBuffer); wrapInnerQuery = true; } @@ -191,7 +191,11 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { } return stringBuffer; - + } + + @Override + public StringBuffer createMatchQuery(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { + return null; } }