Fixed projection
This commit is contained in:
parent
c324b3ab41
commit
30e8c84258
|
@ -2,11 +2,14 @@ package org.gcube.informationsystem.resourceregistry.queries.json;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
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.ArrayNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
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.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
@ -145,10 +148,39 @@ public class JsonQuery {
|
||||||
|
|
||||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||||
|
|
||||||
|
boolean projection = entryPoint.isProjection();
|
||||||
|
boolean first = true;
|
||||||
|
|
||||||
|
Set<String> keys = new HashSet<>();
|
||||||
|
|
||||||
while(resultSet.hasNext()) {
|
while(resultSet.hasNext()) {
|
||||||
OResult oResult = resultSet.next();
|
OResult oResult = resultSet.next();
|
||||||
|
|
||||||
|
if(projection) {
|
||||||
|
if(first) {
|
||||||
|
keys = oResult.getPropertyNames();
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||||
|
|
||||||
|
for(String key : keys) {
|
||||||
|
Object value = oResult.getProperty(key);
|
||||||
|
|
||||||
|
if(value == null) {
|
||||||
|
objectNode.put(key, "");
|
||||||
|
}else if(value instanceof String) {
|
||||||
|
objectNode.put(key, (String) value);
|
||||||
|
}else if(value instanceof Integer) {
|
||||||
|
objectNode.put(key, (Integer) value);
|
||||||
|
}else if(value instanceof Long) {
|
||||||
|
objectNode.put(key, (Long) value);
|
||||||
|
}else {
|
||||||
|
objectNode.put(key, value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
arrayNode.add(objectNode);
|
||||||
|
}else {
|
||||||
OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement());
|
OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -163,6 +195,7 @@ public class JsonQuery {
|
||||||
element.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
element.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return objectMapper.writeValueAsString(arrayNode);
|
return objectMapper.writeValueAsString(arrayNode);
|
||||||
|
|
||||||
|
|
|
@ -291,6 +291,10 @@ public abstract class JsonQueryERElement {
|
||||||
StringBuffer b = new StringBuffer();
|
StringBuffer b = new StringBuffer();
|
||||||
b.append(getAlias(true));
|
b.append(getAlias(true));
|
||||||
b.append(".");
|
b.append(".");
|
||||||
|
if(fieldNamePrefix !=null) {
|
||||||
|
b.append(fieldNamePrefix);
|
||||||
|
b.append(".");
|
||||||
|
}
|
||||||
b.append(fieldNameToEmit);
|
b.append(fieldNameToEmit);
|
||||||
b.append(" AS `");
|
b.append(" AS `");
|
||||||
b.append(nameOfFieldToEmit);
|
b.append(nameOfFieldToEmit);
|
||||||
|
|
|
@ -250,8 +250,8 @@ public class JsonQueryTest extends ContextTest {
|
||||||
|
|
||||||
Assert.assertTrue(compareQueries(createdStringBuffer, expectedStringBuffer));
|
Assert.assertTrue(compareQueries(createdStringBuffer, expectedStringBuffer));
|
||||||
|
|
||||||
// String result = jsonQuery.query();
|
String result = jsonQuery.query();
|
||||||
// logger.info("Result : {}", result);
|
logger.info("Result : {}", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -287,8 +287,8 @@ public class JsonQueryTest extends ContextTest {
|
||||||
logger.info("Expected Query from JSON: {}", expectedStringBuffer.toString());
|
logger.info("Expected Query from JSON: {}", expectedStringBuffer.toString());
|
||||||
Assert.assertTrue(compareQueries(createdStringBuffer, expectedStringBuffer));
|
Assert.assertTrue(compareQueries(createdStringBuffer, expectedStringBuffer));
|
||||||
|
|
||||||
//String result = jsonQuery.query();
|
String result = jsonQuery.query();
|
||||||
//logger.info("Result : {}", result);
|
logger.info("Result : {}", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,4 @@ RETURN
|
||||||
((memoryfacet020.size - memoryfacet020.used) + ' ' + memoryfacet020.unit) AS `HD Space Left`,
|
((memoryfacet020.size - memoryfacet020.used) + ' ' + memoryfacet020.unit) AS `HD Space Left`,
|
||||||
(memoryfacet030.size + ' ' + memoryfacet030.unit) AS `Mem. Available.`,
|
(memoryfacet030.size + ' ' + memoryfacet030.unit) AS `Mem. Available.`,
|
||||||
hostingnode0.id AS `ID`,
|
hostingnode0.id AS `ID`,
|
||||||
hostingnode0.lastUpdateTime AS `Last Update Time`
|
hostingnode0.metadata.lastUpdateTime AS `Last Update Time`
|
Loading…
Reference in New Issue