diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java index da636f3..b796916 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java @@ -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 void exists(Class clazz, UUID uuid) throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException; @@ -33,12 +38,6 @@ public interface ResourceRegistryClient { public List getInstancesFromEntity(String relationType, Boolean polymorphic, UUID reference, Direction direction) throws ResourceRegistryException; - public List getSchema(Class clazz, Boolean polymorphic) - throws SchemaNotFoundException, ResourceRegistryException; - - public String query(final String query, final int limit, final String fetchPlan) - throws InvalidQueryException, ResourceRegistryException; - public List getFilteredResources(Class resourceClass, @SuppressWarnings("rawtypes") Class consistsOfClass, Class facetClass, @@ -47,4 +46,11 @@ public interface ResourceRegistryClient { public List getFilteredResources(String resourceType, String consistsOfType, String facetType, boolean polymorphic, Map map) throws ResourceRegistryException; + public List getSchema(Class clazz, Boolean polymorphic) + throws SchemaNotFoundException, ResourceRegistryException; + + public Context getContext(UUID uuid) + throws ContextNotFoundException, ResourceRegistryException; + + } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java index a762791..e9475c7 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -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); + } + } }