From 1fcceb17c5de3e2ec0bdeceb17521ed8a3fd598f Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Tue, 12 Jun 2018 15:24:19 +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@169083 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../resourceregistry/er/ERManagement.java | 10 ++-------- .../resourceregistry/rest/Access.java | 2 +- .../resourceregistry/rest/InstancesManager.java | 15 ++++++++------- 3 files changed, 11 insertions(+), 16 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 3917bc0..b49a3b6 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java @@ -429,16 +429,10 @@ public abstract class ERManagement { } } - public boolean exists(boolean writer) + public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { try { - 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); - }else { - orientGraph = getWorkingContext().getGraph(PermissionMode.READER); - } + orientGraph = getWorkingContext().getGraph(PermissionMode.READER); getElement(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java index 2ae3d99..639b1a2 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java @@ -209,7 +209,7 @@ public class Access { try { erManagement.setUUID(UUID.fromString(uuid)); - boolean found = erManagement.exists(false); + boolean found = erManagement.exists(); if(found) { return Response.status(Status.NO_CONTENT).build(); } else { 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 6177cc3..f1bb85c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java @@ -99,7 +99,7 @@ public class InstancesManager { try { erManagement.setUUID(UUID.fromString(uuid)); - boolean found = erManagement.exists(false); + boolean found = erManagement.exists(); if(found) { return Response.status(Status.NO_CONTENT).build(); } else { @@ -155,18 +155,19 @@ 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 { - erManagement.exists(true); + @SuppressWarnings("rawtypes") + ERManagement erManagement = ERManagementUtility.getERManagement(type); + erManagement.setUUID(UUID.fromString(uuid)); + erManagement.exists(); } 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) {