Added exists method which use HTTP HEAD method

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@146396 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-03-28 14:00:55 +00:00
parent ae306fb53b
commit 4ccf287add
3 changed files with 37 additions and 2 deletions

View File

@ -18,6 +18,10 @@ import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
*/
public interface ResourceRegistryClient {
public <ERType extends ER> void exists(
Class<ERType> clazz, UUID uuid) throws ERNotFoundException,
ResourceRegistryException;
public <ERType extends ER> ERType getInstance(
Class<ERType> clazz, UUID uuid) throws ERNotFoundException,
ResourceRegistryException;

View File

@ -20,8 +20,7 @@ public class ResourceRegistryClientCall<C> implements Call<EndpointReference, C>
protected String getURLStringFromEndpointReference(
EndpointReference endpoint) throws IOException {
JaxRSEndpointReference jaxRSEndpointReference = new JaxRSEndpointReference(
endpoint);
JaxRSEndpointReference jaxRSEndpointReference = new JaxRSEndpointReference(endpoint);
return jaxRSEndpointReference.toString();
}

View File

@ -47,6 +47,38 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
this.delegate = new AsyncProxyDelegate<EndpointReference>(config);
}
@Override
public <ERType extends ER> void exists(Class<ERType> clazz, UUID uuid)
throws ERNotFoundException, ResourceRegistryException {
String type = clazz.getSimpleName();
try {
logger.info("Going to check if {} with UUID {} exists", type, uuid);
StringWriter stringWriter = new StringWriter();
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(AccessPath.ACCESS_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(AccessPath.INSTANCE_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(type);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(uuid.toString());
HTTPCall<ERType> httpCall = new HTTPCall<>(stringWriter.toString(),
HTTPMETHOD.HEAD, null);
ResourceRegistryClientCall<ERType> call = new ResourceRegistryClientCall<>(
clazz, httpCall);
delegate.make(call);
logger.info("{} with UUID {} exists", type, uuid);
} catch (ResourceRegistryException e) {
throw e;
} catch (Exception e) {
throw new ServiceException(e);
}
}
@Override
public <ERType extends ER> ERType getInstance(Class<ERType> clazz, UUID uuid)
throws ERNotFoundException, ResourceRegistryException {