2019-11-04 18:01:20 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.instances.base;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2017-01-18 14:57:20 +01:00
|
|
|
import java.text.DateFormat;
|
2019-11-04 18:01:20 +01:00
|
|
|
import java.util.ArrayList;
|
2017-01-18 14:57:20 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Date;
|
2016-12-19 14:59:27 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
2019-11-04 18:01:20 +01:00
|
|
|
import java.util.List;
|
2016-12-19 14:59:27 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Set;
|
2016-12-30 17:31:12 +01:00
|
|
|
import java.util.UUID;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2017-06-28 16:29:01 +02:00
|
|
|
import javax.activation.UnsupportedDataTypeException;
|
|
|
|
|
2019-10-25 17:45:59 +02:00
|
|
|
import org.gcube.informationsystem.base.reference.AccessType;
|
|
|
|
import org.gcube.informationsystem.base.reference.ER;
|
|
|
|
import org.gcube.informationsystem.base.reference.ISManageable;
|
|
|
|
import org.gcube.informationsystem.base.reference.properties.Header;
|
|
|
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
2018-06-04 15:31:13 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2016-12-30 17:31:12 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
2017-03-27 15:04:44 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
2017-11-28 17:34:43 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
2019-11-04 18:01:20 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.base.properties.BasePropertyManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
2017-01-18 14:57:20 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.utils.HeaderOrient;
|
2016-12-30 17:31:12 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
2016-12-30 17:31:12 +01:00
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2019-02-13 12:33:29 +01:00
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
2016-12-19 14:59:27 +01:00
|
|
|
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
2019-02-13 12:33:29 +01:00
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
import com.fasterxml.jackson.databind.node.TextNode;
|
2017-01-18 14:57:20 +01:00
|
|
|
import com.orientechnologies.orient.core.metadata.OMetadata;
|
2017-01-11 12:06:50 +01:00
|
|
|
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
2017-01-18 14:57:20 +01:00
|
|
|
import com.orientechnologies.orient.core.metadata.schema.OProperty;
|
|
|
|
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
|
|
|
import com.orientechnologies.orient.core.metadata.schema.OType;
|
|
|
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
|
|
import com.orientechnologies.orient.core.util.ODateHelper;
|
2016-12-19 14:59:27 +01:00
|
|
|
import com.tinkerpop.blueprints.Edge;
|
|
|
|
import com.tinkerpop.blueprints.Element;
|
|
|
|
import com.tinkerpop.blueprints.Vertex;
|
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
2016-12-30 17:31:12 +01:00
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
2017-01-18 14:57:20 +01:00
|
|
|
import com.tinkerpop.blueprints.util.StringFactory;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2019-11-05 09:28:55 +01:00
|
|
|
public abstract class ERManagement<El extends Element> {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
protected Logger logger = LoggerFactory.getLogger(this.getClass());
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
private static Logger staticLogger = LoggerFactory.getLogger(ERManagement.class);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
public final String AT = "@";
|
|
|
|
public final String UNDERSCORE = "_";
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public final static String DELETED = "deleted";
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
protected final Set<String> ignoreKeys;
|
|
|
|
protected final Set<String> ignoreStartWithKeys;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-03-29 16:53:37 +02:00
|
|
|
protected Class<El> elementClass;
|
2017-11-17 11:42:37 +01:00
|
|
|
protected final AccessType accessType;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
protected OrientGraph orientGraph;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
protected UUID uuid;
|
|
|
|
protected JsonNode jsonNode;
|
2017-03-29 16:53:37 +02:00
|
|
|
protected OClass oClass;
|
2018-06-08 18:18:48 +02:00
|
|
|
protected String elementType;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
protected El element;
|
2017-11-21 18:18:11 +01:00
|
|
|
protected boolean reload;
|
2017-11-15 19:31:49 +01:00
|
|
|
|
2018-06-04 15:34:20 +02:00
|
|
|
public UUID getUUID() {
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
2017-11-21 18:18:11 +01:00
|
|
|
public boolean isReload() {
|
|
|
|
return reload;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-21 18:18:11 +01:00
|
|
|
public void setReload(boolean reload) {
|
|
|
|
this.reload = reload;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
public AccessType getAccessType() {
|
|
|
|
return accessType;
|
|
|
|
}
|
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
protected SecurityContext workingContext;
|
|
|
|
|
|
|
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
|
|
|
if(workingContext == null) {
|
|
|
|
workingContext = ContextUtility.getCurrentSecurityContext();
|
|
|
|
}
|
|
|
|
return workingContext;
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|
2017-11-28 17:34:43 +01:00
|
|
|
|
|
|
|
public void setWorkingContext(SecurityContext workingContext) {
|
|
|
|
this.workingContext = workingContext;
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-03-29 16:53:37 +02:00
|
|
|
protected ERManagement(AccessType accessType) {
|
|
|
|
this.accessType = accessType;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
this.ignoreKeys = new HashSet<String>();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
this.ignoreStartWithKeys = new HashSet<String>();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
this.ignoreStartWithKeys.add(AT);
|
|
|
|
this.ignoreStartWithKeys.add(UNDERSCORE);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-21 18:18:11 +01:00
|
|
|
this.reload = false;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
public void setUUID(UUID uuid) throws ResourceRegistryException {
|
|
|
|
this.uuid = uuid;
|
2017-11-30 18:06:08 +01:00
|
|
|
if(jsonNode != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
checkUUIDMatch();
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public void setJsonNode(JsonNode jsonNode) throws ResourceRegistryException {
|
2016-12-30 17:31:12 +01:00
|
|
|
this.jsonNode = jsonNode;
|
2019-02-13 12:33:29 +01:00
|
|
|
checkJsonNode();
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public void setJson(String jsonRepresentation) throws ResourceRegistryException {
|
2016-12-30 17:31:12 +01:00
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
try {
|
|
|
|
this.jsonNode = mapper.readTree(jsonRepresentation);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(IOException e) {
|
2016-12-30 17:31:12 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
2019-02-13 12:33:29 +01:00
|
|
|
checkJsonNode();
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
protected OClass getOClass() throws SchemaException, ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(oClass == null) {
|
|
|
|
if(element != null) {
|
2017-03-29 16:14:03 +02:00
|
|
|
OrientElement orientElement = (OrientElement) element;
|
2019-02-13 16:53:17 +01:00
|
|
|
OMetadata oMetadata = orientElement.getRecord().getDatabase().getMetadata();
|
2017-03-29 16:14:03 +02:00
|
|
|
OSchema oSchema = oMetadata.getSchema();
|
|
|
|
String type = orientElement.getRecord().getClassName();
|
|
|
|
oClass = oSchema.getClass(type);
|
2017-11-28 17:34:43 +01:00
|
|
|
} else {
|
2018-06-08 18:18:48 +02:00
|
|
|
oClass = SchemaManagementImpl.getTypeSchema(elementType, accessType);
|
2017-03-29 16:14:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return oClass;
|
2017-03-27 15:04:44 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
public void setElementType(String erType) throws ResourceRegistryException {
|
2018-06-12 18:09:36 +02:00
|
|
|
if(this.elementType == null) {
|
2018-06-12 16:43:47 +02:00
|
|
|
if(erType == null || erType.compareTo("") == 0) {
|
|
|
|
erType = accessType.getName();
|
|
|
|
}
|
|
|
|
this.elementType = erType;
|
2018-06-12 18:09:36 +02:00
|
|
|
} else {
|
|
|
|
if(elementType.compareTo(erType) != 0) {
|
|
|
|
throw new ResourceRegistryException(
|
|
|
|
"Provided type " + erType + " does not match with the one already known " + this.accessType);
|
2018-06-12 16:43:47 +02:00
|
|
|
}
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
2018-06-12 16:43:47 +02:00
|
|
|
|
2017-11-30 18:06:08 +01:00
|
|
|
if(jsonNode != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
checkERMatch();
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-08 18:18:48 +02:00
|
|
|
public String getElementType() {
|
|
|
|
return elementType;
|
|
|
|
}
|
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
protected void checkJsonNode() throws ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(uuid == null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
try {
|
2019-02-13 12:33:29 +01:00
|
|
|
uuid = org.gcube.informationsystem.utils.Utility.getUUIDFromJsonNode(jsonNode);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-11-28 17:34:43 +01:00
|
|
|
}
|
2016-12-30 17:31:12 +01:00
|
|
|
} else {
|
|
|
|
checkUUIDMatch();
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-08 18:18:48 +02:00
|
|
|
if(this.elementType == null) {
|
|
|
|
this.elementType = getClassProperty(jsonNode);
|
2017-03-29 16:14:03 +02:00
|
|
|
getOClass();
|
2016-12-30 17:31:12 +01:00
|
|
|
} else {
|
|
|
|
checkERMatch();
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
protected void checkERMatch() throws ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(jsonNode != null) {
|
2017-01-13 17:06:57 +01:00
|
|
|
String type = getClassProperty(jsonNode);
|
2018-06-08 18:18:48 +02:00
|
|
|
if(type != null && type.compareTo(elementType) != 0) {
|
2018-06-06 19:26:19 +02:00
|
|
|
String error = String.format("Requested type does not match with json representation %s!=%s",
|
2018-06-08 18:18:48 +02:00
|
|
|
elementType, type);
|
2017-01-13 17:06:57 +01:00
|
|
|
logger.trace(error);
|
|
|
|
throw new ResourceRegistryException(error);
|
|
|
|
}
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
2017-03-29 16:14:03 +02:00
|
|
|
getOClass();
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
protected void checkUUIDMatch() throws ResourceRegistryException {
|
|
|
|
Header header = null;
|
|
|
|
try {
|
|
|
|
header = HeaderUtility.getHeader(jsonNode, false);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2016-12-30 17:31:12 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(header != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
UUID resourceUUID = header.getUUID();
|
2017-11-30 18:06:08 +01:00
|
|
|
if(resourceUUID.compareTo(uuid) != 0) {
|
2017-11-28 17:34:43 +01:00
|
|
|
String error = String.format(
|
|
|
|
"UUID provided in header (%s) differs from the one (%s) used to identify the %s instance",
|
2018-06-08 18:18:48 +02:00
|
|
|
resourceUUID.toString(), uuid.toString(), elementType);
|
2016-12-30 17:31:12 +01:00
|
|
|
throw new ResourceRegistryException(error);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public JsonNode serializeSelfOnly() throws ResourceRegistryException {
|
2017-01-17 16:53:24 +01:00
|
|
|
try {
|
2019-02-13 12:33:29 +01:00
|
|
|
return toJsonNode();
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-01-17 16:53:24 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
public abstract String serialize() throws ResourceRegistryException;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public abstract JsonNode serializeAsJson() throws ResourceRegistryException;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
protected abstract El reallyCreate() throws AlreadyPresentException, ResourceRegistryException;
|
2017-11-28 17:34:43 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public El internalCreate() throws AlreadyPresentException, ResourceRegistryException {
|
2017-10-26 17:09:07 +02:00
|
|
|
try {
|
|
|
|
reallyCreate();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(entityHeader != null) {
|
2018-06-11 11:01:10 +02:00
|
|
|
element.setProperty(ER.HEADER_PROPERTY, entityHeader);
|
2017-10-26 17:09:07 +02:00
|
|
|
} else {
|
|
|
|
entityHeader = HeaderUtility.addHeader(element, null);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
getWorkingContext().addElement(element, orientGraph);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
((OrientElement) element).save();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
return element;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-10-26 17:09:07 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2018-06-08 18:18:48 +02:00
|
|
|
throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e);
|
2017-10-26 17:09:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
protected abstract El reallyUpdate() throws NotFoundException, ResourceRegistryException;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public El internalUpdate() throws NotFoundException, ResourceRegistryException {
|
2017-10-26 17:09:07 +02:00
|
|
|
try {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
reallyUpdate();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-13 12:41:41 +01:00
|
|
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
2017-11-17 17:34:29 +01:00
|
|
|
((OrientElement) element).save();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
return element;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-10-26 17:09:07 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2018-06-08 18:18:48 +02:00
|
|
|
throw new ResourceRegistryException("Error Updating " + elementType + " with " + jsonNode, e);
|
2017-10-26 17:09:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
public El internalCreateOrUdate() throws ResourceRegistryException {
|
2017-07-06 17:45:22 +02:00
|
|
|
try {
|
2017-10-26 17:09:07 +02:00
|
|
|
return internalUpdate();
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch(NotFoundException e) {
|
2017-10-26 17:09:07 +02:00
|
|
|
return internalCreate();
|
2017-07-06 17:45:22 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
protected abstract boolean reallyDelete() throws NotFoundException, ResourceRegistryException;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public boolean internalDelete() throws NotFoundException, ResourceRegistryException {
|
2017-10-26 17:09:07 +02:00
|
|
|
// Added for consistency with create and update addToContext removeFromContext.
|
|
|
|
return reallyDelete();
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
protected abstract boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
public boolean internalAddToContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException {
|
2017-10-26 17:09:07 +02:00
|
|
|
try {
|
2018-06-06 19:26:19 +02:00
|
|
|
boolean ret = reallyAddToContext(targetSecurityContext);
|
2017-11-17 17:34:29 +01:00
|
|
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
|
|
|
((OrientElement) element).save();
|
2017-10-26 17:09:07 +02:00
|
|
|
return ret && true;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-10-26 17:09:07 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2018-06-12 18:09:36 +02:00
|
|
|
throw new ResourceRegistryException(
|
|
|
|
"Error Adding " + elementType + " to " + targetSecurityContext.toString(), e.getCause());
|
2017-10-26 17:09:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
protected abstract boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
public boolean internalRemoveFromContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException {
|
2017-10-26 17:09:07 +02:00
|
|
|
try {
|
2018-06-06 19:26:19 +02:00
|
|
|
boolean ret = reallyRemoveFromContext(targetSecurityContext);
|
2017-11-13 12:41:41 +01:00
|
|
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
2017-11-17 17:34:29 +01:00
|
|
|
((OrientElement) element).save();
|
2017-10-26 17:09:07 +02:00
|
|
|
return ret && true;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-10-26 17:09:07 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2018-06-12 18:09:36 +02:00
|
|
|
throw new ResourceRegistryException(
|
|
|
|
"Error Removing " + elementType + " from " + targetSecurityContext.toString(), e.getCause());
|
2017-10-26 17:09:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
public void setElement(El element) throws ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(element == null) {
|
2017-11-28 17:34:43 +01:00
|
|
|
throw new ResourceRegistryException("Trying to set null " + elementClass.getSimpleName() + " in " + this);
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
|
|
|
this.element = element;
|
|
|
|
this.uuid = HeaderUtility.getHeader(element).getUUID();
|
2018-06-08 18:18:48 +02:00
|
|
|
this.elementType = ((OrientElement) element).getLabel();
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
protected abstract NotFoundException getSpecificElementNotFoundException(NotFoundException e);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
protected abstract AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
2017-11-28 17:34:43 +01:00
|
|
|
String message);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
protected abstract AlreadyPresentException getSpecificERAlreadyPresentException(String message);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public El getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(element == null) {
|
2017-04-04 15:03:25 +02:00
|
|
|
try {
|
|
|
|
element = retrieveElement();
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch(NotFoundException e) {
|
2017-04-04 15:03:25 +02:00
|
|
|
try {
|
|
|
|
retrieveElementFromAnyContext();
|
2018-06-08 18:18:48 +02:00
|
|
|
throw getSpecificERAvailableInAnotherContextException(elementType == null ? accessType.getName()
|
|
|
|
: elementType + " with UUID " + uuid + " is available in another "
|
2017-11-28 17:34:43 +01:00
|
|
|
+ Context.class.getSimpleName());
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch(AvailableInAnotherContextException e1) {
|
2017-04-04 15:03:25 +02:00
|
|
|
throw e1;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e1) {
|
2017-04-04 15:03:25 +02:00
|
|
|
throw e;
|
2017-11-28 17:34:43 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-04-04 15:03:25 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-04-04 15:03:25 +02:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
} else {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(reload) {
|
2017-11-21 18:18:11 +01:00
|
|
|
((OrientElement) element).reload();
|
|
|
|
}
|
2017-03-29 16:14:03 +02:00
|
|
|
}
|
2017-04-04 15:03:25 +02:00
|
|
|
return element;
|
2017-03-29 16:14:03 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public El retrieveElement() throws NotFoundException, ResourceRegistryException {
|
2016-12-30 17:31:12 +01:00
|
|
|
try {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(uuid == null) {
|
2018-06-04 15:31:13 +02:00
|
|
|
throw new NotFoundException("null UUID does not allow to retrieve the Element");
|
2017-07-06 17:45:22 +02:00
|
|
|
}
|
2018-06-08 18:18:48 +02:00
|
|
|
return Utility.getElementByUUID(orientGraph, elementType == null ? accessType.getName() : elementType, uuid,
|
2017-11-28 17:34:43 +01:00
|
|
|
elementClass);
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch(NotFoundException e) {
|
2017-04-28 17:43:30 +02:00
|
|
|
throw getSpecificElementNotFoundException(e);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-03-29 16:14:03 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-03-29 16:14:03 +02:00
|
|
|
throw new ResourceRegistryException(e);
|
2016-12-30 17:31:12 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public El retrieveElementFromAnyContext() throws NotFoundException, ResourceRegistryException {
|
2017-11-28 17:34:43 +01:00
|
|
|
try {
|
2018-06-12 18:09:36 +02:00
|
|
|
return Utility.getElementByUUIDAsAdmin(elementType == null ? accessType.getName() : elementType, uuid,
|
|
|
|
elementClass);
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch(NotFoundException e) {
|
2017-04-28 17:43:30 +02:00
|
|
|
throw getSpecificElementNotFoundException(e);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-04-04 15:03:25 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-04-04 15:03:25 +02:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
2017-11-28 17:34:43 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-01-11 12:06:50 +01:00
|
|
|
public String all(boolean polymorphic) throws ResourceRegistryException {
|
|
|
|
try {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-01-11 12:06:50 +01:00
|
|
|
return reallyGetAll(polymorphic);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-01-11 12:06:50 +01:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-01-11 12:06:50 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2017-01-11 12:06:50 +01:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2017-03-28 16:02:23 +02:00
|
|
|
try {
|
2018-06-12 18:09:36 +02:00
|
|
|
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-04-04 15:03:25 +02:00
|
|
|
getElement();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-04-04 15:03:25 +02:00
|
|
|
return true;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to find {} with UUID {}", accessType.getName(), uuid);
|
2017-03-28 16:02:23 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to find {} with UUID {}", accessType.getName(), uuid, e);
|
2017-03-28 16:02:23 +02:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2017-03-28 16:02:23 +02:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public String createOrUpdate()
|
|
|
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2018-06-12 18:09:36 +02:00
|
|
|
try {
|
|
|
|
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
|
|
|
orientGraph.setAutoStartTx(false);
|
|
|
|
orientGraph.begin();
|
|
|
|
|
|
|
|
boolean update = false;
|
|
|
|
try {
|
|
|
|
getElement();
|
|
|
|
update = true;
|
|
|
|
element = internalUpdate();
|
2019-02-13 12:33:29 +01:00
|
|
|
} catch(NotFoundException e) {
|
2018-06-12 18:09:36 +02:00
|
|
|
element = internalCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
orientGraph.commit();
|
|
|
|
|
|
|
|
if(update) {
|
|
|
|
setReload(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Notify to subscriptionNotification
|
|
|
|
|
|
|
|
return serialize();
|
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
|
|
|
if(orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid, e);
|
|
|
|
if(orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
|
|
|
if(orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
2018-06-12 17:55:46 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
public String create() throws AlreadyPresentException, ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-05-03 11:21:45 +02:00
|
|
|
try {
|
2018-06-12 18:09:36 +02:00
|
|
|
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
|
|
|
orientGraph.setAutoStartTx(false);
|
|
|
|
orientGraph.begin();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
element = internalCreate();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-05-03 11:21:45 +02:00
|
|
|
orientGraph.commit();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
// TODO Notify to subscriptionNotification
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-05-03 11:21:45 +02:00
|
|
|
return serialize();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to create {}", accessType.getName());
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2017-05-03 11:21:45 +02:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to create {}", accessType.getName(), e);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2017-05-03 11:21:45 +02:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2017-05-03 11:21:45 +02:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2016-12-30 17:31:12 +01:00
|
|
|
try {
|
2017-11-28 17:34:43 +01:00
|
|
|
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
getElement();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
return serialize();
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid);
|
2016-12-30 17:31:12 +01:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid, e);
|
2016-12-30 17:31:12 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-04 15:31:13 +02:00
|
|
|
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2016-12-30 17:31:12 +01:00
|
|
|
try {
|
2018-06-12 18:09:36 +02:00
|
|
|
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
|
|
|
orientGraph.setAutoStartTx(false);
|
|
|
|
orientGraph.begin();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
element = internalUpdate();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.commit();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-21 18:18:11 +01:00
|
|
|
setReload(true);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-10-26 17:09:07 +02:00
|
|
|
// TODO Notify to subscriptionNotification
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
return serialize();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid, e);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
public boolean delete() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2017-03-29 16:53:37 +02:00
|
|
|
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
try {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
orientGraph = ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
2017-12-05 10:10:34 +01:00
|
|
|
orientGraph.setAutoStartTx(false);
|
|
|
|
orientGraph.begin();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
boolean deleted = reallyDelete();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(deleted) {
|
2017-04-04 15:03:25 +02:00
|
|
|
orientGraph.commit();
|
2017-11-28 17:34:43 +01:00
|
|
|
logger.info("{} with UUID {} was successfully deleted.", accessType.getName(), uuid);
|
|
|
|
} else {
|
2019-02-13 12:33:29 +01:00
|
|
|
throw new ResourceRegistryException("Error while deleting " + accessType.getName() + " with UUID " + uuid);
|
2017-04-04 15:03:25 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
return deleted;
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
2017-11-23 12:40:35 +01:00
|
|
|
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-03-29 16:53:37 +02:00
|
|
|
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid, e);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
public boolean addToContext(UUID contextUUID)
|
|
|
|
throws NotFoundException, ContextException, ResourceRegistryException {
|
2018-06-06 19:26:19 +02:00
|
|
|
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
try {
|
2017-11-28 17:34:43 +01:00
|
|
|
orientGraph = ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
2017-12-05 10:10:34 +01:00
|
|
|
orientGraph.setAutoStartTx(false);
|
|
|
|
orientGraph.begin();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-06 19:26:19 +02:00
|
|
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
|
|
|
|
|
|
|
boolean added = internalAddToContext(targetSecurityContext);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.commit();
|
2018-06-08 18:18:48 +02:00
|
|
|
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
return added;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2018-06-08 18:18:48 +02:00
|
|
|
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2017-11-23 12:40:35 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2018-06-08 18:18:48 +02:00
|
|
|
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID, e);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ContextException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-12 18:09:36 +02:00
|
|
|
public boolean removeFromContext(UUID contextUUID)
|
|
|
|
throws NotFoundException, ContextException, ResourceRegistryException {
|
2018-06-08 18:18:48 +02:00
|
|
|
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
try {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
orientGraph = ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
2017-12-05 10:10:34 +01:00
|
|
|
orientGraph.setAutoStartTx(false);
|
|
|
|
orientGraph.begin();
|
2017-11-28 17:34:43 +01:00
|
|
|
|
2018-06-06 19:26:19 +02:00
|
|
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
|
|
|
|
|
|
|
boolean removed = internalRemoveFromContext(targetSecurityContext);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.commit();
|
2018-06-12 18:09:36 +02:00
|
|
|
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid,
|
|
|
|
contextUUID);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
return removed;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2018-06-08 18:18:48 +02:00
|
|
|
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2017-11-23 12:40:35 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2018-06-12 18:09:36 +02:00
|
|
|
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID,
|
|
|
|
e);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ContextException(e);
|
|
|
|
} finally {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(orientGraph != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
public static String getClassProperty(JsonNode jsonNode) {
|
2017-11-30 18:06:08 +01:00
|
|
|
if(jsonNode.has(ISManageable.CLASS_PROPERTY)) {
|
2017-01-23 17:41:11 +01:00
|
|
|
return jsonNode.get(ISManageable.CLASS_PROPERTY).asText();
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
public static Object getObjectFromElement(JsonNode value)
|
2017-11-28 17:34:43 +01:00
|
|
|
throws UnsupportedDataTypeException, ResourceRegistryException {
|
2016-12-19 14:59:27 +01:00
|
|
|
JsonNodeType jsonNodeType = value.getNodeType();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
switch(jsonNodeType) {
|
|
|
|
case OBJECT:
|
2019-11-04 18:01:20 +01:00
|
|
|
return BasePropertyManagement.getPropertyDocument(value);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
case ARRAY:
|
|
|
|
List<Object> list = new ArrayList<Object>();
|
|
|
|
Iterator<JsonNode> arrayElement = value.elements();
|
|
|
|
while(arrayElement.hasNext()) {
|
|
|
|
JsonNode arrayNode = arrayElement.next();
|
|
|
|
Object objectNode = getObjectFromElement(arrayNode);
|
|
|
|
if(objectNode != null) {
|
|
|
|
list.add(objectNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
2019-11-04 18:01:20 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354
|
|
|
|
*
|
2017-11-30 18:06:08 +01:00
|
|
|
throw new UnsupportedDataTypeException(
|
|
|
|
"List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
|
2019-11-04 18:01:20 +01:00
|
|
|
*/
|
2017-11-30 18:06:08 +01:00
|
|
|
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;
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
return null;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
public static Map<String,Object> getPropertyMap(JsonNode jsonNode, Set<String> ignoreKeys,
|
2017-11-28 17:34:43 +01:00
|
|
|
Set<String> ignoreStartWith) throws JsonProcessingException, IOException {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
if(ignoreKeys == null) {
|
2016-12-19 14:59:27 +01:00
|
|
|
ignoreKeys = new HashSet<>();
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(ignoreStartWith == null) {
|
2016-12-19 14:59:27 +01:00
|
|
|
ignoreStartWith = new HashSet<>();
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
Iterator<Entry<String,JsonNode>> fields = jsonNode.fields();
|
|
|
|
|
|
|
|
OUTER_WHILE: while(fields.hasNext()) {
|
|
|
|
Entry<String,JsonNode> entry = fields.next();
|
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
String key = entry.getKey();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(ignoreKeys.contains(key)) {
|
2016-12-19 14:59:27 +01:00
|
|
|
continue;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
for(String prefix : ignoreStartWith) {
|
|
|
|
if(key.startsWith(prefix)) {
|
2016-12-19 14:59:27 +01:00
|
|
|
continue OUTER_WHILE;
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
JsonNode value = entry.getValue();
|
|
|
|
Object object = null;
|
|
|
|
try {
|
|
|
|
object = getObjectFromElement(value);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(object != null) {
|
2016-12-19 14:59:27 +01:00
|
|
|
map.put(key, object);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-11-15 19:31:49 +01:00
|
|
|
staticLogger.warn("An invalidy property has been provided. It will be ignored.");
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
return map;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
/**
|
|
|
|
* @param oClass
|
|
|
|
* @param element
|
|
|
|
* @param jsonNode
|
|
|
|
* @param ignoreKeys
|
|
|
|
* @param ignoreStartWithKeys
|
|
|
|
* @return
|
|
|
|
* @throws ResourceRegistryException
|
|
|
|
*/
|
2017-11-28 17:34:43 +01:00
|
|
|
public static Element updateProperties(OClass oClass, Element element, JsonNode jsonNode, Set<String> ignoreKeys,
|
|
|
|
Set<String> ignoreStartWithKeys) throws ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
Set<String> oldKeys = element.getPropertyKeys();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
Map<String,Object> properties;
|
|
|
|
if(element instanceof Vertex || element instanceof Edge) {
|
2016-12-19 14:59:27 +01:00
|
|
|
try {
|
2017-11-28 17:34:43 +01:00
|
|
|
properties = getPropertyMap(jsonNode, ignoreKeys, ignoreStartWithKeys);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(IOException e) {
|
2016-12-19 14:59:27 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
|
|
|
} else {
|
2017-11-28 17:34:43 +01:00
|
|
|
String error = String.format("Error while updating %s properties", element.toString());
|
2016-12-19 14:59:27 +01:00
|
|
|
throw new ResourceRegistryException(error);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
oldKeys.removeAll(properties.keySet());
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
for(String key : properties.keySet()) {
|
2016-12-19 14:59:27 +01:00
|
|
|
try {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-03-27 15:04:44 +02:00
|
|
|
Object object = properties.get(key);
|
2019-02-13 12:33:29 +01:00
|
|
|
|
|
|
|
boolean set = false;
|
|
|
|
|
|
|
|
if(object instanceof ODocument) {
|
|
|
|
ODocument oDocument = (ODocument) object;
|
|
|
|
((OrientElement) element).setProperty(key, oDocument, OType.EMBEDDED);
|
|
|
|
set = true;
|
2017-03-27 15:04:44 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
/*
|
|
|
|
* List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354
|
|
|
|
*/
|
|
|
|
if(object instanceof Set) {
|
|
|
|
((OrientElement) element).setProperty(key, object, OType.EMBEDDEDSET);
|
|
|
|
set = true;
|
|
|
|
}
|
|
|
|
if(object instanceof List) {
|
|
|
|
((OrientElement) element).setProperty(key, object, OType.EMBEDDEDLIST);
|
|
|
|
set = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!set) {
|
|
|
|
element.setProperty(key, object);
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-11-28 17:34:43 +01:00
|
|
|
String error = String.format("Error while setting property %s : %s (%s)", key,
|
|
|
|
properties.get(key).toString(), e.getMessage());
|
2017-11-15 19:31:49 +01:00
|
|
|
staticLogger.error(error);
|
2016-12-19 14:59:27 +01:00
|
|
|
throw new ResourceRegistryException(error, e);
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
OUTER_FOR: for(String key : oldKeys) {
|
|
|
|
|
|
|
|
if(ignoreKeys.contains(key)) {
|
2016-12-19 14:59:27 +01:00
|
|
|
continue;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
for(String prefix : ignoreStartWithKeys) {
|
|
|
|
if(key.startsWith(prefix)) {
|
2016-12-19 14:59:27 +01:00
|
|
|
continue OUTER_FOR;
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
element.removeProperty(key);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
((OrientElement) element).save();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
return element;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
protected JsonNode getPropertyForJson(String key, Object object) throws ResourceRegistryException {
|
2017-01-18 14:57:20 +01:00
|
|
|
try {
|
2019-02-13 12:33:29 +01:00
|
|
|
if(object instanceof JsonNode) {
|
|
|
|
return (JsonNode) object;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
2017-11-30 18:06:08 +01:00
|
|
|
if(key.compareTo(ER.HEADER_PROPERTY) == 0) {
|
2017-03-29 16:14:03 +02:00
|
|
|
// Keeping the header
|
|
|
|
HeaderOrient headerOrient = HeaderUtility.getHeaderOrient((ODocument) object);
|
2019-02-13 12:33:29 +01:00
|
|
|
return Utility.toJsonNode(headerOrient, false);
|
2017-03-29 16:14:03 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(ignoreKeys.contains(key)) {
|
2017-03-29 16:14:03 +02:00
|
|
|
return null;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
for(String prefix : ignoreStartWithKeys) {
|
|
|
|
if(key.startsWith(prefix)) {
|
2017-03-29 16:14:03 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(object instanceof ODocument) {
|
2019-02-13 12:33:29 +01:00
|
|
|
ODocument oDocument = (ODocument) object;
|
2019-11-04 18:01:20 +01:00
|
|
|
return BasePropertyManagement.getJsonNode(oDocument);
|
2017-03-29 16:14:03 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(object instanceof Date) {
|
2017-03-29 16:14:03 +02:00
|
|
|
OProperty oProperty = getOClass().getProperty(key);
|
|
|
|
OType oType = oProperty.getType();
|
|
|
|
DateFormat dateFormat = ODateHelper.getDateTimeFormatInstance();
|
2017-11-30 18:06:08 +01:00
|
|
|
switch(oType) {
|
|
|
|
case DATE:
|
|
|
|
dateFormat = ODateHelper.getDateFormatInstance();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATETIME:
|
|
|
|
dateFormat = ODateHelper.getDateTimeFormatInstance();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2017-01-18 14:57:20 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
return new TextNode(dateFormat.format((Date) object));
|
2017-03-29 16:14:03 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
if(object instanceof Collection) {
|
2017-04-26 11:40:34 +02:00
|
|
|
Collection<?> collection = (Collection<?>) object;
|
2019-02-13 12:33:29 +01:00
|
|
|
ArrayNode arrayNode = objectMapper.createArrayNode();
|
|
|
|
|
2017-11-30 18:06:08 +01:00
|
|
|
for(Object o : collection) {
|
2017-11-28 17:34:43 +01:00
|
|
|
Object obj = getPropertyForJson("PLACEHOLDER", o);
|
2019-02-13 12:33:29 +01:00
|
|
|
|
|
|
|
if(obj!=null) {
|
|
|
|
arrayNode.add((JsonNode) obj);
|
|
|
|
}
|
2017-01-18 14:57:20 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
return arrayNode;
|
2017-01-18 14:57:20 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
return new TextNode(object.toString());
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
} catch(Exception e) {
|
2017-11-28 17:34:43 +01:00
|
|
|
throw new ResourceRegistryException(
|
|
|
|
"Error while serializing " + key + "=" + object.toString() + " in " + getElement().toString(), e);
|
2017-03-29 16:14:03 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
protected Collection<String> getSuperclasses() throws SchemaException, ResourceRegistryException {
|
2017-03-29 16:14:03 +02:00
|
|
|
Collection<OClass> allSuperClasses = getOClass().getAllSuperClasses();
|
|
|
|
Collection<String> superClasses = new HashSet<>();
|
2017-11-30 18:06:08 +01:00
|
|
|
for(OClass oSuperClass : allSuperClasses) {
|
2017-03-29 16:14:03 +02:00
|
|
|
String name = oSuperClass.getName();
|
2017-11-30 18:06:08 +01:00
|
|
|
if(name.compareTo(StringFactory.V.toUpperCase()) == 0 || name.compareTo(StringFactory.E.toUpperCase()) == 0
|
2017-11-28 17:34:43 +01:00
|
|
|
|| name.compareTo(DatabaseEnvironment.O_RESTRICTED_CLASS) == 0) {
|
2017-03-29 16:14:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
superClasses.add(name);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-03-29 16:14:03 +02:00
|
|
|
return superClasses;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public JsonNode toJsonNode() throws ResourceRegistryException {
|
2017-03-29 16:14:03 +02:00
|
|
|
try {
|
|
|
|
OrientElement orientElement = (OrientElement) getElement();
|
2019-02-13 12:33:29 +01:00
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
ObjectNode objectNode = objectMapper.createObjectNode();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
Map<String,Object> properties = orientElement.getProperties();
|
|
|
|
for(String key : orientElement.getPropertyKeys()) {
|
2017-03-29 16:14:03 +02:00
|
|
|
Object object = properties.get(key);
|
2019-02-13 12:33:29 +01:00
|
|
|
JsonNode jsonNode = getPropertyForJson(key, object);
|
|
|
|
if(jsonNode != null) {
|
|
|
|
objectNode.replace(key, jsonNode);
|
2017-01-18 14:57:20 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-03-29 16:14:03 +02:00
|
|
|
String type = orientElement.getRecord().getClassName();
|
2019-02-13 12:33:29 +01:00
|
|
|
objectNode.put(ISManageable.CLASS_PROPERTY, type);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-03-29 16:14:03 +02:00
|
|
|
Collection<String> superClasses = getSuperclasses();
|
2019-02-13 12:33:29 +01:00
|
|
|
ArrayNode arrayNode = objectMapper.valueToTree(superClasses);
|
|
|
|
|
|
|
|
objectNode.replace(ISManageable.SUPERCLASSES_PROPERTY, arrayNode);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
return objectNode;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-03-29 16:14:03 +02:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-03-29 16:14:03 +02:00
|
|
|
throw new ResourceRegistryException("Error while serializing " + getElement().toString(), e);
|
2017-01-18 14:57:20 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|