JSON queries has been switched to match queries

This commit is contained in:
luca.frosini 2023-11-28 16:57:54 +01:00
parent 8af757f3db
commit c5531d7c54
11 changed files with 150 additions and 93 deletions

View File

@ -96,16 +96,30 @@ public class JsonQueryFacet extends JsonQueryEntity {
throws SchemaException, ResourceRegistryException {
StringBuffer newBuffer = new StringBuffer();
boolean traverseBack = this.traverseBack;
if(jsonNode.has(_SOURCE)) {
if(!entryPoint) {
throw new InvalidQueryException(_SOURCE + " property cannot be used in a facet if it is not the entry object");
}
traverseBack = true;
JsonNode consistsOfNode = jsonNode.get(_SOURCE);
JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfNode);
jsonQueryConsistsOf.setTraverseBack(traverseBack);
jsonQueryConsistsOf.setDirection(Direction.OUT);
jsonQueryConsistsOf.setDirection(Direction.IN);
jsonQueryConsistsOf.setBreadcrumb(childrenBreadcrumb);
newBuffer = jsonQueryConsistsOf.createMatchQuery(newBuffer);
newBuffer.append("\n\t");
newBuffer.append(".inV('");
newBuffer.append(type);
newBuffer.append("')");
newBuffer.append(" { where: ($matched.");
newBuffer.append(alias);
newBuffer.append(" == $currentMatch)}");
traverseBack = false;
/* Need to substract 1 from size otherwise
* it add WHERE at the end because _in
* is not a property to be used for a WHERE compare
@ -153,15 +167,15 @@ public class JsonQueryFacet extends JsonQueryEntity {
buffer.append(newBuffer);
if(traverseBack) {
buffer.append("\n\t");
buffer.append(".outV('");
buffer.append(type);
buffer.append("')");
buffer.append(" { where: ($matched.");
buffer.append(alias);
buffer.append(" == $currentMatch)}");
}
// if(traverseBack) {
// buffer.append("\n\t");
// buffer.append(".inV('");
// buffer.append(type);
// buffer.append("')");
// buffer.append(" { where: ($matched.");
// buffer.append(alias);
// buffer.append(" == $currentMatch)}");
// }
return buffer;

View File

@ -130,10 +130,14 @@ public class JsonQueryResource extends JsonQueryEntity {
consistsOfSize = consistsOfArray.size();
}
int total = consistsOfSize;
ArrayNode isRelatedToArray = (ArrayNode) jsonNode.get(Resource.IS_RELATED_TO_PROPERTY);
if(isRelatedToArray!=null && isRelatedToArray.size()>0) {
--size;
isRelatedToSize = isRelatedToArray.size();
total += isRelatedToSize;
for(int i=0; i<isRelatedToSize; i++) {
JsonNode isRelatedToJsonNode = isRelatedToArray.get(i);
JsonQueryIsRelatedTo jsonQueryIsRelatedTo = new JsonQueryIsRelatedTo(isRelatedToJsonNode);
@ -150,7 +154,6 @@ public class JsonQueryResource extends JsonQueryEntity {
jsonQueryIsRelatedTo.setTraverseBack(traverseBack);
newBuffer = jsonQueryIsRelatedTo.createMatchQuery(newBuffer);
if(traverseBack) {
newBuffer.append("\n\t.");
@ -161,7 +164,8 @@ public class JsonQueryResource extends JsonQueryEntity {
newBuffer.append("{ where: ($matched.");
newBuffer.append(getAlias(true));
newBuffer.append(" == $currentMatch)}");
if(i<(isRelatedToSize-1) || consistsOfSize>0) {
if(entryPoint && i<(total-1)) {
newBuffer.append("\n");
}
}
@ -192,14 +196,13 @@ public class JsonQueryResource extends JsonQueryEntity {
newBuffer.append(" { where: ($matched.");
newBuffer.append(getAlias(true));
newBuffer.append(" == $currentMatch)}");
if(i<(consistsOfSize-1)) {
if(entryPoint && i<(consistsOfSize-1)) {
newBuffer.append("\n");
}
}
}
}
StringBuffer buffer = new StringBuffer();
if(!entryPoint) {

View File

@ -143,6 +143,8 @@ public class JsonQueryConsistsOf extends JsonQueryRelation {
throws SchemaException, ResourceRegistryException {
int childrenPosition = 0;
boolean traverseBack = this.traverseBack;
StringBuffer newBuffer = new StringBuffer();
if(jsonNode.has(ConsistsOf.TARGET_PROPERTY)) {
--size;
@ -150,9 +152,22 @@ public class JsonQueryConsistsOf extends JsonQueryRelation {
JsonQueryFacet jsonQueryFacet = new JsonQueryFacet(facetJsonNode);
jsonQueryFacet.setBreadcrumb(childrenBreadcrumb);
jsonQueryFacet.setPosition(childrenPosition++);
jsonQueryFacet.setTraverseBack(false);
jsonQueryFacet.setDirection(Direction.IN);
jsonQueryFacet.setTraverseBack(true);
Direction direction = Direction.IN;
jsonQueryFacet.setDirection(direction);
newBuffer = jsonQueryFacet.createMatchQuery(newBuffer);
newBuffer.append("\n\t");
newBuffer.append(".");
newBuffer.append(direction.name().toLowerCase());
newBuffer.append("E('");
newBuffer.append(type);
newBuffer.append("') ");
newBuffer.append(" { where: ($matched.");
newBuffer.append(getAlias(true));
newBuffer.append(" == $currentMatch)}");
traverseBack = false;
}
if(jsonNode.has(ConsistsOf.SOURCE_PROPERTY)) {
@ -162,8 +177,21 @@ public class JsonQueryConsistsOf extends JsonQueryRelation {
jsonQueryResource.setBreadcrumb(childrenBreadcrumb);
jsonQueryResource.setPosition(childrenPosition++);
jsonQueryResource.setTraverseBack(true);
jsonQueryResource.setDirection(Direction.OUT);
Direction direction = Direction.OUT;
jsonQueryResource.setDirection(direction);
newBuffer = jsonQueryResource.createMatchQuery(newBuffer);
newBuffer.append("\n\t");
newBuffer.append(".");
newBuffer.append(direction.name().toLowerCase());
newBuffer.append("E('");
newBuffer.append(type);
newBuffer.append("') ");
newBuffer.append(" { where: ($matched.");
newBuffer.append(getAlias(true));
newBuffer.append(" == $currentMatch)}");
traverseBack = false;
}
StringBuffer buffer = new StringBuffer();

View File

@ -214,27 +214,56 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation {
int childrenPosition = 0;
boolean traverseBack = this.traverseBack;
StringBuffer newBuffer = new StringBuffer();
if(jsonNode.has(ConsistsOf.TARGET_PROPERTY)) {
--size;
JsonNode targetJsonNode = jsonNode.get(IsRelatedTo.TARGET_PROPERTY);
JsonQueryResource jsonQueryResource = new JsonQueryResource(targetJsonNode);
jsonQueryResource.setDirection(Direction.IN);
Direction direction = Direction.IN;
jsonQueryResource.setDirection(direction);
jsonQueryResource.setBreadcrumb(childrenBreadcrumb);
jsonQueryResource.setPosition(childrenPosition++);
jsonQueryResource.setTraverseBack(true);
newBuffer = jsonQueryResource.createMatchQuery(newBuffer);
newBuffer.append("\n\t");
newBuffer.append(".");
newBuffer.append(direction.name().toLowerCase());
newBuffer.append("E('");
newBuffer.append(type);
newBuffer.append("') ");
newBuffer.append(" { where: ($matched.");
newBuffer.append(getAlias(true));
newBuffer.append(" == $currentMatch)}");
traverseBack = false;
}
if(jsonNode.has(ConsistsOf.SOURCE_PROPERTY)) {
--size;
JsonNode sourceJsonNode = jsonNode.get(IsRelatedTo.SOURCE_PROPERTY);
JsonQueryResource jsonQueryResource = new JsonQueryResource(sourceJsonNode);
jsonQueryResource.setDirection(Direction.OUT);
Direction direction = Direction.OUT;
jsonQueryResource.setDirection(direction);
jsonQueryResource.setBreadcrumb(childrenBreadcrumb);
jsonQueryResource.setPosition(childrenPosition++);
jsonQueryResource.setTraverseBack(true);
newBuffer = jsonQueryResource.createMatchQuery(newBuffer);
newBuffer.append("\n\t");
newBuffer.append(".");
newBuffer.append(direction.name().toLowerCase());
newBuffer.append("E('");
newBuffer.append(type);
newBuffer.append("') ");
newBuffer.append(" { where: ($matched.");
newBuffer.append(getAlias(true));
newBuffer.append(" == $currentMatch)}");
traverseBack = false;
}
StringBuffer buffer = new StringBuffer();
@ -288,7 +317,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation {
buffer.append(type);
buffer.append("') ");
buffer.append(" { where: ($matched.");
buffer.append(alias);
buffer.append(getAlias(true));
buffer.append(" == $currentMatch)}");
}

View File

@ -73,7 +73,7 @@ public class JsonQueryTest extends ContextTest {
}
@Test
public void testJsonQueries() throws Exception {
public void testQueries() throws Exception {
ContextTest.setContextByName(DEVVRE);
File queriesDirectory = getQueriesDirectory();
@ -115,9 +115,9 @@ public class JsonQueryTest extends ContextTest {
}
@Test
public void testSingleCreateQuery() throws Exception {
public void testSingleQuery() throws Exception {
File queriesDirectory = getQueriesDirectory();
File jsonQueryFile = new File(queriesDirectory, "query9.json");
File jsonQueryFile = new File(queriesDirectory, "query2.json");
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonQueryFile);
logger.info("Going to test the following JSON query {}", jsonNode.toString());
@ -225,7 +225,7 @@ public class JsonQueryTest extends ContextTest {
}
@Test
public void testSingleMatchQuery() throws Exception {
public void testSingleProjectionQuery() throws Exception {
File queriesDirectory = getProjectionQueriesDirectory();
File jsonQueryFile = new File(queriesDirectory, "HostingNode-query.json");
ObjectMapper objectMapper = new ObjectMapper();
@ -255,7 +255,7 @@ public class JsonQueryTest extends ContextTest {
}
@Test
public void testMatchQueries() throws Exception {
public void testProjectionQueries() throws Exception {
File queriesDirectory = getProjectionQueriesDirectory();
FilenameFilter filenameFilter = new FilenameFilter() {

View File

@ -1,15 +1,11 @@
DA FIXARE
SELECT EXPAND(ret) FROM (
MATCH
{class: StateFacet, as: statefacet0, where: (($currentMatch['@class'] INSTANCEOF 'StateFacet') AND (statefacet0.value = "down"))}
DOVREBBE ESSERE consistsof00 e tutto di conseguenza
.outE('ConsistsOf') { as: consistsof0, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('EService') { as: eservice00, where: (($currentMatch['@class'] INSTANCEOF 'EService') AND (eservice00.id = "93995af0-4f95-4816-a53e-3e1bc27ef475"))}
MANCA -> .outE('ConsistsOf') { where: ($matched.consistsof0 == $currentMatch)}
MANCA -> .inV('StateFacet') { where: ($matched.statefacet0 == $currentMatch)}
.inE('ConsistsOf') { as: consistsof00, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('EService') { as: eservice000, where: (($currentMatch['@class'] INSTANCEOF 'EService') AND (eservice000.id = "93995af0-4f95-4816-a53e-3e1bc27ef475"))}
.outE('ConsistsOf') { where: ($matched.consistsof00 == $currentMatch)}
.inV('StateFacet') { where: ($matched.statefacet0 == $currentMatch)}
RETURN
DISTINCT(statefacet0) as ret
)

View File

@ -2,11 +2,10 @@ SELECT EXPAND(ret) FROM (
MATCH
{class: StateFacet, as: statefacet0, where: (($currentMatch['@class'] INSTANCEOF 'StateFacet') AND (statefacet0.value = "down"))}
DOVREBBE ESSERE consistsof00
.outE('ConsistsOf') { as: consistsof0, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('EService') { as: eservice00, where: (($currentMatch['@class'] INSTANCEOF 'EService') AND (((eservice00.id = "93995af0-4f95-4816-a53e-3e1bc27ef475" AND eservice00.metadata.createdBy <> "luca.frosini") OR (eservice00.id = "bd4402a0-2b72-41c5-a970-321343649e7d" AND eservice00.metadata.createdBy = "DataTransfer:data-transfer-service:smartexecutor1.dev.int.d4science.net_80"))))}
MANCA -> .outE('ConsistsOf') { where: ($matched.consistsof0 == $currentMatch)}
MANCA -> .inV('StateFacet') { where: ($matched.statefacet0 == $currentMatch)}
.inE('ConsistsOf') { as: consistsof00, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('EService') { as: eservice000, where: (($currentMatch['@class'] INSTANCEOF 'EService') AND (((eservice000.id = "93995af0-4f95-4816-a53e-3e1bc27ef475" AND eservice000.metadata.createdBy <> "luca.frosini") OR (eservice000.id = "bd4402a0-2b72-41c5-a970-321343649e7d" AND eservice000.metadata.createdBy = "DataTransfer:data-transfer-service:smartexecutor1.dev.int.d4science.net_80"))))}
.outE('ConsistsOf') { where: ($matched.consistsof00 == $currentMatch)}
.inV('StateFacet') { where: ($matched.statefacet0 == $currentMatch)}
RETURN
DISTINCT(statefacet0) as ret
)

View File

@ -27,5 +27,5 @@ SELECT EXPAND(ret) FROM (
.outV('EService') { where: ($matched.eservice0 == $currentMatch)}
RETURN
DISTINCT(eservice0) as ret
DISTINCT(eservice0) as ret
)

View File

@ -1,14 +1,11 @@
DA FIXARE
SELECT EXPAND(ret) FROM (
MATCH
{class: StateFacet, as: statefacet0, where: ($currentMatch['@class'] INSTANCEOF 'StateFacet')}
DOVREBBE ESSERE consistsof00
.outE('ConsistsOf') { as: consistsof0, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('EService') { as: eservice00, where: (($currentMatch['@class'] INSTANCEOF 'EService') AND (((eservice00.id = "93995af0-4f95-4816-a53e-3e1bc27ef475" AND eservice00.metadata.createdBy <> "luca.frosini") OR (eservice00.id = "bd4402a0-2b72-41c5-a970-321343649e7d" AND eservice00.metadata.createdBy = "DataTransfer:data-transfer-service:smartexecutor1.dev.int.d4science.net_80"))))}
MANCA -> .inE('ConsistsOf') { where: ($matched.consistsof0 == $currentMatch)}
MANCA -> .inV('StateFacet') { where: ($matched.statefacet0 == $currentMatch)}
.inE('ConsistsOf') { as: consistsof00, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('EService') { as: eservice000, where: (($currentMatch['@class'] INSTANCEOF 'EService') AND (((eservice000.id = "93995af0-4f95-4816-a53e-3e1bc27ef475" AND eservice000.metadata.createdBy <> "luca.frosini") OR (eservice000.id = "bd4402a0-2b72-41c5-a970-321343649e7d" AND eservice000.metadata.createdBy = "DataTransfer:data-transfer-service:smartexecutor1.dev.int.d4science.net_80"))))}
.outE('ConsistsOf') { where: ($matched.consistsof00 == $currentMatch)}
.inV('StateFacet') { where: ($matched.statefacet0 == $currentMatch)}
RETURN
DISTINCT(statefacet0) as ret
)

View File

@ -1,23 +1,21 @@
DA FIXARE
SELECT EXPAND(ret) FROM (
MATCH
{class: CallsFor, as: callsfor0, where: ($currentMatch['@class'] INSTANCEOF 'CallsFor')}
.inV('VirtualService') { as: virtualservice00, where: ($currentMatch['@class'] INSTANCEOF 'VirtualService')}
.outE('IsIdentifiedBy') { as: isidentifiedby000, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('SoftwareFacet') { as: softwarefacet0000, where: (($currentMatch['@class'] INSTANCEOF 'SoftwareFacet') AND (softwarefacet0000.group = "org.gcube.data-catalogue" AND softwarefacet0000.name = "catalogue-virtual-service"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby000 == $currentMatch)}
.outV('VirtualService') { where: ($matched.virtualservice00 == $currentMatch)}
MANCA -> .inE('CallsFor') { where: ($matched.callsfor0 == $currentMatch)}
MATCH
{class: CallsFor, as: callsfor0, where: ($currentMatch['@class'] INSTANCEOF 'CallsFor')}
.outV('EService') { as: eservice01, where: ($currentMatch['@class'] INSTANCEOF 'EService')}
.outE('IsIdentifiedBy') { as: isidentifiedby010, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('SoftwareFacet') { as: softwarefacet0100, where: (($currentMatch['@class'] INSTANCEOF 'SoftwareFacet') AND (softwarefacet0100.group = "org.gcube.data-catalogue" AND softwarefacet0100.name = "gcat"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby010 == $currentMatch)}
.outV('EService') { where: ($matched.eservice01 == $currentMatch)}
MANCA -> .outE('CallsFor') { where: ($matched.callsfor0 == $currentMatch)}
RETURN
DISTINCT(callsfor0) as ret
.inV('VirtualService') { as: virtualservice00, where: ($currentMatch['@class'] INSTANCEOF 'VirtualService')}
.outE('IsIdentifiedBy') { as: isidentifiedby000, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('SoftwareFacet') { as: softwarefacet0000, where: (($currentMatch['@class'] INSTANCEOF 'SoftwareFacet') AND (softwarefacet0000.group = "org.gcube.data-catalogue" AND softwarefacet0000.name = "catalogue-virtual-service"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby000 == $currentMatch)}
.outV('VirtualService') { where: ($matched.virtualservice00 == $currentMatch)}
.inE('CallsFor') { where: ($matched.callsfor0 == $currentMatch)}
.outV('EService') { as: eservice01, where: ($currentMatch['@class'] INSTANCEOF 'EService')}
.outE('IsIdentifiedBy') { as: isidentifiedby010, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('SoftwareFacet') { as: softwarefacet0100, where: (($currentMatch['@class'] INSTANCEOF 'SoftwareFacet') AND (softwarefacet0100.group = "org.gcube.data-catalogue" AND softwarefacet0100.name = "gcat"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby010 == $currentMatch)}
.outV('EService') { where: ($matched.eservice01 == $currentMatch)}
.outE('CallsFor') { where: ($matched.callsfor0 == $currentMatch)}
RETURN
DISTINCT(callsfor0) as ret
)

View File

@ -1,30 +1,23 @@
SELECT EXPAND(ret) FROM (
MATCH
{class: SimpleFacet, as: simplefacet0, where: ($currentMatch['@class'] INSTANCEOF 'SimpleFacet')}
DOVREBBE ESSERE consistsof00 e tutto di conseguenza
.outE('ConsistsOf') { as: consistsof0, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('Configuration') { as: configuration00, where: ($currentMatch['@class'] INSTANCEOF 'Configuration')}
.inE('IsCustomizedBy') { as: iscustomizedby000, where: ($currentMatch['@class'] INSTANCEOF 'IsCustomizedBy')}
.outV('VirtualService') { as: virtualservice0000, where: ($currentMatch['@class'] INSTANCEOF 'VirtualService')}
.outE('IsIdentifiedBy') { as: isidentifiedby00000, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('SoftwareFacet') { as: softwarefacet000000, where: (($currentMatch['@class'] INSTANCEOF 'SoftwareFacet') AND (softwarefacet000000.group = "org.gcube.data-catalogue" AND softwarefacet000000.name = "catalogue-virtual-service"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby00000 == $currentMatch)}
.outV('VirtualService') { where: ($matched.virtualservice0000 == $currentMatch)}
.outE('IsCustomizedBy') { where: ($matched.iscustomizedby000 == $currentMatch)}
.inV('Configuration') { where: ($matched.configuration00 == $currentMatch)}
MANCA -> .outE('ConsistsOf') { where: ($matched.consistsof0 == $currentMatch)}
MANCA -> .inV('SimpleFacet') { where: ($matched.simplefacet0 == $currentMatch)}
MATCH
{class: SimpleFacet, as: simplefacet0, where: ($currentMatch['@class'] INSTANCEOF 'SimpleFacet')}
.outE('IsIdentifiedBy') { as: isidentifiedby001, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('IdentifierFacet') { as: identifierfacet0010, where: (($currentMatch['@class'] INSTANCEOF 'IdentifierFacet') AND (identifierfacet0010.value = "gcat-configuration"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby001 == $currentMatch)}
.outV('Configuration') { where: ($matched.configuration00 == $currentMatch)}
MANCA -> .outE('ConsistsOf') { where: ($matched.consistsof0 == $currentMatch)}
MANCA -> .inV('SimpleFacet') { where: ($matched.simplefacet0 == $currentMatch)}
RETURN
DISTINCT(simplefacet0) as ret
.inE('ConsistsOf') { as: consistsof00, where: ($currentMatch['@class'] INSTANCEOF 'ConsistsOf')}
.outV('Configuration') { as: configuration000, where: ($currentMatch['@class'] INSTANCEOF 'Configuration')}
.inE('IsCustomizedBy') { as: iscustomizedby0000, where: ($currentMatch['@class'] INSTANCEOF 'IsCustomizedBy')}
.outV('VirtualService') { as: virtualservice00000, where: ($currentMatch['@class'] INSTANCEOF 'VirtualService')}
.outE('IsIdentifiedBy') { as: isidentifiedby000000, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('SoftwareFacet') { as: softwarefacet0000000, where: (($currentMatch['@class'] INSTANCEOF 'SoftwareFacet') AND (softwarefacet0000000.group = "org.gcube.data-catalogue" AND softwarefacet0000000.name = "catalogue-virtual-service"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby000000 == $currentMatch)}
.outV('VirtualService') { where: ($matched.virtualservice00000 == $currentMatch)}
.outE('IsCustomizedBy') { where: ($matched.iscustomizedby0000 == $currentMatch)}
.inV('Configuration') { where: ($matched.configuration000 == $currentMatch)}
.outE('IsIdentifiedBy') { as: isidentifiedby0001, where: ($currentMatch['@class'] INSTANCEOF 'IsIdentifiedBy')}
.inV('IdentifierFacet') { as: identifierfacet00010, where: (($currentMatch['@class'] INSTANCEOF 'IdentifierFacet') AND (identifierfacet00010.value = "gcat-configuration"))}
.inE('IsIdentifiedBy') { where: ($matched.isidentifiedby0001 == $currentMatch)}
.outV('Configuration') { where: ($matched.configuration000 == $currentMatch)}
.outE('ConsistsOf') { where: ($matched.consistsof00 == $currentMatch)}
.inV('SimpleFacet') { where: ($matched.simplefacet0 == $currentMatch)}
RETURN
DISTINCT(simplefacet0) as ret
)