From f25aa078de7dd51970d8d7f68b0daf55cc9c330b Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Tue, 12 Jun 2018 15:55:46 +0000 Subject: [PATCH] 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 --- .../resourceregistry/er/ERManagement.java | 39 +++++++++++++++---- .../rest/InstancesManager.java | 15 ++++--- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java index b49a3b6..1f0bf2a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java @@ -431,8 +431,21 @@ public abstract class ERManagement { 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 { } 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 { } 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(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java index f1bb85c..ef8e811 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java @@ -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); } /*