From 17d9b96aa114f4ac7efddfa5780b91cb3dbbc7df Mon Sep 17 00:00:00 2001 From: "manuele.simi" Date: Mon, 2 Apr 2018 03:49:57 +0000 Subject: [PATCH] Force to use the resource registry client when a FORCE_RRURL parameter is specified in the request. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@165589 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../manager/webapp/context/CreateRequest.java | 2 +- .../manager/webapp/context/DeleteRequest.java | 2 +- .../manager/webapp/context/Queries.java | 4 ++-- .../context/RequestToResourceRegistry.java | 16 ++++++++++++++++ .../manager/webapp/context/QueriesTest.java | 12 ++++++++---- .../manager/webapp/context/RMContextTest.java | 1 - 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/CreateRequest.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/CreateRequest.java index b31cc26..220932f 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/CreateRequest.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/CreateRequest.java @@ -37,7 +37,7 @@ public final class CreateRequest extends RequestToResourceRegistry { try { IsParentOf relationship = this.context.getParent(); logger.info("Fetching parent with UUID: " + relationship.getSource().getHeader().getUUID().toString()); - Context parent = new Queries(this.getContextClient()).fetchContext(relationship.getSource().getHeader().getUUID()); + Context parent = new Queries(this.getContextClient(), this.getRegistryClient()).fetchContext(relationship.getSource().getHeader().getUUID()); if (Objects.isNull(parent)) { throw new LocalCodeException(RMCreateContextCode.CONTEXT_PARENT_DOES_NOT_EXIST); } diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java index 6aee09e..eb8a7ec 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java @@ -30,7 +30,7 @@ public final class DeleteRequest extends RequestToResourceRegistry { */ @Override public void validate() throws LocalCodeException { - Queries queries = new Queries(this.getContextClient()); + Queries queries = new Queries(this.getContextClient(), this.getRegistryClient()); if (!queries.contextExists(context)) { throw new LocalCodeException(RMDeleteContextCode.CONTEXT_DOES_NOT_EXIST); } diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java index c146ee6..f873330 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java @@ -33,9 +33,9 @@ final class Queries { * * @param cclient */ - protected Queries(ResourceRegistryContextClient cclient) { + protected Queries(ResourceRegistryContextClient cclient, ResourceRegistryClient rclient) { this.cclient = cclient; - this.rclient = ResourceRegistryClientFactory.create(); + this.rclient =rclient; } /** diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java index 342bf29..1563ce8 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java @@ -3,6 +3,9 @@ package org.gcube.resourcemanagement.manager.webapp.context; import java.util.Objects; import org.gcube.common.gxrest.response.outbound.LocalCodeException; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl; @@ -18,6 +21,7 @@ import org.slf4j.LoggerFactory; public abstract class RequestToResourceRegistry { protected ResourceRegistryContextClient resourceRegistryContextClient; + private ResourceRegistryClientImpl resourceResourceRegistryClient; protected static Logger logger = LoggerFactory.getLogger(RequestToResourceRegistry.class); /** @@ -27,6 +31,7 @@ public abstract class RequestToResourceRegistry { */ public RequestToResourceRegistry forceURL(String forceURL) { this.resourceRegistryContextClient = new ResourceRegistryContextClientImpl(forceURL); + this.resourceResourceRegistryClient = new ResourceRegistryClientImpl(forceURL); return this; } @@ -71,6 +76,17 @@ public abstract class RequestToResourceRegistry { return ResourceRegistryContextClientFactory.create(); } } + + /** + * @return the registry client + */ + ResourceRegistryClient getRegistryClient() { + if (Objects.nonNull(this.resourceResourceRegistryClient)) { + return this.resourceResourceRegistryClient; + } else { + return ResourceRegistryClientFactory.create(); + } + } /** * Submits the request to the RR. diff --git a/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/QueriesTest.java b/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/QueriesTest.java index 1f34c5f..2dbc3df 100644 --- a/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/QueriesTest.java +++ b/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/QueriesTest.java @@ -16,6 +16,8 @@ import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.informationsystem.model.entity.Context; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl; import org.junit.AfterClass; @@ -90,8 +92,9 @@ public class QueriesTest { public void testContextExists() { if (skipTest) return; - ResourceRegistryContextClient client = new ResourceRegistryContextClientImpl(RR); - Queries queries = new Queries(client); + ResourceRegistryContextClient cclient = new ResourceRegistryContextClientImpl(RR); + ResourceRegistryClient rclient = new ResourceRegistryClientImpl(RR); + Queries queries = new Queries(cclient, rclient); assertFalse("Context does exist, but it should not", queries.contextExists(UUID.randomUUID())); } @@ -102,8 +105,9 @@ public class QueriesTest { public void testFetchContext() { if (skipTest) return; - ResourceRegistryContextClient client = new ResourceRegistryContextClientImpl(RR); - Queries queries = new Queries(client); + ResourceRegistryContextClient cclient = new ResourceRegistryContextClientImpl(RR); + ResourceRegistryClient rclient = new ResourceRegistryClientImpl(RR); + Queries queries = new Queries(cclient, rclient); Context context = queries.fetchContext(context1UUID); assertNotNull("Context does not exist.", context); assertEquals("Unexpected uuid for context", context1UUID, context.getHeader().getUUID()); diff --git a/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java b/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java index 8372a23..3a2c3ba 100644 --- a/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java +++ b/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java @@ -28,7 +28,6 @@ import org.gcube.informationsystem.model.entity.Context; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl; import org.gcube.resourcemanagement.manager.io.rs.RMCreateContextCode; -import org.gcube.resourcemanagement.manager.io.rs.RMContextDoesNotExistException; import org.gcube.resourcemanagement.manager.io.rs.RMContextPath; import org.gcube.resourcemanagement.manager.webapp.rs.RMContext; import org.glassfish.jersey.server.ResourceConfig;