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;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OElement updateProperties(OClass oClass, OElement element, JsonNode jsonNode, Set<String> ignoreKeys,
|
public void setProperty(OProperty oProperty, String key, JsonNode value) throws Exception {
|
||||||
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 {
|
|
||||||
switch (oProperty.getType()) {
|
switch (oProperty.getType()) {
|
||||||
|
|
||||||
case EMBEDDED:
|
case EMBEDDED:
|
||||||
ODocument oDocument = PropertyElementManagement.getPropertyDocument(value);
|
ODocument oDocument = PropertyElementManagement.getPropertyDocument(value);
|
||||||
element.setProperty(key, oDocument, OType.EMBEDDED);
|
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);
|
element.setProperty(key, map, OType.EMBEDDEDMAP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case STRING:
|
||||||
|
|
||||||
|
if(value.getNodeType() == JsonNodeType.OBJECT) {
|
||||||
|
element.setProperty(key, value.toString());
|
||||||
|
}else {
|
||||||
|
element.setProperty(key, getObjectFromJsonNode(value));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Object object = getObjectFromJsonNode(value);
|
Object obj = getObjectFromJsonNode(value);
|
||||||
if(object != null) {
|
if(obj != null) {
|
||||||
element.setProperty(key, object);
|
element.setProperty(key, obj);
|
||||||
}
|
}
|
||||||
break;
|
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) {
|
} catch(Exception e) {
|
||||||
String error = String.format("Error while setting property %s : %s (%s)", key,
|
String error = String.format("Error while setting property %s : %s (%s)", key,
|
||||||
properties.get(key).toString(), e.getMessage());
|
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.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.queries.templates.reference.entities.QueryTemplate;
|
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||||
|
@ -100,8 +101,19 @@ public class QueryTemplateManagement extends EntityElementManagement<QueryTempla
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
|
try {
|
||||||
JsonNode queryTemplate = serializeSelfAsJsonNode();
|
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;
|
return queryTemplate;
|
||||||
|
}catch (ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected StringBuffer getSelectQuery() {
|
protected StringBuffer getSelectQuery() {
|
||||||
|
|
Loading…
Reference in New Issue