Added Operation enum to be able to check which action has been executed
This commit is contained in:
parent
0a807d74a2
commit
f36ff52dcf
|
@ -40,6 +40,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecur
|
|||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.properties.PropertyElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.Operation;
|
||||
import org.gcube.informationsystem.resourceregistry.types.CachedType;
|
||||
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderOrient;
|
||||
|
@ -105,6 +106,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
*/
|
||||
protected boolean entryPoint;
|
||||
|
||||
/**
|
||||
* It is assigned only in the entry point
|
||||
*/
|
||||
protected Operation operation;
|
||||
|
||||
protected ElementManagement(AccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
|
||||
|
@ -118,6 +124,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
this.reload = false;
|
||||
|
||||
this.entryPoint = false;
|
||||
this.operation = null;
|
||||
}
|
||||
|
||||
protected void setAsEntryPoint(Operation operation) {
|
||||
entryPoint = true;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public void cleanCachedSerialization() {
|
||||
|
@ -488,7 +500,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException;
|
||||
|
||||
public String all(boolean polymorphic) throws ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.QUERY);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
@ -509,7 +521,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
}
|
||||
|
||||
public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.EXISTS);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
@ -536,17 +548,18 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
|
||||
public String createOrUpdate()
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
boolean update = false;
|
||||
try {
|
||||
setAsEntryPoint(Operation.UPDATE);
|
||||
getElement();
|
||||
update = true;
|
||||
internalUpdate();
|
||||
} catch(NotFoundException e) {
|
||||
setAsEntryPoint(Operation.CREATE);
|
||||
String calledMethod = CalledMethodProvider.instance.get();
|
||||
calledMethod = calledMethod.replace("update", "create");
|
||||
CalledMethodProvider.instance.set(calledMethod);
|
||||
|
@ -587,7 +600,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
}
|
||||
|
||||
public String create() throws AlreadyPresentException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.CREATE);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
@ -625,7 +638,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
}
|
||||
|
||||
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.READ);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
@ -651,7 +664,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
}
|
||||
|
||||
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.UPDATE);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
@ -691,7 +704,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
}
|
||||
|
||||
public boolean delete() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.DELETE);
|
||||
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
@ -735,7 +748,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
|
||||
|
||||
public Set<String> getContextsSet() throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.GET_METADATA);
|
||||
logger.debug("Going to get contexts for {} with UUID", typeName, uuid);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.model;
|
||||
|
||||
public enum Operation {
|
||||
|
||||
CREATE,
|
||||
EXISTS(true),
|
||||
READ(true),
|
||||
UPDATE,
|
||||
DELETE,
|
||||
ADD_TO_CONTEXT,
|
||||
REMOVE_FROM_CONTEXT,
|
||||
QUERY(true),
|
||||
// GET_METADATA e.g. getinstanceContexts
|
||||
GET_METADATA;
|
||||
|
||||
private final boolean safe;
|
||||
|
||||
private Operation() {
|
||||
this.safe = false;
|
||||
}
|
||||
|
||||
private Operation(boolean safe) {
|
||||
this.safe = safe;
|
||||
}
|
||||
|
||||
public boolean isSafe() {
|
||||
return safe;
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage
|
|||
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.Operation;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
|
@ -347,7 +348,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.ADD_TO_CONTEXT);
|
||||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
@ -439,7 +440,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
|
||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.REMOVE_FROM_CONTEXT);
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
@ -796,7 +797,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
|
||||
try {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.QUERY);
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
||||
TypesCache typesCache = TypesCache.getInstance();
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
||||
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
@ -60,4 +61,13 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||
super.sanityCheck();
|
||||
if(entryPoint) {
|
||||
// We need to check the Resource
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -445,7 +445,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
|
||||
private String facetMustBePresentErrorMessage(String consistsOfType, UUID consistsOfUUID, String facetType, UUID facetUUID) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("To avoid to have an incosistent graph, add to context no follows cannot add a ");
|
||||
stringBuffer.append("To avoid to have an inconsistent graph, add to context no follows cannot add a ");
|
||||
stringBuffer.append(ConsistsOf.NAME);
|
||||
stringBuffer.append(" relation (i.e. ");
|
||||
stringBuffer.append(consistsOfType);
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage
|
|||
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.Operation;
|
||||
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;
|
||||
|
@ -536,7 +537,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.ADD_TO_CONTEXT);
|
||||
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
@ -679,7 +680,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
entryPoint = true;
|
||||
setAsEntryPoint(Operation.REMOVE_FROM_CONTEXT);
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue