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:
Luca Frosini 2018-06-12 15:55:46 +00:00
parent 1fcceb17c5
commit f25aa078de
2 changed files with 39 additions and 15 deletions

View File

@ -431,8 +431,21 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
public boolean exists() public boolean exists()
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
return exists(false);
}
public boolean exists(boolean writer)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try { 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(); getElement();
@ -451,11 +464,17 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
} }
public String create() throws AlreadyPresentException, ResourceRegistryException { public String create() throws AlreadyPresentException, ResourceRegistryException {
return create(false);
}
public String create(boolean transactionStarted) throws AlreadyPresentException, ResourceRegistryException {
try { try {
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER); if(!transactionStarted) {
orientGraph.setAutoStartTx(false); orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
orientGraph.begin(); orientGraph.setAutoStartTx(false);
orientGraph.begin();
}
element = internalCreate(); element = internalCreate();
@ -505,10 +524,16 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
} }
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
return update(false);
}
public String update(boolean transactionStarted) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try { try {
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER); if(!transactionStarted) {
orientGraph.setAutoStartTx(false); orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
orientGraph.begin(); orientGraph.setAutoStartTx(false);
orientGraph.begin();
}
element = internalUpdate(); element = internalUpdate();

View File

@ -155,26 +155,25 @@ public class InstancesManager {
logger.trace("Requested to update/create {} with id {} with json {}", type, uuid, json); logger.trace("Requested to update/create {} with id {} with json {}", type, uuid, json);
setCalledMethod(HTTPMETHOD.PUT, type, true); setCalledMethod(HTTPMETHOD.PUT, type, true);
@SuppressWarnings("rawtypes")
ERManagement erManagement = ERManagementUtility.getERManagement(type);
erManagement.setUUID(UUID.fromString(uuid));
boolean create = false; boolean create = false;
try { try {
@SuppressWarnings("rawtypes") erManagement.exists(false);
ERManagement erManagement = ERManagementUtility.getERManagement(type);
erManagement.setUUID(UUID.fromString(uuid));
erManagement.exists();
} catch(NotFoundException e) { } catch(NotFoundException e) {
create = true; create = true;
} }
@SuppressWarnings("rawtypes")
ERManagement erManagement = ERManagementUtility.getERManagement(type);
erManagement.setUUID(UUID.fromString(uuid)); erManagement.setUUID(UUID.fromString(uuid));
erManagement.setElementType(type); erManagement.setElementType(type);
erManagement.setJSON(json); erManagement.setJSON(json);
if(create) { if(create) {
return erManagement.create(); return erManagement.create(true);
} }
return erManagement.update(); return erManagement.update(true);
} }
/* /*