Ported changes from master

This commit is contained in:
Luca Frosini 2023-02-02 14:26:59 +01:00
parent 54ac1596a2
commit ac54fe6694
9 changed files with 161 additions and 41 deletions

View File

@ -5,13 +5,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [v5.0.0-SNAPSHOT]
- Switched to gcube-smartgears-bom 3.0.0
## [v4.1.1]
- Fixed bug on JSONQuery for Facets which does not have any properties to match [#24237]
- Fixed bug on JSONQuery for IsRelatedTo relations indicating both source and target resources [#24264]
- Fixed bug on returned boolean values as string [#24240]
- Enabled array properties [#24225]
## [v4.1.0-SNAPSHOT]
## [v4.1.0]
- Relation source-target instance types are validated against Relation schema [#7355]
- The instances are validated with the defined schema [#18216]

View File

@ -20,6 +20,7 @@ import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.BooleanNode;
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
@ -893,7 +894,16 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
return PropertyElementManagement.getPropertyDocument(value);
case ARRAY:
break;
/*
* Due to bug https://github.com/orientechnologies/orientdb/issues/7354
* we should not support ArrayList
*/
List<Object> list = new ArrayList<>();
ArrayNode arrayNode = (ArrayNode) value;
for(JsonNode node : arrayNode) {
list.add(getObjectFromJsonNode(node));
}
return list;
case BINARY:
break;
@ -1194,6 +1204,10 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
return objectNode;
}
if(object instanceof Boolean) {
return BooleanNode.valueOf((Boolean) object);
}
return new TextNode(object.toString());
} catch(Exception e) {

View File

@ -3,7 +3,7 @@ package org.gcube.informationsystem.resourceregistry.queries.json.base.relations
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.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
@ -32,7 +32,19 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation {
StringBuffer buffer = new StringBuffer();
int size = jsonNode.size();
if(size > 2) {
// Remove @class from size
--size;
if(jsonNode.has(IsRelatedTo.SOURCE_PROPERTY)) {
--size;
}
if(jsonNode.has(IsRelatedTo.TARGET_PROPERTY)) {
--size;
}
if(size > 0) {
buffer.append("SELECT FROM ");
if(entryPoint) {
buffer.append(type);
@ -60,8 +72,8 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation {
stringBuffer = buffer;
// Size 2 means that only '@class' and 'target'/'source' properties are present
if(size > 2) {
// Size 0 means that only '@class' and 'target'/'source' properties are present
if(size > 0) {
if(!entryPoint) {
stringBuffer.append(" )"); // Close ) SELECT
}
@ -75,8 +87,8 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation {
@Override
public StringBuffer analize(StringBuffer stringBuffer) throws SchemaException, ResourceRegistryException {
JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY);
JsonNode targetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY);
JsonNode sourceJsonNode = jsonNode.get(IsRelatedTo.SOURCE_PROPERTY);
JsonNode targetJsonNode = jsonNode.get(IsRelatedTo.TARGET_PROPERTY);
JsonNode resourceJsonNode = null;
@ -96,11 +108,13 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation {
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("\") FROM ( ");
if(requestedResourceType!=null) {
buffer.append("TRAVERSE ");
buffer.append(direction.opposite().name().toLowerCase());
buffer.append("V(\"");
buffer.append(requestedResourceType);
buffer.append("\") FROM ( ");
}
buffer.append("TRAVERSE ");
buffer.append(direction.name().toLowerCase());
buffer.append("E(\"");
@ -108,13 +122,29 @@ public class JsonQueryIsRelatedTo extends JsonQueryRelation {
buffer.append("\") FROM ( ");
buffer.append(stringBuffer);
buffer.append(")");
buffer.append(")");
if(requestedResourceType!=null) {
buffer.append(")");
}
stringBuffer = buffer;
if(sourceJsonNode!=null && targetJsonNode!=null) {
// Target has still to be analised
jsonQueryResource = new JsonQueryResource(targetJsonNode);
jsonQueryResource.setDirection(Direction.IN);
jsonQueryResource.setEntryPoint(false);
stringBuffer = jsonQueryResource.analize(stringBuffer);
boolean entryPointOldValue = entryPoint;
// It is no more and entry point for the function traverseThisEdge
entryPoint = false;
stringBuffer = traverseThisEdge(stringBuffer);
// Restoring entryPoint indication
entryPoint = entryPointOldValue;
}
return stringBuffer;
}
}

View File

@ -95,23 +95,23 @@ public class ERManagementTest extends ContextTest {
public static final String VERSION = "1.0.0";
public static final String NEW_VERSION = "2.0.0";
@Before
@After
public void cleanInstances() throws Exception {
// Clean the environment first to avoid error if a previous tests fails without cleaning the env
ResourceManagement rm = (ResourceManagement) ElementManagementUtility.getERManagement(Resource.NAME);
String all = rm.all(true);
List<Resource> allResources = ElementMapper.unmarshalList(Resource.class, all);
for(Resource r : allResources) {
try {
ERManagementTest.deleteResource(r);
}catch (ResourceNotFoundException e) {
// A resource could be already deleted deleting another resource giving the propagation constraint
}catch (ODatabaseException e) {
// could occur
}
}
}
// @Before
// @After
// public void cleanInstances() throws Exception {
// // Clean the environment first to avoid error if a previous tests fails without cleaning the env
// ResourceManagement rm = (ResourceManagement) ElementManagementUtility.getERManagement(Resource.NAME);
// String all = rm.all(true);
// List<Resource> allResources = ElementMapper.unmarshalList(Resource.class, all);
// for(Resource r : allResources) {
// try {
// ERManagementTest.deleteResource(r);
// }catch (ResourceNotFoundException e) {
// // A resource could be already deleted deleting another resource giving the propagation constraint
// }catch (ODatabaseException e) {
// // could occur
// }
// }
// }
public static SoftwareFacet getSoftwareFacet() {

View File

@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.queries;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.net.URL;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
@ -34,8 +35,16 @@ public class JsonQueryTest extends ContextTest {
File queriesDirectory = getQueriesDirectory();
for(int i=1; i<7; i++) {
File jsonQueryFile = new File(queriesDirectory, "query" + i + ".json");
FilenameFilter filenameFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".json");
}
};
for(File jsonQueryFile : queriesDirectory.listFiles(filenameFilter)) {
logger.info("Going to read JSON query frtm file {}", jsonQueryFile.getAbsolutePath());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonQueryFile);
logger.info("Going to test the following JSON query {}", jsonNode.toString());
@ -47,7 +56,7 @@ public class JsonQueryTest extends ContextTest {
logger.info("Created Query from JSON: {}", createdStringBuffer.toString());
StringBuffer expectedStringBuffer = new StringBuffer();
File expectedQueryFile = new File(queriesDirectory, "query" + i + ".query");
File expectedQueryFile = new File(queriesDirectory, jsonQueryFile.getName().replace("json", "query"));
try(BufferedReader br = new BufferedReader(new FileReader(expectedQueryFile))) {
for(String line; (line = br.readLine()) != null; ) {
expectedStringBuffer.append(line);
@ -66,7 +75,7 @@ public class JsonQueryTest extends ContextTest {
@Test
public void testSingleCreateQuery() throws Exception {
File queriesDirectory = getQueriesDirectory();
File jsonQueryFile = new File(queriesDirectory, "query7.json");
File jsonQueryFile = new File(queriesDirectory, "query9.json");
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonQueryFile);
logger.info("Going to test the following JSON query {}", jsonNode.toString());

View File

@ -0,0 +1,29 @@
{
"@class": "CallsFor",
"source": {
"@class": "EService",
"consistsOf": [
{
"@class": "IsIdentifiedBy",
"target": {
"@class": "SoftwareFacet",
"group": "org.gcube.data-catalogue",
"name": "gcat"
}
}
]
},
"target":{
"@class": "VirtualService",
"consistsOf": [
{
"@class": "IsIdentifiedBy",
"target": {
"@class": "SoftwareFacet",
"group": "org.gcube.data-catalogue",
"name": "catalogue-virtual-service"
}
}
]
}
}

View File

@ -0,0 +1 @@
TRAVERSE inE("CallsFor") FROM ( TRAVERSE outV("VirtualService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE inV("VirtualService") FROM ( TRAVERSE outE("CallsFor") 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 CallsFor)))) WHERE group = "org.gcube.data-catalogue" AND name = "gcat"))))))) WHERE group = "org.gcube.data-catalogue" AND name = "catalogue-virtual-service")))

View File

@ -0,0 +1,36 @@
{
"@class": "SimpleFacet",
"_in": {
"@class": "ConsistsOf",
"source": {
"@class": "Configuration",
"consistsOf": [
{
"@class": "IsIdentifiedBy",
"target": {
"@class": "IdentifierFacet",
"value": "gcat-configuration"
}
}
],
"isRelatedTo": [
{
"@class": "IsCustomizedBy",
"source": {
"@class": "VirtualService",
"consistsOf": [
{
"@class": "IsIdentifiedBy",
"target": {
"@class": "SoftwareFacet",
"group": "org.gcube.data-catalogue",
"name": "catalogue-virtual-service"
}
}
]
}
}
]
}
}
}

View File

@ -0,0 +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")))))