Compare commits

...

49 Commits

Author SHA1 Message Date
Luca Frosini 45f837ae61 Removed uneeded dependency 2024-05-24 11:01:47 +02:00
Luca Frosini 94e11b2665 Added test 2024-05-24 11:01:19 +02:00
Luca Frosini 8bccea574f Fixed API interface 2024-01-24 16:10:42 +01:00
luca.frosini c171876186 Generalised runQueryTempalte function 2023-11-29 16:17:01 +01:00
luca.frosini 7d4bb7d70f Fixed changelog 2023-11-16 11:20:14 +01:00
luca.frosini fdf33f87a1 Added test 2023-11-16 11:20:02 +01:00
luca.frosini 85cb4a4e55 Fixing getAllContextsFromServer() 2023-11-09 19:04:12 +01:00
luca.frosini c26b70520a Improved contexts limit offset 2023-11-09 18:56:02 +01:00
luca.frosini 848d1ee835 Improved limit offset request for contexts 2023-11-09 18:52:54 +01:00
luca.frosini 5189194b5e Fixed changelog 2023-11-09 18:03:11 +01:00
luca.frosini 384a7bdaf7 Added limit offset support for instances listing 2023-10-31 16:57:08 +01:00
luca.frosini 2113a6ee97 Added cache for ModelKnowledge 2023-10-31 15:59:26 +01:00
luca.frosini 30eac775f6 Added renew for TypesKnowledge 2023-10-31 15:51:06 +01:00
luca.frosini 660f0ea4a5 Improved test 2023-10-30 17:47:03 +01:00
luca.frosini b17edcb160 Fixed changelog 2023-10-30 17:11:42 +01:00
luca.frosini 3b125dfa15 Added full support for ModelKnowledge 2023-10-30 17:08:46 +01:00
luca.frosini 9eceb98059 fixing issue 2023-10-27 18:15:38 +02:00
luca.frosini 0cc1ead630 Adding support for types as tree using ModelKnowledge as cache 2023-10-27 18:14:16 +02:00
luca.frosini 29b559a71a Added getContextCache() to be able to get Context as Tree 2023-10-27 15:05:44 +02:00
luca.frosini 164be53064 Extended BaseRequestInfo to get new query parameters management for free 2023-09-13 18:42:25 +02:00
luca.frosini de47918497 Removed -SNAPSHOT for release 2023-07-21 14:24:22 +02:00
luca.frosini 5128f4ad63 Ignored MacOs File 2023-06-21 11:44:52 +02:00
Luca Frosini 1f0835775b Fixed tests 2023-05-17 18:11:56 +02:00
Luca Frosini cb7bd04bc2 Fixed sent query parameters 2023-05-15 16:48:40 +02:00
Luca Frosini 5df6c19a24 Added missing query parameters to request 2023-05-05 12:12:30 +02:00
Luca Frosini c933cc3f85 Using RequestInfo 2023-05-02 17:24:03 +02:00
Luca Frosini 047e0d448d Removed wrong comment 2023-04-28 14:53:17 +02:00
Luca Frosini 34a2dd7959 Fixed code to comply with uuid property rename to id 2023-04-28 11:45:23 +02:00
Luca Frosini b04623028e Refactored due to is-model constant name change 2023-04-27 10:42:22 +02:00
Luca Frosini 75b5acb932 Getting type indication property from constant 2023-04-26 21:44:40 +02:00
Luca Frosini 3faac2a236 Fixed changelog 2023-04-26 09:37:01 +02:00
Luca Frosini 484a467d55 Fixed changelog 2023-04-26 09:35:33 +02:00
Luca Frosini bb9e1fdd93 Maintaining backward compatibility 2023-04-26 09:31:43 +02:00
Luca Frosini 037d119697 Enhanced version 2023-04-26 09:22:13 +02:00
Luca Frosini faa0642224 Reorganized utilities and their usage 2023-04-21 15:57:08 +02:00
Luca Frosini ac164abb46 Porting code to redesigned E/R format 2023-04-19 11:37:12 +02:00
Luca Frosini fdf9e71068 Redesigning E/R instance definition 2023-04-18 17:51:47 +02:00
Luca Frosini e9611dcafc Removed -SNAPSHOT to release the component 2023-03-03 12:06:18 +01:00
Luca Frosini 6639589e9e Added facilities to use the client outside of container 2023-03-02 14:51:22 +01:00
Luca Frosini 022b3acc8b Removed wrong TODO comment 2023-03-01 20:09:11 +01:00
Luca Frosini 91a03750a0 Added addHeader in the interface 2023-03-01 14:23:11 +01:00
Luca Frosini d4ba9022d4 Fixed changelog 2023-02-27 18:53:21 +01:00
Luca Frosini a0dd4422b0 Added the possibility to create a client instance by context 2023-02-27 18:52:23 +01:00
Luca Frosini 59f4abda63 Added the possibility for a client to add additional HTTP headers 2023-02-27 18:20:12 +01:00
Luca Frosini 46091ad285 common-utility 1.X.X has been renamed to common-utility-sg3 2023-02-24 14:56:47 +01:00
Luca Frosini ee9344cee1 Added usage of common-utility 2023-02-22 15:14:18 +01:00
Luca Frosini 9b84168926 authorization-utils added as test dependency 2023-02-16 15:57:47 +01:00
Luca Frosini 196907d4de Fixed ContextTest 2023-02-09 17:57:59 +01:00
Luca Frosini 91e3f790cd Enhanced gcube-bom version and migrated code to new is-model version 2023-02-09 17:07:58 +01:00
11 changed files with 895 additions and 275 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
target
.classpath
.project
/.DS_Store
/bin/

View File

@ -2,6 +2,26 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Resource Registry Client
## [v4.5.0-SNAPSHOT]
- Added getContextCache() to be able to get Context as Tree [#24555]
- Added support for model knowledge [#25922]
- Added support for paginated results [#24648]
## [v4.4.0]
- Migrated code to reorganized E/R format [#24992]
## [v4.3.0]
- Enhanced gcube-bom version
- Added usage of common-utility to overcome issues with different Smartgears version (i.e. 3 and 4)
- Added the possibility for a client to add additional HTTP headers
- Added the possibility to create a client instance by specifying context
## [v4.2.0]
- Aligned APIs to other clients [#22011]

18
pom.xml
View File

@ -9,7 +9,7 @@
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-client</artifactId>
<version>4.2.0</version>
<version>4.5.0-SNAPSHOT</version>
<name>Resource Registry Client</name>
<description>Resource Registry Client is a library designed to interact with idempotent Resource Registry APIs</description>
@ -29,7 +29,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.1.0</version>
<version>2.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -37,14 +37,6 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-api</artifactId>
@ -78,5 +70,11 @@
<artifactId>gcube-model</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,30 @@
package org.gcube.informationsystem.resourceregistry.client;
import java.util.Collection;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.knowledge.TypesDiscoverer;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.types.reference.Type;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class RRCTypesDiscoverer implements TypesDiscoverer<Type> {
protected ResourceRegistryClientImpl resourceRegistryClient;
public RRCTypesDiscoverer(ResourceRegistryClientImpl resourceRegistryClient) {
this.resourceRegistryClient = resourceRegistryClient;
}
@Override
public Collection<Type> discover(AccessType accessType) {
try {
return resourceRegistryClient.getTypeFromServer(accessType.getTypeClass(), true);
} catch (ResourceRegistryException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -7,13 +7,16 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
@ -21,24 +24,37 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.Cont
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo;
import org.gcube.informationsystem.tree.Node;
import org.gcube.informationsystem.types.knowledge.TypeInformation;
import org.gcube.informationsystem.types.reference.Type;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public interface ResourceRegistryClient {
public boolean isHierarchicalMode();
public void setHierarchicalMode(boolean hierarchicalMode);
public interface ResourceRegistryClient extends RequestInfo {
/**
* Use {@link #includeContexts()} instead
* @return
*/
@Deprecated
public boolean isIncludeContextsInHeader();
public void setIncludeContextsInHeader(boolean includeContextsInHeader);
/**
* Use {@link #includeContexts(boolean)} instead
* @param includeContextsInHeader
*/
@Deprecated
public void setIncludeContextsInHeader(boolean includeContexts);
public void addHeader(String name, String value);
public List<Context> getAllContext() throws ResourceRegistryException;
public ContextCache getContextCache();
public boolean existContext(String uuid) throws ContextNotFoundException, ResourceRegistryException;
public boolean existContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
@ -51,16 +67,32 @@ public interface ResourceRegistryClient {
/* ---------------------------------------------------------------------- */
public ModelKnowledge<Type, TypeInformation> getModelKnowledge();
public void renewModelKnowledge();
public boolean existType(String typeName) throws ResourceRegistryException;
public <ERElem extends ERElement> boolean existType(Class<ERElem> clazz) throws ResourceRegistryException;
public <ME extends ModelElement> boolean existType(Class<ME> clazz) throws ResourceRegistryException;
public String getType(String typeName, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException;
public <ERElem extends ERElement> List<Type> getType(Class<ERElem> clazz, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException;
public String getType(String typeName, int level)
throws SchemaNotFoundException, ResourceRegistryException;
public <ME extends ModelElement> List<Type> getType(Class<ME> clazz, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException;
public <ME extends ModelElement> List<Type> getType(Class<ME> clazz, int level)
throws SchemaNotFoundException, ResourceRegistryException;
public <ME extends ModelElement> Node<Type> getTypeTreeNode(Class<ME> clazz)
throws SchemaNotFoundException, ResourceRegistryException;
public Node<Type> getTypeTreeNode(String typeName)
throws SchemaNotFoundException, ResourceRegistryException;
/* ---------------------------------------------------------------------- */
public <ERElem extends ERElement> List<ERElem> getInstances(Class<ERElem> clazz, Boolean polymorphic)
@ -108,19 +140,19 @@ public interface ResourceRegistryClient {
public String runQueryTemplateGetString(String name)
throws QueryTemplateNotFoundException, ResourceRegistryException;
public <E extends Entity> List<E> runQueryTemplate(String name)
public String runQueryTemplate(String name)
throws QueryTemplateNotFoundException, ResourceRegistryException;
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate)
public String runQueryTemplate(QueryTemplate queryTemplate)
throws QueryTemplateNotFoundException, ResourceRegistryException;
public String runQueryTemplate(String name, String params)
throws QueryTemplateNotFoundException, ResourceRegistryException;
public <E extends Entity> List<E> runQueryTemplate(String name, JsonNode jsonNode)
public String runQueryTemplate(String name, JsonNode jsonNode)
throws QueryTemplateNotFoundException, ResourceRegistryException;
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
public String runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
throws QueryTemplateNotFoundException, ResourceRegistryException;
/* ---------------------------------------------------------------------- */

View File

@ -1,8 +1,5 @@
package org.gcube.informationsystem.resourceregistry.client;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.resourceregistry.api.Constants;
import org.gcube.informationsystem.resourceregistry.api.rest.ServiceInstance;
import org.slf4j.Logger;
@ -15,19 +12,24 @@ public class ResourceRegistryClientFactory {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryClientFactory.class);
public static String getCurrentContextFullName() {
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry = null;
try {
authorizationEntry = org.gcube.common.authorization.client.Constants.authorizationService().get(token);
} catch(Exception e) {
return ScopeProvider.instance.get();
}
return authorizationEntry.getContext();
public static String getResourceRegistryURL() {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
return address;
}
public static String getResourceRegistryURL(String context) {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME);
return address;
}
public static ResourceRegistryClient create() {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
String address = getResourceRegistryURL();
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
return new ResourceRegistryClientImpl(address);
}
public static ResourceRegistryClient create(String context) {
String address = getResourceRegistryURL(context);
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
return new ResourceRegistryClientImpl(address);
}

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JavaType;
@ -13,9 +14,12 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
@ -33,107 +37,191 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.Cont
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
import org.gcube.informationsystem.resourceregistry.api.rest.QueryTemplatePath;
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.tree.Node;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.knowledge.TypeInformation;
import org.gcube.informationsystem.types.knowledge.TypesKnowledge;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.utils.TypeUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public class ResourceRegistryClientImpl extends BaseRequestInfo implements ResourceRegistryClient {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryClientImpl.class);
private static final String ACCEPT_HTTP_HEADER_KEY = "Accept";
private static final String CONTENT_TYPE_HTTP_HEADER_KEY = "Content-Type";
protected final String address;
protected boolean hierarchicalMode;
protected boolean includeContextsInHeader;
protected Map<String, String> headers;
@Override
public boolean isHierarchicalMode() {
return hierarchicalMode;
}
protected ContextCache contextCache;
@Override
public void setHierarchicalMode(boolean hierarchicalMode) {
this.hierarchicalMode = hierarchicalMode;
}
protected TypesKnowledge typesKnowledge;
@Deprecated
@Override
public boolean isIncludeContextsInHeader() {
return includeContextsInHeader;
}
@Override
public void setIncludeContextsInHeader(boolean includeContextsInHeader) {
this.includeContextsInHeader = includeContextsInHeader;
return includeContexts();
}
@Deprecated
@Override
public void setIncludeContextsInHeader(boolean includeContexts) {
setIncludeContexts(includeContexts);
}
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
addHierarchicalMode(queryParams);
addIncludeContexts(queryParams);
addIncludeMeta(queryParams);
addIncludeAllMeta(queryParams);
}
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
return includeAdditionalQueryParameters(gxHTTPStringRequest, null);
Map<String,String> queryParams = new HashMap<>();
return includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
}
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
if(queryParams==null) {
queryParams = new HashMap<>();
}
addOptionalQueryParameters(queryParams);
return gxHTTPStringRequest.queryParams(queryParams);
}
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
private void addHierarchicalMode(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(hierarchicalMode) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode));
}
return gxHTTPStringRequest.queryParams(queryParams);
}
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
if(includeContextsInHeader) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_QUERY_PARAMETER, Boolean.toString(includeContextsInHeader));
private void addIncludeContexts(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(includeContexts) {
queryParams.put(AccessPath.INCLUDE_CONTEXTS_QUERY_PARAMETER, Boolean.toString(includeContexts));
}
return gxHTTPStringRequest.queryParams(queryParams);
}
private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
addIncludeMeta(queryParams, includeMeta);
}
private void addIncludeMeta(Map<String,String> queryParams, boolean includeMeta) throws UnsupportedEncodingException{
if(includeMeta) {
queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
}
}
private void addIncludeAllMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(allMeta) {
queryParams.put(AccessPath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER, Boolean.toString(allMeta));
}
}
private void addOffset(Map<String,String> queryParams) throws UnsupportedEncodingException{
addOffset(queryParams, offset);
}
private void addOffset(Map<String,String> queryParams, Integer offset) throws UnsupportedEncodingException{
if(offset!=null) {
queryParams.put(AccessPath.OFFSET_QUERY_PARAMETER, offset.toString());
}
}
private void addLimit(Map<String,String> queryParams) throws UnsupportedEncodingException{
addLimit(queryParams, limit);
}
private void addLimit(Map<String,String> queryParams, Integer limit) throws UnsupportedEncodingException{
if(limit!=null) {
queryParams.put(AccessPath.LIMIT_QUERY_PARAMETER, limit.toString());
}
}
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@Override
public List<Context> renew() throws ResourceRegistryException {
return getAllContextFromServer();
return getAllContextFromServer(true, 0, BaseRequestInfo.UNBOUNDED_LIMIT);
}
};
public ResourceRegistryClientImpl(String address) {
this.address = address;
this.hierarchicalMode = false;
this.includeContextsInHeader = false;
ContextCache contextCache = ContextCache.getInstance();
contextCache.setContextCacheRenewal(contextCacheRenewal);
@Override
public void addHeader(String name, String value) {
headers.put(name, value);
}
protected GXHTTPStringRequest getGXHTTPStringRequest() {
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
gxHTTPStringRequest.from(this.getClass().getSimpleName());
for(String name : headers.keySet()) {
gxHTTPStringRequest.header(name, headers.get(name));
}
return gxHTTPStringRequest;
}
public ResourceRegistryClientImpl(String address) {
this(address, true, true);
}
public ResourceRegistryClientImpl(String address, boolean sharedContextCache, boolean sharedModelKnowledge) {
super();
this.address = address;
this.headers = new HashMap<>();
if(sharedContextCache) {
this.contextCache = ContextCache.getInstance();
}else {
this.contextCache = new ContextCache();
}
this.contextCache.setContextCacheRenewal(contextCacheRenewal);
if(sharedModelKnowledge) {
this.typesKnowledge = TypesKnowledge.getInstance();
}else {
this.typesKnowledge = new TypesKnowledge();
}
typesKnowledge.setTypesDiscoverer(new RRCTypesDiscoverer(this));
}
/**
* It reads all the contexts from server.
* The cache used for contexts is bypassed and not updated.
* @return All Contexts read from server
* @throws ResourceRegistryException
*/
public List<Context> getAllContextFromServer() throws ResourceRegistryException {
return getAllContextFromServer(includeMeta, offset, limit);
}
protected List<Context> getAllContextFromServer(boolean includeMeta, Integer offset, Integer limit) throws ResourceRegistryException {
try {
logger.info("Going to read all {}s", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters, includeMeta);
addOffset(parameters, offset);
addLimit(parameters, limit);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -155,22 +243,49 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public List<Context> getAllContext() throws ResourceRegistryException {
ContextCache contextCache = ContextCache.getInstance();
return contextCache.getContexts();
}
@Override
public ContextCache getContextCache() {
return contextCache;
}
@Override
public ModelKnowledge<Type, TypeInformation> getModelKnowledge() {
return typesKnowledge.getModelKnowledge();
}
@Override
public void renewModelKnowledge() {
typesKnowledge.renew();
}
/**
* It reads the context from server.
* The cache used for contexts is bypassed and not updated.
* @param uuid
* @return the Contexts read from server
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/
public Context getContextFromServer(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
return getContextFromServer(uuid.toString());
}
protected Context getContextFromServer(String uuid) throws ContextNotFoundException, ResourceRegistryException {
try {
// TODO use cache
logger.info("Going to get current {} ", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
gxHTTPStringRequest.path(uuid);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
Context context = HTTPUtility.getResponse(Context.class, httpURLConnection);
@ -211,13 +326,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
ContextCache contextCache = ContextCache.getInstance();
Context context = ContextCache.getInstance().getContextByUUID(uuid);;
Context context = contextCache.getContextByUUID(uuid);;
if(context == null) {
context = getContextFromServer(ContextPath.CURRENT_CONTEXT_PATH_PART);
contextCache.cleanCache();
contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
Context c = contextCache.getContextByUUID(context.getID());
if(c!=null){
context = c;
}else {
@ -229,15 +343,14 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException {
String contextFullName = ResourceRegistryClientFactory.getCurrentContextFullName();
ContextCache contextCache = ContextCache.getInstance();
String contextFullName = org.gcube.common.context.ContextUtility.getCurrentContextFullName();
UUID uuid = contextCache.getUUIDByFullName(contextFullName);
Context context = null;
if(uuid == null) {
context = getContextFromServer(ContextPath.CURRENT_CONTEXT_PATH_PART);
contextCache.cleanCache();
contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
Context c = contextCache.getContextByUUID(context.getID());
if(c!=null){
context = c;
}else {
@ -250,17 +363,24 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
}
@Override
public <ERElem extends ERElement> boolean existType(Class<ERElem> clazz) throws ResourceRegistryException {
return existType(Utility.getTypeName(clazz));
public <ME extends ModelElement> boolean existType(Class<ME> clazz) throws ResourceRegistryException {
return existType(TypeUtility.getTypeName(clazz));
}
@Override
public boolean existType(String typeName) throws ResourceRegistryException {
try {
return typesKnowledge.getModelKnowledge().getTypeByName(typeName) != null;
}catch (RuntimeException e) {
return false;
}
}
public boolean existTypeFromServer(String typeName) throws ResourceRegistryException {
try {
logger.info("Going to get {} schema", typeName);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.TYPES_PATH_PART);
gxHTTPStringRequest.path(typeName);
@ -283,36 +403,150 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
// logger.trace("Error while getting {}schema for {}", polymorphic ?
// AccessPath.POLYMORPHIC_PARAM + " " : "",
// type, e);
throw new RuntimeException(e);
throw new ResourceRegistryException(e);
}
}
public <ERElem extends ERElement> List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException {
return getTypeFromTypesKnowledge(typeName, polymorphic, -1);
}
public <ERElem extends ERElement> List<Type> getTypeFromTypesKnowledge(String typeName, int level)
throws SchemaNotFoundException, ResourceRegistryException {
return getTypeFromTypesKnowledge(typeName, true, level);
}
protected List<Type> addChildren(Node<Type> node, List<Type> types, int currentLevel, int maxLevel) {
if(maxLevel>=0 && maxLevel <= currentLevel) {
return types;
}
Set<Node<Type>> children = node.getChildrenNodes();
if(children!=null && children.size()>0) {
for(Node<Type> child : children) {
types.add(child.getNodeElement());
types = addChildren(child, types, ++currentLevel, maxLevel);
}
}
return types;
}
public <ERElem extends ERElement> List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic, int level)
throws SchemaNotFoundException, ResourceRegistryException {
Node<Type> node = getTypeTreeNode(typeName);
List<Type> types = new ArrayList<>();
types.add(node.getNodeElement());
if (polymorphic) {
addChildren(node, types, 0, level);
}
return types;
}
@Override
public String getType(String typeName, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException {
try {
List<Type> types = getTypeFromTypesKnowledge(typeName, polymorphic);
return TypeMapper.serializeTypeDefinitions(types);
} catch(ResourceRegistryException e) {
throw e;
} catch(Exception e) {
throw new ResourceRegistryException(e);
}
}
@Override
public String getType(String typeName, int level) throws SchemaNotFoundException, ResourceRegistryException {
try {
List<Type> types = getTypeFromTypesKnowledge(typeName, level);
return TypeMapper.serializeTypeDefinitions(types);
} catch(ResourceRegistryException e) {
throw e;
} catch(Exception e) {
throw new ResourceRegistryException(e);
}
}
@Override
public <ERElem extends ERElement> List<Type> getType(Class<ERElem> clazz, Boolean polymorphic)
public <ME extends ModelElement> List<Type> getType(Class<ME> clazz, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException {
try {
String json = getType(Utility.getTypeName(clazz), polymorphic);
String typeName = TypeUtility.getTypeName(clazz);
return getTypeFromTypesKnowledge(typeName, polymorphic);
} catch (Exception e) {
throw new ResourceRegistryException(e);
}
}
@Override
public <ME extends ModelElement> List<Type> getType(Class<ME> clazz, int level)
throws SchemaNotFoundException, ResourceRegistryException {
try {
String typeName = TypeUtility.getTypeName(clazz);
return getTypeFromTypesKnowledge(typeName, level);
} catch (Exception e) {
throw new ResourceRegistryException(e);
}
}
@Override
public Node<Type> getTypeTreeNode(String typeName) throws SchemaNotFoundException, ResourceRegistryException {
try {
Node<Type> node = null;
try {
node = typesKnowledge.getModelKnowledge().getNodeByName(typeName);
} catch (RuntimeException e) {
throw new SchemaNotFoundException(e);
}
return node;
} catch(ResourceRegistryException e) {
throw e;
} catch(Exception e) {
throw new ResourceRegistryException(e);
}
}
@Override
public <ME extends ModelElement> Node<Type> getTypeTreeNode(Class<ME> clazz)
throws SchemaNotFoundException, ResourceRegistryException {
try {
String typeName = TypeUtility.getTypeName(clazz);
return getTypeTreeNode(typeName);
} catch (Exception e) {
throw new ResourceRegistryException(e);
}
}
public <ME extends ModelElement> List<Type> getTypeFromServer(Class<ME> clazz, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException {
try {
String json = getTypeFromServer(TypeUtility.getTypeName(clazz), polymorphic);
return TypeMapper.deserializeTypeDefinitions(json);
} catch(ResourceRegistryException e) {
throw e;
} catch(Exception e) {
throw new RuntimeException(e);
throw new ResourceRegistryException(e);
}
}
@Override
public String getType(String typeName, Boolean polymorphic)
public String getTypeFromServer(String typeName, Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException {
try {
logger.info("Going to get {} schema", typeName);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.TYPES_PATH_PART);
gxHTTPStringRequest.path(typeName);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters);
parameters.put(TypePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
gxHTTPStringRequest.queryParams(parameters);
@ -337,7 +571,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public <ERElem extends ERElement> List<ERElem> getInstances(Class<ERElem> clazz, Boolean polymorphic)
throws ResourceRegistryException {
String type = Utility.getTypeName(clazz);
String type = TypeUtility.getTypeName(clazz);
String ret = getInstances(type, polymorphic);
try {
return (List<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret);
@ -350,14 +584,15 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException {
try {
logger.info("Going to get all instances of {} ", type);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
Map<String,String> parameters = new HashMap<>();
addOffset(parameters);
addLimit(parameters);
parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
@ -379,7 +614,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public <ERElem extends ERElement> boolean existInstance(Class<ERElem> clazz, UUID uuid)
throws AvailableInAnotherContextException, ResourceRegistryException {
String type = Utility.getTypeName(clazz);
String type = TypeUtility.getTypeName(clazz);
return existInstance(type, uuid);
}
@ -388,15 +623,16 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
throws AvailableInAnotherContextException, ResourceRegistryException {
try {
logger.info("Going to check if {} with UUID {} exists", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, 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());
includeAdditionalQueryParameters(gxHTTPStringRequest);
Map<String,String> queryParams = new HashMap<>();
addHierarchicalMode(queryParams);
gxHTTPStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
HTTPUtility.getResponse(String.class, httpURLConnection);
@ -419,7 +655,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public <ERElem extends ERElement> ERElem getInstance(Class<ERElem> clazz, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
String type = Utility.getTypeName(clazz);
String type = TypeUtility.getTypeName(clazz);
String ret = getInstance(type, uuid);
try {
return ElementMapper.unmarshal(clazz, ret);
@ -432,9 +668,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try {
logger.info("Going to get {} with UUID {}", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
@ -468,9 +703,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
try {
logger.info("Going to query. {}", query);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.QUERY_PATH_PART);
@ -478,7 +712,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
parameters.put(AccessPath.Q_QUERY_PARAMETER, query);
parameters.put(AccessPath.RAW_QUERY_PARAMETER, Boolean.toString(raw));
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
if(raw) {
addHierarchicalMode(parameters);
gxHTTPStringRequest.queryParams(parameters);
} else {
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
}
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
@ -500,9 +739,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
throws ResourceRegistryException {
try {
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.QUERY_PATH_PART);
gxHTTPStringRequest.path(entityType);
@ -556,7 +794,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
Class<R> resourceClass, Class<C> consistsOfClass, F referenceFacet,
boolean polymorphic) throws ResourceRegistryException {
UUID referenceFacetUUID = referenceFacet.getHeader().getUUID();
UUID referenceFacetUUID = referenceFacet.getID();
@SuppressWarnings("unchecked")
Class<F> facetClass = (Class<F>) referenceFacet.getClass();
return getResourcesFromReferenceFacet(resourceClass, consistsOfClass, facetClass, referenceFacetUUID,
@ -567,9 +805,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, UUID referenceFacetUUID,
boolean polymorphic) throws ResourceRegistryException {
String resourceType = Utility.getTypeName(resourceClass);
String consistsOfType = Utility.getTypeName(consistsOfClass);
String facetType = Utility.getTypeName(facetClass);
String resourceType = TypeUtility.getTypeName(resourceClass);
String consistsOfType = TypeUtility.getTypeName(consistsOfClass);
String facetType = TypeUtility.getTypeName(facetClass);
String ret = getResourcesFromReferenceFacet(resourceType, consistsOfType, facetType, referenceFacetUUID,
polymorphic);
try {
@ -590,9 +828,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getFilteredResources(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, boolean polymorphic,
Map<String,String> facetConstraints) throws ResourceRegistryException {
String resourceType = Utility.getTypeName(resourceClass);
String consistsOfType = Utility.getTypeName(consistsOfClass);
String facetType = Utility.getTypeName(facetClass);
String resourceType = TypeUtility.getTypeName(resourceClass);
String consistsOfType = TypeUtility.getTypeName(consistsOfClass);
String facetType = TypeUtility.getTypeName(facetClass);
String ret = getFilteredResources(resourceType, consistsOfType, facetType, polymorphic, facetConstraints);
try {
return (List<R>) ElementMapper.unmarshalList(Resource.class, ret);
@ -611,7 +849,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResourcesFromReferenceResource(
Class<R> resourceClass, Class<I> isRelatedToClass, RR referenceResource,
Direction direction, boolean polymorphic) throws ResourceRegistryException {
UUID referenceResourceUUID = referenceResource.getHeader().getUUID();
UUID referenceResourceUUID = referenceResource.getID();
@SuppressWarnings("unchecked")
Class<RR> referenceResourceClass = (Class<RR>) referenceResource.getClass();
return getRelatedResourcesFromReferenceResource(resourceClass, isRelatedToClass, referenceResourceClass,
@ -623,9 +861,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResourcesFromReferenceResource(
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> referenceResourceClass,
UUID referenceResourceUUID, Direction direction, boolean polymorphic) throws ResourceRegistryException {
String resourceType = Utility.getTypeName(resourceClass);
String isRelatedToType = Utility.getTypeName(isRelatedToClass);
String referenceResourceType = Utility.getTypeName(referenceResourceClass);
String resourceType = TypeUtility.getTypeName(resourceClass);
String isRelatedToType = TypeUtility.getTypeName(isRelatedToClass);
String referenceResourceType = TypeUtility.getTypeName(referenceResourceClass);
String ret = getRelatedResourcesFromReferenceResource(resourceType, isRelatedToType, referenceResourceType,
referenceResourceUUID, direction, polymorphic);
try {
@ -648,9 +886,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResources(
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> referenceResourceClass, Direction direction,
boolean polymorphic) throws ResourceRegistryException {
String resourceType = Utility.getTypeName(resourceClass);
String isRelatedToType = Utility.getTypeName(isRelatedToClass);
String referenceResourceType = Utility.getTypeName(referenceResourceClass);
String resourceType = TypeUtility.getTypeName(resourceClass);
String isRelatedToType = TypeUtility.getTypeName(isRelatedToClass);
String referenceResourceType = TypeUtility.getTypeName(referenceResourceClass);
String ret = getRelatedResources(resourceType, isRelatedToType, referenceResourceType, direction, polymorphic);
try {
return (List<R>) ElementMapper.unmarshalList(Resource.class, ret);
@ -670,9 +908,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected <E extends Entity, R extends Relation<?,?>, RE extends Entity> List<E> getRelated(Class<E> entityClass,
Class<R> relationClass, Class<RE> referenceEntityClass, Direction direction, boolean polymorphic,
Map<String,String> map) throws ResourceRegistryException {
String entityType = Utility.getTypeName(entityClass);
String relationType = Utility.getTypeName(relationClass);
String referenceEntityType = Utility.getTypeName(referenceEntityClass);
String entityType = TypeUtility.getTypeName(entityClass);
String relationType = TypeUtility.getTypeName(relationClass);
String referenceEntityType = TypeUtility.getTypeName(referenceEntityClass);
String ret = getRelated(entityType, relationType, referenceEntityType, direction, polymorphic, map);
try {
return (List<E>) ElementMapper.unmarshalList(Resource.class, ret);
@ -691,7 +929,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected <E extends Entity, R extends Relation<?,?>, RE extends Entity> List<E> getRelated(Class<E> entityClass,
Class<R> relationClass, Class<RE> referenceEntityClass, RE referenceEntity, Direction direction,
boolean polymorphic) throws ResourceRegistryException {
UUID referenceEntityUUID = referenceEntity.getHeader().getUUID();
UUID referenceEntityUUID = referenceEntity.getID();
return getRelated(entityClass, relationClass, referenceEntityClass, referenceEntityUUID, direction,
polymorphic);
}
@ -701,9 +939,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected <E extends Entity, R extends Relation<?,?>, RE extends Entity> List<E> getRelated(Class<E> entityClass,
Class<R> relationClass, Class<RE> referenceEntityClass, UUID referenceEntityUUID, Direction direction,
boolean polymorphic) throws ResourceRegistryException {
String entityType = Utility.getTypeName(entityClass);
String relationType = Utility.getTypeName(relationClass);
String referenceEntityType = Utility.getTypeName(referenceEntityClass);
String entityType = TypeUtility.getTypeName(entityClass);
String relationType = TypeUtility.getTypeName(relationClass);
String referenceEntityType = TypeUtility.getTypeName(referenceEntityClass);
String ret = getRelated(entityType, relationType, referenceEntityType, referenceEntityUUID, direction,
polymorphic);
try {
@ -722,7 +960,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public <ERElem extends ERElement> Map<UUID, String> getInstanceContexts(Class<ERElem> clazz, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
String typeName = Utility.getTypeName(clazz);
String typeName = TypeUtility.getTypeName(clazz);
return getInstanceContexts(typeName, uuid);
}
@ -731,9 +969,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
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 gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
@ -760,12 +997,15 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public List<QueryTemplate> getAllQueryTemplates() throws ResourceRegistryException {
try {
logger.trace("Going to list {}s", QueryTemplate.NAME);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String all = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -794,9 +1034,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
logger.trace("Going to read {} with name {}", QueryTemplate.NAME, queryTemplateName);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
gxHTTPStringRequest.path(queryTemplateName);
@ -816,7 +1055,6 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public QueryTemplate readQueryTemplate(QueryTemplate queryTemplate)
throws QueryTemplateNotFoundException, ResourceRegistryException {
// TODO Auto-generated method stub
return readQueryTemplate(queryTemplate.getName());
}
@ -838,13 +1076,16 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
logger.trace("Going to read {} with name {}", QueryTemplate.NAME, queryTemplateName);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
gxHTTPStringRequest.path(queryTemplateName);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -865,22 +1106,35 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
return runQueryTemplate(name, "");
}
// @Override
// public <E extends Entity> List<E> runQueryTemplate(String name)
// throws QueryTemplateNotFoundException, ResourceRegistryException {
// try {
// String ret = runQueryTemplateGetString(name);
// JavaType type = ElementMapper.getObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Entity.class);
// return ElementMapper.getObjectMapper().readValue(ret, type);
// } catch(ResourceRegistryException e) {
// throw e;
// } catch(Exception e) {
// throw new RuntimeException(e);
// }
// }
@Override
public <E extends Entity> List<E> runQueryTemplate(String name)
public String runQueryTemplate(String name)
throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
String ret = runQueryTemplateGetString(name);
JavaType type = ElementMapper.getObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Entity.class);
return ElementMapper.getObjectMapper().readValue(ret, type);
return ret;
} catch(ResourceRegistryException e) {
throw e;
} catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate)
public String runQueryTemplate(QueryTemplate queryTemplate)
throws QueryTemplateNotFoundException, ResourceRegistryException {
return runQueryTemplate(queryTemplate.getName());
}
@ -896,14 +1150,15 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
logger.trace("Going to run {} with the following parameters {}", QueryTemplate.NAME, params);
}
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
gxHTTPStringRequest.path(name);
includeAdditionalQueryParameters(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(params);
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -917,7 +1172,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
}
@Override
public <E extends Entity> List<E> runQueryTemplate(String name, JsonNode jsonNode)
public String runQueryTemplate(String name, JsonNode jsonNode)
throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
ObjectMapper objectMapper = new ObjectMapper();
@ -932,7 +1187,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
}
@Override
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
public String runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
throws QueryTemplateNotFoundException, ResourceRegistryException {
return runQueryTemplate(queryTemplate.getName(), jsonNode);
}
@ -942,13 +1197,14 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
try {
logger.trace("Going to run the following JSON Query {}", query);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.QUERY_PATH_PART);
includeAdditionalQueryParameters(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(query);
String c = HTTPUtility.getResponse(String.class, httpURLConnection);

View File

@ -7,14 +7,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.KeycloakClientHelper;
import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@ -22,77 +23,147 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "token.properties";
protected static final String CONFIG_INI_FILENAME = "config.ini";
public static final String PARENT_DEFAULT_TEST_SCOPE;
public static final String DEFAULT_TEST_SCOPE;
public static final String ALTERNATIVE_TEST_SCOPE;
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
public static final String GCUBE;
public static final String DEVNEXT;
public static final String NEXTNEXT;
public static final String DEVSEC;
public static final String DEVVRE;
protected static final Properties properties;
public static final String TYPE_PROPERTY_KEY = "type";
public static final String USERNAME_PROPERTY_KEY = "username";
public static final String PASSWORD_PROPERTY_KEY = "password";
public static final String CLIENT_ID_PROPERTY_KEY = "clientId";
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
public static final String RESOURCE_REGISTRY_URL;
static {
properties = new Properties();
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
GCUBE = "/gcube";
DEVNEXT = GCUBE + "/devNext";
NEXTNEXT = DEVNEXT + "/NextNext";
DEVSEC = GCUBE + "/devsec";
DEVVRE = DEVSEC + "/devVRE";
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
DEFAULT_TEST_SCOPE = DEVNEXT;
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
properties = new Properties();
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
try {
// load the properties file
properties.load(input);
} catch(IOException e) {
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
} catch (IOException e) {
throw new RuntimeException(e);
}
// PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
}
private enum Type{
USER, CLIENT_ID
};
public static void set(Secret secret) throws Exception {
SecretManagerProvider.instance.reset();
SecretManager secretManager = new SecretManager();
secretManager.addSecret(secret);
SecretManagerProvider.instance.set(secretManager);
SecretManagerProvider.instance.get().set();
}
public static void setContextByName(String fullContextName) throws Exception {
logger.debug("Going to set credentials for context {}", fullContextName);
Secret secret = getSecretByContextName(fullContextName);
set(secret);
}
private static TokenResponse getJWTAccessToken(String context) throws Exception {
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
TokenResponse tr = null;
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
int index = context.indexOf('/', 1);
String root = context.substring(0, index == -1 ? context.length() : index);
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
switch (type) {
case CLIENT_ID:
String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
String clientSecret = properties.getProperty(root);
tr = KeycloakClientFactory.newInstance().queryUMAToken(context, clientId, clientSecret, context, null);
break;
try {
setContextByName(DEFAULT_TEST_SCOPE);
} catch(Exception e) {
throw new RuntimeException(e);
case USER:
default:
String username = properties.getProperty(USERNAME_PROPERTY_KEY);
String password = properties.getProperty(PASSWORD_PROPERTY_KEY);
switch (root) {
case "/gcube":
default:
clientId = "next.d4science.org";
break;
case "/pred4s":
clientId = "pre.d4science.org";
break;
case "/d4science.research-infrastructures.eu":
clientId = "services.d4science.org";
break;
}
clientSecret = null;
tr = KeycloakClientHelper.getTokenForUser(context, username, password);
break;
}
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
return tr;
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context);
return context;
public static Secret getSecretByContextName(String context) throws Exception {
TokenResponse tr = getJWTAccessToken(context);
Secret secret = new JWTSecret(tr.getAccessToken());
return secret;
}
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
String token = ContextTest.properties.getProperty(fullContextName);
setContext(token);
public static void setContext(String token) throws Exception {
Secret secret = getSecret(token);
set(secret);
}
private static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
ClientInfo clientInfo = authorizationEntry.getClientInfo();
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
String qualifier = authorizationEntry.getQualifier();
Caller caller = new Caller(clientInfo, qualifier);
AuthorizationProvider.instance.set(caller);
ScopeProvider.instance.set(getCurrentScope(token));
private static Secret getSecret(String token) throws Exception {
Secret secret = SecretUtility.getSecretByTokenString(token);
return secret;
}
public static String getUser() {
String user = Metadata.UNKNOWN_USER;
try {
user = SecretManagerProvider.instance.get().getUser().getUsername();
} catch(Exception e) {
logger.error("Unable to retrieve user. {} will be used", user);
}
return user;
}
@BeforeClass
@ -102,8 +173,7 @@ public class ContextTest {
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
SecretManagerProvider.instance.reset();
}
}

View File

@ -0,0 +1,99 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.client;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ResourceRegistryClientNoGcubeModel extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(ResourceRegistryClientNoGcubeModel.class);
protected ResourceRegistryClient resourceRegistryClient;
public ResourceRegistryClientNoGcubeModel() {
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
}else {
resourceRegistryClient = ResourceRegistryClientFactory.create();
}
resourceRegistryClient.setIncludeMeta(true);
}
@Test
public void testQuery() throws ResourceRegistryException {
String res = resourceRegistryClient.rawQuery("SELECT FROM V");
logger.trace(res);
}
protected List<String> getTypeNames(List<Type> types){
List<String> list = new ArrayList<String>();
for(Type t : types) {
list.add(t.getName());
}
return list;
}
protected <ME extends ModelElement> void getTypesFromKnowledge(Class<ME> clazz) throws SchemaNotFoundException, ResourceRegistryException {
List<Type> types = resourceRegistryClient.getType(clazz, true);
logger.trace("List size {}\n{}", types.size(), getTypeNames(types));
}
@Test
public void testTypesKnowledgeExpiring() throws Exception {
resourceRegistryClient.getModelKnowledge();
resourceRegistryClient.renewModelKnowledge();
}
@Test
public void testModelKnowledge() throws SchemaNotFoundException, ResourceRegistryException {
AccessType[] modelTypes = AccessType.getModelTypes();
for(AccessType accessType : modelTypes) {
getTypesFromKnowledge(accessType.getTypeClass());
}
}
@Test
public void testGetInstancesAndUnmashal() throws Exception {
resourceRegistryClient.setIncludeMeta(true);
resourceRegistryClient.setOffset(0);
resourceRegistryClient.setLimit(-1);
String instances = resourceRegistryClient.getInstances("EService", false);
logger.info("{}", instances);
List<Resource> list = ElementMapper.unmarshalList(Resource.class, instances);
logger.info("{}", list);
}
@Test
public void testGetInstanceFromStringAndUnmashal() throws Exception {
String instance = "{\"type\":\"EService\",\"supertypes\":[\"Service\",\"GCubeResource\",\"Resource\"],\"id\":\"f1b0994a-1ad5-4f32-9a0e-59e5c8667456\",\"metadata\":{\"type\":\"Metadata\",\"creationTime\":\"2024-04-15 11:50:15.415 +0200\",\"createdBy\":\"luca.frosini\",\"lastUpdateBy\":\"luca.frosini\",\"lastUpdateTime\":\"2024-04-15 15:25:49.860 +0200\",\"supertypes\":[\"Property\"]},\"consistsOf\":[{\"type\":\"IsIdentifiedBy\",\"supertypes\":[\"ConsistsOf\"],\"id\":\"f9f0d6f7-a6f9-4d56-ac34-0798899694a7\",\"propagationConstraint\":{\"type\":\"PropagationConstraint\",\"add\":\"propagate\",\"delete\":\"cascade\",\"remove\":\"cascade\",\"supertypes\":[\"Property\"]},\"target\":{\"type\":\"SoftwareFacet\",\"supertypes\":[\"Facet\"],\"id\":\"e1d2242d-3fc6-4432-af2a-d406193b20bc\",\"qualifier\":null,\"name\":\"Liferay\",\"description\":\"D4Science Infrastructure Portal container\",\"optional\":false,\"version\":\"6.2.6-0\",\"group\":\"Liferay\"}},{\"type\":\"ConsistsOf\",\"id\":\"24bf44d4-2e6a-4df8-95ab-7e11d2d22d2c\",\"propagationConstraint\":{\"type\":\"PropagationConstraint\",\"add\":\"propagate\",\"delete\":\"cascade\",\"remove\":\"cascade\",\"supertypes\":[\"Property\"]},\"target\":{\"type\":\"AccessPointFacet\",\"supertypes\":[\"Facet\"],\"id\":\"57444f71-16a4-4f72-8905-3fdf5d456547\",\"authorization\":null,\"endpoint\":\"https://services.d4science.org\",\"protocol\":null,\"entryName\":\"JSONWSUser\",\"description\":\"\",\"users\":[{\"password\":{\"type\":\"Encrypted\",\"value\":\"s9kkLvli1L5SADpvdu2GiQeld0XXZGVrzANNngBo9Xo=\",\"supertypes\":[\"Property\"]},\"username\":{\"type\":\"Encrypted\",\"value\":\"mW35KImZ2LBxWvtKhKLs1NDyphJdt0/JTBMu564HJtk=\",\"supertypes\":[\"Property\"]}}]}},{\"type\":\"ConsistsOf\",\"id\":\"0013ffe4-2103-41fd-8e2d-d4cf330da646\",\"propagationConstraint\":{\"type\":\"PropagationConstraint\",\"add\":\"propagate\",\"delete\":\"cascade\",\"remove\":\"cascade\",\"supertypes\":[\"Property\"]},\"target\":{\"type\":\"StateFacet\",\"supertypes\":[\"Facet\"],\"id\":\"050f48d0-3283-4af6-a47a-73fa70b667b1\",\"date\":\"2024-03-01 15:00:00.000 +0100\",\"value\":\"ready\"}},{\"type\":\"ConsistsOf\",\"id\":\"086214a1-43d8-4a35-9654-2b2e5e1298ab\",\"propagationConstraint\":{\"type\":\"PropagationConstraint\",\"add\":\"propagate\",\"delete\":\"cascade\",\"remove\":\"cascade\",\"supertypes\":[\"Property\"]},\"target\":{\"type\":\"EventFacet\",\"supertypes\":[\"Facet\"],\"id\":\"398bfa1c-ddc5-427d-b6c2-1467fc70b324\",\"date\":\"2024-03-01 15:00:00.000 +0100\",\"event\":\"ready\"}}]}";
Resource r = ElementMapper.unmarshal(Resource.class, instance);
logger.info("{}", r);
}
@Test
public void testGetInstanceAndUnmashal() throws Exception {
ContextTest.setContextByName("/gcube");
String instance = resourceRegistryClient.getInstance("EService", UUID.fromString("f1b0994a-1ad5-4f32-9a0e-59e5c8667456"));
Resource r = ElementMapper.unmarshal(Resource.class, instance);
logger.info("{}", r);
}
}

View File

@ -3,24 +3,33 @@
*/
package org.gcube.informationsystem.resourceregistry.client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.tree.Node;
import org.gcube.informationsystem.tree.Tree;
import org.gcube.informationsystem.types.knowledge.TypeInformation;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.informationsystem.utils.UUIDUtility;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet;
@ -28,6 +37,7 @@ import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFace
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
import org.gcube.resourcemanagement.model.reference.entities.resources.VirtualService;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.junit.Assert;
import org.junit.Test;
@ -49,6 +59,7 @@ public class ResourceRegistryClientTest extends ContextTest {
}else {
resourceRegistryClient = ResourceRegistryClientFactory.create();
}
resourceRegistryClient.setIncludeMeta(true);
}
@Test
@ -57,16 +68,82 @@ public class ResourceRegistryClientTest extends ContextTest {
logger.trace(res);
}
protected List<String> getTypeNames(List<Type> types){
List<String> list = new ArrayList<String>();
for(Type t : types) {
list.add(t.getName());
}
return list;
}
protected <ME extends ModelElement> void getTypesFromKnowledge(Class<ME> clazz) throws SchemaNotFoundException, ResourceRegistryException {
List<Type> types = resourceRegistryClient.getType(clazz, true);
logger.trace("List size {}\n{}", types.size(), getTypeNames(types));
}
@Test
public void testTypesKnowledgeExpiring() throws Exception {
resourceRegistryClient.getModelKnowledge();
resourceRegistryClient.renewModelKnowledge();
}
@Test
public void testModelKnowledge() throws SchemaNotFoundException, ResourceRegistryException {
AccessType[] modelTypes = AccessType.getModelTypes();
for(AccessType accessType : modelTypes) {
getTypesFromKnowledge(accessType.getTypeClass());
}
}
@Test
public void testGetFacetSchema() throws SchemaNotFoundException, ResourceRegistryException {
List<Type> typeDefinitions = resourceRegistryClient.getType(ContactFacet.class, true);
logger.trace("{}", typeDefinitions);
List<Type> types = resourceRegistryClient.getType(ContactFacet.class, true);
logger.trace("List size {}\n{}", types.size(), getTypeNames(types));
}
@Test
public void testGetResourceSchema() throws SchemaNotFoundException, ResourceRegistryException {
List<Type> typeDefinitions = resourceRegistryClient.getType(HostingNode.class, true);
logger.trace("{}", typeDefinitions);
List<Type> types = resourceRegistryClient.getType(HostingNode.class, true);
logger.trace("List size {}\n{}", types.size(), getTypeNames(types));
types = resourceRegistryClient.getType(VirtualService.class, true);
logger.trace("List size {}\n{}", types.size(), getTypeNames(types));
types = resourceRegistryClient.getType(Service.class, true);
logger.trace("List size {}\n{}", types.size(), getTypeNames(types));
}
@Test
public void testGetResourceWithLevel() throws SchemaNotFoundException, ResourceRegistryException {
for(int i=0; i<5; i++) {
List<Type> types = resourceRegistryClient.getType(Resource.class, i);
logger.trace("List size with level {} is {}\n{}", i, types.size(), getTypeNames(types));
}
}
@Test
public void testGetModelKnowledge() throws SchemaNotFoundException, ResourceRegistryException {
AccessType[] modelTypes = AccessType.getModelTypes();
ModelKnowledge<Type, TypeInformation> modelKnowledge = ((ResourceRegistryClientImpl) resourceRegistryClient).getModelKnowledge();
for(AccessType accessType : modelTypes) {
Tree<Type> tree = modelKnowledge.getTree(accessType);
logger.trace("{}", tree);
}
}
@Test
public void testGetResourceTree() throws SchemaNotFoundException, ResourceRegistryException {
Tree<Type> tree = ((ResourceRegistryClientImpl) resourceRegistryClient).getModelKnowledge().getTree(AccessType.RESOURCE);
logger.trace("{}", tree);
}
@Test
public void testGetNode() throws SchemaNotFoundException, ResourceRegistryException {
AccessType[] modelTypes = AccessType.getModelTypes();
for(AccessType accessType : modelTypes) {
Node<Type> node = resourceRegistryClient.getTypeTreeNode(accessType.getTypeClass());
logger.trace("{}", node);
}
}
interface Aux extends Service {
@ -75,7 +152,7 @@ public class ResourceRegistryClientTest extends ContextTest {
@Test(expected = SchemaNotFoundException.class)
public void testException() throws SchemaNotFoundException, ResourceRegistryException {
resourceRegistryClient.getType(Aux.class, true);
resourceRegistryClient.getType("Aux", true);
}
/* The following tests are commented because we need to create the instances for tests. this is done in
@ -89,21 +166,21 @@ public class ResourceRegistryClientTest extends ContextTest {
}
// @Test
public void testExistsByClass() throws ResourceRegistryException {
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
public void testExistsByClass() throws Exception {
UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
resourceRegistryClient.existInstance(EService.class, uuid);
}
// @Test
public void testGetInstance() throws ResourceRegistryException {
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
public void testGetInstance() throws Exception {
UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
String eService = resourceRegistryClient.getInstance(EService.NAME, uuid);
logger.trace("{}", eService);
}
// @Test
public void testGetInstanceByClass() throws ResourceRegistryException {
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
public void testGetInstanceByClass() throws Exception {
UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
EService eService = resourceRegistryClient.getInstance(EService.class, uuid);
logger.trace("{}", eService);
}
@ -128,11 +205,12 @@ public class ResourceRegistryClientTest extends ContextTest {
}
// @Test
public void testGetRelatedResourcesFromReferenceResourceByClasses() throws ResourceRegistryException {
UUID uuid = UUID.fromString("b0d15e45-62af-4221-b785-7d014f10e631");
public void testGetRelatedResourcesFromReferenceResourceByClasses() throws Exception {
UUID uuid = UUIDUtility.fromString("b0d15e45-62af-4221-b785-7d014f10e631");
HostingNode hostingNode = new HostingNodeImpl();
Header header = new HeaderImpl(uuid);
hostingNode.setHeader(header);
hostingNode.setID(uuid);
Metadata metadata = new MetadataImpl();
hostingNode.setMetadata(metadata);
List<EService> eServices = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class,
IsRelatedTo.class, hostingNode, Direction.OUT, true);
logger.trace("{}", eServices);
@ -154,9 +232,9 @@ public class ResourceRegistryClientTest extends ContextTest {
// @Test
public void testGetResourcesFromReferenceFacet() throws ResourceRegistryException, JsonProcessingException {
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
UUID uuid = UUID.fromString("cbdf3e61-524c-4800-91a6-3ff3e06fbee3");
Header header = new HeaderImpl(uuid);
softwareFacet.setHeader(header);
softwareFacet.setID(UUIDManager.getInstance().generateValidUUID());
Metadata metadata = new MetadataImpl();
softwareFacet.setMetadata(metadata);
List<EService> eServices = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacet, true);
for(EService eService : eServices) {
logger.trace("{}", ElementMapper.marshal(eService));
@ -174,11 +252,11 @@ public class ResourceRegistryClientTest extends ContextTest {
for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID();
UUID uuid = c.getID();
if(c.getParent()!=null) {
IsParentOf isParentOf = c.getParent();
Context parentContext = isParentOf.getSource();
UUID parentUUID = parentContext.getHeader().getUUID();
UUID parentUUID = parentContext.getID();
Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID));
List<IsParentOf> children = parentContext.getChildren();
boolean found = false;
@ -189,9 +267,9 @@ public class ResourceRegistryClientTest extends ContextTest {
}
}
Assert.assertTrue(found);
logger.debug("{} : {} (parent {} : {})", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
logger.debug("{} : {} (parent {} : {})", c.getID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
}else {
logger.debug("{} : {}", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid));
logger.debug("{} : {}", c.getID(), contextCache.getContextFullNameByUUID(uuid));
}
}
@ -199,11 +277,39 @@ public class ResourceRegistryClientTest extends ContextTest {
logger.debug("Current context : {}", currentContext);
for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID();
UUID uuid = c.getID();
Context context = resourceRegistryClient.getContext(uuid);
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
logger.debug("{} - {} : {}", uuid, fullName, context);
}
}
@Test
public void testParameters() throws Exception {
resourceRegistryClient.setLimit(1);
resourceRegistryClient.setIncludeMeta(true);
List<Context> contexts = ((ResourceRegistryClientImpl) resourceRegistryClient).getAllContextFromServer();
Assert.assertTrue(contexts.size()==1);
Assert.assertTrue(contexts.get(0).getMetadata()!=null);
resourceRegistryClient.setLimit(1);
resourceRegistryClient.setIncludeMeta(false);
contexts = ((ResourceRegistryClientImpl) resourceRegistryClient).getAllContextFromServer();
Assert.assertTrue(contexts.size()==1);
Assert.assertTrue(contexts.get(0).getMetadata()==null);
}
@Test
public void testRunQueryTemplates() throws Exception {
String ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-HostingNode");
logger.trace(ret);
ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-EService");
logger.trace(ret);
ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-HostingNode", "{}");
logger.trace(ret);
ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-EService", "{}");
logger.trace(ret);
}
}

View File

@ -9,12 +9,12 @@ import java.util.Map;
import java.util.UUID;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.UUIDUtility;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet;
@ -24,6 +24,7 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNo
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Hosts;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -64,25 +65,27 @@ public class ResourceRegistryClientTestWikiExamples extends ContextTest {
}
@Test
public void testExample2() throws ResourceRegistryException {
UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
@Ignore
public void testExample2() throws Exception {
UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
List<EService> list = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, uuid, true);
logger.debug("{}", list);
}
@Test
@Ignore
public void testExample2Alt() throws ResourceRegistryException, Exception{
SoftwareFacet softwareFacetInstance = new SoftwareFacetImpl();
UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
Header header = new HeaderImpl(uuid);
softwareFacetInstance.setHeader(header);
UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
softwareFacetInstance.setID(uuid);
List<EService> list = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacetInstance, true);
logger.debug("{}", list);
}
@Test
@Ignore
public void testExample2Alt2() throws ResourceRegistryException, Exception{
UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
String jsonString = resourceRegistryClient.getResourcesFromReferenceFacet("EService", "IsIdentifiedBy", "SoftwareFacet", uuid, true);
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
logger.debug("{}", list);
@ -164,32 +167,34 @@ public class ResourceRegistryClientTestWikiExamples extends ContextTest {
}
@Test
public void testExample7Alt() throws ResourceRegistryException, Exception {
public void testExample7Alt() throws Exception {
String jsonString = resourceRegistryClient.getRelatedResources("EService", "Hosts", "HostingNode", Direction.IN, true);
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
logger.debug("{}", list);
}
@Test
public void testExample8() throws ResourceRegistryException {
UUID uuid = UUID.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
@Ignore
public void testExample8() throws Exception {
UUID uuid = UUIDUtility.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
List<EService> list = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class, Hosts.class, HostingNode.class, uuid, Direction.IN, true);
logger.debug("{}", list);
}
@Test
public void testExample8Alt() throws ResourceRegistryException, Exception{
@Ignore
public void testExample8Alt() throws Exception{
HostingNode hostingNodeInstance = new HostingNodeImpl();
UUID uuid = UUID.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
Header header = new HeaderImpl(uuid);
hostingNodeInstance.setHeader(header);
UUID uuid = UUIDUtility.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
hostingNodeInstance.setID(uuid);
List<EService> list = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class, Hosts.class, hostingNodeInstance, Direction.IN, true);
logger.debug("{}", list);
}
@Test
public void testExample8Alt2() throws ResourceRegistryException, Exception{
UUID uuid = UUID.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
@Ignore
public void testExample8Alt2() throws Exception{
UUID uuid = UUIDUtility.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
String jsonString = resourceRegistryClient.getRelatedResourcesFromReferenceResource("EService", "Hosts", "HostingNode", uuid, Direction.IN, true);
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
logger.debug("{}", list);
@ -211,23 +216,23 @@ public class ResourceRegistryClientTestWikiExamples extends ContextTest {
@Test
public void jsonQueryExample1() throws ResourceRegistryException, Exception{
String jsonQuery = "{\n"
+ " \"@class\": \"EService\",\n"
+ " \"" + Element.TYPE_PROPERTY + "\": \"EService\",\n"
+ " \"consistsOf\": [\n"
+ " {\n"
+ " \"@class\": \"IsIdentifiedBy\",\n"
+ " \"" + Element.TYPE_PROPERTY + "\": \"IsIdentifiedBy\",\n"
+ " \"target\": {\n"
+ " \"@class\": \"SoftwareFacet\",\n"
+ " \"" + Element.TYPE_PROPERTY + "\": \"SoftwareFacet\",\n"
+ " \"group\": \"DataTransfer\",\n"
+ " \"name\": \"data-transfer-service\"\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " {\n"
+ " \"@class\": \"ConsistsOf\",\n"
+ " \"" + Element.TYPE_PROPERTY + "\": \"ConsistsOf\",\n"
+ " \"target\": {\n"
+ " \"@class\": \"StateFacet\",\n"
+ " \"" + Element.TYPE_PROPERTY + "\": \"StateFacet\",\n"
+ " \"value\": \"down\"\n"
+ " }\n"
+ " },\n"
+ " }\n"
+ " \n"
+ " ]\n"
+ "}";