Reorganizing code
This commit is contained in:
parent
cd8627cf32
commit
64a2ced9ec
|
@ -14,7 +14,6 @@ import java.util.Map.Entry;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.activation.UnsupportedDataTypeException;
|
||||
import javax.ws.rs.ForbiddenException;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
@ -1014,64 +1013,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
return getContextsAsObjectNode(objectMapper);
|
||||
}
|
||||
|
||||
public static Object getObjectFromJsonNode(JsonNode value)
|
||||
throws UnsupportedDataTypeException, ResourceRegistryException {
|
||||
JsonNodeType jsonNodeType = value.getNodeType();
|
||||
|
||||
switch(jsonNodeType) {
|
||||
case OBJECT:
|
||||
return PropertyElementManagement.getPropertyDocument(value);
|
||||
|
||||
case ARRAY:
|
||||
/*
|
||||
* 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;
|
||||
|
||||
case BOOLEAN:
|
||||
return value.asBoolean();
|
||||
|
||||
case NULL:
|
||||
break;
|
||||
|
||||
case NUMBER:
|
||||
if(value.isDouble() || value.isFloat()) {
|
||||
return value.asDouble();
|
||||
}
|
||||
if(value.isBigInteger() || value.isShort() || value.isInt()) {
|
||||
return value.asInt();
|
||||
}
|
||||
|
||||
if(value.isLong()) {
|
||||
return value.asLong();
|
||||
}
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
return value.asText();
|
||||
|
||||
case MISSING:
|
||||
break;
|
||||
|
||||
case POJO:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String,JsonNode> getPropertyMap(JsonNode jsonNode, Set<String> ignoreKeys,
|
||||
Set<String> ignoreStartWith) throws JsonProcessingException, IOException {
|
||||
|
||||
|
@ -1126,7 +1067,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
Object object = null;
|
||||
|
||||
if(oProperty.getLinkedType()!=null) {
|
||||
object = getObjectFromJsonNode(elementOfArray);
|
||||
object = ElementManagementUtility.getObjectFromJsonNode(elementOfArray);
|
||||
}else {
|
||||
object = PropertyElementManagement.getPropertyDocument(elementOfArray);
|
||||
}
|
||||
|
@ -1143,7 +1084,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
Object object = null;
|
||||
|
||||
if(oProperty.getLinkedType()!=null) {
|
||||
object = getObjectFromJsonNode(elementOfSet);
|
||||
object = ElementManagementUtility.getObjectFromJsonNode(elementOfSet);
|
||||
}else {
|
||||
object = PropertyElementManagement.getPropertyDocument(elementOfSet);
|
||||
}
|
||||
|
@ -1159,7 +1100,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
String fieldKey = fieldNames.next();
|
||||
Object object = null;
|
||||
if(oProperty.getLinkedType()!=null) {
|
||||
object = getObjectFromJsonNode(value.get(fieldKey));
|
||||
object = ElementManagementUtility.getObjectFromJsonNode(value.get(fieldKey));
|
||||
}else {
|
||||
object = PropertyElementManagement.getPropertyDocument(value.get(fieldKey));
|
||||
}
|
||||
|
@ -1173,12 +1114,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
if(value.getNodeType() == JsonNodeType.OBJECT) {
|
||||
element.setProperty(key, value.toString());
|
||||
}else {
|
||||
element.setProperty(key, getObjectFromJsonNode(value));
|
||||
element.setProperty(key, ElementManagementUtility.getObjectFromJsonNode(value));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Object obj = getObjectFromJsonNode(value);
|
||||
Object obj = ElementManagementUtility.getObjectFromJsonNode(value);
|
||||
if(obj != null) {
|
||||
element.setProperty(key, obj);
|
||||
}
|
||||
|
@ -1209,7 +1150,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
OProperty oProperty = oClass.getProperty(key);
|
||||
|
||||
if(oProperty==null) {
|
||||
Object object = getObjectFromJsonNode(value);
|
||||
Object object = ElementManagementUtility.getObjectFromJsonNode(value);
|
||||
if(object != null) {
|
||||
if(object instanceof ODocument) {
|
||||
element.setProperty(key, object, OType.EMBEDDED);
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
package org.gcube.informationsystem.resourceregistry.base;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.activation.UnsupportedDataTypeException;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.base.properties.PropertyElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.environments.Environment;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||
|
@ -149,5 +157,63 @@ public class ElementManagementUtility {
|
|||
throw new ResourceRegistryException("An element not belonging to any defined type should not exists. Please contact the administrator.");
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getObjectFromJsonNode(JsonNode value)
|
||||
throws UnsupportedDataTypeException, ResourceRegistryException {
|
||||
JsonNodeType jsonNodeType = value.getNodeType();
|
||||
|
||||
switch(jsonNodeType) {
|
||||
case OBJECT:
|
||||
return PropertyElementManagement.getPropertyDocument(value);
|
||||
|
||||
case ARRAY:
|
||||
/*
|
||||
* 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;
|
||||
|
||||
case BOOLEAN:
|
||||
return value.asBoolean();
|
||||
|
||||
case NULL:
|
||||
break;
|
||||
|
||||
case NUMBER:
|
||||
if(value.isDouble() || value.isFloat()) {
|
||||
return value.asDouble();
|
||||
}
|
||||
if(value.isBigInteger() || value.isShort() || value.isInt()) {
|
||||
return value.asInt();
|
||||
}
|
||||
|
||||
if(value.isLong()) {
|
||||
return value.asLong();
|
||||
}
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
return value.asText();
|
||||
|
||||
case MISSING:
|
||||
break;
|
||||
|
||||
case POJO:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue