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.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 ");

View File

@ -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<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.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);
}

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.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);

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.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();

View File

@ -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();