Fixing bug on properties
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134345 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
14e35279bb
commit
daf61bc522
|
@ -48,7 +48,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||||
import com.fasterxml.jackson.databind.node.NullNode;
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
import com.tinkerpop.blueprints.Direction;
|
import com.tinkerpop.blueprints.Direction;
|
||||||
import com.tinkerpop.blueprints.Edge;
|
import com.tinkerpop.blueprints.Edge;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
|
@ -144,7 +144,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkEmbeddedType(JsonNode jsonNode)
|
private static ODocument getEmbeddedType(JsonNode jsonNode)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
if (jsonNode.has(Entities.CLASS_PROPERTY)) {
|
if (jsonNode.has(Entities.CLASS_PROPERTY)) {
|
||||||
// Complex type
|
// Complex type
|
||||||
|
@ -173,16 +173,20 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
"An embedded object cannot have an Header");
|
"An embedded object cannot have an Header");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ODocument oDocument = new ODocument(type);
|
||||||
|
return oDocument.fromJSON(jsonNode.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getObejctFromElement(JsonNode value)
|
public static Object getObejctFromElement(JsonNode value)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
JsonNodeType jsonNodeType = value.getNodeType();
|
JsonNodeType jsonNodeType = value.getNodeType();
|
||||||
|
|
||||||
switch (jsonNodeType) {
|
switch (jsonNodeType) {
|
||||||
case OBJECT:
|
case OBJECT:
|
||||||
checkEmbeddedType(value);
|
return getEmbeddedType(value);
|
||||||
return null;
|
|
||||||
|
|
||||||
case ARRAY:
|
case ARRAY:
|
||||||
List<Object> array = new ArrayList<>();
|
List<Object> array = new ArrayList<>();
|
||||||
|
@ -239,6 +243,10 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
|
if(ignoreKeys == null){
|
||||||
|
ignoreKeys = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
Iterator<Entry<String, JsonNode>> fields = jsonNode.fields();
|
Iterator<Entry<String, JsonNode>> fields = jsonNode.fields();
|
||||||
while (fields.hasNext()) {
|
while (fields.hasNext()) {
|
||||||
Entry<String, JsonNode> entry = fields.next();
|
Entry<String, JsonNode> entry = fields.next();
|
||||||
|
@ -334,6 +342,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
Set<String> ignoreKeys = new HashSet<>();
|
Set<String> ignoreKeys = new HashSet<>();
|
||||||
ignoreKeys.add(Relation.TARGET_PROPERTY);
|
ignoreKeys.add(Relation.TARGET_PROPERTY);
|
||||||
ignoreKeys.add(Relation.SOURCE_PROPERTY);
|
ignoreKeys.add(Relation.SOURCE_PROPERTY);
|
||||||
|
ignoreKeys.add(Relation.HEADER_PROPERTY);
|
||||||
|
|
||||||
Map<String, Object> edgeProperties = null;
|
Map<String, Object> edgeProperties = null;
|
||||||
try {
|
try {
|
||||||
|
@ -403,6 +412,30 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
if (Resource.class.isAssignableFrom(entity)) {
|
if (Resource.class.isAssignableFrom(entity)) {
|
||||||
// Facet and relation are created in calling method
|
// Facet and relation are created in calling method
|
||||||
} else {
|
} else {
|
||||||
|
Set<String> ignoreKeys = new HashSet<>();
|
||||||
|
Map<String, Object> properties = null;
|
||||||
|
try {
|
||||||
|
properties = getPropertyMap(jsonNode, ignoreKeys);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String error = "Error while parsing json to get Relation properties";
|
||||||
|
logger.error(error, e);
|
||||||
|
throw new ResourceRegistryException(error, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String key : properties.keySet()) {
|
||||||
|
try {
|
||||||
|
vertex.setProperty(key, properties.get(key));
|
||||||
|
} catch (Exception e) {
|
||||||
|
String error = String.format(
|
||||||
|
"Error while setting property %s : %s", key,
|
||||||
|
properties.get(key).toString());
|
||||||
|
logger.error(error);
|
||||||
|
throw new ResourceRegistryException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
Iterator<Entry<String, JsonNode>> iterator = jsonNode.fields();
|
Iterator<Entry<String, JsonNode>> iterator = jsonNode.fields();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Entry<String, JsonNode> entry = iterator.next();
|
Entry<String, JsonNode> entry = iterator.next();
|
||||||
|
@ -418,6 +451,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
vertex.setProperty(entry.getKey(), value.asText());
|
vertex.setProperty(entry.getKey(), value.asText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextUtility.addToActualContext(orientGraph, vertex);
|
ContextUtility.addToActualContext(orientGraph, vertex);
|
||||||
|
@ -522,7 +556,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
Map<String, Object> edgeProperties, boolean deferredCommit)
|
Map<String, Object> edgeProperties, boolean deferredCommit)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
|
|
||||||
logger.debug("Trying to create {} with {}", relationType,
|
logger.debug("Trying to create {} with properties {}", relationType,
|
||||||
edgeProperties);
|
edgeProperties);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -571,20 +605,20 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("{} with {} successfully created", relationType,
|
logger.info("{} with properties {} successfully created", relationType,
|
||||||
edgeProperties);
|
edgeProperties);
|
||||||
|
|
||||||
return edge;
|
return edge;
|
||||||
|
|
||||||
} catch (ResourceRegistryException rre) {
|
} catch (ResourceRegistryException rre) {
|
||||||
logger.error("Error Creating {} with {}", relationType,
|
logger.error("Error Creating {} with properties {}", relationType,
|
||||||
edgeProperties, rre);
|
edgeProperties, rre);
|
||||||
if (orientGraph != null) {
|
if (orientGraph != null) {
|
||||||
orientGraph.rollback();
|
orientGraph.rollback();
|
||||||
}
|
}
|
||||||
throw rre;
|
throw rre;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error Creating {} with {}", relationType,
|
logger.error("Error Creating {} with properties {}", relationType,
|
||||||
edgeProperties, e);
|
edgeProperties, e);
|
||||||
if (orientGraph != null) {
|
if (orientGraph != null) {
|
||||||
orientGraph.rollback();
|
orientGraph.rollback();
|
||||||
|
@ -668,6 +702,33 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
|
|
||||||
Set<String> oldKeys = facet.getPropertyKeys();
|
Set<String> oldKeys = facet.getPropertyKeys();
|
||||||
|
|
||||||
|
|
||||||
|
Set<String> ignoreKeys = new HashSet<>();
|
||||||
|
Map<String, Object> properties = null;
|
||||||
|
try {
|
||||||
|
properties = getPropertyMap(jsonNode, ignoreKeys);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String error = "Error while parsing json to get Relation properties";
|
||||||
|
logger.error(error, e);
|
||||||
|
throw new ResourceRegistryException(error, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
oldKeys.removeAll(properties.keySet());
|
||||||
|
|
||||||
|
for (String key : properties.keySet()) {
|
||||||
|
try {
|
||||||
|
facet.setProperty(key, properties.get(key));
|
||||||
|
} catch (Exception e) {
|
||||||
|
String error = String.format(
|
||||||
|
"Error while setting property %s : %s", key,
|
||||||
|
properties.get(key).toString());
|
||||||
|
logger.error(error);
|
||||||
|
throw new ResourceRegistryException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
Iterator<Entry<String, JsonNode>> iterator = jsonNode.fields();
|
Iterator<Entry<String, JsonNode>> iterator = jsonNode.fields();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
|
||||||
|
@ -690,6 +751,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
oldKeys.remove(key);
|
oldKeys.remove(key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
for (String key : oldKeys) {
|
for (String key : oldKeys) {
|
||||||
if (key.startsWith("_")) {
|
if (key.startsWith("_")) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
<logger name="org.gcube.informationsystem" level="DEBUG" />
|
<logger name="org.gcube.informationsystem" level="DEBUG" />
|
||||||
<logger name="org.gcube.informationsystem.resourceregistry.context" level="INFO" />
|
<logger name="org.gcube.informationsystem.resourceregistry.context" level="INFO" />
|
||||||
<logger name="org.gcube.informationsystem.resourceregistry.resources.utils" level="INFO" />
|
<logger name="org.gcube.informationsystem.resourceregistry.resources.utils" level="INFO" />
|
||||||
|
<logger name="org.gcube.informationsystem.resourceregistry.resources.impl" level="TRACE" />
|
||||||
<logger name="org.gcube.informationsystem.impl.utils.discovery" level="ERROR" />
|
<logger name="org.gcube.informationsystem.impl.utils.discovery" level="ERROR" />
|
||||||
|
|
||||||
<root level="WARN">
|
<root level="WARN">
|
||||||
|
|
Loading…
Reference in New Issue