diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java index 6b9bffa..4045545 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java @@ -32,8 +32,8 @@ import org.gcube.informationsystem.resourceregistry.contexts.relations.IsParentO import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement; -import org.gcube.informationsystem.resourceregistry.queries.operators.QueryConditionalOperator; -import org.gcube.informationsystem.resourceregistry.queries.operators.QueryLogicalOperator; +import org.gcube.informationsystem.resourceregistry.queries.operators.ConditionalOperator; +import org.gcube.informationsystem.resourceregistry.queries.operators.LogicalOperator; import org.gcube.informationsystem.resourceregistry.requests.RequestUtility; import org.gcube.informationsystem.resourceregistry.requests.ServerRequestInfo; import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; @@ -142,13 +142,13 @@ public class ContextManagement extends EntityElementManagement { public final static String AT = "@"; public final static String UNDERSCORE = "_"; + public final static String DOLLAR = "$"; protected final Set ignoreKeys; protected final Set ignoreStartWithKeys; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java index 71422e9..fdb5e2d 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java @@ -52,6 +52,7 @@ public class PropertyElementManagement { PROPERTY_IGNORE_START_WITH_KEYS = new HashSet(); PROPERTY_IGNORE_START_WITH_KEYS.add(ElementManagement.AT); PROPERTY_IGNORE_START_WITH_KEYS.add(ElementManagement.UNDERSCORE); + PROPERTY_IGNORE_START_WITH_KEYS.add(ElementManagement.DOLLAR); } 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 cea2525..4d4916d 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 @@ -101,6 +101,7 @@ public class JsonQuery { public StringBuffer createQuery() throws SchemaException, InvalidQueryException, ResourceRegistryException { entryPoint = getJsonQueryERElement(jsonQuery); entryPoint.setEntryPoint(true); + entryPoint.setNoTraversal(true); return entryPoint.analize(new StringBuffer()); } @@ -114,9 +115,14 @@ public class JsonQuery { oDatabaseDocument.begin(); ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get(); - int limit = requestInfo.getLimit(); - int offset = requestInfo.getOffset(); - + Integer limit = requestInfo.getLimit(); + if(limit==null) { + limit = -1; + } + Integer offset = requestInfo.getOffset(); + if(offset == null) { + offset = 0; + } int position = -1; int count = 0; @@ -154,7 +160,8 @@ public class JsonQuery { ElementManagement erManagement = ElementManagementUtility.getERManagement(securityContext, oDatabaseDocument, element); - // To support polymorphism we do not include ="TypeName" in query. So we need post processing filtering of results + // TODO remove this post filter using INSTANCEOF + // To support polymorphism we do not include = "TypeName" in query. So we need post processing filtering of results String requestedType = entryPoint.getType(); String gotType = erManagement.getTypeName(); 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 877448f..e6a19a9 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 @@ -16,8 +16,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException; -import org.gcube.informationsystem.resourceregistry.queries.operators.QueryConditionalOperator; -import org.gcube.informationsystem.resourceregistry.queries.operators.QueryLogicalOperator; +import org.gcube.informationsystem.resourceregistry.queries.operators.ConditionalOperator; +import org.gcube.informationsystem.resourceregistry.queries.operators.LogicalOperator; import org.gcube.informationsystem.resourceregistry.types.TypesCache; import org.gcube.informationsystem.utils.TypeUtility; @@ -42,12 +42,15 @@ public abstract class JsonQueryERElement { protected Direction direction; protected boolean entryPoint; + protected boolean noTraversal; + public JsonQueryERElement(JsonNode jsonQuery, AccessType accessType) throws SchemaException, ResourceRegistryException { this.objectMapper = new ObjectMapper(); this.type = TypeUtility.getTypeName(jsonQuery); this.jsonNode = jsonQuery; this.accessType = accessType; this.entryPoint = false; + this.noTraversal = false; this.fieldNamesToRemove = new HashSet<>(); this.fieldNamesToRemove.add(Element.TYPE_PROPERTY); @@ -76,15 +79,23 @@ public abstract class JsonQueryERElement { public void setEntryPoint(boolean entryPoint) { this.entryPoint = entryPoint; } + + public boolean isNoTraversal() { + return noTraversal; + } + + public void setNoTraversal(boolean noTraversal) { + this.noTraversal = noTraversal; + } public abstract StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException, SchemaException, ResourceRegistryException; - protected StringBuffer addConstraints(JsonNode jsonNode, QueryLogicalOperator queryLogicalOperator, String fieldNamePrefix) throws InvalidQueryException { + protected StringBuffer addConstraints(JsonNode jsonNode, LogicalOperator queryLogicalOperator, String fieldNamePrefix) throws InvalidQueryException { StringBuffer stringBuffer = new StringBuffer(); if(queryLogicalOperator==null) { - queryLogicalOperator = QueryLogicalOperator.AND; + queryLogicalOperator = LogicalOperator.AND; } JsonNode copiedJsonNode = jsonNode.deepCopy(); @@ -130,18 +141,18 @@ public abstract class JsonQueryERElement { protected StringBuffer evaluateNode(JsonNode jsonNode, String fieldName, String fieldNamePrefix) throws InvalidQueryException { StringBuffer stringBuffer = new StringBuffer(); - if(QueryLogicalOperator.getOperators().contains(fieldName)) { - QueryLogicalOperator queryLogicalOperator = QueryLogicalOperator.getQueryLogicalOperator(fieldName); + if(LogicalOperator.getOperators().contains(fieldName)) { + LogicalOperator queryLogicalOperator = LogicalOperator.getQueryLogicalOperator(fieldName); stringBuffer.append("("); stringBuffer.append(addConstraints(jsonNode, queryLogicalOperator, fieldNamePrefix)); stringBuffer.append(")"); return stringBuffer; } - if(QueryConditionalOperator.getOperators().contains(fieldName)) { - QueryConditionalOperator queryConditionalOperator = QueryConditionalOperator.getQueryComparisonOperator(fieldName); + if(ConditionalOperator.getOperators().contains(fieldName)) { + ConditionalOperator queryConditionalOperator = ConditionalOperator.getQueryComparisonOperator(fieldName); - if(queryConditionalOperator == QueryConditionalOperator.IN) { + if(queryConditionalOperator == ConditionalOperator.IN) { throw new UnsupportedOperationException(); } @@ -171,13 +182,13 @@ public abstract class JsonQueryERElement { if(jsonNode.isTextual() || jsonNode.isNumber()) { StringBuffer key = getKey(fieldName, fieldNamePrefix); StringBuffer value = getValue(jsonNode); - stringBuffer.append(addCondition(QueryConditionalOperator.EQ, key, value)); + stringBuffer.append(addCondition(ConditionalOperator.EQ, key, value)); } return stringBuffer; } - protected StringBuffer addCondition(QueryConditionalOperator queryConditionalOperator, StringBuffer key, StringBuffer value) { + protected StringBuffer addCondition(ConditionalOperator queryConditionalOperator, StringBuffer key, StringBuffer value) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(key); stringBuffer.append(queryConditionalOperator.getConditionalOperator()); 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 7476f9c..5683e70 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 @@ -7,36 +7,37 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException; import org.gcube.informationsystem.resourceregistry.queries.json.base.relations.JsonQueryConsistsOf; +import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; /** * @author Luca Frosini (ISTI - CNR) */ public class JsonQueryFacet extends JsonQueryEntity { - public final static String _IN = "_in"; + public final static String _SOURCE = "_source"; public JsonQueryFacet(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException { super(jsonQuery, AccessType.FACET); - fieldNamesToRemove.add(JsonQueryFacet._IN); + fieldNamesToRemove.add(JsonQueryFacet._SOURCE); } - + @Override public StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { StringBuffer newBuffer = new StringBuffer(); int size = jsonNode.size(); - boolean entry = entryPoint; - if(jsonNode.has(_IN)) { + boolean noTraversalLocal = noTraversal; + if(jsonNode.has(_SOURCE)) { if(!entryPoint) { - throw new InvalidQueryException(_IN + " property cannot be used in a facet if it is not the entry object"); + throw new InvalidQueryException(_SOURCE + " property cannot be used in a facet if it is not the entry object"); } - JsonNode consistsOfNode = jsonNode.get(_IN); + JsonNode consistsOfNode = jsonNode.get(_SOURCE); JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfNode); - jsonQueryConsistsOf.setEntryPoint(entryPoint); + jsonQueryConsistsOf.setNoTraversal(noTraversal); jsonQueryConsistsOf.setDirection(Direction.OUT); stringBuffer = jsonQueryConsistsOf.analize(stringBuffer); - entry = false; + noTraversalLocal = false; /* Need to substract 1 from size otherwise * it add WHERE at the end because _in @@ -47,24 +48,41 @@ public class JsonQueryFacet extends JsonQueryEntity { newBuffer.append("SELECT FROM "); - if(!entry) { + if(!noTraversalLocal) { newBuffer.append("( "); newBuffer.append("TRAVERSE inV(\""); } newBuffer.append(type); - if(!entry) { + if(!noTraversalLocal) { newBuffer.append("\") FROM ( "); newBuffer.append(stringBuffer); newBuffer.append(")"); newBuffer.append(")"); } + /* + * If size >1 I have to add constraints. + * If is an entry point I have to add the INSTANCEOF to properly support polymorphism + */ + if(size > 1 || entryPoint) { + newBuffer.append(" WHERE "); + } + // Size 1 means that only 'type' property is present if(size > 1) { - newBuffer.append(" WHERE "); newBuffer.append(addConstraints(jsonNode, null, null)); + if(entryPoint) { + newBuffer.append(" AND "); + } + } + + if(entryPoint) { + newBuffer.append(OrientDBUtility.ORIENTDB_CLASS_PROPERTY); + newBuffer.append(" INSTANCEOF \""); + newBuffer.append(type); + newBuffer.append("\""); } return newBuffer; 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 00dfb77..a090d3a 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 @@ -9,6 +9,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException; import org.gcube.informationsystem.resourceregistry.queries.json.base.relations.JsonQueryConsistsOf; import org.gcube.informationsystem.resourceregistry.queries.json.base.relations.JsonQueryIsRelatedTo; +import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; /** * @author Luca Frosini (ISTI - CNR) @@ -27,7 +28,7 @@ public class JsonQueryResource extends JsonQueryEntity { int size = jsonNode.size(); - if(!entryPoint) { + if(!noTraversal) { StringBuffer newBuffer = new StringBuffer(); newBuffer.append("TRAVERSE "); newBuffer.append(direction.name().toLowerCase()); @@ -49,7 +50,7 @@ public class JsonQueryResource extends JsonQueryEntity { JsonNode isRelatedToJsonNode = isRelatedToArray.get(i); JsonQueryIsRelatedTo jsonQueryIsRelatedTo = new JsonQueryIsRelatedTo(isRelatedToJsonNode); jsonQueryIsRelatedTo.setRequestedResourceType(type); - jsonQueryIsRelatedTo.setEntryPoint(entryPoint && i==0); + jsonQueryIsRelatedTo.setNoTraversal(noTraversal && i==0); stringBuffer = jsonQueryIsRelatedTo.analize(stringBuffer); } @@ -63,44 +64,50 @@ public class JsonQueryResource extends JsonQueryEntity { JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfJsonNode); jsonQueryConsistsOf.setRequestedResourceType(type); jsonQueryConsistsOf.setDirection(Direction.IN); - jsonQueryConsistsOf.setEntryPoint(entryPoint && !initFound && i==0); + jsonQueryConsistsOf.setNoTraversal(noTraversal && !initFound && i==0); stringBuffer = jsonQueryConsistsOf.analize(stringBuffer); } initFound = true; // Must be set after the cycle and not before } - if(entryPoint) { - if(!initFound) { - stringBuffer = new StringBuffer(); - stringBuffer.append("SELECT FROM "); - stringBuffer.append(type); - if(size > 1) { - stringBuffer.append(" WHERE "); - stringBuffer.append(addConstraints(jsonNode, null, null)); - } - }else { - if(size > 1) { - StringBuffer newBuffer = new StringBuffer(); - newBuffer.append("SELECT FROM ( "); - newBuffer.append(stringBuffer); - newBuffer.append(")"); - newBuffer.append(" WHERE "); - newBuffer.append(addConstraints(jsonNode, null, null)); - stringBuffer = newBuffer; - } - } - }else { - if(initFound && size > 1) { - StringBuffer newBuffer = new StringBuffer(); - newBuffer.append("SELECT FROM ( "); - newBuffer.append(stringBuffer); - newBuffer.append(")"); - newBuffer.append(" WHERE "); - newBuffer.append(addConstraints(jsonNode, null, null)); - stringBuffer = newBuffer; - } + StringBuffer newBuffer = new StringBuffer(); + if(entryPoint || ((initFound && size >1) || !initFound)) { + newBuffer.append("SELECT FROM "); } + if(initFound) { + if(size > 1 || entryPoint){ + newBuffer.append("( "); + } + newBuffer.append(stringBuffer); + + if(size > 1 || entryPoint){ + newBuffer.append(")"); + } + }else { + newBuffer.append(type); + } + + if(size > 1 || entryPoint ) { + newBuffer.append(" WHERE "); + } + + if(size > 1) { + newBuffer.append(addConstraints(jsonNode, null, null)); + if(entryPoint) { + newBuffer.append(" AND "); + } + } + + if(entryPoint) { + newBuffer.append(OrientDBUtility.ORIENTDB_CLASS_PROPERTY); + newBuffer.append(" INSTANCEOF \""); + newBuffer.append(type); + newBuffer.append("\""); + } + + stringBuffer = newBuffer; + return stringBuffer; } 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 6f449c6..1528e2e 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 @@ -52,7 +52,7 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { consistsOfBuffer.append(type); consistsOfBuffer.append("\") FROM ( "); // Open ( 2 - if(!entryPoint) { + if(!noTraversal) { StringBuffer buffer = new StringBuffer(); buffer.append("TRAVERSE "); buffer.append(direction.opposite().name().toLowerCase()); @@ -67,12 +67,12 @@ public class JsonQueryConsistsOf extends JsonQueryRelation { if(jsonNode.has(ConsistsOf.TARGET_PROPERTY)) { JsonNode facetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY); JsonQueryFacet jsonQueryFacet = new JsonQueryFacet(facetJsonNode); - jsonQueryFacet.setEntryPoint(entryPoint); + jsonQueryFacet.setNoTraversal(noTraversal); stringBuffer = jsonQueryFacet.analize(stringBuffer); } else if(jsonNode.has(ConsistsOf.SOURCE_PROPERTY)) { JsonNode resourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY); JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode); - jsonQueryResource.setEntryPoint(entryPoint); + jsonQueryResource.setNoTraversal(noTraversal); stringBuffer = jsonQueryResource.analize(stringBuffer); } 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 b0ff7b5..103ca24 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 @@ -46,20 +46,20 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { if(size > 0) { buffer.append("SELECT FROM "); - if(entryPoint) { + if(noTraversal) { buffer.append(type); }else { buffer.append(" ( "); // Open ( SELECT } }else { - if(entryPoint) { + if(noTraversal) { buffer.append("SELECT FROM "); buffer.append(type); } } - if(!entryPoint) { + if(!noTraversal) { buffer.append("TRAVERSE "); buffer.append(direction.opposite().name().toLowerCase()); buffer.append("E(\""); @@ -74,7 +74,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { // Size 0 means that only 'type' and 'target'/'source' properties are present if(size > 0) { - if(!entryPoint) { + if(!noTraversal) { stringBuffer.append(" )"); // Close ) SELECT } stringBuffer.append(" WHERE "); @@ -104,7 +104,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode); jsonQueryResource.setDirection(direction); - jsonQueryResource.setEntryPoint(false); + jsonQueryResource.setNoTraversal(false); stringBuffer = jsonQueryResource.analize(stringBuffer); StringBuffer buffer = new StringBuffer(); @@ -132,15 +132,15 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation { jsonQueryResource = new JsonQueryResource(targetJsonNode); jsonQueryResource.setDirection(Direction.IN); - jsonQueryResource.setEntryPoint(false); + jsonQueryResource.setNoTraversal(false); stringBuffer = jsonQueryResource.analize(stringBuffer); - boolean entryPointOldValue = entryPoint; + boolean noTraversalOldValue = noTraversal; // It is no more and entry point for the function traverseThisEdge - entryPoint = false; + noTraversal = false; stringBuffer = traverseThisEdge(stringBuffer); // Restoring entryPoint indication - entryPoint = entryPointOldValue; + noTraversal = noTraversalOldValue; } return stringBuffer; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/ConditionalOperator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/ConditionalOperator.java new file mode 100644 index 0000000..115d6da --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/ConditionalOperator.java @@ -0,0 +1,82 @@ +package org.gcube.informationsystem.resourceregistry.queries.operators; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.gcube.informationsystem.types.PropertyTypeName.BaseTypeGroup; + +/** + * @author Luca Frosini (ISTI - CNR) + * See https://www.orientdb.com/docs/3.0.x/sql/SQL-Where.html + */ +public enum ConditionalOperator { + + EQ("_eq", " = ", BaseTypeGroup.ANY, "Matches values that are equal to a specified value. E.g. `name = 'Luke'`"), + GT("_gt", " > ", BaseTypeGroup.ANY, "Matches values that are greater than a specified value. "), + GTE("_gte", " >= ", BaseTypeGroup.ANY, "Matches values that are greater than or equal to a specified value."), + LT("_lt", " < ", BaseTypeGroup.ANY, "Matches values that are less than a specified value."), + LTE("_lte", " <= ", BaseTypeGroup.ANY, "Matches values that are less than or equal to a specified value."), + NE("_ne", " <> ", BaseTypeGroup.ANY, "Matches all values that are not equal to a specified value."), + BETWEEN("_between", " BETWEEN ", BaseTypeGroup.ANY, "The value is between a range. E.g. `price BETWEEN 10 AND 30`. It's equivalent to `price >= 10 AND price <= 30`."), + IS("_is", " IS ", BaseTypeGroup.ANY, "Used to test if a value is NULL"), + + LIKE("_like", " LIKE ", BaseTypeGroup.STRING, "Similar to equals, but allow the wildcard '%' that means 'any'. E.g. `name LIKE 'Luk%'`"), + CONTAINS_TEXT("_containsText", " CONTAINSTEXT ", BaseTypeGroup.STRING, "The string contains such text. E.g. `text CONTAINSTEXT 'jay'`"), + MATCHES("_matches", " MATCHES ", BaseTypeGroup.STRING, "Matches the string using a Regular Expression. E.g. `text MATCHES '\b[A-Z0-9.%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}\b'`"), + + IN("_in", " IN ", BaseTypeGroup.COLLECTION, "Matches any of the values specified in an array. E.g. `name in ['European','Asiatic']`"), + CONTAINS("_contains", " CONTAINS ", BaseTypeGroup.COLLECTION, "True if the collection contains at least one element that satisfy the next condition. Condition can be a single item: in this case the behaviour is like the IN operator. E.g. `children contains (name = 'Luke')` - `map.values() contains (name = 'Luke')`"), + CONTAINS_ALL("_containsAll", " CONTAINSALL ", BaseTypeGroup.COLLECTION, "True if all the elements of the collection satisfy the next condition. E.g. `children CONTAINSALL (name = 'Luke')`"), + CONTAINS_ANY("_containsAny", " CONTAINSANY ", BaseTypeGroup.COLLECTION, "True if all the elements of the collection satisfy the next condition. E.g. `children CONTAINSANY (name = 'Luke')`"), + + CONTAINS_KEY("_containsKey", " CONTAINSKEY ", BaseTypeGroup.MAP, "True if the map contains at least one key equals to the requested. You can also use map.keys() CONTAINS in place of it. E.g. `connections CONTAINSKEY 'Luke'`"), + CONTAINS_VALUE("_containsValue", " CONTAINSVALUE ", BaseTypeGroup.MAP , "True if the map contains at least one value equals to the requested. You can also use map.values() CONTAINS in place of it. E.g. `connections containsValue 10:3`"); + + + protected final String operator; + protected final String conditionalOperator; + protected final BaseTypeGroup allowed; + protected final String description; + + private ConditionalOperator(String operator, String conditionalOperator, BaseTypeGroup allowed, String description) { + this.operator = operator; + this.conditionalOperator = conditionalOperator; + this.allowed = allowed; + this.description = description; + } + + public String getOperator() { + return operator; + } + + public String getConditionalOperator() { + return conditionalOperator; + } + + public String getDescription() { + return description; + } + + private static Set operators; + private static Map operatorByKey; + + static { + ConditionalOperator.operators = new HashSet<>(); + ConditionalOperator.operatorByKey = new HashMap<>(); + + for(ConditionalOperator queryComparisonOperator : ConditionalOperator.values()) { + ConditionalOperator.operators.add(queryComparisonOperator.getOperator()); + ConditionalOperator.operatorByKey.put(queryComparisonOperator.getOperator(), queryComparisonOperator); + } + } + + public static Set getOperators() { + return ConditionalOperator.operators; + } + + public static ConditionalOperator getQueryComparisonOperator(String key) { + return operatorByKey.get(key); + } +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/LogicalOperator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/LogicalOperator.java new file mode 100644 index 0000000..46536a7 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/LogicalOperator.java @@ -0,0 +1,60 @@ +package org.gcube.informationsystem.resourceregistry.queries.operators; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author Luca Frosini (ISTI - CNR) + * See https://www.orientdb.com/docs/3.0.x/sql/SQL-Where.html + */ +public enum LogicalOperator { + + AND("_and", " AND ", "true if both the conditions are true"), + OR("_or", " OR ", "true if at least one of the condition is true"), + NOT("_not", " NOT ", "true if the condition is false."); + + protected final String operator; + protected final String logicalOperator; + protected final String description; + + private LogicalOperator(String operator, String logicalOperator, String description) { + this.operator = operator; + this.logicalOperator = logicalOperator; + this.description = description; + } + + public String getOperator() { + return operator; + } + + public String getLogicalOperator() { + return logicalOperator; + } + + public String getDescription() { + return description; + } + + private static Set operators; + private static Map operatorByKey; + + static { + LogicalOperator.operators = new HashSet<>(); + LogicalOperator.operatorByKey = new HashMap<>(); + + for(LogicalOperator queryLogicalOperator : LogicalOperator.values()) { + LogicalOperator.operators.add(queryLogicalOperator.getOperator()); + LogicalOperator.operatorByKey.put(queryLogicalOperator.getOperator(), queryLogicalOperator); + } + } + + public static Set getOperators() { + return LogicalOperator.operators; + } + + public static LogicalOperator getQueryLogicalOperator(String key) { + return operatorByKey.get(key); + } +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/MatemathicsOperator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/MatemathicsOperator.java new file mode 100644 index 0000000..11b8234 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/MatemathicsOperator.java @@ -0,0 +1,68 @@ +package org.gcube.informationsystem.resourceregistry.queries.operators; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author Luca Frosini (ISTI - CNR) + * See https://www.orientdb.com/docs/3.0.x/sql/SQL-Where.html + */ +public enum MatemathicsOperator { + + SUM("_sum", " + ", ""), + MINUS("_minus", " - ", ""), + MULTIPLY("_multiply", " * ", ""), + DIVIDE("_divide", " / ", ""), + MODULE("_mod", " % ", ""), + BITWISE_RIGHT_SHIFT("_bitrshift", " >> ", ""), + BITWISE_LEFT_SHIFT("_bitlshift", " << ", ""), + BITWISE_AND("_bitand", " & ", ""), + BITWISE_OR("_bitor", " | ", ""), + BITWISE_XOR("_bitxor", " ^ ", ""), + ARRAY_CONCATENATION("_arrayconcat", " || ", ""); + + protected final String operator; + protected final String matemathicsOperator; + protected final String description; + + private MatemathicsOperator(String operator, String matemathicsOperator, String description) { + this.operator = operator; + this.matemathicsOperator = matemathicsOperator; + this.description = description; + } + + public String getOperator() { + return operator; + } + + public String getMatemathicsOperator() { + return matemathicsOperator; + } + + public String getDescription() { + return description; + } + + private static Set operators; + private static Map operatorByKey; + + static { + MatemathicsOperator.operators = new HashSet<>(); + MatemathicsOperator.operatorByKey = new HashMap<>(); + + for(MatemathicsOperator queryLogicalOperator : MatemathicsOperator.values()) { + MatemathicsOperator.operators.add(queryLogicalOperator.getOperator()); + MatemathicsOperator.operatorByKey.put(queryLogicalOperator.getOperator(), queryLogicalOperator); + } + } + + public static Set getOperators() { + return MatemathicsOperator.operators; + } + + public static MatemathicsOperator getQueryLogicalOperator(String key) { + return operatorByKey.get(key); + } +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/QueryConditionalOperator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/QueryConditionalOperator.java deleted file mode 100644 index f6d52f2..0000000 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/QueryConditionalOperator.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.gcube.informationsystem.resourceregistry.queries.operators; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public enum QueryConditionalOperator { - - EQ("$eq", " = ", "Matches values that are equal to a specified value."), - GT("$gt", " > ", "Matches values that are greater than a specified value."), - GTE("$gte", " >= ", "Matches values that are greater than or equal to a specified value."), - LT("$lt", " < ", "Matches values that are less than a specified value."), - LTE("$lte", " <= ", "Matches values that are less than or equal to a specified value."), - NE("$ne", " <> ", "Matches all values that are not equal to a specified value."), - - IN("$in", " IN ", "Matches any of the values specified in an array."); - - protected final String operator; - protected final String conditionalOperator; - protected final String description; - - private QueryConditionalOperator(String operator, String conditionalOperator, String description) { - this.operator = operator; - this.conditionalOperator = conditionalOperator; - this.description = description; - } - - public String getOperator() { - return operator; - } - - public String getConditionalOperator() { - return conditionalOperator; - } - - public String getDescription() { - return description; - } - - private static Set operators; - private static Map operatorByKey; - - static { - QueryConditionalOperator.operators = new HashSet<>(); - QueryConditionalOperator.operatorByKey = new HashMap<>(); - - for(QueryConditionalOperator queryComparisonOperator : QueryConditionalOperator.values()) { - QueryConditionalOperator.operators.add(queryComparisonOperator.getOperator()); - QueryConditionalOperator.operatorByKey.put(queryComparisonOperator.getOperator(), queryComparisonOperator); - } - } - - public static Set getOperators() { - return QueryConditionalOperator.operators; - } - - public static QueryConditionalOperator getQueryComparisonOperator(String key) { - return operatorByKey.get(key); - } -} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/QueryLogicalOperator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/QueryLogicalOperator.java deleted file mode 100644 index 1665eb9..0000000 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/operators/QueryLogicalOperator.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.gcube.informationsystem.resourceregistry.queries.operators; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public enum QueryLogicalOperator { - - AND("$and", " AND ", "true if both the conditions are true"), - OR("$or", " OR ", "true if at least one of the condition is true"), - NOT("$not", " NOT ", "true if the condition is false."); - - protected final String operator; - protected final String logicalOperator; - protected final String description; - - private QueryLogicalOperator(String operator, String logicalOperator, String description) { - this.operator = operator; - this.logicalOperator = logicalOperator; - this.description = description; - } - - public String getOperator() { - return operator; - } - - public String getLogicalOperator() { - return logicalOperator; - } - - public String getDescription() { - return description; - } - - private static Set operators; - private static Map operatorByKey; - - static { - QueryLogicalOperator.operators = new HashSet<>(); - QueryLogicalOperator.operatorByKey = new HashMap<>(); - - for(QueryLogicalOperator queryLogicalOperator : QueryLogicalOperator.values()) { - QueryLogicalOperator.operators.add(queryLogicalOperator.getOperator()); - QueryLogicalOperator.operatorByKey.put(queryLogicalOperator.getOperator(), queryLogicalOperator); - } - } - - public static Set getOperators() { - return QueryLogicalOperator.operators; - } - - public static QueryLogicalOperator getQueryLogicalOperator(String key) { - return operatorByKey.get(key); - } -} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java index b4ee4f7..4c38b67 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java @@ -1,4 +1,4 @@ -package org.gcube.informationsystem.resourceregistry.utils; + package org.gcube.informationsystem.resourceregistry.utils; import java.util.HashMap; import java.util.UUID; diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java index 5455c86..00fdae5 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/queries/JsonQueryTest.java @@ -81,7 +81,7 @@ public class JsonQueryTest extends ContextTest { @Test public void testSingleCreateQuery() throws Exception { File queriesDirectory = getQueriesDirectory(); - File jsonQueryFile = new File(queriesDirectory, "query6.json"); + File jsonQueryFile = new File(queriesDirectory, "query3.json"); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(jsonQueryFile); logger.info("Going to test the following JSON query {}", jsonNode.toString()); @@ -108,11 +108,10 @@ public class JsonQueryTest extends ContextTest { logger.info("Result : {}", result); } - // @Test public List testSingleQuery(int offset, int limit) throws Exception { ContextTest.setContextByName(DEVVRE); File queriesDirectory = getQueriesDirectory(); - File jsonQueryFile = new File(queriesDirectory, "query3.json"); + File jsonQueryFile = new File(queriesDirectory, "query1.json"); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(jsonQueryFile); logger.info("Going to test the following JSON query {}", jsonNode.toString()); diff --git a/src/test/resources/queries/query1.query b/src/test/resources/queries/query1.query index cc04ebd..a1884cf 100644 --- a/src/test/resources/queries/query1.query +++ b/src/test/resources/queries/query1.query @@ -1 +1 @@ -TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM StateFacet WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer")) \ No newline at end of file +SELECT FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM StateFacet WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))) WHERE @class INSTANCEOF "EService" \ No newline at end of file diff --git a/src/test/resources/queries/query2.query b/src/test/resources/queries/query2.query index f2dac88..84082d6 100644 --- a/src/test/resources/queries/query2.query +++ b/src/test/resources/queries/query2.query @@ -1 +1 @@ -TRAVERSE outV("EService") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("AccessPointFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE inV("EService") FROM ( TRAVERSE outE("Activates") FROM ( SELECT FROM ( TRAVERSE outV("HostingNode") FROM ( SELECT FROM Activates WHERE id = "d3f58e52-5346-47bc-b736-9d77a0b554ce")) WHERE id = "5fbc1a56-d450-4f0f-85c1-9b1684581717"))))) WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))))) WHERE endpoint = "http://pc-frosini.isti.cnr.it:8080/data-transfer-service/gcube/service")) \ No newline at end of file +SELECT FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("AccessPointFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE inV("EService") FROM ( TRAVERSE outE("Activates") FROM ( SELECT FROM ( TRAVERSE outV("HostingNode") FROM ( SELECT FROM Activates WHERE id = "d3f58e52-5346-47bc-b736-9d77a0b554ce")) WHERE id = "5fbc1a56-d450-4f0f-85c1-9b1684581717"))))) WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))))) WHERE endpoint = "http://pc-frosini.isti.cnr.it:8080/data-transfer-service/gcube/service"))) WHERE @class INSTANCEOF "EService" \ No newline at end of file diff --git a/src/test/resources/queries/query3.query b/src/test/resources/queries/query3.query index 4d80ab9..7a2abac 100644 --- a/src/test/resources/queries/query3.query +++ b/src/test/resources/queries/query3.query @@ -1 +1 @@ -TRAVERSE outV("EService") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("AccessPointFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE inV("EService") FROM ( TRAVERSE outE("Activates") FROM ( TRAVERSE outV("HostingNode") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("CPUFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("HostingNode") FROM ( SELECT FROM Activates)))) WHERE vendor = "GenuineIntel"))))))) WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))))) WHERE endpoint = "http://pc-frosini.isti.cnr.it:8080/data-transfer-service/gcube/service")) \ No newline at end of file +SELECT FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("AccessPointFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE inV("EService") FROM ( TRAVERSE outE("Activates") FROM ( TRAVERSE outV("HostingNode") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("CPUFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("HostingNode") FROM ( SELECT FROM Activates)))) WHERE vendor = "GenuineIntel"))))))) WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))))) WHERE endpoint = "http://pc-frosini.isti.cnr.it:8080/data-transfer-service/gcube/service"))) WHERE @class INSTANCEOF "EService" \ No newline at end of file diff --git a/src/test/resources/queries/query4.json b/src/test/resources/queries/query4.json index 2c1b1f6..4ef7a57 100644 --- a/src/test/resources/queries/query4.json +++ b/src/test/resources/queries/query4.json @@ -1,7 +1,7 @@ { "type": "StateFacet", "value": "down", - "_in": { + "_source": { "type": "ConsistsOf", "source" : { "type" : "EService", diff --git a/src/test/resources/queries/query4.query b/src/test/resources/queries/query4.query index b10a1e4..5156621 100644 --- a/src/test/resources/queries/query4.query +++ b/src/test/resources/queries/query4.query @@ -1 +1 @@ -SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( SELECT FROM EService WHERE id = "0255b7ec-e3da-4071-b456-9a2907ece1db"))) WHERE value = "down" \ No newline at end of file +SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( SELECT FROM EService WHERE id = "0255b7ec-e3da-4071-b456-9a2907ece1db"))) WHERE value = "down" AND @class INSTANCEOF "StateFacet" \ No newline at end of file diff --git a/src/test/resources/queries/query5.json b/src/test/resources/queries/query5.json index 9eb3f57..958caa0 100644 --- a/src/test/resources/queries/query5.json +++ b/src/test/resources/queries/query5.json @@ -1,16 +1,16 @@ { "type": "StateFacet", "value": "down", - "_in": { + "_source": { "type": "ConsistsOf", "source" : { "type" : "EService", - "$or": [ - {"$and": { + "_or": [ + {"_and": { "id" : "aec0ef31-c735-4a4c-b2f4-57dfbd2fe925", - "metadata" :{ "createdBy": {"$ne": "luca.frosini"} } + "metadata" :{ "createdBy": {"_ne": "luca.frosini"} } }}, - {"$and": { + {"_and": { "id" : "0255b7ec-e3da-4071-b456-9a2907ece1db", "metadata" : { "createdBy": "DataTransfer:data-transfer-service:pc-frosini.isti.cnr.it_8080" } }} diff --git a/src/test/resources/queries/query5.query b/src/test/resources/queries/query5.query index 627dc6f..c0c14f9 100644 --- a/src/test/resources/queries/query5.query +++ b/src/test/resources/queries/query5.query @@ -1 +1 @@ -SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( SELECT FROM EService WHERE ((id = "aec0ef31-c735-4a4c-b2f4-57dfbd2fe925" AND metadata.createdBy <> "luca.frosini") OR (id = "0255b7ec-e3da-4071-b456-9a2907ece1db" AND metadata.createdBy = "DataTransfer:data-transfer-service:pc-frosini.isti.cnr.it_8080"))))) WHERE value = "down" \ No newline at end of file +SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( SELECT FROM EService WHERE ((id = "aec0ef31-c735-4a4c-b2f4-57dfbd2fe925" AND metadata.createdBy <> "luca.frosini") OR (id = "0255b7ec-e3da-4071-b456-9a2907ece1db" AND metadata.createdBy = "DataTransfer:data-transfer-service:pc-frosini.isti.cnr.it_8080"))))) WHERE value = "down" AND @class INSTANCEOF "StateFacet" \ No newline at end of file diff --git a/src/test/resources/queries/query6.query b/src/test/resources/queries/query6.query index 8dbf31c..7892004 100644 --- a/src/test/resources/queries/query6.query +++ b/src/test/resources/queries/query6.query @@ -1 +1 @@ -SELECT FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("AccessPointFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE inV("EService") FROM ( TRAVERSE outE("Activates") FROM ( SELECT FROM ( TRAVERSE outV("HostingNode") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("CPUFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("HostingNode") FROM ( SELECT FROM Activates WHERE id = "d3f58e52-5346-47bc-b736-9d77a0b554ce")))) WHERE vendor = "GenuineIntel"))) WHERE id = "5fbc1a56-d450-4f0f-85c1-9b1684581717"))))) WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))))) WHERE endpoint = "http://pc-frosini.isti.cnr.it:8080/data-transfer-service/gcube/service"))) WHERE id = "0255b7ec-e3da-4071-b456-9a2907ece1db" \ No newline at end of file +SELECT FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("AccessPointFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE inV("EService") FROM ( TRAVERSE outE("Activates") FROM ( SELECT FROM ( TRAVERSE outV("HostingNode") FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM ( TRAVERSE inV("CPUFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("HostingNode") FROM ( SELECT FROM Activates WHERE id = "d3f58e52-5346-47bc-b736-9d77a0b554ce")))) WHERE vendor = "GenuineIntel"))) WHERE id = "5fbc1a56-d450-4f0f-85c1-9b1684581717"))))) WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))))) WHERE endpoint = "http://pc-frosini.isti.cnr.it:8080/data-transfer-service/gcube/service"))) WHERE id = "0255b7ec-e3da-4071-b456-9a2907ece1db" AND @class INSTANCEOF "EService" \ No newline at end of file diff --git a/src/test/resources/queries/query7.json b/src/test/resources/queries/query7.json index be68c5f..4c75644 100644 --- a/src/test/resources/queries/query7.json +++ b/src/test/resources/queries/query7.json @@ -1,15 +1,15 @@ { "type": "StateFacet", - "_in": { + "_source": { "type": "ConsistsOf", "source" : { "type" : "EService", - "$or": [ - {"$and": { + "_or": [ + {"_and": { "id" : "aec0ef31-c735-4a4c-b2f4-57dfbd2fe925", - "metadata" :{ "createdBy": {"$ne": "luca.frosini"} } + "metadata" :{ "createdBy": {"_ne": "luca.frosini"} } }}, - {"$and": { + {"_and": { "id" : "0255b7ec-e3da-4071-b456-9a2907ece1db", "metadata" : { "createdBy": "DataTransfer:data-transfer-service:pc-frosini.isti.cnr.it_8080" } }} diff --git a/src/test/resources/queries/query7.query b/src/test/resources/queries/query7.query index dce7b47..d2ac59a 100644 --- a/src/test/resources/queries/query7.query +++ b/src/test/resources/queries/query7.query @@ -1 +1 @@ -SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( SELECT FROM EService WHERE ((id = "aec0ef31-c735-4a4c-b2f4-57dfbd2fe925" AND metadata.createdBy <> "luca.frosini") OR (id = "0255b7ec-e3da-4071-b456-9a2907ece1db" AND metadata.createdBy = "DataTransfer:data-transfer-service:pc-frosini.isti.cnr.it_8080"))))) \ No newline at end of file +SELECT FROM ( TRAVERSE inV("StateFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( SELECT FROM EService WHERE ((id = "aec0ef31-c735-4a4c-b2f4-57dfbd2fe925" AND metadata.createdBy <> "luca.frosini") OR (id = "0255b7ec-e3da-4071-b456-9a2907ece1db" AND metadata.createdBy = "DataTransfer:data-transfer-service:pc-frosini.isti.cnr.it_8080"))))) WHERE @class INSTANCEOF "StateFacet" \ No newline at end of file diff --git a/src/test/resources/queries/query9.json b/src/test/resources/queries/query9.json index 1836af8..9ecfdb1 100644 --- a/src/test/resources/queries/query9.json +++ b/src/test/resources/queries/query9.json @@ -1,6 +1,6 @@ { "type": "SimpleFacet", - "_in": { + "_source": { "type": "ConsistsOf", "source": { "type": "Configuration", diff --git a/src/test/resources/queries/query9.query b/src/test/resources/queries/query9.query index b723d4b..258bbba 100644 --- a/src/test/resources/queries/query9.query +++ b/src/test/resources/queries/query9.query @@ -1 +1 @@ -SELECT FROM ( TRAVERSE inV("SimpleFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("Configuration") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("IdentifierFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE inV("Configuration") FROM ( TRAVERSE outE("IsCustomizedBy") FROM ( TRAVERSE outV("VirtualService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("VirtualService") FROM ( SELECT FROM IsCustomizedBy)))) WHERE group = "org.gcube.data-catalogue" AND name = "catalogue-virtual-service"))))))) WHERE value = "gcat-configuration"))))) \ No newline at end of file +SELECT FROM ( TRAVERSE inV("SimpleFacet") FROM ( TRAVERSE outE("ConsistsOf") FROM ( TRAVERSE outV("Configuration") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("IdentifierFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE inV("Configuration") FROM ( TRAVERSE outE("IsCustomizedBy") FROM ( TRAVERSE outV("VirtualService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("VirtualService") FROM ( SELECT FROM IsCustomizedBy)))) WHERE group = "org.gcube.data-catalogue" AND name = "catalogue-virtual-service"))))))) WHERE value = "gcat-configuration"))))) WHERE @class INSTANCEOF "SimpleFacet" \ No newline at end of file