Refs #10246: Add read Context API in resource registry client

Task-Url: https://support.d4science.org/issues/10246

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@158262 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-11-07 17:45:36 +00:00
parent 116e81d849
commit 8ec2d249b1
2 changed files with 46 additions and 6 deletions

View File

@ -6,11 +6,13 @@ import java.util.UUID;
import org.gcube.informationsystem.model.ER;
import org.gcube.informationsystem.model.ISManageable;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
@ -22,6 +24,9 @@ import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
*/
public interface ResourceRegistryClient {
public String query(final String query, final int limit, final String fetchPlan)
throws InvalidQueryException, ResourceRegistryException;
public <ERType extends ER> void exists(Class<ERType> clazz, UUID uuid)
throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException;
@ -33,12 +38,6 @@ public interface ResourceRegistryClient {
public List<Resource> getInstancesFromEntity(String relationType, Boolean polymorphic, UUID reference,
Direction direction) throws ResourceRegistryException;
public <ISM extends ISManageable> List<TypeDefinition> getSchema(Class<ISM> clazz, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException;
public String query(final String query, final int limit, final String fetchPlan)
throws InvalidQueryException, ResourceRegistryException;
public <R extends Resource> List<R> getFilteredResources(Class<R> resourceClass,
@SuppressWarnings("rawtypes") Class<? extends ConsistsOf> consistsOfClass,
Class<? extends Facet> facetClass,
@ -47,4 +46,11 @@ public interface ResourceRegistryClient {
public List<Resource> getFilteredResources(String resourceType, String consistsOfType, String facetType,
boolean polymorphic, Map<String, Object> map) throws ResourceRegistryException;
public <ISM extends ISManageable> List<TypeDefinition> getSchema(Class<ISM> clazz, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException;
public Context getContext(UUID uuid)
throws ContextNotFoundException, ResourceRegistryException;
}

View File

@ -13,11 +13,13 @@ import java.util.UUID;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.ER;
import org.gcube.informationsystem.model.ISManageable;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
@ -294,5 +296,37 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
throw new RuntimeException(e);
}
}
@Override
public Context getContext(UUID uuid)
throws ContextNotFoundException, ResourceRegistryException {
try {
logger.info("Going to get {} with UUID {}", Context.NAME, uuid.toString());
StringWriter stringWriter = new StringWriter();
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(AccessPath.ACCESS_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(AccessPath.CONTEXT_PATH_PART);
stringWriter.append(PATH_SEPARATOR);
stringWriter.append(uuid.toString());
HTTPCall httpCall = getHTTPCall();
Context context = httpCall.call(Context.class, stringWriter.toString(), HTTPMETHOD.GET);
logger.debug("Got Context is {}", ISMapper.marshal(context));
return context;
} catch (ResourceRegistryException e) {
// logger.trace("Error while getting {} schema for {}", polymorphic ?
// AccessPath.POLYMORPHIC_PARAM + " " : "",
// type, e);
throw e;
} catch (Exception e) {
// logger.trace("Error while getting {}schema for {}", polymorphic ?
// AccessPath.POLYMORPHIC_PARAM + " " : "",
// type, e);
throw new RuntimeException(e);
}
}
}