Improving code
This commit is contained in:
parent
a0ffe74776
commit
44631557da
|
@ -4,7 +4,6 @@ import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
@ -89,9 +88,9 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if(name == null) {
|
if (name == null) {
|
||||||
if(element == null) {
|
if (element == null) {
|
||||||
if(jsonNode != null) {
|
if (jsonNode != null) {
|
||||||
name = jsonNode.get(Context.NAME_PROPERTY).asText();
|
name = jsonNode.get(Context.NAME_PROPERTY).asText();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -103,7 +102,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if(workingContext == null) {
|
if (workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = ContextUtility.getInstance()
|
||||||
.getSecurityContextByUUID(DatabaseEnvironment.CONTEXT_SECURITY_CONTEXT_UUID);
|
.getSecurityContextByUUID(DatabaseEnvironment.CONTEXT_SECURITY_CONTEXT_UUID);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +122,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
protected void checkContext(ContextManagement parentContext)
|
protected void checkContext(ContextManagement parentContext)
|
||||||
throws ContextNotFoundException, ContextAlreadyPresentException, ResourceRegistryException {
|
throws ContextNotFoundException, ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
|
|
||||||
if(parentContext != null) {
|
if (parentContext != null) {
|
||||||
String parentId = parentContext.getElement().getIdentity().toString();
|
String parentId = parentContext.getElement().getIdentity().toString();
|
||||||
|
|
||||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME + ") FROM " + parentId
|
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME + ") FROM " + parentId
|
||||||
|
@ -142,18 +141,17 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
|
|
||||||
OResultSet resultSet = oDatabaseDocument.command(select, new HashMap<>());
|
OResultSet resultSet = oDatabaseDocument.command(select, new HashMap<>());
|
||||||
|
|
||||||
if(resultSet != null && resultSet.hasNext()) {
|
if (resultSet != null && resultSet.hasNext()) {
|
||||||
throw new ContextAlreadyPresentException(message.toString());
|
throw new ContextAlreadyPresentException(message.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String select = "SELECT FROM " + Context.NAME + " WHERE "
|
String select = "SELECT FROM " + Context.NAME + " WHERE " + Context.NAME_PROPERTY + " = \"" + getName()
|
||||||
+ Context.NAME_PROPERTY + " = \"" + getName() + "\"" + " AND in(\"" + IsParentOf.NAME
|
+ "\"" + " AND in(\"" + IsParentOf.NAME + "\").size() = 0";
|
||||||
+ "\").size() = 0";
|
|
||||||
|
|
||||||
OResultSet resultSet = oDatabaseDocument.command(select, new HashMap<>());
|
OResultSet resultSet = oDatabaseDocument.command(select, new HashMap<>());
|
||||||
|
|
||||||
if(resultSet != null && resultSet.hasNext()) {
|
if (resultSet != null && resultSet.hasNext()) {
|
||||||
throw new ContextAlreadyPresentException(
|
throw new ContextAlreadyPresentException(
|
||||||
"A root context with the same name (" + this.getName() + ") already exist");
|
"A root context with the same name (" + this.getName() + ") already exist");
|
||||||
}
|
}
|
||||||
|
@ -169,35 +167,35 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Iterable<OEdge> parents = getElement().getEdges(ODirection.IN);
|
Iterable<OEdge> parents = getElement().getEdges(ODirection.IN);
|
||||||
for(OEdge edge : parents) {
|
for (OEdge edge : parents) {
|
||||||
if(++count > 1) {
|
if (++count > 1) {
|
||||||
throw new ContextException("A " + Context.NAME + " can not have more than one parent");
|
throw new ContextException("A " + Context.NAME + " can not have more than one parent");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||||
isParentOfManagement.setElement(edge);
|
isParentOfManagement.setElement(edge);
|
||||||
JsonNode isParentOf = isParentOfManagement.createCompleteJsonNode(true, false);
|
JsonNode isParentOf = isParentOfManagement.createCompleteJsonNode(true, false);
|
||||||
if(isParentOf!=null) {
|
if (isParentOf != null) {
|
||||||
((ObjectNode) context).replace(Context.PARENT_PROPERTY, isParentOf);
|
((ObjectNode) context).replace(Context.PARENT_PROPERTY, isParentOf);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ContextException("");
|
throw new ContextException("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<OEdge> childrenEdges = getElement().getEdges(ODirection.OUT);
|
Iterable<OEdge> childrenEdges = getElement().getEdges(ODirection.OUT);
|
||||||
for(OEdge edge : childrenEdges) {
|
for (OEdge edge : childrenEdges) {
|
||||||
|
|
||||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||||
isParentOfManagement.setElement(edge);
|
isParentOfManagement.setElement(edge);
|
||||||
try {
|
try {
|
||||||
JsonNode isParentOf = isParentOfManagement.serializeAsJsonNode();
|
JsonNode isParentOf = isParentOfManagement.serializeAsJsonNode();
|
||||||
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
|
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
@ -214,7 +212,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
try {
|
try {
|
||||||
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||||
|
|
||||||
if(isParentOfJsonNode != null && !(isParentOfJsonNode instanceof NullNode)) {
|
if (isParentOfJsonNode != null && !(isParentOfJsonNode instanceof NullNode)) {
|
||||||
|
|
||||||
JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
||||||
ContextManagement parentContextManagement = new ContextManagement(oDatabaseDocument);
|
ContextManagement parentContextManagement = new ContextManagement(oDatabaseDocument);
|
||||||
|
@ -222,9 +220,8 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
UUID parentUUID = parentContextManagement.uuid;
|
UUID parentUUID = parentContextManagement.uuid;
|
||||||
parentSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(parentUUID);
|
parentSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(parentUUID);
|
||||||
|
|
||||||
|
|
||||||
checkContext(parentContextManagement);
|
checkContext(parentContextManagement);
|
||||||
if(uuid == null) {
|
if (uuid == null) {
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,11 +246,11 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
ContextUtility.getInstance().addSecurityContext(securityContext);
|
ContextUtility.getInstance().addSecurityContext(securityContext);
|
||||||
|
|
||||||
return getElement();
|
return getElement();
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
oDatabaseDocument.rollback();
|
oDatabaseDocument.rollback();
|
||||||
if(securityContext != null) {
|
if (securityContext != null) {
|
||||||
securityContext.delete(oDatabaseDocument);
|
securityContext.delete(oDatabaseDocument);
|
||||||
if(parentSecurityContext!=null && securityContext!=null) {
|
if (parentSecurityContext != null && securityContext != null) {
|
||||||
parentSecurityContext.getChildren().remove(securityContext);
|
parentSecurityContext.getChildren().remove(securityContext);
|
||||||
}
|
}
|
||||||
ContextCache.getInstance().cleanCache();
|
ContextCache.getInstance().cleanCache();
|
||||||
|
@ -272,8 +269,8 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
||||||
Iterable<OVertex> iterable = getElement().getVertices(ODirection.IN, IsParentOf.NAME);
|
Iterable<OVertex> iterable = getElement().getVertices(ODirection.IN, IsParentOf.NAME);
|
||||||
for(OVertex p : iterable) {
|
for (OVertex p : iterable) {
|
||||||
if(found) {
|
if (found) {
|
||||||
String message = String.format("{} has more than one parent. {}", Context.NAME,
|
String message = String.format("{} has more than one parent. {}", Context.NAME,
|
||||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(message.toString());
|
throw new ResourceRegistryException(message.toString());
|
||||||
|
@ -283,7 +280,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextManagement actualParentContextManagement = null;
|
ContextManagement actualParentContextManagement = null;
|
||||||
if(parent != null) {
|
if (parent != null) {
|
||||||
actualParentContextManagement = new ContextManagement(oDatabaseDocument);
|
actualParentContextManagement = new ContextManagement(oDatabaseDocument);
|
||||||
actualParentContextManagement.setElement(parent);
|
actualParentContextManagement.setElement(parent);
|
||||||
}
|
}
|
||||||
|
@ -292,26 +289,26 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
|
|
||||||
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||||
JsonNode parentContextJsonNode = null;
|
JsonNode parentContextJsonNode = null;
|
||||||
if(isParentOfJsonNode != null && !(isParentOfJsonNode instanceof NullNode)) {
|
if (isParentOfJsonNode != null && !(isParentOfJsonNode instanceof NullNode)) {
|
||||||
parentContextJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
parentContextJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parentContextJsonNode != null && !(parentContextJsonNode instanceof NullNode)) {
|
if (parentContextJsonNode != null && !(parentContextJsonNode instanceof NullNode)) {
|
||||||
UUID parentUUID = org.gcube.informationsystem.utils.Utility.getUUIDFromJsonNode(parentContextJsonNode);
|
UUID parentUUID = org.gcube.informationsystem.utils.Utility.getUUIDFromJsonNode(parentContextJsonNode);
|
||||||
if(actualParentContextManagement != null) {
|
if (actualParentContextManagement != null) {
|
||||||
if(parentUUID.compareTo(actualParentContextManagement.uuid) != 0) {
|
if (parentUUID.compareTo(actualParentContextManagement.uuid) != 0) {
|
||||||
parentChanged = true;
|
parentChanged = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parentChanged = true;
|
parentChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parentChanged) {
|
if (parentChanged) {
|
||||||
newParentContextManagement = new ContextManagement(oDatabaseDocument);
|
newParentContextManagement = new ContextManagement(oDatabaseDocument);
|
||||||
newParentContextManagement.setJsonNode(parentContextJsonNode);
|
newParentContextManagement.setJsonNode(parentContextJsonNode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(actualParentContextManagement != null) {
|
if (actualParentContextManagement != null) {
|
||||||
parentChanged = true;
|
parentChanged = true;
|
||||||
newParentContextManagement = null;
|
newParentContextManagement = null;
|
||||||
}
|
}
|
||||||
|
@ -320,21 +317,20 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
|
|
||||||
String oldName = getElement().getProperty(Context.NAME_PROPERTY);
|
String oldName = getElement().getProperty(Context.NAME_PROPERTY);
|
||||||
String newName = jsonNode.get(Context.NAME_PROPERTY).asText();
|
String newName = jsonNode.get(Context.NAME_PROPERTY).asText();
|
||||||
if(oldName.compareTo(newName) != 0) {
|
if (oldName.compareTo(newName) != 0) {
|
||||||
nameChanged = true;
|
nameChanged = true;
|
||||||
name = newName;
|
name = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parentChanged || nameChanged) {
|
if (parentChanged || nameChanged) {
|
||||||
checkContext(newParentContextManagement);
|
checkContext(newParentContextManagement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parentChanged) {
|
if (parentChanged) {
|
||||||
move(newParentContextManagement, false);
|
move(newParentContextManagement, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
element = (OVertex) updateProperties(oClass, getElement(), jsonNode, ignoreKeys,
|
element = (OVertex) updateProperties(oClass, getElement(), jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||||
ignoreStartWithKeys);
|
|
||||||
|
|
||||||
ContextCache.getInstance().cleanCache();
|
ContextCache.getInstance().cleanCache();
|
||||||
|
|
||||||
|
@ -343,7 +339,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
|
|
||||||
private void move(ContextManagement newParentContextManagement, boolean check)
|
private void move(ContextManagement newParentContextManagement, boolean check)
|
||||||
throws ContextNotFoundException, ContextAlreadyPresentException, ResourceRegistryException {
|
throws ContextNotFoundException, ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
if(check) {
|
if (check) {
|
||||||
checkContext(newParentContextManagement);
|
checkContext(newParentContextManagement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,27 +347,28 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
|
|
||||||
// Removing the old parent relationship if any
|
// Removing the old parent relationship if any
|
||||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.IN, IsParentOf.NAME);
|
Iterable<OEdge> edges = getElement().getEdges(ODirection.IN, IsParentOf.NAME);
|
||||||
if(edges != null && edges.iterator().hasNext()) {
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
Iterator<OEdge> edgeIterator = edges.iterator();
|
Iterator<OEdge> edgeIterator = edges.iterator();
|
||||||
OEdge edge = edgeIterator.next();
|
OEdge edge = edgeIterator.next();
|
||||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement();
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement();
|
||||||
isParentOfManagement.setElement(edge);
|
isParentOfManagement.setElement(edge);
|
||||||
isParentOfManagement.internalDelete();
|
isParentOfManagement.internalDelete();
|
||||||
|
|
||||||
if(edgeIterator.hasNext()) {
|
if (edgeIterator.hasNext()) {
|
||||||
throw new ContextException(
|
throw new ContextException(
|
||||||
"Seems that the Context has more than one Parent. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
"Seems that the Context has more than one Parent. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newParentContextManagement != null) {
|
if (newParentContextManagement != null) {
|
||||||
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||||
isParentOfManagement.setJsonNode(isParentOfJsonNode);
|
isParentOfManagement.setJsonNode(isParentOfJsonNode);
|
||||||
isParentOfManagement.setSourceEntityManagement(newParentContextManagement);
|
isParentOfManagement.setSourceEntityManagement(newParentContextManagement);
|
||||||
isParentOfManagement.setTargetEntityManagement(this);
|
isParentOfManagement.setTargetEntityManagement(this);
|
||||||
isParentOfManagement.internalCreate();
|
isParentOfManagement.internalCreate();
|
||||||
newParentSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(newParentContextManagement.uuid);
|
newParentSecurityContext = ContextUtility.getInstance()
|
||||||
|
.getSecurityContextByUUID(newParentContextManagement.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
SecurityContext thisSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
SecurityContext thisSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
||||||
|
@ -382,7 +379,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||||
Iterable<OEdge> iterable = getElement().getEdges(ODirection.OUT);
|
Iterable<OEdge> iterable = getElement().getEdges(ODirection.OUT);
|
||||||
Iterator<OEdge> iterator = iterable.iterator();
|
Iterator<OEdge> iterator = iterable.iterator();
|
||||||
while(iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
throw new ContextException("Cannot remove a " + Context.NAME + " having children");
|
throw new ContextException("Cannot remove a " + Context.NAME + " having children");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,20 +400,20 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||||
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(typeName, polymorphic);
|
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(typeName, polymorphic);
|
||||||
for(ODocument vertex : iterable) {
|
for (ODocument vertex : iterable) {
|
||||||
ContextManagement contextManagement = new ContextManagement();
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
contextManagement.setElement((OVertex) vertex);
|
contextManagement.setElement((OVertex) vertex);
|
||||||
try {
|
try {
|
||||||
JsonNode jsonObject = contextManagement.serializeAsJsonNode();
|
JsonNode jsonObject = contextManagement.serializeAsJsonNode();
|
||||||
arrayNode.add(jsonObject);
|
arrayNode.add(jsonObject);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||||
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.writeValueAsString(arrayNode);
|
return objectMapper.writeValueAsString(arrayNode);
|
||||||
} catch(JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,11 +432,13 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readFromServer() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
public String readFromServer()
|
||||||
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
return super.read().toString();
|
return super.read().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readAsString() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
public String readAsString()
|
||||||
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
ContextCache contextCache = ContextCache.getInstance();
|
ContextCache contextCache = ContextCache.getInstance();
|
||||||
return ElementMapper.marshal(contextCache.getContextByUUID(uuid));
|
return ElementMapper.marshal(contextCache.getContextByUUID(uuid));
|
||||||
|
@ -449,8 +448,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances)
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
throws SchemaViolationException, ResourceRegistryException {
|
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.contexts.relations;
|
package org.gcube.informationsystem.resourceregistry.contexts.relations;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
|
@ -27,7 +24,7 @@ import com.orientechnologies.orient.core.record.OVertex;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
public class IsParentOfManagement extends RelationElementManagement<ContextManagement,ContextManagement> {
|
public class IsParentOfManagement extends RelationElementManagement<ContextManagement, ContextManagement> {
|
||||||
|
|
||||||
public IsParentOfManagement() {
|
public IsParentOfManagement() {
|
||||||
super(AccessType.IS_PARENT_OF, Context.class, Context.class);
|
super(AccessType.IS_PARENT_OF, Context.class, Context.class);
|
||||||
|
@ -41,7 +38,7 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if(workingContext == null) {
|
if (workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = ContextUtility.getInstance()
|
||||||
.getSecurityContextByUUID(DatabaseEnvironment.CONTEXT_SECURITY_CONTEXT_UUID);
|
.getSecurityContextByUUID(DatabaseEnvironment.CONTEXT_SECURITY_CONTEXT_UUID);
|
||||||
}
|
}
|
||||||
|
@ -64,28 +61,31 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget)
|
||||||
|
throws ResourceRegistryException {
|
||||||
JsonNode relation = serializeSelfAsJsonNode();
|
JsonNode relation = serializeSelfAsJsonNode();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OVertex source = element.getVertex(ODirection.OUT);
|
OVertex source = element.getVertex(ODirection.OUT);
|
||||||
ContextManagement sourceContextManagement = new ContextManagement(oDatabaseDocument);
|
ContextManagement sourceContextManagement = new ContextManagement(oDatabaseDocument);
|
||||||
sourceContextManagement.setElement(source);
|
sourceContextManagement.setElement(source);
|
||||||
if(includeSource) {
|
if (includeSource) {
|
||||||
((ObjectNode)relation).replace(Relation.SOURCE_PROPERTY, sourceContextManagement.serializeSelfAsJsonNode());
|
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY,
|
||||||
|
sourceContextManagement.serializeSelfAsJsonNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
OVertex target = element.getVertex(ODirection.IN);
|
OVertex target = element.getVertex(ODirection.IN);
|
||||||
ContextManagement targetContextManagement = new ContextManagement(oDatabaseDocument);
|
ContextManagement targetContextManagement = new ContextManagement(oDatabaseDocument);
|
||||||
targetContextManagement.setElement(target);
|
targetContextManagement.setElement(target);
|
||||||
if(includeTarget) {
|
if (includeTarget) {
|
||||||
((ObjectNode)relation).replace(Relation.TARGET_PROPERTY, targetContextManagement.serializeSelfAsJsonNode());
|
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY,
|
||||||
|
targetContextManagement.serializeSelfAsJsonNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,7 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances)
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
throws SchemaViolationException, ResourceRegistryException {
|
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -448,7 +448,9 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException;
|
public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException;
|
||||||
|
|
||||||
public abstract void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException;
|
public abstract void sanityCheck() throws SchemaViolationException, ResourceRegistryException;
|
||||||
|
|
||||||
|
//public abstract void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException;
|
||||||
|
|
||||||
public String all(boolean polymorphic) throws ResourceRegistryException {
|
public String all(boolean polymorphic) throws ResourceRegistryException {
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
|
@ -513,7 +515,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
element = internalCreate();
|
element = internalCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
sanityCheck(null);
|
sanityCheck();
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
|
|
||||||
|
@ -556,7 +558,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
element = internalCreate();
|
element = internalCreate();
|
||||||
|
|
||||||
sanityCheck(null);
|
sanityCheck();
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
|
|
||||||
|
@ -621,7 +623,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
element = internalUpdate();
|
element = internalUpdate();
|
||||||
|
|
||||||
sanityCheck(null);
|
sanityCheck();
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@ public interface ERManagement {
|
||||||
public Map<UUID, JsonNode> removeFromContext(UUID contextUUID)
|
public Map<UUID, JsonNode> removeFromContext(UUID contextUUID)
|
||||||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
|
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
|
||||||
|
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException;
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException;
|
||||||
|
//public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException;
|
||||||
|
|
||||||
public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message);
|
public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.gcube.informationsystem.base.reference.Element;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
|
@ -39,6 +38,7 @@ public class ERManagementUtility {
|
||||||
|
|
||||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
|
Map<UUID, ElementManagement<?>> instancesManagement = new HashMap<>();
|
||||||
for(UUID uuid : expectedInstances.keySet()) {
|
for(UUID uuid : expectedInstances.keySet()) {
|
||||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(type);
|
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
|
@ -49,7 +49,13 @@ public class ERManagementUtility {
|
||||||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||||
((ERManagement) elementManagement).internalAddToContext(targetSecurityContext);
|
((ERManagement) elementManagement).internalAddToContext(targetSecurityContext);
|
||||||
((ERManagement) elementManagement).sanityCheck(expectedInstances);
|
instancesManagement.put(uuid, elementManagement);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(UUID uuid : expectedInstances.keySet()) {
|
||||||
|
ElementManagement<?> elementManagement = instancesManagement.get(uuid);
|
||||||
|
// TODO
|
||||||
|
elementManagement.sanityCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -120,14 +126,16 @@ public class ERManagementUtility {
|
||||||
|
|
||||||
affectedInstances.putAll(((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext));
|
affectedInstances.putAll(((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext));
|
||||||
|
|
||||||
((ERManagement) elementManagement).sanityCheck(expectedInstances);
|
((ERManagement) elementManagement).sanityCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.REMOVE);
|
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.REMOVE);
|
||||||
|
|
||||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
staticLogger.info("{} successfully removed from Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
staticLogger.info("{} successfully removed from Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.instances.model.entities;
|
package org.gcube.informationsystem.resourceregistry.instances.model.entities;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
|
@ -63,7 +60,7 @@ public class FacetManagement extends EntityManagement<Facet> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException {
|
public void sanityCheck() throws ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,9 @@ 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.ArrayNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
|
||||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
|
||||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||||
|
@ -311,25 +309,6 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String facetMustBePresentErrorMessage(String consistsOfType, UUID consistsOfUUID, String facetType, UUID facetUUID) {
|
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
|
||||||
stringBuffer.append("To avoid to have an incosistent graph, add to context no follows cannot add a ");
|
|
||||||
stringBuffer.append(ConsistsOf.NAME);
|
|
||||||
stringBuffer.append(" relation (i.e. ");
|
|
||||||
stringBuffer.append(consistsOfType);
|
|
||||||
stringBuffer.append(" with UUID ");
|
|
||||||
stringBuffer.append(consistsOfUUID.toString());
|
|
||||||
stringBuffer.append(") without indicating the target ");
|
|
||||||
stringBuffer.append(Facet.NAME);
|
|
||||||
stringBuffer.append(" (i.e. ");
|
|
||||||
stringBuffer.append(facetType);
|
|
||||||
stringBuffer.append(" with UUID ");
|
|
||||||
stringBuffer.append(facetUUID.toString());
|
|
||||||
stringBuffer.append(").");
|
|
||||||
return stringBuffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected Set<LinkedEntity> getResourceTypeConstraint() throws SchemaException, ResourceRegistryException{
|
protected Set<LinkedEntity> getResourceTypeConstraint() throws SchemaException, ResourceRegistryException{
|
||||||
Set<LinkedEntity> constraints = new HashSet<>();
|
Set<LinkedEntity> constraints = new HashSet<>();
|
||||||
|
|
||||||
|
@ -420,6 +399,76 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
|
JsonNode resourceInstance = createCompleteJsonNode();
|
||||||
|
|
||||||
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
|
|
||||||
|
Set<LinkedEntity> consistsOfFacetConstraints = getResourceTypeConstraint();
|
||||||
|
Map<LinkedEntity, Integer> satisfiedConsistsOfFacet = new HashMap<>();
|
||||||
|
|
||||||
|
ArrayNode consistsOfArrayNode = (ArrayNode) resourceInstance.get(Resource.CONSISTS_OF_PROPERTY);
|
||||||
|
for(JsonNode consistsOfJsonNode : consistsOfArrayNode) {
|
||||||
|
String consistsOfType = consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText();
|
||||||
|
JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY);
|
||||||
|
String facetType = facetJsonNode.get(Element.CLASS_PROPERTY).asText();
|
||||||
|
|
||||||
|
for(LinkedEntity constraint : consistsOfFacetConstraints) {
|
||||||
|
if(constraintSatisfied(typesCache, constraint, consistsOfType, facetType)) {
|
||||||
|
Integer integer = satisfiedConsistsOfFacet.get(constraint);
|
||||||
|
if(integer==null) {
|
||||||
|
satisfiedConsistsOfFacet.put(constraint, 1);
|
||||||
|
}else {
|
||||||
|
satisfiedConsistsOfFacet.put(constraint, ++integer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
consistsOfFacetConstraints.removeAll(satisfiedConsistsOfFacet.keySet());
|
||||||
|
|
||||||
|
if(!consistsOfFacetConstraints.isEmpty()) {
|
||||||
|
String message = constraintNotSatisfiedErrorMessage(consistsOfFacetConstraints.iterator().next(), 0);
|
||||||
|
throw new SchemaViolationException(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(LinkedEntity linkedEntity : satisfiedConsistsOfFacet.keySet()) {
|
||||||
|
Integer satisfiedTimes = satisfiedConsistsOfFacet.get(linkedEntity);
|
||||||
|
if(satisfiedTimes<linkedEntity.getMin()) {
|
||||||
|
String message = constraintNotSatisfiedErrorMessage(linkedEntity, satisfiedTimes);
|
||||||
|
throw new SchemaViolationException(message);
|
||||||
|
}
|
||||||
|
Integer max = linkedEntity.getMax();
|
||||||
|
if((max!=null && max>0) && satisfiedTimes>max) {
|
||||||
|
String message = constraintNotSatisfiedErrorMessage(linkedEntity, satisfiedTimes);
|
||||||
|
throw new SchemaViolationException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
private String facetMustBePresentErrorMessage(String consistsOfType, UUID consistsOfUUID, String facetType, UUID facetUUID) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
stringBuffer.append("To avoid to have an incosistent graph, add to context no follows cannot add a ");
|
||||||
|
stringBuffer.append(ConsistsOf.NAME);
|
||||||
|
stringBuffer.append(" relation (i.e. ");
|
||||||
|
stringBuffer.append(consistsOfType);
|
||||||
|
stringBuffer.append(" with UUID ");
|
||||||
|
stringBuffer.append(consistsOfUUID.toString());
|
||||||
|
stringBuffer.append(") without indicating the target ");
|
||||||
|
stringBuffer.append(Facet.NAME);
|
||||||
|
stringBuffer.append(" (i.e. ");
|
||||||
|
stringBuffer.append(facetType);
|
||||||
|
stringBuffer.append(" with UUID ");
|
||||||
|
stringBuffer.append(facetUUID.toString());
|
||||||
|
stringBuffer.append(").");
|
||||||
|
return stringBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
|
||||||
JsonNode resourceInstance = createCompleteJsonNode();
|
JsonNode resourceInstance = createCompleteJsonNode();
|
||||||
|
@ -519,7 +568,6 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
throw new SchemaViolationException(stringBuffer.toString());
|
throw new SchemaViolationException(stringBuffer.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
|
@ -60,7 +56,7 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
|
@ -60,7 +56,7 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.types.entities;
|
package org.gcube.informationsystem.resourceregistry.types.entities;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
|
@ -44,7 +42,7 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if(workingContext == null) {
|
if (workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = ContextUtility.getInstance()
|
||||||
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
||||||
}
|
}
|
||||||
|
@ -56,9 +54,9 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if(name == null) {
|
if (name == null) {
|
||||||
if(element == null) {
|
if (element == null) {
|
||||||
if(jsonNode != null) {
|
if (jsonNode != null) {
|
||||||
name = jsonNode.get(EntityType.NAME_PROPERTY).asText();
|
name = jsonNode.get(EntityType.NAME_PROPERTY).asText();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -83,8 +81,8 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||||
logger.debug("Going to update {} for {}", this.typeName, getName());
|
logger.debug("Going to update {} for {}", this.typeName, getName());
|
||||||
OVertex entityTypeDefinition = getElement();
|
OVertex entityTypeDefinition = getElement();
|
||||||
entityTypeDefinition = (OVertex) updateProperties(oClass, entityTypeDefinition, jsonNode,
|
entityTypeDefinition = (OVertex) updateProperties(oClass, entityTypeDefinition, jsonNode, ignoreKeys,
|
||||||
ignoreKeys, ignoreStartWithKeys);
|
ignoreStartWithKeys);
|
||||||
return entityTypeDefinition;
|
return entityTypeDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,19 +95,19 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OVertex getElement() throws NotFoundException, ResourceRegistryException {
|
public OVertex getElement() throws NotFoundException, ResourceRegistryException {
|
||||||
if(element == null) {
|
if (element == null) {
|
||||||
try {
|
try {
|
||||||
element = retrieveElement();
|
element = retrieveElement();
|
||||||
} catch(NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(reload) {
|
if (reload) {
|
||||||
element.reload();
|
element.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,16 +117,16 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
@Override
|
@Override
|
||||||
public OVertex retrieveElement() throws NotFoundException, ResourceRegistryException {
|
public OVertex retrieveElement() throws NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
if(getName() == null) {
|
if (getName() == null) {
|
||||||
throw new NotFoundException("null name does not allow to retrieve the Element");
|
throw new NotFoundException("null name does not allow to retrieve the Element");
|
||||||
}
|
}
|
||||||
|
|
||||||
String select = "SELECT FROM " + typeName + " WHERE " + EntityType.NAME_PROPERTY + " = \""
|
String select = "SELECT FROM " + typeName + " WHERE " + EntityType.NAME_PROPERTY + " = \"" + getName()
|
||||||
+ getName() + "\"";
|
+ "\"";
|
||||||
|
|
||||||
OResultSet resultSet = oDatabaseDocument.query(select, new HashMap<>());
|
OResultSet resultSet = oDatabaseDocument.query(select, new HashMap<>());
|
||||||
|
|
||||||
if(resultSet == null || !resultSet.hasNext()) {
|
if (resultSet == null || !resultSet.hasNext()) {
|
||||||
String error = String.format("No %s with name %s was found", typeName, getName());
|
String error = String.format("No %s with name %s was found", typeName, getName());
|
||||||
logger.info(error);
|
logger.info(error);
|
||||||
throw new NotFoundException(error);
|
throw new NotFoundException(error);
|
||||||
|
@ -139,17 +137,17 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
|
|
||||||
logger.trace("{} with id {} is : {}", typeName, getName(), Utility.toJsonString(element, true));
|
logger.trace("{} with id {} is : {}", typeName, getName(), Utility.toJsonString(element, true));
|
||||||
|
|
||||||
if(resultSet.hasNext()) {
|
if (resultSet.hasNext()) {
|
||||||
throw new ResourceRegistryException("Found more than one " + typeName + " with name " + getName()
|
throw new ResourceRegistryException("Found more than one " + typeName + " with name " + getName()
|
||||||
+ ". This is a fatal error please contact Admnistrator");
|
+ ". This is a fatal error please contact Admnistrator");
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
} catch(NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
throw getSpecificElementNotFoundException(e);
|
throw getSpecificElementNotFoundException(e);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,9 +167,9 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
logger.info("Created {} is {}", OVertex.class.getSimpleName(), Utility.toJsonString(element, true));
|
logger.info("Created {} is {}", OVertex.class.getSimpleName(), Utility.toJsonString(element, true));
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
logger.trace("Error while creating {} for {} ({}) using {}", OVertex.class.getSimpleName(),
|
logger.trace("Error while creating {} for {} ({}) using {}", OVertex.class.getSimpleName(),
|
||||||
accessType.getName(), typeName, jsonNode, e);
|
accessType.getName(), typeName, jsonNode, e);
|
||||||
throw new ResourceRegistryException("Error Creating " + typeName + " with " + jsonNode, e.getCause());
|
throw new ResourceRegistryException("Error Creating " + typeName + " with " + jsonNode, e.getCause());
|
||||||
|
@ -194,8 +192,7 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances)
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
throws SchemaViolationException, ResourceRegistryException {
|
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.types.entities;
|
package org.gcube.informationsystem.resourceregistry.types.entities;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||||
|
@ -18,8 +14,7 @@ public class ResourceTypeDefinitionManagement extends EntityTypeDefinitionManage
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances)
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
throws SchemaViolationException, ResourceRegistryException {
|
|
||||||
// TODO
|
// TODO
|
||||||
// We should check that a constraint defined here is not in contrast with the constraint of supertypes
|
// We should check that a constraint defined here is not in contrast with the constraint of supertypes
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.types.properties;
|
package org.gcube.informationsystem.resourceregistry.types.properties;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
|
@ -195,8 +193,8 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances)
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
throws SchemaViolationException, ResourceRegistryException {
|
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.types.relations;
|
package org.gcube.informationsystem.resourceregistry.types.relations;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.types.entities.FacetTypeDefinitionManagement;
|
import org.gcube.informationsystem.resourceregistry.types.entities.FacetTypeDefinitionManagement;
|
||||||
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
||||||
|
@ -33,4 +34,9 @@ public class ConsistsOfTypeDefinitionManagement
|
||||||
return ftdm;
|
return ftdm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.types.relations;
|
package org.gcube.informationsystem.resourceregistry.types.relations;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.types.entities.ResourceTypeDefinitionManagement;
|
import org.gcube.informationsystem.resourceregistry.types.entities.ResourceTypeDefinitionManagement;
|
||||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||||
|
@ -33,4 +34,8 @@ public class IsRelatedToTypeDefinitionManagement
|
||||||
return rtdm;
|
return rtdm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.types.relations;
|
package org.gcube.informationsystem.resourceregistry.types.relations;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||||
|
@ -13,7 +10,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||||
|
@ -45,7 +41,8 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
this.typeName = RelationType.NAME;
|
this.typeName = RelationType.NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelationTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument, Class<TT> clz) throws ResourceRegistryException {
|
public RelationTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument,
|
||||||
|
Class<TT> clz) throws ResourceRegistryException {
|
||||||
this(clz);
|
this(clz);
|
||||||
this.oDatabaseDocument = oDatabaseDocument;
|
this.oDatabaseDocument = oDatabaseDocument;
|
||||||
setWorkingContext(securityContext);
|
setWorkingContext(securityContext);
|
||||||
|
@ -53,7 +50,7 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if(workingContext == null) {
|
if (workingContext == null) {
|
||||||
this.workingContext = ContextUtility.getInstance()
|
this.workingContext = ContextUtility.getInstance()
|
||||||
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
||||||
}
|
}
|
||||||
|
@ -65,9 +62,9 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if(name == null) {
|
if (name == null) {
|
||||||
if(element == null) {
|
if (element == null) {
|
||||||
if(jsonNode != null) {
|
if (jsonNode != null) {
|
||||||
name = jsonNode.get(RelationType.NAME_PROPERTY).asText();
|
name = jsonNode.get(RelationType.NAME_PROPERTY).asText();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,8 +77,8 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
@Override
|
@Override
|
||||||
protected OEdge reallyCreate() throws ResourceRegistryException {
|
protected OEdge reallyCreate() throws ResourceRegistryException {
|
||||||
logger.debug("Going to create {} for {}", RelationType.NAME, getName());
|
logger.debug("Going to create {} for {}", RelationType.NAME, getName());
|
||||||
if(sourceEntityManagement == null) {
|
if (sourceEntityManagement == null) {
|
||||||
if(!jsonNode.has(Relation.SOURCE_PROPERTY)) {
|
if (!jsonNode.has(Relation.SOURCE_PROPERTY)) {
|
||||||
throw new ResourceRegistryException("Error while creating relation. No source definition found");
|
throw new ResourceRegistryException("Error while creating relation. No source definition found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +87,8 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
sourceEntityManagement.setJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
sourceEntityManagement.setJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(targetEntityManagement == null) {
|
if (targetEntityManagement == null) {
|
||||||
if(!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
if (!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
||||||
throw new ResourceRegistryException(
|
throw new ResourceRegistryException(
|
||||||
"Error while creating " + typeName + ". No target definition found");
|
"Error while creating " + typeName + ". No target definition found");
|
||||||
}
|
}
|
||||||
|
@ -104,8 +101,7 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
OVertex source = (OVertex) getSourceEntityManagement().getElement();
|
OVertex source = (OVertex) getSourceEntityManagement().getElement();
|
||||||
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
||||||
|
|
||||||
logger.trace("Creating {} beetween {} -> {}", typeName, source.toString(),
|
logger.trace("Creating {} beetween {} -> {}", typeName, source.toString(), target.toString());
|
||||||
target.toString());
|
|
||||||
|
|
||||||
element = oDatabaseDocument.newEdge(source, target, typeName);
|
element = oDatabaseDocument.newEdge(source, target, typeName);
|
||||||
|
|
||||||
|
@ -118,8 +114,8 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
protected OEdge reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
protected OEdge reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||||
logger.debug("Going to update {} for {}", RelationType.NAME, getName());
|
logger.debug("Going to update {} for {}", RelationType.NAME, getName());
|
||||||
OEdge relationTypeDefinition = getElement();
|
OEdge relationTypeDefinition = getElement();
|
||||||
relationTypeDefinition = (OEdge) updateProperties(oClass, relationTypeDefinition, jsonNode,
|
relationTypeDefinition = (OEdge) updateProperties(oClass, relationTypeDefinition, jsonNode, ignoreKeys,
|
||||||
ignoreKeys, ignoreStartWithKeys);
|
ignoreStartWithKeys);
|
||||||
return relationTypeDefinition;
|
return relationTypeDefinition;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,19 +129,19 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OEdge getElement() throws NotFoundException, ResourceRegistryException {
|
public OEdge getElement() throws NotFoundException, ResourceRegistryException {
|
||||||
if(element == null) {
|
if (element == null) {
|
||||||
try {
|
try {
|
||||||
element = retrieveElement();
|
element = retrieveElement();
|
||||||
} catch(NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(reload) {
|
if (reload) {
|
||||||
element.reload();
|
element.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,16 +151,16 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
@Override
|
@Override
|
||||||
public OEdge retrieveElement() throws NotFoundException, ResourceRegistryException {
|
public OEdge retrieveElement() throws NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
if(getName() == null) {
|
if (getName() == null) {
|
||||||
throw new NotFoundException("null name does not allow to retrieve the Element");
|
throw new NotFoundException("null name does not allow to retrieve the Element");
|
||||||
}
|
}
|
||||||
|
|
||||||
String select = "SELECT FROM " + typeName + " WHERE " + RelationType.NAME_PROPERTY + " = \""
|
String select = "SELECT FROM " + typeName + " WHERE " + RelationType.NAME_PROPERTY + " = \"" + getName()
|
||||||
+ getName() + "\"";
|
+ "\"";
|
||||||
|
|
||||||
OResultSet resultSet = oDatabaseDocument.query(select, new HashMap<>());
|
OResultSet resultSet = oDatabaseDocument.query(select, new HashMap<>());
|
||||||
|
|
||||||
if(resultSet == null || !resultSet.hasNext()) {
|
if (resultSet == null || !resultSet.hasNext()) {
|
||||||
String error = String.format("No %s with name %s was found", typeName, getName());
|
String error = String.format("No %s with name %s was found", typeName, getName());
|
||||||
logger.info(error);
|
logger.info(error);
|
||||||
throw new NotFoundException(error);
|
throw new NotFoundException(error);
|
||||||
|
@ -175,17 +171,17 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
|
|
||||||
logger.trace("{} with id {} is : {}", typeName, getName(), Utility.toJsonString(element, true));
|
logger.trace("{} with id {} is : {}", typeName, getName(), Utility.toJsonString(element, true));
|
||||||
|
|
||||||
if(resultSet.hasNext()) {
|
if (resultSet.hasNext()) {
|
||||||
throw new ResourceRegistryException("Found more than one " + typeName + " with name " + getName()
|
throw new ResourceRegistryException("Found more than one " + typeName + " with name " + getName()
|
||||||
+ ". This is a fatal error please contact Admnistrator");
|
+ ". This is a fatal error please contact Admnistrator");
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
} catch(NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
throw getSpecificElementNotFoundException(e);
|
throw getSpecificElementNotFoundException(e);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,10 +209,4 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
return rtdm;
|
return rtdm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances)
|
|
||||||
throws SchemaViolationException, ResourceRegistryException {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue