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
This commit is contained in:
Manuele Simi 2018-04-02 03:49:57 +00:00
parent fecaee352c
commit 17d9b96aa1
6 changed files with 28 additions and 9 deletions

View File

@ -37,7 +37,7 @@ public final class CreateRequest extends RequestToResourceRegistry {
try {
IsParentOf<Context, Context> 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);
}

View File

@ -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);
}

View File

@ -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;
}
/**

View File

@ -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.

View File

@ -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());

View File

@ -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;