Starting supporting facet as result

This commit is contained in:
Luca Frosini 2021-10-18 16:23:41 +02:00
parent 5486954750
commit c8d9007121
6 changed files with 28 additions and 19 deletions

View File

@ -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.AccessType;
import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -14,7 +14,7 @@ public class JsonQueryConsistsOf extends JsonQueryERElement{
protected String requestedResourceType; protected String requestedResourceType;
public JsonQueryConsistsOf(JsonNode jsonQuery) throws SchemaNotFoundException { public JsonQueryConsistsOf(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException {
super(jsonQuery, AccessType.CONSISTS_OF); super(jsonQuery, AccessType.CONSISTS_OF);
this.direction = Direction.IN; this.direction = Direction.IN;
} }
@ -28,7 +28,7 @@ public class JsonQueryConsistsOf extends JsonQueryERElement{
} }
@Override @Override
protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException { protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException {
StringBuffer consistsOfBuffer = new StringBuffer(); StringBuffer consistsOfBuffer = new StringBuffer();
consistsOfBuffer.append("TRAVERSE "); consistsOfBuffer.append("TRAVERSE ");

View File

@ -8,15 +8,21 @@ import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.Relation; 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.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.api.exceptions.schema.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
public abstract class JsonQueryERElement { public abstract class JsonQueryERElement {
// private Logger logger = LoggerFactory.getLogger(this.getClass()); // private Logger logger = LoggerFactory.getLogger(this.getClass());
public static void validateType(String type, AccessType resource) throws SchemaNotFoundException { public static void validateType(String type, AccessType requiredAccessType) throws SchemaException, ResourceRegistryException {
// TODO Auto-generated method stub 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; protected final String type;
@ -26,7 +32,7 @@ public abstract class JsonQueryERElement {
protected Direction direction; protected Direction direction;
protected boolean entryPoint; 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.type = jsonQuery.get(Element.CLASS_PROPERTY).asText();
this.jsonNode = jsonQuery; this.jsonNode = jsonQuery;
this.accessType = accessType; this.accessType = accessType;
@ -54,7 +60,7 @@ public abstract class JsonQueryERElement {
this.entryPoint = entryPoint; 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 { protected StringBuffer addWhereConstraint(JsonNode jsonNode, StringBuffer stringBuffer, String fieldNamePrefix) throws InvalidQueryException {
Iterator<String> iterator = jsonNode.fieldNames(); Iterator<String> iterator = jsonNode.fieldNames();

View File

@ -2,7 +2,9 @@ package org.gcube.informationsystem.resourceregistry.query.json;
import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.AccessType; 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.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.api.exceptions.schema.SchemaNotFoundException;
/** /**
@ -10,7 +12,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
*/ */
public class JsonQueryFacet extends JsonQueryERElement{ public class JsonQueryFacet extends JsonQueryERElement{
public JsonQueryFacet(JsonNode jsonQuery) throws SchemaNotFoundException { public JsonQueryFacet(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException {
super(jsonQuery, AccessType.FACET); super(jsonQuery, AccessType.FACET);
} }

View File

@ -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.AccessType;
import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; 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.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) * @author Luca Frosini (ISTI - CNR)
@ -14,7 +15,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryERElement{
protected String requestedResourceType; protected String requestedResourceType;
public JsonQueryIsRelatedTo(JsonNode jsonQuery) throws SchemaNotFoundException { public JsonQueryIsRelatedTo(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException {
super(jsonQuery, AccessType.IS_RELATED_TO); super(jsonQuery, AccessType.IS_RELATED_TO);
} }
@ -72,7 +73,7 @@ public class JsonQueryIsRelatedTo extends JsonQueryERElement{
} }
@Override @Override
protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException { protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException {
JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY); JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY);

View File

@ -6,20 +6,20 @@ import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
public class JsonQueryResource extends JsonQueryERElement { public class JsonQueryResource extends JsonQueryERElement {
public JsonQueryResource(JsonNode jsonQuery) throws SchemaNotFoundException { public JsonQueryResource(JsonNode jsonQuery) throws SchemaException, ResourceRegistryException {
super(jsonQuery, AccessType.RESOURCE); super(jsonQuery, AccessType.RESOURCE);
} }
@Override @Override
protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException { protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException {
if(!entryPoint) { if(!entryPoint) {
StringBuffer newBuffer = new StringBuffer(); StringBuffer newBuffer = new StringBuffer();

View File

@ -65,10 +65,10 @@ public class JsonQueryTest extends ContextTest {
} }
//@Test @Test
public void testSingleCreateQuery() throws Exception { public void testSingleCreateQuery() throws Exception {
File queriesDirectory = getQueriesDirectory(); File queriesDirectory = getQueriesDirectory();
File jsonQueryFile = new File(queriesDirectory, "query3.json"); File jsonQueryFile = new File(queriesDirectory, "facet.json");
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonQueryFile); JsonNode jsonNode = objectMapper.readTree(jsonQueryFile);
logger.info("Going to test the following JSON query {}", jsonNode.toString()); 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()); logger.info("Created Query from JSON: {}", createdStringBuffer.toString());
} }
@Test // @Test
public void testSingleQuery() throws Exception { public void testSingleQuery() throws Exception {
ContextTest.setContextByName(DEVVRE); ContextTest.setContextByName(DEVVRE);
File queriesDirectory = getQueriesDirectory(); File queriesDirectory = getQueriesDirectory();