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-context-client@167856 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-06-04 10:31:09 +00:00
parent 46c0c21929
commit 8b7429168c
1 changed files with 32 additions and 12 deletions

View File

@ -13,6 +13,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.context.Conte
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -60,13 +61,29 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
public String create(String context) throws ContextAlreadyPresentException, ResourceRegistryException {
try {
logger.trace("Going to create: {}", context);
String uuid = null;
try {
uuid = Utility.getUUIDStringFromJsonString(context);
}catch (Exception e) {
// Creating a context without proving an UUID. This is feasible
}
StringWriter stringWriter = new StringWriter();
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
stringWriter.append(ContextPath.CONTEXTS_PATH_PART);
HTTPCall httpCall = getHTTPCall();
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, context);
String c = null;
if(uuid==null) {
c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, context);
}else {
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(uuid);
c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, context);
}
logger.trace("{} successfully created", c);
return c;
@ -105,7 +122,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
logger.trace("Going to read {} with UUID {}", Context.NAME);
StringWriter stringWriter = new StringWriter();
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
stringWriter.append(ContextPath.CONTEXTS_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(uuid);
@ -143,12 +160,17 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
public String update(String context) throws ContextAlreadyPresentException, ResourceRegistryException {
try {
logger.trace("Going to update: {}", context);
String uuid = Utility.getUUIDStringFromJsonString(context);
StringWriter stringWriter = new StringWriter();
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
stringWriter.append(ContextPath.CONTEXTS_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(uuid);
HTTPCall httpCall = getHTTPCall();
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, context);
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, context);
logger.trace("{} successfully updated", c);
return c;
@ -178,7 +200,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
logger.trace("Going to delete {} with UUID {}", Context.NAME, uuid);
StringWriter stringWriter = new StringWriter();
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
stringWriter.append(ContextPath.CONTEXTS_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(uuid);
@ -203,9 +225,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
logger.trace("Going to read {} with UUID {}", Context.NAME);
StringWriter stringWriter = new StringWriter();
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(ContextPath.ALL_PATH_PART);
stringWriter.append(ContextPath.CONTEXTS_PATH_PART);
HTTPCall httpCall = getHTTPCall();
String all = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET);