Refs #10172: Add getFilteredResources() in ResourceRegistryClient
Task-Url: https://support.d4science.org/issues/10172 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@158123 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e09391b7d2
commit
116e81d849
|
@ -1,12 +1,15 @@
|
|||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.ER;
|
||||
import org.gcube.informationsystem.model.ISManageable;
|
||||
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.er.ERAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
||||
|
@ -19,29 +22,29 @@ import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
|||
*/
|
||||
public interface ResourceRegistryClient {
|
||||
|
||||
public <ERType extends ER> void exists(
|
||||
Class<ERType> clazz, UUID uuid) throws ERNotFoundException,
|
||||
ERAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <ERType extends ER> ERType getInstance(
|
||||
Class<ERType> clazz, UUID uuid) throws ERNotFoundException,
|
||||
ERAvailableInAnotherContextException, ResourceRegistryException;
|
||||
public <ERType extends ER> void exists(Class<ERType> clazz, UUID uuid)
|
||||
throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public List<? extends Entity> getInstances(
|
||||
String type, Boolean polymorphic) throws
|
||||
ResourceRegistryException;
|
||||
|
||||
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)
|
||||
public <ERType extends ER> ERType getInstance(Class<ERType> clazz, UUID uuid)
|
||||
throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public List<? extends Entity> getInstances(String type, Boolean polymorphic) throws ResourceRegistryException;
|
||||
|
||||
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 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,
|
||||
boolean polymorphic, Map<String, Object> map) throws ResourceRegistryException;
|
||||
|
||||
public List<Resource> getFilteredResources(String resourceType, String consistsOfType, String facetType,
|
||||
boolean polymorphic, Map<String, Object> map) throws ResourceRegistryException;
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ 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.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.er.ERAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
||||
|
@ -23,6 +25,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
|||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
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.gcube.informationsystem.types.TypeBinder;
|
||||
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -55,7 +58,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
@Override
|
||||
public <ERType extends ER> void exists(Class<ERType> clazz, UUID uuid)
|
||||
throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException {
|
||||
String type = clazz.getSimpleName();
|
||||
String type = Utility.getType(clazz);
|
||||
try {
|
||||
logger.info("Going to check if {} with UUID {} exists", type, uuid);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
@ -73,10 +76,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
|
||||
logger.debug("{} with UUID {} exists", type, uuid);
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error while checking if {} with UUID {} exists.", type, uuid, e);
|
||||
// logger.trace("Error while checking if {} with UUID {} exists.", type, uuid,
|
||||
// e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error while checking if {} with UUID {} exists.", type, uuid, e);
|
||||
// logger.trace("Error while checking if {} with UUID {} exists.", type, uuid,
|
||||
// e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +89,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
@Override
|
||||
public <ERType extends ER> ERType getInstance(Class<ERType> clazz, UUID uuid)
|
||||
throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException {
|
||||
String type = clazz.getSimpleName();
|
||||
String type = Utility.getType(clazz);
|
||||
try {
|
||||
logger.info("Going to get {} with UUID {}", type, uuid);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
@ -103,10 +108,10 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
logger.debug("Got {} with UUID {} is {}", type, uuid, erType);
|
||||
return erType;
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error while getting {} with UUID {}", type, uuid, 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);
|
||||
// logger.trace("Error while getting {} with UUID {}", type, uuid, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -132,10 +137,10 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
logger.debug("Got instances of {} are {}", type, ret);
|
||||
return ISMapper.unmarshalList(Entity.class, ret);
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error while getting {} instances", type, e);
|
||||
// logger.trace("Error while getting {} instances", type, e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error while getting {} instances", type, e);
|
||||
// logger.trace("Error while getting {} instances", type, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -164,10 +169,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
logger.debug("Got instances of {} from/to {} are {}", relationType, reference.toString(), ret);
|
||||
return ISMapper.unmarshalList(Resource.class, ret);
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error while getting instances of {} from/to {}", relationType, e);
|
||||
// logger.trace("Error while getting instances of {} from/to {}", relationType,
|
||||
// e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error while getting instances of {} from/to {}", relationType, e);
|
||||
// logger.trace("Error while getting instances of {} from/to {}", relationType,
|
||||
// e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -175,8 +182,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
@Override
|
||||
public <ISM extends ISManageable> List<TypeDefinition> getSchema(Class<ISM> clazz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
|
||||
String type = clazz.getSimpleName();
|
||||
String type = Utility.getType(clazz);
|
||||
try {
|
||||
logger.info("Going to get {} schema", type);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
@ -191,17 +197,19 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String schema = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET, parameters);
|
||||
String json = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET, parameters);
|
||||
|
||||
logger.debug("Got schema for {} is {}", type, schema);
|
||||
return TypeBinder.deserializeTypeDefinitions(schema);
|
||||
logger.debug("Got schema for {} is {}", type, json);
|
||||
return TypeBinder.deserializeTypeDefinitions(json);
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error while getting {}schema for {}", polymorphic ? AccessPath.POLYMORPHIC_PARAM + " " : "",
|
||||
// type, 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);
|
||||
// logger.trace("Error while getting {}schema for {}", polymorphic ?
|
||||
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
||||
// type, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -233,10 +241,56 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
logger.debug("Query result is {}", ret);
|
||||
return ret;
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error while querying", e);
|
||||
// logger.trace("Error while querying", e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// logger.trace("Error while querying", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends Resource> List<R> getFilteredResources(Class<R> resourceClass,
|
||||
@SuppressWarnings("rawtypes") Class<? extends ConsistsOf> consistsOfClass, Class<? extends Facet> facetClass,
|
||||
boolean polymorphic, Map<String, Object> map) throws ResourceRegistryException {
|
||||
String resourceType = Utility.getType(resourceClass);
|
||||
String consistsOfType = Utility.getType(consistsOfClass);
|
||||
String facetType = Utility.getType(facetClass);
|
||||
return (List<R>) getFilteredResources(resourceType, consistsOfType, facetType, polymorphic, map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> getFilteredResources(String resourceType, String consistsOfType, String facetType,
|
||||
boolean polymorphic, Map<String, Object> map) throws ResourceRegistryException {
|
||||
try {
|
||||
logger.info("Going to get Filtered Resources ({}) linked by a ConsistsOf Relation ({}) to a Facet ({})"
|
||||
+ " having {}", resourceType, consistsOfType, facetType, map);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(AccessPath.ACCESS_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(AccessPath.RESOURCE_INSTANCES_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(resourceType);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(consistsOfType);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(facetType);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
|
||||
Map<String, Object> parameters = new HashMap<>(map);
|
||||
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic);
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String json = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET, parameters);
|
||||
|
||||
logger.info("Filtered Resources ({}) linked by a ConsistsOf Relation ({}) to a Facet ({})"
|
||||
+ " having {} are : {}", resourceType, consistsOfType, facetType, map, json);
|
||||
return ISMapper.unmarshalList(Resource.class, json);
|
||||
} catch (ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error while querying", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,22 +3,27 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||
import org.gcube.informationsystem.model.entity.facet.ContactFacet;
|
||||
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
||||
import org.gcube.informationsystem.model.entity.resource.EService;
|
||||
import org.gcube.informationsystem.model.entity.resource.HostingNode;
|
||||
import org.gcube.informationsystem.model.entity.resource.Service;
|
||||
import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
|
@ -78,4 +83,15 @@ public class ResourceRegistryClientTest extends ScopedTest {
|
|||
public void testGetInstances() throws ResourceRegistryException {
|
||||
resourceRegistryClient.getInstances(EService.NAME, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFilteredResources() throws ResourceRegistryException, JsonProcessingException {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("group", "VREManagement");
|
||||
map.put("name", "SmartExecutor");
|
||||
List<EService> eServices = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, map);
|
||||
for(EService eService : eServices) {
|
||||
logger.trace("{}", ISMapper.marshal(eService));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue