Refs #11288: Made resource-registry more RESTful
Task-Url: https://support.d4science.org/issues/11288 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@169086 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1fcceb17c5
commit
f25aa078de
|
@ -431,8 +431,21 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
|
||||
public boolean exists()
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
return exists(false);
|
||||
}
|
||||
|
||||
public boolean exists(boolean writer)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
if(writer) {
|
||||
// Exists is used to understand if it is a create or update.
|
||||
// In any case the we need writing right on this instance
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
}else {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
}
|
||||
|
||||
getElement();
|
||||
|
||||
|
@ -451,11 +464,17 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
}
|
||||
|
||||
public String create() throws AlreadyPresentException, ResourceRegistryException {
|
||||
return create(false);
|
||||
}
|
||||
|
||||
public String create(boolean transactionStarted) throws AlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
if(!transactionStarted) {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
}
|
||||
|
||||
element = internalCreate();
|
||||
|
||||
|
@ -505,10 +524,16 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
}
|
||||
|
||||
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
return update(false);
|
||||
}
|
||||
|
||||
public String update(boolean transactionStarted) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
if(!transactionStarted) {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
}
|
||||
|
||||
element = internalUpdate();
|
||||
|
||||
|
|
|
@ -155,26 +155,25 @@ public class InstancesManager {
|
|||
logger.trace("Requested to update/create {} with id {} with json {}", type, uuid, json);
|
||||
setCalledMethod(HTTPMETHOD.PUT, type, true);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ERManagement erManagement = ERManagementUtility.getERManagement(type);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
|
||||
boolean create = false;
|
||||
try {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ERManagement erManagement = ERManagementUtility.getERManagement(type);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
erManagement.exists();
|
||||
erManagement.exists(false);
|
||||
} catch(NotFoundException e) {
|
||||
create = true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ERManagement erManagement = ERManagementUtility.getERManagement(type);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
erManagement.setElementType(type);
|
||||
erManagement.setJSON(json);
|
||||
if(create) {
|
||||
return erManagement.create();
|
||||
return erManagement.create(true);
|
||||
}
|
||||
|
||||
return erManagement.update();
|
||||
return erManagement.update(true);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue