enhancing query capabilities

This commit is contained in:
Luca Frosini 2021-10-15 11:33:07 +02:00
parent 4d62dc6a6a
commit b62f51e53c
3 changed files with 60 additions and 53 deletions

View File

@ -26,75 +26,73 @@ public class JsonQueryIsRelatedTo extends JsonQueryERElement{
this.requestedResourceType = requestedResourceType; this.requestedResourceType = requestedResourceType;
} }
private StringBuffer traverseThisEdge(StringBuffer stringBuffer) throws InvalidQueryException {
StringBuffer buffer = new StringBuffer();
int size = jsonNode.size();
if(size > 2) {
buffer.append("SELECT FROM ( "); // Open ( SELECT
}
buffer.append("TRAVERSE ");
buffer.append(direction.opposite().name().toLowerCase());
buffer.append("E(\"");
buffer.append(type);
buffer.append("\") FROM (");
buffer.append(stringBuffer);
buffer.append(")");
stringBuffer = buffer;
// Size 2 means that only '@class' and 'target'/'source' properties are present
if(size > 2) {
stringBuffer.append(") WHERE "); // Close ) SELECT
stringBuffer = addWhereConstraint(jsonNode, buffer, null);
}
return stringBuffer;
}
@Override @Override
protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException { protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException {
StringBuffer isRelatedToBuffer = new StringBuffer();
JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY); JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY);
JsonNode targetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY); JsonNode targetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY);
JsonNode resourceJsonNode = null; JsonNode resourceJsonNode = null;
if(targetJsonNode!=null) { if(sourceJsonNode!=null) {
resourceJsonNode = targetJsonNode;
direction = Direction.IN;
}else if(sourceJsonNode!=null) {
resourceJsonNode = sourceJsonNode; resourceJsonNode = sourceJsonNode;
direction = Direction.OUT; direction = Direction.OUT;
} else if(targetJsonNode!=null) {
resourceJsonNode = targetJsonNode;
direction = Direction.IN;
} }
isRelatedToBuffer.append("TRAVERSE "); stringBuffer = traverseThisEdge(stringBuffer);
isRelatedToBuffer.append(direction.opposite().name().toLowerCase());
isRelatedToBuffer.append("V(\"");
isRelatedToBuffer.append(requestedResourceType);
isRelatedToBuffer.append("\") FROM ("); // Open ( 1
int size = jsonNode.size();
if(size > 2) {
isRelatedToBuffer.append("SELECT FROM ( "); // Open ( SELECT
}
isRelatedToBuffer.append("TRAVERSE ");
isRelatedToBuffer.append(direction.name().toLowerCase());
isRelatedToBuffer.append("E(\"");
isRelatedToBuffer.append(type);
isRelatedToBuffer.append("\") FROM ("); // Open ( 2
if(!entryPoint) {
StringBuffer buffer = new StringBuffer();
buffer.append(" TRAVERSE ");
buffer.append(direction.opposite().name().toLowerCase());
buffer.append("V(\"");
buffer.append(requestedResourceType);
buffer.append("\").");
buffer.append(direction.opposite().name().toLowerCase());
buffer.append("E(\"");
buffer.append(type);
buffer.append("\") FROM (");
buffer.append(stringBuffer);
buffer.append(")");
stringBuffer = buffer;
}
JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode); JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode);
jsonQueryResource.setDirection(direction); jsonQueryResource.setDirection(direction);
jsonQueryResource.setEntryPoint(false); jsonQueryResource.setEntryPoint(false);
stringBuffer = jsonQueryResource.analize(stringBuffer); stringBuffer = jsonQueryResource.analize(stringBuffer);
StringBuffer buffer = new StringBuffer();
buffer.append(" TRAVERSE ");
buffer.append(direction.opposite().name().toLowerCase());
buffer.append("V(\"");
buffer.append(requestedResourceType);
buffer.append("\").");
buffer.append(direction.name().toLowerCase());
buffer.append("E(\"");
buffer.append(type);
buffer.append("\") FROM (");
buffer.append(stringBuffer);
buffer.append(")");
stringBuffer = buffer;
isRelatedToBuffer.append(stringBuffer); return stringBuffer;
isRelatedToBuffer.append(")"); // Close ) 2
// Size 2 means that only '@class' and 'target'/'source' properties are present
if(size > 2) {
isRelatedToBuffer.append(") WHERE "); // Close ) SELECT
isRelatedToBuffer = addWhereConstraint(jsonNode, isRelatedToBuffer, null);
}
isRelatedToBuffer.append(")"); // Close ) 1
return isRelatedToBuffer;
} }

View File

@ -30,7 +30,7 @@ public class JsonQueryResource extends JsonQueryERElement {
JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfJsonNode); JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfJsonNode);
jsonQueryConsistsOf.setRequestedResourceType(type); jsonQueryConsistsOf.setRequestedResourceType(type);
jsonQueryConsistsOf.setDirection(Direction.IN); jsonQueryConsistsOf.setDirection(Direction.IN);
jsonQueryConsistsOf.setEntryPoint(i==0); jsonQueryConsistsOf.setEntryPoint(entryPoint && i==0);
stringBuffer = jsonQueryConsistsOf.analize(stringBuffer); stringBuffer = jsonQueryConsistsOf.analize(stringBuffer);
} }
} }
@ -41,7 +41,7 @@ public class JsonQueryResource extends JsonQueryERElement {
JsonNode isRelatedToJsonNode = isRelatedToArray.get(i); JsonNode isRelatedToJsonNode = isRelatedToArray.get(i);
JsonQueryIsRelatedTo jsonQueryIsRelatedTo = new JsonQueryIsRelatedTo(isRelatedToJsonNode); JsonQueryIsRelatedTo jsonQueryIsRelatedTo = new JsonQueryIsRelatedTo(isRelatedToJsonNode);
jsonQueryIsRelatedTo.setRequestedResourceType(type); jsonQueryIsRelatedTo.setRequestedResourceType(type);
jsonQueryIsRelatedTo.setEntryPoint(!initFound && i==0); jsonQueryIsRelatedTo.setEntryPoint(entryPoint && !initFound && i==0);
stringBuffer = jsonQueryIsRelatedTo.analize(stringBuffer); stringBuffer = jsonQueryIsRelatedTo.analize(stringBuffer);
} }
initFound = true; // Must be set after the cycle and not before initFound = true; // Must be set after the cycle and not before

View File

@ -32,7 +32,16 @@
{ {
"@class": "Activates", "@class": "Activates",
"source": { "source": {
"@class": "HostingNode" "@class": "HostingNode",
"consistsOf": [
{
"@class": "ConsistsOf",
"target": {
"@class": "CPUFacet",
"vendor": "GenuineIntel"
}
}
]
} }
} }
] ]