Start shaping ResourcesInContext collection. Rename few path params.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@169755 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2018-07-12 00:44:44 +00:00
parent 18cba050f6
commit 162881f1ff
10 changed files with 126 additions and 45 deletions

View File

@ -28,9 +28,9 @@ public class RMContextPath {
public static final String FORCE_RRURL_PARAM = "rrURL";
/**
* The identifier of the resource on which the method will operate.
* The identifier of the context on which the method will operate.
*/
public static final String UUID_PARAM = "ContextUUID";
public static final String CONTEXT_UUID_PARAM = "ContextUUID";

View File

@ -1,12 +0,0 @@
package org.gcube.resourcemanagement.manager.io.rs;
/**
* REST paths exposed by the webapp for RMResource.
*
* @author Manuele Simi (ISTI - CNR)
*
*/
public class RMResourcePath {
public static final String ROOT = "resource";
}

View File

@ -0,0 +1,15 @@
package org.gcube.resourcemanagement.manager.io.rs;
/**
* Paths and parameters for the ResourcesInContext collection of resources.
*
* @author Manuele Simi (ISTI - CNR)
*
*/
public class ResourcesInContextPath {
public static final String ROOT = "resource";
public static final String CONTEXT_UUID_PARAM = "ContextUUID";
public static final String RESOURCE_UUID_PARAM = "ResourceUUID";
}

View File

@ -56,6 +56,8 @@
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>

View File

@ -45,7 +45,7 @@ public class RMContext {
CalledMethodProvider.instance.set(String.format("POST /%s/%s", APPLICATION_PATH, CONTEXT_ROOT));
logger.info("Requested to create context {} with json {}", Context.NAME, json);
logger.info("Force URL: " + rrURL);
ContextHolder holder = new ContextHolder(json);
ContextHolder holder = new ContextHolder(json);
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL(rrURL).submit();
if (!returned.wasSuccessful()) {
if (returned.getException().isPresent())
@ -65,9 +65,9 @@ public class RMContext {
* registry
*/
@DELETE
@Path("{" + UUID_PARAM + "}")
@Path("{" + CONTEXT_UUID_PARAM + "}")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response delete(@PathParam(UUID_PARAM) String uuid, @QueryParam(FORCE_RRURL_PARAM) String rrURL) {
public Response delete(@PathParam(CONTEXT_UUID_PARAM) String uuid, @QueryParam(FORCE_RRURL_PARAM) String rrURL) {
CalledMethodProvider.instance.set(String.format("DELETE /%s/%s/ID", APPLICATION_PATH, CONTEXT_ROOT));
logger.info("Requested to delete context with id {}", uuid);
logger.info("Force URL: " + rrURL);

View File

@ -1,21 +0,0 @@
package org.gcube.resourcemanagement.manager.webapp.rs;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import org.gcube.resourcemanagement.manager.io.rs.RMResourcePath;
/**
* Methods for {@link org.gcube.informationsystem.model.entity.Resource} operations.
*
* @author Manuele Simi (ISTI-CNR)
*
*/
@Path(RMResourcePath.ROOT)
public class RMResource {
@PUT
public void addToContext() {
}
}

View File

@ -1,20 +1,42 @@
package org.gcube.resourcemanagement.manager.webapp.rs;
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.GXREST_ROOT;
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.UUID_PARAM;
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.UUID;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.Unmarshaller;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse;
import org.gcube.common.gxrest.response.outbound.GXOutboundSuccessResponse;
import org.gcube.informationsystem.impl.entity.ContextImpl;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.resourcemanagement.manager.io.rs.RMContextDoesNotExistException;
import org.gcube.resourcemanagement.manager.webapp.ResourceInitializer;
import org.gcube.resourcemanagement.manager.webapp.context.ContextHolder;
import org.gcube.resourcemanagement.manager.webapp.context.CreateRequest;
import org.gcube.resourcemanagement.manager.webapp.context.ResponseFromResourceRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Tests for gxrest
*
@ -31,13 +53,57 @@ public class RMTestForGXRest {
* registry
*/
@DELETE
@Path("{" + UUID_PARAM + "}")
@Path("{" + CONTEXT_UUID_PARAM + "}")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response delete(@PathParam(UUID_PARAM) String uuid) {
public Response delete(@PathParam(CONTEXT_UUID_PARAM) String uuid) {
CalledMethodProvider.instance.set(String.format("DELETE /%s/%s", APPLICATION_PATH, GXREST_ROOT));
methodOne();
return null;
}
/*
* e.g. POST
* /resource-manager/context?rrURL=http://registry:port//resource-registry
*/
@POST
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response create(@QueryParam(FORCE_RRURL_PARAM) String rrURL, String context) throws URISyntaxException {
CalledMethodProvider.instance.set(String.format("POST /%s/%s", APPLICATION_PATH, GXREST_ROOT));
logger.info("Requested to create resource with context {}", context);
//logger.info("Force URL: " + rrURL);
Context newContext = null;
try {
newContext = ISMapper.unmarshal(Context.class, context);
} catch (JsonParseException e) {
e.printStackTrace();
GXOutboundErrorResponse.throwExceptionWithTrace(e, 5);
} catch (JsonMappingException e) {
GXOutboundErrorResponse.throwExceptionWithTrace(e, 5);
} catch (IOException e) {
GXOutboundErrorResponse.throwExceptionWithTrace(e, 5);
}
return GXOutboundSuccessResponse.newCREATEResponse(new URI(newContext.getHeader().getUUID().toString())).withContent("Context successfully created.")
.ofType(MediaType.TEXT_PLAIN).build();
}/*
/*
* e.g. PUT
* /resource-manager/context?rrURL=http://registry:port//resource-registry
*/
@PUT
@Path("{" + CONTEXT_UUID_PARAM + "}")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response update(@PathParam(CONTEXT_UUID_PARAM) String id, @QueryParam(FORCE_RRURL_PARAM) String rrURL) throws URISyntaxException, JsonProcessingException {
CalledMethodProvider.instance.set(String.format("GET /%s/%s", APPLICATION_PATH, GXREST_ROOT));
logger.info("Requested to update resource with id {}", id);
logger.info("Force URL: " + rrURL);
Context newContext = new ContextImpl("gxTest");
newContext.getHeader().setUUID(UUID.fromString("6f86dc81-2f59-486b-8aa9-3ab5486313c4"));
return GXOutboundSuccessResponse.newCREATEResponse(new URI(newContext.getHeader().getUUID().toString())).withContent(ISMapper.marshal(newContext))
.ofType(MediaType.APPLICATION_JSON).build();
}
private void methodOne() {
methodTwo();
}

View File

@ -0,0 +1,31 @@
package org.gcube.resourcemanagement.manager.webapp.rs;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import org.gcube.common.gxrest.response.outbound.GXOutboundSuccessResponse;
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.CONTEXT_UUID_PARAM;
import static org.gcube.resourcemanagement.manager.io.rs.ResourcesInContextPath.*;
/**
* Methods for {@link org.gcube.informationsystem.model.entity.Resource} operations.
*
* @author Manuele Simi (ISTI-CNR)
*
*/
@Path(ROOT)
public class ResourcesInContext {
@PUT
@Path("{" + CONTEXT_UUID_PARAM + "}/{"+ RESOURCE_UUID_PARAM +"}")
public Response addToContext(@PathParam(CONTEXT_UUID_PARAM) String contextUUID,
@PathParam(CONTEXT_UUID_PARAM) String resourceUUID) {
return GXOutboundSuccessResponse.newCREATEResponse(null).build();
}
}

View File

@ -96,7 +96,7 @@ public class QueriesTest {
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()));
assertFalse("Context does exist, but it should not", queries.contextExists(RMContextTest.context1UUID));
}
/**

View File

@ -52,13 +52,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RMContextTest extends JerseyTest {
private final static String context1 = "ContextA";
private final static String context1 = "ContextLLLLL";
private final static String context2 = "ContextB";
private final static String context3 = "ContextC";
public static final UUID context1UUID = UUID.fromString("5f86dc81-2f59-486b-8aa9-3ab5486313c4");
public static final UUID context1UUID = UUID.fromString("b252e6ce-8b9a-4142-9bca-2ada9171034b");
public static final UUID context2UUID = UUID.fromString("6f86dc81-2f59-486b-8aa9-3ab5486313c4");