Added getInstanceContexts()
This commit is contained in:
parent
d822121adf
commit
fa0e18b580
|
@ -2,6 +2,7 @@ package org.gcube.informationsystem.resourceregistry.client;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
|
@ -27,13 +28,13 @@ public interface ResourceRegistryClient {
|
||||||
public <IE extends IdentifiableElement> boolean exists(Class<IE> clazz, UUID uuid)
|
public <IE extends IdentifiableElement> boolean exists(Class<IE> clazz, UUID uuid)
|
||||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||||
|
|
||||||
public boolean exists(String typeName, UUID uuid)
|
public boolean exists(String type, UUID uuid)
|
||||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||||
|
|
||||||
public <IE extends IdentifiableElement> IE getInstance(Class<IE> clazz, UUID uuid)
|
public <IE extends IdentifiableElement> IE getInstance(Class<IE> clazz, UUID uuid)
|
||||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||||
|
|
||||||
public String getInstance(String typeName, UUID uuid)
|
public String getInstance(String type, UUID uuid)
|
||||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||||
|
|
||||||
public <IE extends IdentifiableElement, R extends Resource> List<R> getInstances(Class<IE> clazz, Boolean polymorphic)
|
public <IE extends IdentifiableElement, R extends Resource> List<R> getInstances(Class<IE> clazz, Boolean polymorphic)
|
||||||
|
@ -118,4 +119,10 @@ public interface ResourceRegistryClient {
|
||||||
|
|
||||||
public List<Context> getAllContext() throws ResourceRegistryException;
|
public List<Context> getAllContext() throws ResourceRegistryException;
|
||||||
|
|
||||||
|
public <IE extends IdentifiableElement> Set<UUID> getInstanceContexts(Class<IE> clazz, UUID uuid)
|
||||||
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public Set<UUID> getInstanceContexts(String type, UUID uuid)
|
||||||
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.net.HttpURLConnection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||||
|
@ -20,6 +21,7 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
@ -183,15 +185,15 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
@Override
|
@Override
|
||||||
public <E extends Element> List<Type> getSchema(Class<E> clazz, Boolean polymorphic)
|
public <E extends Element> List<Type> getSchema(Class<E> clazz, Boolean polymorphic)
|
||||||
throws SchemaNotFoundException, ResourceRegistryException {
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
String typeName = Utility.getTypeName(clazz);
|
String type = Utility.getTypeName(clazz);
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get {} schema", typeName);
|
logger.info("Going to get {} schema", type);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||||
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
|
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
||||||
gxHTTPStringRequest.path(AccessPath.TYPES_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.TYPES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(typeName);
|
gxHTTPStringRequest.path(type);
|
||||||
|
|
||||||
Map<String,String> parameters = new HashMap<>();
|
Map<String,String> parameters = new HashMap<>();
|
||||||
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
||||||
|
@ -200,7 +202,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||||
String json = HTTPUtility.getResponse(String.class, httpURLConnection);
|
String json = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||||
|
|
||||||
logger.debug("Got schema for {} is {}", typeName, json);
|
logger.debug("Got schema for {} is {}", type, json);
|
||||||
return TypeMapper.deserializeTypeDefinitions(json);
|
return TypeMapper.deserializeTypeDefinitions(json);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
// logger.trace("Error while getting {} schema for {}", polymorphic ? AccessPath.POLYMORPHIC_PARAM + " " : "",
|
// logger.trace("Error while getting {} schema for {}", polymorphic ? AccessPath.POLYMORPHIC_PARAM + " " : "",
|
||||||
|
@ -602,4 +604,41 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
return getRelated(entityType, relationType, referenceEntityType, referenceEntity, direction, polymorphic, null);
|
return getRelated(entityType, relationType, referenceEntityType, referenceEntity, direction, polymorphic, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <IE extends IdentifiableElement> Set<UUID> getInstanceContexts(Class<IE> clazz, UUID uuid)
|
||||||
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
|
String typeName = Utility.getTypeName(clazz);
|
||||||
|
return getInstanceContexts(typeName, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<UUID> getInstanceContexts(String type, UUID uuid)
|
||||||
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
logger.trace("Going to get contexts of {} with UUID {}", type, uuid);
|
||||||
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||||
|
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
|
||||||
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
||||||
|
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
||||||
|
gxHTTPStringRequest.path(type);
|
||||||
|
gxHTTPStringRequest.path(uuid.toString());
|
||||||
|
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
||||||
|
|
||||||
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||||
|
String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||||
|
|
||||||
|
logger.info("Contexts of {} with UUID {} are {}", type, uuid, jsonArray);
|
||||||
|
|
||||||
|
Set<UUID> contexts = ContextUtility.getContextUUIDSet(jsonArray);
|
||||||
|
return contexts;
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error while getting {} with UUID {}", type, uuid, e);
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
// logger.trace("Error while getting {} with UUID {}", type, uuid, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue