Added methods to create match query

This commit is contained in:
luca.frosini 2023-11-16 14:29:32 +01:00
parent 816c7693dc
commit 46cb4f0975
6 changed files with 38 additions and 16 deletions

View File

@ -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 {

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}