Refactoring service
This commit is contained in:
parent
f722c2b148
commit
3434f373f6
|
@ -4,7 +4,6 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
@ -27,7 +26,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.relations.IsParentOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
|
@ -116,11 +114,6 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
|||
return new ContextNotFoundException(e.getMessage(), e.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
return new EntityAvailableInAnotherContextException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContextAlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
||||
return new ContextAlreadyPresentException(message);
|
||||
|
@ -432,19 +425,6 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
public String allFromServer(boolean polymorphic) throws ResourceRegistryException {
|
||||
return super.all(polymorphic);
|
||||
}
|
||||
|
@ -460,11 +440,10 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
|||
}
|
||||
|
||||
public String readFromServer() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
return super.read();
|
||||
return super.read().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
public String readAsString() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
return ElementMapper.marshal(contextCache.getContextByUUID(uuid));
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
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.node.ObjectNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
|
@ -103,23 +98,6 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
|||
return new ContextManagement(oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
|||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
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.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
|
@ -36,14 +35,12 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.properties.PropertyElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.SharingOperationValidator;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderOrient;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
@ -95,69 +92,6 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
protected El element;
|
||||
protected boolean reload;
|
||||
|
||||
/**
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
*
|
||||
* Setting this variable to false the system just simulate
|
||||
* the operation of context sharing
|
||||
* i.e. AddToContext, RemoveFromContext.
|
||||
*
|
||||
* This option can also be used in conjunction with
|
||||
* {@link ElementManagement#honourPropagationConstraintsInContextSharing}=false.
|
||||
* This allow to simulate a sharing operation which requires
|
||||
* do not honour the propagation constraints.
|
||||
*/
|
||||
protected boolean dryRunContextSharing;
|
||||
|
||||
/**
|
||||
* By the default the system honour the propagation constraints
|
||||
* so this variable is initialised as true.
|
||||
*
|
||||
* To revert a previous operation or for particular a maintenance
|
||||
* we could request to the service do not honour the propagation
|
||||
* constraints but under certain conditions and with some limitation
|
||||
* only.
|
||||
* These limitation are required to keep the system in a consistent
|
||||
* state.
|
||||
* In fact, this directive is only valid for Resources and IsRelatedTo
|
||||
* relations. We need to take in account that to add an
|
||||
* IsRelatedTo to a context always the source and target
|
||||
* Resources must be in such a Context.
|
||||
* Please also take into account that adding a Resource
|
||||
* to a context always imply to honour the propagation constraints
|
||||
* of ConsistsOf relations. In fact, a resource must be characterised
|
||||
* least by one facet in any context it belongs. Giving that we
|
||||
* cannot made assumption on which facets must be used.
|
||||
* A way could be to consider just the facets are mandatory for such a
|
||||
* Resource Type, but the type could not have mandatory facets
|
||||
* (even every Resource Type in the gCube Model has one mandatory facet).
|
||||
* As counterpart, when a Resource is removed from a Context all the facets
|
||||
* charactering it must be removed.
|
||||
*
|
||||
* This option can also be used in conjunction with
|
||||
* {@link ElementManagement#dryRunContextSharing}=true.
|
||||
* This allow to simulate a sharing operation which requires
|
||||
* do not honour the propagation constraints.
|
||||
*/
|
||||
protected boolean honourPropagationConstraintsInContextSharing;
|
||||
|
||||
public boolean isDryRunContextSharing() {
|
||||
return dryRunContextSharing;
|
||||
}
|
||||
|
||||
public void setDryRunContextSharing(boolean dryRunContextSharing) {
|
||||
this.dryRunContextSharing = dryRunContextSharing;
|
||||
}
|
||||
|
||||
public boolean isHonourPropagationConstraintsInContextSharing() {
|
||||
return honourPropagationConstraintsInContextSharing;
|
||||
}
|
||||
|
||||
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
|
||||
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
@ -201,18 +135,6 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
|
||||
this.superClassesToBeExcluded = new HashSet<>();
|
||||
|
||||
/*
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
*/
|
||||
this.dryRunContextSharing = false;
|
||||
|
||||
/*
|
||||
* By the default the system honour the propagation constraints
|
||||
* so this variable is initialised as true.
|
||||
*/
|
||||
this.honourPropagationConstraintsInContextSharing = true;
|
||||
|
||||
}
|
||||
|
||||
public void setUUID(UUID uuid) throws ResourceRegistryException {
|
||||
|
@ -350,7 +272,9 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
}
|
||||
}
|
||||
|
||||
public abstract String serialize() throws ResourceRegistryException;
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
public abstract JsonNode serializeAsJson() throws ResourceRegistryException;
|
||||
|
||||
|
@ -412,48 +336,6 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
return reallyDelete();
|
||||
}
|
||||
|
||||
protected abstract Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID,JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(targetSecurityContext);
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
}
|
||||
affectedInstances.put(uuid, serializeSelfOnly());
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error Adding " + elementType + " to " + targetSecurityContext.toString(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(targetSecurityContext);
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
}
|
||||
affectedInstances.put(uuid, serializeSelfOnly());
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error Removing " + elementType + " from " + targetSecurityContext.toString(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public void setElement(El element) throws ResourceRegistryException {
|
||||
if(element == null) {
|
||||
throw new ResourceRegistryException("Trying to set null " + elementClass.getSimpleName() + " in " + this);
|
||||
|
@ -466,9 +348,6 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
|
||||
protected abstract NotFoundException getSpecificElementNotFoundException(NotFoundException e);
|
||||
|
||||
protected abstract AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
String message);
|
||||
|
||||
protected abstract AlreadyPresentException getSpecificERAlreadyPresentException(String message);
|
||||
|
||||
public El getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
|
@ -476,16 +355,7 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
try {
|
||||
element = retrieveElement();
|
||||
} catch(NotFoundException e) {
|
||||
try {
|
||||
retrieveElementFromAnyContext();
|
||||
throw getSpecificERAvailableInAnotherContextException(elementType == null ? accessType.getName()
|
||||
: elementType + " with UUID " + uuid + " is available in another "
|
||||
+ Context.class.getSimpleName());
|
||||
} catch(AvailableInAnotherContextException e1) {
|
||||
throw e1;
|
||||
} catch(Exception e1) {
|
||||
throw e;
|
||||
}
|
||||
throw e;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -665,7 +535,7 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
}
|
||||
}
|
||||
|
||||
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
public JsonNode read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
||||
|
@ -673,7 +543,7 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
|
||||
getElement();
|
||||
|
||||
return serialize();
|
||||
return serializeAsJson();
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid);
|
||||
throw e;
|
||||
|
@ -772,195 +642,6 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
}
|
||||
}
|
||||
|
||||
public static Map<UUID,JsonNode> addToContextNoPropagationConstraint(Map<UUID, JsonNode> expectedInstances, UUID contextUUID, boolean dryRun)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
Set<UUID> instances = expectedInstances.keySet();
|
||||
staticLogger.info("Going to add {} to Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(oDatabaseDocument, type);
|
||||
elementManagement.setUUID(uuid);
|
||||
elementManagement.setHonourPropagationConstraintsInContextSharing(false);
|
||||
elementManagement.setDryRunContextSharing(dryRun);
|
||||
|
||||
affectedInstances.putAll(elementManagement.internalAddToContext(targetSecurityContext));
|
||||
}
|
||||
|
||||
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.ADD);
|
||||
|
||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||
oDatabaseDocument.commit();
|
||||
}
|
||||
|
||||
staticLogger.info("{} successfully added to Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
staticLogger.error("Unable to add {} to Context with UUID {} not following Propagation Constraints - Reason is {}", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
staticLogger.error("Unable to add {} to Context with UUID {} not following Propagation Constraints.", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalAddToContext(targetSecurityContext);
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {} - Reason is {}", elementType, uuid, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID, e);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<UUID,JsonNode> removeFromContextNoPropagationConstraint(Map<UUID, JsonNode> expectedInstances, UUID contextUUID, boolean dryRun)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
Set<UUID> instances = expectedInstances.keySet();
|
||||
staticLogger.info("Going to remove {} from Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(oDatabaseDocument, type);
|
||||
elementManagement.setUUID(uuid);
|
||||
elementManagement.setHonourPropagationConstraintsInContextSharing(false);
|
||||
elementManagement.setDryRunContextSharing(dryRun);
|
||||
|
||||
affectedInstances.putAll(elementManagement.internalRemoveFromContext(targetSecurityContext));
|
||||
}
|
||||
|
||||
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.REMOVE);
|
||||
|
||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||
oDatabaseDocument.commit();
|
||||
}
|
||||
|
||||
staticLogger.info("{} successfully removed from Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
staticLogger.error("Unable to remove {} from Context with UUID {} not following Propagation Constraints - Reason is {}", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
staticLogger.error("Unable to remove {} from Context with UUID {} not following Propagation Constraints.", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID,
|
||||
e);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getContextsSet() throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.debug("Going to get contexts for {} with UUID", elementType, uuid);
|
||||
|
|
|
@ -64,19 +64,19 @@ public class ElementManagementUtility {
|
|||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ElementManagement getERManagement(ODatabaseDocument oDatabaseDocument, String type) throws ResourceRegistryException {
|
||||
public static ElementManagement getERManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument, String type) throws ResourceRegistryException {
|
||||
|
||||
OClass oClass = ElementManagementUtility.getTypeSchema(oDatabaseDocument, type, null);
|
||||
ElementManagement erManagement = null;
|
||||
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
erManagement = new ResourceManagement();
|
||||
erManagement = new ResourceManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
erManagement = new FacetManagement();
|
||||
erManagement = new FacetManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
erManagement = new ConsistsOfManagement();
|
||||
erManagement = new ConsistsOfManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
erManagement = new IsRelatedToManagement();
|
||||
erManagement = new IsRelatedToManagement(workingContext, oDatabaseDocument);
|
||||
}
|
||||
|
||||
if(erManagement == null) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
|||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.base.reference.relations.RelationElement;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
|
@ -135,11 +136,10 @@ public abstract class EntityElementManagement<E extends EntityElement> extends E
|
|||
} catch(NotFoundException e) {
|
||||
try {
|
||||
OElement el = ElementManagementUtility.getAnyElementByUUID(uuid);
|
||||
String error = String.format("UUID %s is already used by another %s. This is not allowed.",
|
||||
String error = String.format("UUID %s is already used by another Element. This is not allowed.",
|
||||
uuid.toString(),
|
||||
(el instanceof OVertex) ? org.gcube.informationsystem.model.reference.entities.Entity.NAME :
|
||||
org.gcube.informationsystem.model.reference.relations.Relation.NAME);
|
||||
throw getSpecificERAvailableInAnotherContextException(error);
|
||||
(el instanceof OVertex) ? EntityElement.NAME : RelationElement.NAME);
|
||||
throw new ResourceRegistryException(error);
|
||||
|
||||
} catch(NotFoundException e1) {
|
||||
// OK the UUID is not already used.
|
||||
|
|
|
@ -85,11 +85,6 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
|
|||
this.targetEntityManagement = targetEntityManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
return serializeAsJson(true, true);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.model;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
|
||||
public interface ERManagement {
|
||||
|
||||
public boolean isDryRunContextSharing();
|
||||
|
||||
public void setDryRunContextSharing(boolean dryRunContextSharing);
|
||||
|
||||
public boolean isHonourPropagationConstraintsInContextSharing();
|
||||
|
||||
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing);
|
||||
|
||||
public Map<UUID, JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> addToContext(UUID contextUUID)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> removeFromContext(UUID contextUUID)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException;
|
||||
|
||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException;
|
||||
|
||||
public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message);
|
||||
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
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.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
public class ERManagementUtility {
|
||||
|
||||
private static Logger staticLogger = LoggerFactory.getLogger(ERManagementUtility.class);
|
||||
|
||||
public static Map<UUID,JsonNode> addToContextNoPropagationConstraint(Map<UUID, JsonNode> expectedInstances, UUID contextUUID, boolean dryRun)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
Set<UUID> instances = expectedInstances.keySet();
|
||||
staticLogger.info("Going to add {} to Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(adminSecurityContext, oDatabaseDocument, type);
|
||||
elementManagement.setUUID(uuid);
|
||||
elementManagement.setElementType(type);
|
||||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
((ERManagement) elementManagement).internalAddToContext(targetSecurityContext);
|
||||
((ERManagement) elementManagement).sanityCheck(expectedInstances);
|
||||
}
|
||||
|
||||
/*
|
||||
Map<UUID,JsonNode> expectedAdditionaInstances = new HashMap<>();
|
||||
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.ADD);
|
||||
|
||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||
oDatabaseDocument.commit();
|
||||
}
|
||||
*/
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
staticLogger.info("{} successfully added to Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
|
||||
/*
|
||||
* Without following the propagation constraint no instances are enforced to be added
|
||||
* to the context. The sanity check ensure that the graph is consistent otherwise a
|
||||
* an exception is raised.
|
||||
* So no need to collect affected isntance and expected instance can be returned.
|
||||
*/
|
||||
return expectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
staticLogger.error("Unable to add {} to Context with UUID {} not following Propagation Constraints - Reason is {}", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
staticLogger.error("Unable to add {} to Context with UUID {} not following Propagation Constraints.", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<UUID,JsonNode> removeFromContextNoPropagationConstraint(Map<UUID, JsonNode> expectedInstances, UUID contextUUID, boolean dryRun)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
Set<UUID> instances = expectedInstances.keySet();
|
||||
staticLogger.info("Going to remove {} from Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(adminSecurityContext, oDatabaseDocument, type);
|
||||
elementManagement.setUUID(uuid);
|
||||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
|
||||
affectedInstances.putAll(((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext));
|
||||
|
||||
((ERManagement) elementManagement).sanityCheck(expectedInstances);
|
||||
}
|
||||
|
||||
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.REMOVE);
|
||||
|
||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||
oDatabaseDocument.commit();
|
||||
}
|
||||
|
||||
staticLogger.info("{} successfully removed from Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
staticLogger.error("Unable to remove {} from Context with UUID {} not following Propagation Constraints - Reason is {}", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
staticLogger.error("Unable to remove {} from Context with UUID {} not following Propagation Constraints.", instances, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
|
@ -28,12 +28,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.context.Conte
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
@ -50,7 +53,70 @@ import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class EntityManagement<E extends EntityElement> extends EntityElementManagement<E> {
|
||||
public abstract class EntityManagement<E extends Entity> extends EntityElementManagement<E> implements ERManagement {
|
||||
|
||||
/**
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
*
|
||||
* Setting this variable to false the system just simulate
|
||||
* the operation of context sharing
|
||||
* i.e. AddToContext, RemoveFromContext.
|
||||
*
|
||||
* This option can also be used in conjunction with
|
||||
* {@link ElementManagement#honourPropagationConstraintsInContextSharing}=false.
|
||||
* This allow to simulate a sharing operation which requires
|
||||
* do not honour the propagation constraints.
|
||||
*/
|
||||
protected boolean dryRunContextSharing;
|
||||
|
||||
/**
|
||||
* By the default the system honour the propagation constraints
|
||||
* so this variable is initialised as true.
|
||||
*
|
||||
* To revert a previous operation or for particular a maintenance
|
||||
* we could request to the service do not honour the propagation
|
||||
* constraints but under certain conditions and with some limitation
|
||||
* only.
|
||||
* These limitation are required to keep the system in a consistent
|
||||
* state.
|
||||
* In fact, this directive is only valid for Resources and IsRelatedTo
|
||||
* relations. We need to take in account that to add an
|
||||
* IsRelatedTo to a context always the source and target
|
||||
* Resources must be in such a Context.
|
||||
* Please also take into account that adding a Resource
|
||||
* to a context always imply to honour the propagation constraints
|
||||
* of ConsistsOf relations. In fact, a resource must be characterised
|
||||
* least by one facet in any context it belongs. Giving that we
|
||||
* cannot made assumption on which facets must be used.
|
||||
* A way could be to consider just the facets are mandatory for such a
|
||||
* Resource Type, but the type could not have mandatory facets
|
||||
* (even every Resource Type in the gCube Model has one mandatory facet).
|
||||
* As counterpart, when a Resource is removed from a Context all the facets
|
||||
* charactering it must be removed.
|
||||
*
|
||||
* This option can also be used in conjunction with
|
||||
* {@link ElementManagement#dryRunContextSharing}=true.
|
||||
* This allow to simulate a sharing operation which requires
|
||||
* do not honour the propagation constraints.
|
||||
*/
|
||||
protected boolean honourPropagationConstraintsInContextSharing;
|
||||
|
||||
public boolean isDryRunContextSharing() {
|
||||
return dryRunContextSharing;
|
||||
}
|
||||
|
||||
public void setDryRunContextSharing(boolean dryRunContextSharing) {
|
||||
this.dryRunContextSharing = dryRunContextSharing;
|
||||
}
|
||||
|
||||
public boolean isHonourPropagationConstraintsInContextSharing() {
|
||||
return honourPropagationConstraintsInContextSharing;
|
||||
}
|
||||
|
||||
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
|
||||
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a cache edge-internal-id -> RelationManagement
|
||||
|
@ -73,6 +139,18 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
|||
|
||||
this.superClassesToBeExcluded.add(AccessType.ENTITY_ELEMENT.getName());
|
||||
this.superClassesToBeExcluded.add(AccessType.ENTITY.getName());
|
||||
|
||||
/*
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
*/
|
||||
this.dryRunContextSharing = false;
|
||||
|
||||
/*
|
||||
* By the default the system honour the propagation constraints
|
||||
* so this variable is initialised as true.
|
||||
*/
|
||||
this.honourPropagationConstraintsInContextSharing = true;
|
||||
}
|
||||
|
||||
protected EntityManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
|
@ -81,6 +159,29 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
|||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OVertex getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
element = super.getElement();
|
||||
} catch(NotFoundException e) {
|
||||
try {
|
||||
retrieveElementFromAnyContext();
|
||||
throw getSpecificERAvailableInAnotherContextException(elementType == null ? accessType.getName()
|
||||
: elementType + " with UUID " + uuid + " is available in another "
|
||||
+ Context.class.getSimpleName());
|
||||
} catch(AvailableInAnotherContextException e1) {
|
||||
throw e1;
|
||||
} catch(Exception e1) {
|
||||
throw e;
|
||||
}
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
/*
|
||||
* It works perfectly in case of any kind of update. In case of use from create
|
||||
|
@ -192,7 +293,6 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
|
@ -223,6 +323,81 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(targetSecurityContext);
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
}
|
||||
affectedInstances.put(uuid, serializeSelfOnly());
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error Adding " + elementType + " to " + targetSecurityContext.toString(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalAddToContext(targetSecurityContext);
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {} - Reason is {}", elementType, uuid, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID, e);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(targetSecurityContext);
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
}
|
||||
affectedInstances.put(uuid, serializeSelfOnly());
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error Removing " + elementType + " from " + targetSecurityContext.toString(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
|
@ -252,6 +427,46 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
|||
return affectedInstances;
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID,
|
||||
e);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
|
@ -33,7 +36,7 @@ public class FacetManagement extends EntityManagement<Facet> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected FacetAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
public FacetAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
return new FacetAvailableInAnotherContextException(message);
|
||||
}
|
||||
|
||||
|
@ -69,5 +72,11 @@ public class FacetManagement extends EntityManagement<Facet> {
|
|||
getElement().delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,12 +6,17 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
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.model.reference.entities.Facet;
|
||||
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.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
|
@ -50,7 +55,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ResourceAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
public ResourceAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
String message) {
|
||||
return new ResourceAvailableInAnotherContextException(message);
|
||||
}
|
||||
|
@ -60,11 +65,6 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
return new ResourceAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
|
||||
|
@ -247,32 +247,34 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||
*/
|
||||
|
||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||
|
||||
int facetCounter = 0;
|
||||
|
||||
for(OEdge edge : edges) {
|
||||
RelationManagement<?> relationManagement = getRelationManagement(edge);
|
||||
relationManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext(targetSecurityContext);
|
||||
if(relationManagement instanceof ConsistsOfManagement) {
|
||||
facetCounter = facetCounter + resourceCharacterisationInstances.size();
|
||||
if(honourPropagationConstraintsInContextSharing) {
|
||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||
|
||||
int facetCounter = 0;
|
||||
|
||||
for(OEdge edge : edges) {
|
||||
RelationManagement<?> relationManagement = getRelationManagement(edge);
|
||||
relationManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext(targetSecurityContext);
|
||||
if(relationManagement instanceof ConsistsOfManagement) {
|
||||
facetCounter = facetCounter + resourceCharacterisationInstances.size();
|
||||
}
|
||||
affectedInstances.putAll(resourceCharacterisationInstances);
|
||||
}
|
||||
|
||||
if(facetCounter == 0) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Any ");
|
||||
stringBuffer.append(Resource.NAME);
|
||||
stringBuffer.append(" must ");
|
||||
stringBuffer.append(ConsistsOf.NAME);
|
||||
stringBuffer.append(" at least of one ");
|
||||
stringBuffer.append(Facet.NAME);
|
||||
stringBuffer.append(" in any ");
|
||||
stringBuffer.append(Context.NAME);
|
||||
throw new ResourceRegistryException(stringBuffer.toString());
|
||||
}
|
||||
affectedInstances.putAll(resourceCharacterisationInstances);
|
||||
}
|
||||
|
||||
if(facetCounter == 0) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Any ");
|
||||
stringBuffer.append(Resource.NAME);
|
||||
stringBuffer.append(" must ");
|
||||
stringBuffer.append(ConsistsOf.NAME);
|
||||
stringBuffer.append(" at least of one ");
|
||||
stringBuffer.append(Facet.NAME);
|
||||
stringBuffer.append(" in any ");
|
||||
stringBuffer.append(Context.NAME);
|
||||
throw new ResourceRegistryException(stringBuffer.toString());
|
||||
}
|
||||
|
||||
return affectedInstances;
|
||||
|
@ -294,4 +296,61 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO Create something like SchemaDefinitionNotRespected o ConstaintNotRespected Exception
|
||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException {
|
||||
// TODO check that at least a facet and its consistOf will be added to the context
|
||||
JsonNode jsonNode = read();
|
||||
|
||||
boolean found = false;
|
||||
ArrayNode consistsOfArrayNode = (ArrayNode) jsonNode.get(Resource.CONSISTS_OF_PROPERTY);
|
||||
for(JsonNode consistsOfJsonNode : consistsOfArrayNode) {
|
||||
String consistsOfUUIDString = consistsOfJsonNode.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText();
|
||||
UUID consistsOfUUID = UUID.fromString(consistsOfUUIDString);
|
||||
if(expectedInstances.containsKey(consistsOfUUID)) {
|
||||
// we need to check that also the facets are
|
||||
JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY);
|
||||
String facetUUIDString = facetJsonNode.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText();
|
||||
UUID facetUUID = UUID.fromString(facetUUIDString);
|
||||
if(!expectedInstances.containsKey(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(consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText());
|
||||
stringBuffer.append(" with UUID ");
|
||||
stringBuffer.append(consistsOfUUIDString);
|
||||
stringBuffer.append(") without indicating the target ");
|
||||
stringBuffer.append(Facet.NAME);
|
||||
stringBuffer.append(" (i.e. ");
|
||||
stringBuffer.append(facetJsonNode.get(Element.CLASS_PROPERTY).asText());
|
||||
stringBuffer.append(" with UUID ");
|
||||
stringBuffer.append(facetUUIDString);
|
||||
stringBuffer.append(").");
|
||||
logger.debug(stringBuffer.toString());
|
||||
throw new ResourceRegistryException(stringBuffer.toString());
|
||||
}
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO check Resource definition for mandatory ConsistsOf/Facet
|
||||
|
||||
if(!found) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("To avoid to have an incosistent graph, add to context no follows cannot add a ");
|
||||
stringBuffer.append(Resource.NAME);
|
||||
stringBuffer.append(" (i.e. ");
|
||||
stringBuffer.append(elementType);
|
||||
stringBuffer.append(" with UUID ");
|
||||
stringBuffer.append(uuid.toString());
|
||||
stringBuffer.append(") without adding at least a ");
|
||||
stringBuffer.append(Facet.NAME);
|
||||
logger.debug(stringBuffer.toString());
|
||||
throw new ResourceRegistryException(stringBuffer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
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.model.impl.properties.PropagationConstraintImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
|
@ -43,7 +47,7 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConsistsOfAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
public ConsistsOfAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
String message) {
|
||||
return new ConsistsOfAvailableInAnotherContextException(message);
|
||||
}
|
||||
|
@ -57,5 +61,11 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement> {
|
|||
protected FacetManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new FacetManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
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.model.impl.properties.PropagationConstraintImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
|
@ -43,7 +47,7 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
|||
}
|
||||
|
||||
@Override
|
||||
protected IsRelatedToAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
public IsRelatedToAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
String message) {
|
||||
return new IsRelatedToAvailableInAnotherContextException(message);
|
||||
}
|
||||
|
@ -57,5 +61,11 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
|||
protected ResourceManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
|
@ -27,6 +29,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityCo
|
|||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.relations.RelationElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||
|
@ -46,26 +49,91 @@ import com.orientechnologies.orient.core.record.impl.ODocument;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class RelationManagement<T extends EntityManagement<? extends Entity>>
|
||||
extends RelationElementManagement<ResourceManagement, T>{
|
||||
extends RelationElementManagement<ResourceManagement, T> implements ERManagement {
|
||||
|
||||
/**
|
||||
* Used in AddToContext. The Relation must add/check also the source entity
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
*
|
||||
* Setting this variable to false the system just simulate
|
||||
* the operation of context sharing
|
||||
* i.e. AddToContext, RemoveFromContext.
|
||||
*
|
||||
* This option can also be used in conjunction with
|
||||
* {@link ElementManagement#honourPropagationConstraintsInContextSharing}=false.
|
||||
* This allow to simulate a sharing operation which requires
|
||||
* do not honour the propagation constraints.
|
||||
*/
|
||||
public boolean checkContextOfSourceEntity;
|
||||
protected boolean dryRunContextSharing;
|
||||
|
||||
public void setCheckContextOfSourceEntity(boolean checkContextOfSourceEntity) {
|
||||
this.checkContextOfSourceEntity = checkContextOfSourceEntity;
|
||||
/**
|
||||
* By the default the system honour the propagation constraints
|
||||
* so this variable is initialised as true.
|
||||
*
|
||||
* To revert a previous operation or for particular a maintenance
|
||||
* we could request to the service do not honour the propagation
|
||||
* constraints but under certain conditions and with some limitation
|
||||
* only.
|
||||
* These limitation are required to keep the system in a consistent
|
||||
* state.
|
||||
* In fact, this directive is only valid for Resources and IsRelatedTo
|
||||
* relations. We need to take in account that to add an
|
||||
* IsRelatedTo to a context always the source and target
|
||||
* Resources must be in such a Context.
|
||||
* Please also take into account that adding a Resource
|
||||
* to a context always imply to honour the propagation constraints
|
||||
* of ConsistsOf relations. In fact, a resource must be characterised
|
||||
* least by one facet in any context it belongs. Giving that we
|
||||
* cannot made assumption on which facets must be used.
|
||||
* A way could be to consider just the facets are mandatory for such a
|
||||
* Resource Type, but the type could not have mandatory facets
|
||||
* (even every Resource Type in the gCube Model has one mandatory facet).
|
||||
* As counterpart, when a Resource is removed from a Context all the facets
|
||||
* charactering it must be removed.
|
||||
*
|
||||
* This option can also be used in conjunction with
|
||||
* {@link ElementManagement#dryRunContextSharing}=true.
|
||||
* This allow to simulate a sharing operation which requires
|
||||
* do not honour the propagation constraints.
|
||||
*/
|
||||
protected boolean honourPropagationConstraintsInContextSharing;
|
||||
|
||||
public boolean isDryRunContextSharing() {
|
||||
return dryRunContextSharing;
|
||||
}
|
||||
|
||||
public void setDryRunContextSharing(boolean dryRunContextSharing) {
|
||||
this.dryRunContextSharing = dryRunContextSharing;
|
||||
}
|
||||
|
||||
public boolean isHonourPropagationConstraintsInContextSharing() {
|
||||
return honourPropagationConstraintsInContextSharing;
|
||||
}
|
||||
|
||||
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
|
||||
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
|
||||
}
|
||||
|
||||
public final PropagationConstraint defaultPropagationConstraint;
|
||||
|
||||
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, PropagationConstraint defaultPropagationConstraint) {
|
||||
super(accessType, Resource.class, targetEntityClass);
|
||||
this.defaultPropagationConstraint = defaultPropagationConstraint;
|
||||
this.checkContextOfSourceEntity = false;
|
||||
|
||||
this.superClassesToBeExcluded.add(AccessType.RELATION_ELEMENT.getName());
|
||||
this.superClassesToBeExcluded.add(AccessType.RELATION.getName());
|
||||
|
||||
/*
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
*/
|
||||
this.dryRunContextSharing = false;
|
||||
|
||||
/*
|
||||
* By the default the system honour the propagation constraints
|
||||
* so this variable is initialised as true.
|
||||
*/
|
||||
this.honourPropagationConstraintsInContextSharing = true;
|
||||
}
|
||||
|
||||
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph,
|
||||
|
@ -77,6 +145,31 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
protected PropagationConstraint propagationConstraint;
|
||||
|
||||
@Override
|
||||
public OEdge getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
element = super.getElement();
|
||||
} catch(NotFoundException e) {
|
||||
try {
|
||||
retrieveElementFromAnyContext();
|
||||
throw getSpecificERAvailableInAnotherContextException(elementType == null ? accessType.getName()
|
||||
: elementType + " with UUID " + uuid + " is available in another "
|
||||
+ Context.class.getSimpleName());
|
||||
} catch(AvailableInAnotherContextException e1) {
|
||||
throw e1;
|
||||
} catch(Exception e1) {
|
||||
throw e;
|
||||
}
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Needed for ResourceManagement.serializeAsJson() function to check that
|
||||
* sourceEntityManagement is the same of the instance is creating this
|
||||
|
@ -114,11 +207,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
this.targetEntityManagement = targetEntityManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
return serializeAsJson(true, true);
|
||||
|
@ -275,7 +363,79 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
||||
if(honourPropagationConstraintsInContextSharing) {
|
||||
AddConstraint addConstraint = AddConstraint.unpropagate;
|
||||
|
||||
try {
|
||||
propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, element,
|
||||
Relation.PROPAGATION_CONSTRAINT_PROPERTY);
|
||||
if(propagationConstraint.getAddConstraint() != null) {
|
||||
addConstraint = propagationConstraint.getAddConstraint();
|
||||
} else {
|
||||
String error = String.format("%s.%s in %s is null. %s", Relation.PROPAGATION_CONSTRAINT_PROPERTY,
|
||||
PropagationConstraint.ADD_PROPERTY, Utility.toJsonString(element, true),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
String error = String.format("Error while getting %s from %s while performing AddToContext. %s",
|
||||
Relation.PROPAGATION_CONSTRAINT_PROPERTY, Utility.toJsonString(element, true),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.warn(error);
|
||||
throw new ResourceRegistryException(error, e);
|
||||
}
|
||||
|
||||
switch(addConstraint) {
|
||||
case propagate:
|
||||
/*
|
||||
* The relation must be added only in the case the target vertex must be added.
|
||||
* Otherwise we have a relation which point to an entity outside of the context.
|
||||
*/
|
||||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
affectedInstances.putAll(targetEntityManagement.internalAddToContext(targetSecurityContext));
|
||||
|
||||
if(!dryRunContextSharing) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
}
|
||||
/*
|
||||
* DO NOT UNCOMMENT
|
||||
* // affectedInstances.put(uuid, serializeSelfOnly());
|
||||
* the relation instance is added in internalAddToContext() function after
|
||||
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||
*/
|
||||
|
||||
break;
|
||||
|
||||
case unpropagate:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}else {
|
||||
if(!dryRunContextSharing) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
}
|
||||
/*
|
||||
* DO NOT UNCOMMENT
|
||||
* // affectedInstances.put(uuid, serializeSelfOnly());
|
||||
* the relation instance is added in internalAddToContext() function after
|
||||
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||
*/
|
||||
}
|
||||
|
||||
return affectedInstances;
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
|
@ -296,68 +456,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
||||
AddConstraint addConstraint = AddConstraint.unpropagate;
|
||||
|
||||
try {
|
||||
propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, element,
|
||||
Relation.PROPAGATION_CONSTRAINT_PROPERTY);
|
||||
if(propagationConstraint.getAddConstraint() != null) {
|
||||
addConstraint = propagationConstraint.getAddConstraint();
|
||||
} else {
|
||||
String error = String.format("%s.%s in %s is null. %s", Relation.PROPAGATION_CONSTRAINT_PROPERTY,
|
||||
PropagationConstraint.ADD_PROPERTY, Utility.toJsonString(element, true),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
String error = String.format("Error while getting %s from %s while performing AddToContext. %s",
|
||||
Relation.PROPAGATION_CONSTRAINT_PROPERTY, Utility.toJsonString(element, true),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.warn(error);
|
||||
throw new ResourceRegistryException(error, e);
|
||||
}
|
||||
|
||||
switch(addConstraint) {
|
||||
case propagate:
|
||||
/*
|
||||
* The relation must be added only in the case the target vertex must be added.
|
||||
* Otherwise we have a relation which point to an entity outside of the context.
|
||||
*/
|
||||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
affectedInstances.putAll(targetEntityManagement.internalAddToContext(targetSecurityContext));
|
||||
|
||||
if(!dryRunContextSharing) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
}
|
||||
/*
|
||||
* DO NOT UNCOMMENT
|
||||
* // affectedInstances.put(uuid, serializeSelfOnly());
|
||||
* the relation instance is added in internalAddToContext() function after
|
||||
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||
*/
|
||||
|
||||
break;
|
||||
|
||||
case unpropagate:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return affectedInstances;
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> forcedAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
@ -384,7 +482,35 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
return affectedInstances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
||||
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> added = forcedAddToContext(targetSecurityContext);
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID);
|
||||
|
||||
return added;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID, e);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
@ -472,6 +598,64 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
return affectedInstances;
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(targetSecurityContext);
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
}
|
||||
affectedInstances.put(uuid, serializeSelfOnly());
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error Removing " + elementType + " from " + targetSecurityContext.toString(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID,
|
||||
e);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
|
||||
|
@ -563,34 +747,4 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
return serializeJsonNodeCollectionAsString(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
||||
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> added = forcedAddToContext(targetSecurityContext);
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID);
|
||||
|
||||
return added;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID, e);
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public class Access extends BaseRest {
|
|||
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setUUID(UUID.fromString(uuid));
|
||||
return contextManagement.read();
|
||||
return contextManagement.readAsString();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -262,7 +262,7 @@ public class Access extends BaseRest {
|
|||
|
||||
erManagement.setElementType(type);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
return erManagement.read();
|
||||
return erManagement.read().toString();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public class ContextManager {
|
|||
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setUUID(UUID.fromString(uuid));
|
||||
return contextManagement.read();
|
||||
return contextManagement.readAsString();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -145,7 +145,7 @@ public class InstancesManager extends BaseRest {
|
|||
|
||||
erManagement.setElementType(type);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
return erManagement.read();
|
||||
return erManagement.read().toString();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
|||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagementUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -120,9 +122,9 @@ public class SharingManager {
|
|||
UUID contextUUID = UUID.fromString(contextId);
|
||||
Map<UUID,JsonNode> affectedInstances = null;
|
||||
if(operation == SharingOperation.ADD) {
|
||||
affectedInstances = ElementManagement.addToContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
affectedInstances = ERManagementUtility.addToContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
}else {
|
||||
affectedInstances = ElementManagement.removeFromContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
affectedInstances = ERManagementUtility.removeFromContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
}
|
||||
|
||||
return serializeAffectedInstaces(objectMapper, affectedInstances);
|
||||
|
@ -182,16 +184,16 @@ public class SharingManager {
|
|||
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||
elementManagement.setUUID(UUID.fromString(instanceId));
|
||||
elementManagement.setDryRunContextSharing(dryRun);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
|
||||
UUID contextUUID = UUID.fromString(contextId);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<UUID,JsonNode> affectedInstances = null;
|
||||
if(operation == SharingOperation.ADD) {
|
||||
affectedInstances = elementManagement.addToContext(contextUUID);
|
||||
affectedInstances = ((ERManagement) elementManagement).addToContext(contextUUID);
|
||||
}else {
|
||||
affectedInstances = elementManagement.removeFromContext(contextUUID);
|
||||
affectedInstances = ((ERManagement) elementManagement).removeFromContext(contextUUID);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -200,7 +200,7 @@ public class SchemaManagement {
|
|||
private String getTypeAsString(ElementManagement<? extends OElement> erManagement) throws SchemaException {
|
||||
try {
|
||||
if(erManagement!=null) {
|
||||
String ret = erManagement.read();
|
||||
String ret = erManagement.read().toString();
|
||||
return ret;
|
||||
}else {
|
||||
throw new SchemaException("You can only request schema of IS Model types and their specilization");
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package org.gcube.informationsystem.resourceregistry.types.entities;
|
||||
|
||||
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.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
|
@ -197,18 +193,6 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new SchemaNotFoundException(e.getMessage(), e.getCause());
|
||||
|
@ -219,9 +203,4 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
|||
return new SchemaAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package org.gcube.informationsystem.resourceregistry.types.properties;
|
||||
|
||||
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.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
|
@ -189,18 +185,6 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new SchemaNotFoundException(e.getMessage(), e.getCause());
|
||||
|
@ -211,9 +195,4 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
|
|||
return new SchemaAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
package org.gcube.informationsystem.resourceregistry.types.relations;
|
||||
|
||||
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.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
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.SchemaNotFoundException;
|
||||
|
@ -196,18 +191,6 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new SchemaNotFoundException(e.getMessage(), e.getCause());
|
||||
|
@ -218,11 +201,6 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
|||
return new SchemaAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceTypeDefinitionManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceTypeDefinitionManagement(getWorkingContext(), oDatabaseDocument);
|
||||
|
|
|
@ -117,7 +117,7 @@ public class ContextManagementTest extends ContextTest {
|
|||
protected Context read(UUID uuid) throws ResourceRegistryException, IOException {
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setUUID(uuid);
|
||||
String contextString = contextManagement.read();
|
||||
String contextString = contextManagement.read().toString();
|
||||
logger.debug("Read {}", contextString);
|
||||
roleUserAssertions(uuid, null, false);
|
||||
return ElementMapper.unmarshal(Context.class, contextString);
|
||||
|
|
|
@ -269,7 +269,7 @@ public class ERManagementTest extends ContextTest {
|
|||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
|
||||
|
||||
String read= resourceManagement.read();
|
||||
String read= resourceManagement.read().toString();
|
||||
logger.debug(read);
|
||||
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ public class ERManagementTest extends ContextTest {
|
|||
facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(uuid);
|
||||
|
||||
String readJson = facetManagement.read();
|
||||
String readJson = facetManagement.read().toString();
|
||||
CPUFacet readCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readJson);
|
||||
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson,
|
||||
readCpuFacet);
|
||||
|
@ -390,7 +390,7 @@ public class ERManagementTest extends ContextTest {
|
|||
facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(uuid);
|
||||
|
||||
String readUpdatedJson = facetManagement.read();
|
||||
String readUpdatedJson = facetManagement.read().toString();
|
||||
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class,
|
||||
readUpdatedJson);
|
||||
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}",
|
||||
|
@ -573,7 +573,7 @@ public class ERManagementTest extends ContextTest {
|
|||
facetManagement.setUUID(sharedFacetUUID);
|
||||
|
||||
try {
|
||||
String read = facetManagement.read();
|
||||
String read = facetManagement.read().toString();
|
||||
logger.debug("Read facet is : {}", read);
|
||||
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
|
||||
}catch(FacetNotFoundException e){
|
||||
|
@ -883,7 +883,7 @@ public class ERManagementTest extends ContextTest {
|
|||
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(uuid);
|
||||
String res = resourceManagement.read();
|
||||
String res = resourceManagement.read().toString();
|
||||
logger.debug(res);
|
||||
|
||||
Configuration configuration = ElementMapper.unmarshal(Configuration.class, res);
|
||||
|
|
|
@ -103,7 +103,7 @@ public class SmartgearResourcesTest extends ContextTest {
|
|||
|
||||
resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(hnUUID);
|
||||
String read = resourceManagement.read();
|
||||
String read = resourceManagement.read().toString();
|
||||
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, read);
|
||||
logger.debug("Read {} {}", HostingNode.NAME, readHN);
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class SmartgearResourcesTest extends ContextTest {
|
|||
|
||||
resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(eServiceUUID);
|
||||
String read = resourceManagement.read();
|
||||
String read = resourceManagement.read().toString();
|
||||
EService readEService = ElementMapper.unmarshal(EService.class, read);
|
||||
logger.debug("Read {} {}", EService.NAME, readEService);
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public class FacetManagementTest extends ContextTest {
|
|||
facetManagement.setElementType(facetType);
|
||||
facetManagement.setUUID(uuid);
|
||||
|
||||
String json = facetManagement.read();
|
||||
String json = facetManagement.read().toString();
|
||||
logger.debug("Read : {}", json);
|
||||
@SuppressWarnings("unchecked")
|
||||
F readFacet = (F) ElementMapper.unmarshal(facet.getClass(), json);
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextMan
|
|||
import org.gcube.informationsystem.resourceregistry.instances.SmartgearResourcesTest;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
||||
|
@ -122,7 +123,7 @@ public class BasicTest extends ContextTest {
|
|||
facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(uuid);
|
||||
|
||||
String readJson = facetManagement.read();
|
||||
String readJson = facetManagement.read().toString();
|
||||
logger.debug("Read : {}", readJson);
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
@ -132,7 +133,7 @@ public class BasicTest extends ContextTest {
|
|||
try {
|
||||
facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(uuid);
|
||||
readJson = facetManagement.read();
|
||||
readJson = facetManagement.read().toString();
|
||||
logger.debug("You should not be able to read Facet with UUID {}",
|
||||
uuid);
|
||||
throw new Exception(
|
||||
|
@ -147,7 +148,7 @@ public class BasicTest extends ContextTest {
|
|||
|
||||
facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(uuid);
|
||||
readJson = facetManagement.read();
|
||||
readJson = facetManagement.read().toString();
|
||||
logger.debug("You should be able to read it {}", readJson);
|
||||
|
||||
ContextUtility.getHierarchicalMode().set(false);
|
||||
|
@ -182,7 +183,7 @@ public class BasicTest extends ContextTest {
|
|||
|
||||
facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(uuid);
|
||||
readJson = facetManagement.read();
|
||||
readJson = facetManagement.read().toString();
|
||||
logger.debug("Read Updated : {}", readJson);
|
||||
|
||||
facetManagement = new FacetManagement();
|
||||
|
@ -406,6 +407,62 @@ public class BasicTest extends ContextTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFollows() throws Exception {
|
||||
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setAddConstraint(AddConstraint.propagate);
|
||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||
|
||||
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
|
||||
eService, softwareFacet, null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setElementType(EService.NAME);
|
||||
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||
|
||||
String json = resourceManagement.create();
|
||||
logger.debug("Created : {}", json);
|
||||
eService = ElementMapper.unmarshal(EService.class, json);
|
||||
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
||||
|
||||
JsonNode jsonNode = ElementMapper.getObjectMapper().readTree(json);
|
||||
|
||||
Map<UUID, JsonNode> expectedInstances = new HashMap<>();
|
||||
expectedInstances.put(eService.getHeader().getUUID(), jsonNode);
|
||||
|
||||
UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(ALTERNATIVE_TEST_SCOPE).getUUID();
|
||||
|
||||
try {
|
||||
ERManagementUtility.addToContextNoPropagationConstraint(expectedInstances, contextUUID, true);
|
||||
}catch (ResourceRegistryException e) {
|
||||
logger.debug("As expected", e);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
IsIdentifiedBy<EService, Facet> gotIsIdentifiedBy = (IsIdentifiedBy<EService, Facet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
||||
|
||||
JsonNode gotIsIdentifiedByJsonNode = ElementMapper.getObjectMapper().readTree(ElementMapper.marshal(gotIsIdentifiedBy));
|
||||
expectedInstances.put(gotIsIdentifiedBy.getHeader().getUUID(), gotIsIdentifiedByJsonNode);
|
||||
|
||||
try {
|
||||
ERManagementUtility.addToContextNoPropagationConstraint(expectedInstances, contextUUID, true);
|
||||
}catch (ResourceRegistryException e) {
|
||||
// as expected
|
||||
logger.debug("As expected", e);
|
||||
}finally {
|
||||
resourceManagement.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateEServiceHostingNode() throws Exception {
|
||||
|
@ -554,7 +611,7 @@ public class BasicTest extends ContextTest {
|
|||
|
||||
resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(hostingNodeUUID);
|
||||
String hnString = resourceManagement.read();
|
||||
String hnString = resourceManagement.read().toString();
|
||||
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, hnString);
|
||||
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||
|
||||
|
@ -975,7 +1032,7 @@ public class BasicTest extends ContextTest {
|
|||
|
||||
ContextUtility.getIncludeInstanceContexts().set(true);
|
||||
|
||||
String hostingNodeJson = hostingNodeManagement.read();
|
||||
String hostingNodeJson = hostingNodeManagement.read().toString();
|
||||
HostingNode hostingNodeRead = ElementMapper.unmarshal(HostingNode.class, hostingNodeJson);
|
||||
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNodeRead);
|
||||
|
||||
|
@ -997,7 +1054,7 @@ public class BasicTest extends ContextTest {
|
|||
String typeName = Utility.getTypeName(facet.getClass());
|
||||
facetManagement.setElementType(typeName);
|
||||
|
||||
String facetJson = facetManagement.read();
|
||||
String facetJson = facetManagement.read().toString();
|
||||
Facet facetRead = ElementMapper.unmarshal(Facet.class, facetJson);
|
||||
logger.debug("Unmarshalled {} {}", Utility.getTypeName(facetRead.getClass()), facetRead);
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -1032,7 +1089,7 @@ public class BasicTest extends ContextTest {
|
|||
activatesManagement.setUUID(createdActivates.getHeader().getUUID());
|
||||
activatesManagement.setElementType(Utility.getTypeName(createdActivates.getClass()));
|
||||
// reading again
|
||||
String activatesReadJson = activatesManagement.read();
|
||||
String activatesReadJson = activatesManagement.read().toString();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Activates<HostingNode, EService> activatesRead = ElementMapper.unmarshal(Activates.class, activatesReadJson);
|
||||
|
@ -1051,7 +1108,7 @@ public class BasicTest extends ContextTest {
|
|||
eServiceManagement = new ResourceManagement();
|
||||
eServiceManagement.setUUID(eService.getHeader().getUUID());
|
||||
eServiceManagement.setElementType(Utility.getTypeName(eService.getClass()));
|
||||
String eServiceReadJson = eServiceManagement.read();
|
||||
String eServiceReadJson = eServiceManagement.read().toString();
|
||||
EService eServiceRead = ElementMapper.unmarshal(EService.class, eServiceReadJson);
|
||||
logger.debug("Unmarshalled {} {}", Utility.getTypeName(eServiceRead.getClass()), eServiceRead);
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -56,7 +56,7 @@ public class RuleTest extends ContextTest {
|
|||
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(eServiceUUID);
|
||||
String json = resourceManagement.read();
|
||||
String json = resourceManagement.read().toString();
|
||||
EService readEService = ElementMapper.unmarshal(EService.class, json);
|
||||
Assert.assertTrue(readEService.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class RuleTest extends ContextTest {
|
|||
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(softwareFacetUUID);
|
||||
String json = facetManagement.read();
|
||||
String json = facetManagement.read().toString();
|
||||
SoftwareFacet readSoftwareFacet = ElementMapper.unmarshal(SoftwareFacet.class, json);
|
||||
Assert.assertTrue(readSoftwareFacet.getHeader().getUUID().compareTo(softwareFacetUUID) == 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue