diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryConsistsOf.java b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryConsistsOf.java index 66e562d..938a863 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryConsistsOf.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryConsistsOf.java @@ -4,8 +4,8 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; -import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; /** * @author Luca Frosini (ISTI - CNR) @@ -14,7 +14,7 @@ public class JsonQueryConsistsOf extends JsonQueryERElement{ protected String requestedResourceType; - public JsonQueryConsistsOf(JsonNode jsonQuery) throws SchemaNotFoundException { + public JsonQueryConsistsOf(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException { super(jsonQuery, AccessType.CONSISTS_OF); this.direction = Direction.IN; } @@ -28,7 +28,7 @@ public class JsonQueryConsistsOf extends JsonQueryERElement{ } @Override - protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException { + protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { StringBuffer consistsOfBuffer = new StringBuffer(); consistsOfBuffer.append("TRAVERSE "); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryERElement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryERElement.java index abf1ba7..55745b1 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryERElement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryERElement.java @@ -8,15 +8,21 @@ import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.Relation; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; +import org.gcube.informationsystem.resourceregistry.types.TypesCache; public abstract class JsonQueryERElement { // private Logger logger = LoggerFactory.getLogger(this.getClass()); - public static void validateType(String type, AccessType resource) throws SchemaNotFoundException { - // TODO Auto-generated method stub + public static void validateType(String type, AccessType requiredAccessType) throws SchemaException, ResourceRegistryException { + AccessType accessType = TypesCache.getInstance().getCachedType(type).getAccessType(); + if(!accessType.equals(requiredAccessType)) { + throw new InvalidQueryException(type + "is not an expected " + requiredAccessType.getName() + " type"); + } } protected final String type; @@ -26,7 +32,7 @@ public abstract class JsonQueryERElement { protected Direction direction; protected boolean entryPoint; - public JsonQueryERElement(JsonNode jsonQuery, AccessType accessType) throws SchemaNotFoundException { + public JsonQueryERElement(JsonNode jsonQuery, AccessType accessType) throws SchemaException, ResourceRegistryException { this.type = jsonQuery.get(Element.CLASS_PROPERTY).asText(); this.jsonNode = jsonQuery; this.accessType = accessType; @@ -54,7 +60,7 @@ public abstract class JsonQueryERElement { this.entryPoint = entryPoint; } - protected abstract StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException; + protected abstract StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException, SchemaException, ResourceRegistryException; protected StringBuffer addWhereConstraint(JsonNode jsonNode, StringBuffer stringBuffer, String fieldNamePrefix) throws InvalidQueryException { Iterator iterator = jsonNode.fieldNames(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryFacet.java b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryFacet.java index 591efe3..6ef2260 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryFacet.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryFacet.java @@ -2,7 +2,9 @@ package org.gcube.informationsystem.resourceregistry.query.json; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.informationsystem.base.reference.AccessType; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; /** @@ -10,7 +12,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema */ public class JsonQueryFacet extends JsonQueryERElement{ - public JsonQueryFacet(JsonNode jsonQuery) throws SchemaNotFoundException { + public JsonQueryFacet(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException { super(jsonQuery, AccessType.FACET); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryIsRelatedTo.java b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryIsRelatedTo.java index 88fc98e..28c95ec 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryIsRelatedTo.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryIsRelatedTo.java @@ -4,8 +4,9 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; /** * @author Luca Frosini (ISTI - CNR) @@ -14,7 +15,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryERElement{ protected String requestedResourceType; - public JsonQueryIsRelatedTo(JsonNode jsonQuery) throws SchemaNotFoundException { + public JsonQueryIsRelatedTo(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException { super(jsonQuery, AccessType.IS_RELATED_TO); } @@ -72,7 +73,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryERElement{ } @Override - protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException { + protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryResource.java b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryResource.java index b0f60e5..8dcc950 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryResource.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/query/json/JsonQueryResource.java @@ -6,20 +6,20 @@ import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.model.reference.entities.Resource; -import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; /** * @author Luca Frosini (ISTI - CNR) */ public class JsonQueryResource extends JsonQueryERElement { - public JsonQueryResource(JsonNode jsonQuery) throws SchemaNotFoundException { + public JsonQueryResource(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException { super(jsonQuery, AccessType.RESOURCE); } @Override - protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException { + protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException { if(!entryPoint) { StringBuffer newBuffer = new StringBuffer(); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/query/JsonQueryTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/query/JsonQueryTest.java index 57c48b1..60e550c 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/query/JsonQueryTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/query/JsonQueryTest.java @@ -65,10 +65,10 @@ public class JsonQueryTest extends ContextTest { } - //@Test + @Test public void testSingleCreateQuery() throws Exception { File queriesDirectory = getQueriesDirectory(); - File jsonQueryFile = new File(queriesDirectory, "query3.json"); + File jsonQueryFile = new File(queriesDirectory, "facet.json"); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(jsonQueryFile); logger.info("Going to test the following JSON query {}", jsonNode.toString()); @@ -80,7 +80,7 @@ public class JsonQueryTest extends ContextTest { logger.info("Created Query from JSON: {}", createdStringBuffer.toString()); } - @Test + // @Test public void testSingleQuery() throws Exception { ContextTest.setContextByName(DEVVRE); File queriesDirectory = getQueriesDirectory();