Refs #11905: Use new REST interface in Resource Registry Context Client
Task-Url: https://support.d4science.org/issues/11905 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-context-client@169153 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
91bc27997c
commit
d924a790a2
|
@ -5,7 +5,9 @@ import java.net.MalformedURLException;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.impl.embedded.HeaderImpl;
|
||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||
import org.gcube.informationsystem.model.embedded.Header;
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
||||
|
@ -13,7 +15,6 @@ 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;
|
||||
|
||||
|
@ -41,12 +42,45 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
|
|||
return httpCall;
|
||||
}
|
||||
|
||||
|
||||
protected String internalCreate(Context context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
Header header = context.getHeader();
|
||||
if(header==null) {
|
||||
header = new HeaderImpl(UUID.randomUUID());
|
||||
context.setHeader(header);
|
||||
}
|
||||
UUID uuid = context.getHeader().getUUID();
|
||||
|
||||
String contextString = ISMapper.marshal(context);
|
||||
|
||||
logger.trace("Going to create {}", contextString);
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(ContextPath.CONTEXTS_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(uuid.toString());
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, contextString);
|
||||
|
||||
logger.trace("{} successfully created", c);
|
||||
return c;
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context create(Context context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
String contextString = ISMapper.marshal(context);
|
||||
String res = create(contextString);
|
||||
String res = internalCreate(context);
|
||||
return ISMapper.unmarshal(Context.class, res);
|
||||
} catch (ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
|
@ -60,22 +94,8 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
|
|||
@Override
|
||||
public String create(String context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
logger.trace("Going to create {}", context);
|
||||
|
||||
String uuid = Utility.getUUIDStringFromJsonString(context);
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
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.PUT, context);
|
||||
|
||||
logger.trace("{} successfully created", c);
|
||||
return c;
|
||||
|
||||
Context c = ISMapper.unmarshal(Context.class, context);
|
||||
return internalCreate(c);
|
||||
} catch (ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw e;
|
||||
|
@ -129,12 +149,39 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String internalUpdate(Context context) throws ResourceRegistryException {
|
||||
try {
|
||||
String contextString = ISMapper.marshal(context);
|
||||
logger.trace("Going to update {}", contextString);
|
||||
|
||||
UUID uuid = context.getHeader().getUUID();
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(ContextPath.CONTEXTS_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(uuid.toString());
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, contextString);
|
||||
|
||||
logger.trace("{} successfully updated", c);
|
||||
return c;
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context update(Context context) throws ResourceRegistryException {
|
||||
try {
|
||||
String contextString = ISMapper.marshal(context);
|
||||
String res = update(contextString);
|
||||
String res = internalUpdate(context);
|
||||
return ISMapper.unmarshal(Context.class, res);
|
||||
} catch (ResourceRegistryException e) {
|
||||
// logger.trace("Error Updating {}", facet, e);
|
||||
|
@ -148,27 +195,13 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
|
|||
@Override
|
||||
public String update(String context) throws ResourceRegistryException {
|
||||
try {
|
||||
logger.trace("Going to update {}", context);
|
||||
|
||||
String uuid = Utility.getUUIDStringFromJsonString(context);
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
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.PUT, context);
|
||||
|
||||
logger.trace("{} successfully updated", c);
|
||||
return c;
|
||||
|
||||
Context c = ISMapper.unmarshal(Context.class, context);
|
||||
return internalUpdate(c);
|
||||
} catch (ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
// logger.trace("Error Updating {}", facet, e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
// logger.trace("Error Updating {}", facet, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.gcube.common.authorization.client.Constants;
|
|||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.informationsystem.impl.embedded.HeaderImpl;
|
||||
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||
import org.gcube.informationsystem.model.ER;
|
||||
|
@ -199,11 +198,24 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
// ___A2_______B4____
|
||||
// B3______________A5
|
||||
|
||||
invalidCreate(contextA1); // Trying to recreate A1. Fails
|
||||
invalidCreate(contextA2); // Trying to recreate A2. Fails
|
||||
invalidCreate(contextB3); // Trying to recreate B3. Fails
|
||||
invalidCreate(contextB4); // Trying to recreate B4. Fails
|
||||
invalidCreate(contextA5); // Trying to recreate A5. Fails
|
||||
Context invalidContextA1 = new ContextImpl(CTX_NAME_A);
|
||||
invalidCreate(invalidContextA1);
|
||||
|
||||
Context invalidContextA2 = new ContextImpl(CTX_NAME_A);
|
||||
invalidContextA2.setParent(contextA1);
|
||||
invalidCreate(invalidContextA2);
|
||||
|
||||
Context invalidContextB3 = new ContextImpl(CTX_NAME_B);
|
||||
invalidContextB3.setParent(contextA2);
|
||||
invalidCreate(invalidContextB3);
|
||||
|
||||
Context invalidContextB4 = new ContextImpl(CTX_NAME_B);
|
||||
invalidContextB4.setParent(contextA1);
|
||||
invalidCreate(invalidContextB4);
|
||||
|
||||
Context invalidContextA5 = new ContextImpl(CTX_NAME_A);
|
||||
invalidContextA5.setParent(contextB4);
|
||||
invalidCreate(invalidContextA5); // Trying to recreate A5. Fails
|
||||
|
||||
// Trying to move A5 as child of A1. It fails due to A2.
|
||||
Context nullContext = null;
|
||||
|
@ -341,10 +353,6 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
delete(contextA2);
|
||||
// ________A1________
|
||||
|
||||
Context contextC = new ContextImpl(CTX_NAME_C);
|
||||
contextC.setHeader(new HeaderImpl(contextA1.getHeader().getUUID()));
|
||||
invalidCreate(contextC);
|
||||
|
||||
delete(contextA1);
|
||||
logger.debug("The DB should be now clean");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue