Fixed issue on template property of QueryTemplate serialization
This commit is contained in:
parent
6bd1cc11d0
commit
c6305c9570
|
@ -971,40 +971,9 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
return map;
|
||||
}
|
||||
|
||||
public OElement updateProperties(OClass oClass, OElement element, JsonNode jsonNode, Set<String> ignoreKeys,
|
||||
Set<String> ignoreStartWithKeys) throws ResourceRegistryException {
|
||||
|
||||
Set<String> oldKeys = element.getPropertyNames();
|
||||
|
||||
Map<String,JsonNode> properties;
|
||||
try {
|
||||
properties = getPropertyMap(jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
} catch(IOException e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
|
||||
oldKeys.removeAll(properties.keySet());
|
||||
|
||||
getOClass();
|
||||
|
||||
for(String key : properties.keySet()) {
|
||||
try {
|
||||
|
||||
JsonNode value = properties.get(key);
|
||||
|
||||
OProperty oProperty = oClass.getProperty(key);
|
||||
|
||||
if(oProperty==null) {
|
||||
Object object = getObjectFromJsonNode(value);
|
||||
if(object != null) {
|
||||
if(object instanceof ODocument) {
|
||||
element.setProperty(key, object, OType.EMBEDDED);
|
||||
}else {
|
||||
element.setProperty(key, object);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
public void setProperty(OProperty oProperty, String key, JsonNode value) throws Exception {
|
||||
switch (oProperty.getType()) {
|
||||
|
||||
case EMBEDDED:
|
||||
ODocument oDocument = PropertyElementManagement.getPropertyDocument(value);
|
||||
element.setProperty(key, oDocument, OType.EMBEDDED);
|
||||
|
@ -1060,15 +1029,60 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
element.setProperty(key, map, OType.EMBEDDEDMAP);
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
|
||||
if(value.getNodeType() == JsonNodeType.OBJECT) {
|
||||
element.setProperty(key, value.toString());
|
||||
}else {
|
||||
element.setProperty(key, getObjectFromJsonNode(value));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Object object = getObjectFromJsonNode(value);
|
||||
if(object != null) {
|
||||
element.setProperty(key, object);
|
||||
Object obj = getObjectFromJsonNode(value);
|
||||
if(obj != null) {
|
||||
element.setProperty(key, obj);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public OElement updateProperties(OClass oClass, OElement element, JsonNode jsonNode, Set<String> ignoreKeys,
|
||||
Set<String> ignoreStartWithKeys) throws ResourceRegistryException {
|
||||
|
||||
Set<String> oldKeys = element.getPropertyNames();
|
||||
|
||||
Map<String,JsonNode> properties;
|
||||
try {
|
||||
properties = getPropertyMap(jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
} catch(IOException e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
|
||||
oldKeys.removeAll(properties.keySet());
|
||||
|
||||
getOClass();
|
||||
|
||||
for(String key : properties.keySet()) {
|
||||
try {
|
||||
|
||||
JsonNode value = properties.get(key);
|
||||
|
||||
OProperty oProperty = oClass.getProperty(key);
|
||||
|
||||
if(oProperty==null) {
|
||||
Object object = getObjectFromJsonNode(value);
|
||||
if(object != null) {
|
||||
if(object instanceof ODocument) {
|
||||
element.setProperty(key, object, OType.EMBEDDED);
|
||||
}else {
|
||||
element.setProperty(key, object);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
setProperty(oProperty, key, value);
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
String error = String.format("Error while setting property %s : %s (%s)", key,
|
||||
properties.get(key).toString(), e.getMessage());
|
||||
|
|
|
@ -6,6 +6,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.ObjectNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
|
@ -100,8 +101,19 @@ public class QueryTemplateManagement extends EntityElementManagement<QueryTempla
|
|||
|
||||
@Override
|
||||
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||
try {
|
||||
JsonNode queryTemplate = serializeSelfAsJsonNode();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String templateString = element.getProperty(QueryTemplate.TEMPLATE_PROPERTY);
|
||||
JsonNode templateJsonNode = objectMapper.readTree(templateString);
|
||||
((ObjectNode) queryTemplate).replace(QueryTemplate.TEMPLATE_PROPERTY, templateJsonNode);
|
||||
return queryTemplate;
|
||||
}catch (ResourceRegistryException e) {
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected StringBuffer getSelectQuery() {
|
||||
|
|
Loading…
Reference in New Issue