diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/RMContextPath.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/RMContextPath.java
index c185402..9113969 100644
--- a/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/RMContextPath.java
+++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/RMContextPath.java
@@ -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";
diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/RMResourcePath.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/RMResourcePath.java
deleted file mode 100644
index aca2505..0000000
--- a/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/RMResourcePath.java
+++ /dev/null
@@ -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";
-
-}
diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/ResourcesInContextPath.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/ResourcesInContextPath.java
new file mode 100644
index 0000000..33cdfbb
--- /dev/null
+++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/rs/ResourcesInContextPath.java
@@ -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";
+
+
+}
diff --git a/pom.xml b/pom.xml
index 176c8c9..a9108d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,8 @@
org.gcube.information-system
resource-registry-client
+ 2.0.0-SNAPSHOT
+
diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMContext.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMContext.java
index b0e7e4a..8a7882d 100644
--- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMContext.java
+++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMContext.java
@@ -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);
diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMResource.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMResource.java
deleted file mode 100644
index d289d45..0000000
--- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMResource.java
+++ /dev/null
@@ -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() {
-
- }
-}
diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMTestForGXRest.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMTestForGXRest.java
index c322a64..ad9f8b1 100644
--- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMTestForGXRest.java
+++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/RMTestForGXRest.java
@@ -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();
}
diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/ResourcesInContext.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/ResourcesInContext.java
new file mode 100644
index 0000000..203db39
--- /dev/null
+++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/rs/ResourcesInContext.java
@@ -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();
+ }
+}
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 bef0a9b..9acc9a9 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
@@ -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));
}
/**
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 e5d3b4a..e1acefa 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
@@ -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");