Compare commits
20 Commits
Author | SHA1 | Date |
---|---|---|
|
45f837ae61 | |
|
94e11b2665 | |
|
8bccea574f | |
|
c171876186 | |
|
7d4bb7d70f | |
|
fdf33f87a1 | |
|
85cb4a4e55 | |
|
c26b70520a | |
|
848d1ee835 | |
|
5189194b5e | |
|
384a7bdaf7 | |
|
2113a6ee97 | |
|
30eac775f6 | |
|
660f0ea4a5 | |
|
b17edcb160 | |
|
3b125dfa15 | |
|
9eceb98059 | |
|
0cc1ead630 | |
|
29b559a71a | |
|
164be53064 |
|
@ -2,6 +2,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
# Changelog for Resource Registry Client
|
# 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]
|
## [v4.4.0]
|
||||||
|
|
||||||
- Migrated code to reorganized E/R format [#24992]
|
- Migrated code to reorganized E/R format [#24992]
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.information-system</groupId>
|
<groupId>org.gcube.information-system</groupId>
|
||||||
<artifactId>resource-registry-client</artifactId>
|
<artifactId>resource-registry-client</artifactId>
|
||||||
<version>4.4.0</version>
|
<version>4.5.0-SNAPSHOT</version>
|
||||||
<name>Resource Registry Client</name>
|
<name>Resource Registry Client</name>
|
||||||
<description>Resource Registry Client is a library designed to interact with idempotent Resource Registry APIs</description>
|
<description>Resource Registry Client is a library designed to interact with idempotent Resource Registry APIs</description>
|
||||||
|
|
||||||
|
@ -49,10 +49,6 @@
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>gxHTTP</artifactId>
|
<artifactId>gxHTTP</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>common-utility-sg3</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,13 +7,16 @@ import java.util.UUID;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.informationsystem.base.reference.Direction;
|
import org.gcube.informationsystem.base.reference.Direction;
|
||||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
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.ERElement;
|
||||||
|
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
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.AvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
@ -22,6 +25,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.Inval
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
|
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.exceptions.types.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo;
|
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;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +53,8 @@ public interface ResourceRegistryClient extends RequestInfo {
|
||||||
|
|
||||||
public List<Context> getAllContext() throws ResourceRegistryException;
|
public List<Context> getAllContext() throws ResourceRegistryException;
|
||||||
|
|
||||||
|
public ContextCache getContextCache();
|
||||||
|
|
||||||
public boolean existContext(String uuid) throws ContextNotFoundException, ResourceRegistryException;
|
public boolean existContext(String uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public boolean existContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
|
public boolean existContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
@ -60,16 +67,32 @@ public interface ResourceRegistryClient extends RequestInfo {
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
public ModelKnowledge<Type, TypeInformation> getModelKnowledge();
|
||||||
|
|
||||||
|
public void renewModelKnowledge();
|
||||||
|
|
||||||
public boolean existType(String typeName) throws ResourceRegistryException;
|
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)
|
public String getType(String typeName, Boolean polymorphic)
|
||||||
throws SchemaNotFoundException, ResourceRegistryException;
|
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)
|
public <ERElem extends ERElement> List<ERElem> getInstances(Class<ERElem> clazz, Boolean polymorphic)
|
||||||
|
@ -117,19 +140,19 @@ public interface ResourceRegistryClient extends RequestInfo {
|
||||||
public String runQueryTemplateGetString(String name)
|
public String runQueryTemplateGetString(String name)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Entity> List<E> runQueryTemplate(String name)
|
public String runQueryTemplate(String name)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate)
|
public String runQueryTemplate(QueryTemplate queryTemplate)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public String runQueryTemplate(String name, String params)
|
public String runQueryTemplate(String name, String params)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Entity> List<E> runQueryTemplate(String name, JsonNode jsonNode)
|
public String runQueryTemplate(String name, JsonNode jsonNode)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
|
public String runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JavaType;
|
import org.gcube.com.fasterxml.jackson.databind.JavaType;
|
||||||
|
@ -15,13 +16,13 @@ import org.gcube.common.gxhttp.reference.GXConnection;
|
||||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||||
import org.gcube.common.http.GXHTTPUtility;
|
import org.gcube.common.http.GXHTTPUtility;
|
||||||
import org.gcube.informationsystem.base.reference.Direction;
|
import org.gcube.informationsystem.base.reference.Direction;
|
||||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
|
||||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
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.ERElement;
|
||||||
|
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
|
||||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||||
|
@ -36,6 +37,7 @@ 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.InvalidQueryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
|
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.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.AccessPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
||||||
|
@ -43,7 +45,10 @@ import org.gcube.informationsystem.resourceregistry.api.rest.QueryTemplatePath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
|
import org.gcube.informationsystem.tree.Node;
|
||||||
import org.gcube.informationsystem.types.TypeMapper;
|
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.types.reference.Type;
|
||||||
import org.gcube.informationsystem.utils.TypeUtility;
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -52,7 +57,7 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @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 Logger logger = LoggerFactory.getLogger(ResourceRegistryClientImpl.class);
|
||||||
|
|
||||||
|
@ -63,38 +68,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
|
|
||||||
protected Map<String, String> headers;
|
protected Map<String, String> headers;
|
||||||
|
|
||||||
/**
|
|
||||||
* Track if the client must request the hierarchicalMode
|
|
||||||
*/
|
|
||||||
protected boolean hierarchicalMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Track if the client must request to include contexts
|
|
||||||
*/
|
|
||||||
protected boolean includeContexts;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Track if the client must request to include {@link Metadata}
|
|
||||||
*/
|
|
||||||
protected boolean includeMeta;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Track if the client must request to include {@link Metadata} in all
|
|
||||||
* {@link IdentifiableElement} or just in the root instance
|
|
||||||
*/
|
|
||||||
protected boolean allMeta;
|
|
||||||
|
|
||||||
protected ContextCache contextCache;
|
protected ContextCache contextCache;
|
||||||
|
|
||||||
@Override
|
protected TypesKnowledge typesKnowledge;
|
||||||
public boolean isHierarchicalMode() {
|
|
||||||
return hierarchicalMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHierarchicalMode(boolean hierarchicalMode) {
|
|
||||||
this.hierarchicalMode = hierarchicalMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
|
@ -108,33 +84,6 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
setIncludeContexts(includeContexts);
|
setIncludeContexts(includeContexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean includeContexts() {
|
|
||||||
return includeContexts;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIncludeContexts(boolean includeContexts) {
|
|
||||||
this.includeContexts = includeContexts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean includeMeta() {
|
|
||||||
return includeMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIncludeMeta(boolean includeMeta) {
|
|
||||||
this.includeMeta = includeMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean allMeta() {
|
|
||||||
return allMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllMeta(boolean allMeta) {
|
|
||||||
this.allMeta = allMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
|
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
|
||||||
addHierarchicalMode(queryParams);
|
addHierarchicalMode(queryParams);
|
||||||
addIncludeContexts(queryParams);
|
addIncludeContexts(queryParams);
|
||||||
|
@ -168,6 +117,10 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
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) {
|
if(includeMeta) {
|
||||||
queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
|
queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
|
||||||
}
|
}
|
||||||
|
@ -179,11 +132,31 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Context> renew() throws ResourceRegistryException {
|
public List<Context> renew() throws ResourceRegistryException {
|
||||||
return getAllContextFromServer();
|
return getAllContextFromServer(true, 0, BaseRequestInfo.UNBOUNDED_LIMIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -203,22 +176,26 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceRegistryClientImpl(String address) {
|
public ResourceRegistryClientImpl(String address) {
|
||||||
this(address, true);
|
this(address, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceRegistryClientImpl(String address, boolean sharedContextCache) {
|
public ResourceRegistryClientImpl(String address, boolean sharedContextCache, boolean sharedModelKnowledge) {
|
||||||
|
super();
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.hierarchicalMode = false;
|
|
||||||
this.includeContexts = false;
|
|
||||||
this.includeMeta = false;
|
|
||||||
this.allMeta = false;
|
|
||||||
this.headers = new HashMap<>();
|
this.headers = new HashMap<>();
|
||||||
if(sharedContextCache) {
|
if(sharedContextCache) {
|
||||||
contextCache = ContextCache.getInstance();
|
this.contextCache = ContextCache.getInstance();
|
||||||
}else {
|
}else {
|
||||||
contextCache = new ContextCache();
|
this.contextCache = new ContextCache();
|
||||||
}
|
}
|
||||||
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
this.contextCache.setContextCacheRenewal(contextCacheRenewal);
|
||||||
|
|
||||||
|
if(sharedModelKnowledge) {
|
||||||
|
this.typesKnowledge = TypesKnowledge.getInstance();
|
||||||
|
}else {
|
||||||
|
this.typesKnowledge = new TypesKnowledge();
|
||||||
|
}
|
||||||
|
typesKnowledge.setTypesDiscoverer(new RRCTypesDiscoverer(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,6 +205,10 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
* @throws ResourceRegistryException
|
* @throws ResourceRegistryException
|
||||||
*/
|
*/
|
||||||
public List<Context> getAllContextFromServer() 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 {
|
try {
|
||||||
logger.info("Going to read all {}s", Context.NAME);
|
logger.info("Going to read all {}s", Context.NAME);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
|
@ -236,7 +217,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
||||||
|
|
||||||
Map<String,String> parameters = new HashMap<>();
|
Map<String,String> parameters = new HashMap<>();
|
||||||
addIncludeMeta(parameters);
|
addIncludeMeta(parameters, includeMeta);
|
||||||
|
addOffset(parameters, offset);
|
||||||
|
addLimit(parameters, limit);
|
||||||
gxHTTPStringRequest.queryParams(parameters);
|
gxHTTPStringRequest.queryParams(parameters);
|
||||||
|
|
||||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||||
|
@ -263,6 +246,21 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
return contextCache.getContexts();
|
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.
|
* It reads the context from server.
|
||||||
* The cache used for contexts is bypassed and not updated.
|
* The cache used for contexts is bypassed and not updated.
|
||||||
|
@ -365,12 +363,20 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <ERElem extends ERElement> boolean existType(Class<ERElem> clazz) throws ResourceRegistryException {
|
public <ME extends ModelElement> boolean existType(Class<ME> clazz) throws ResourceRegistryException {
|
||||||
return existType(TypeUtility.getTypeName(clazz));
|
return existType(TypeUtility.getTypeName(clazz));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean existType(String typeName) throws ResourceRegistryException {
|
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 {
|
try {
|
||||||
logger.info("Going to get {} schema", typeName);
|
logger.info("Going to get {} schema", typeName);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
|
@ -397,25 +403,139 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
// logger.trace("Error while getting {}schema for {}", polymorphic ?
|
// logger.trace("Error while getting {}schema for {}", polymorphic ?
|
||||||
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
||||||
// type, e);
|
// 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
|
@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 {
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String json = getType(TypeUtility.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);
|
return TypeMapper.deserializeTypeDefinitions(json);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String getTypeFromServer(String typeName, Boolean polymorphic)
|
||||||
public String getType(String typeName, Boolean polymorphic)
|
|
||||||
throws SchemaNotFoundException, ResourceRegistryException {
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get {} schema", typeName);
|
logger.info("Going to get {} schema", typeName);
|
||||||
|
@ -471,6 +591,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
|
|
||||||
Map<String,String> parameters = new HashMap<>();
|
Map<String,String> parameters = new HashMap<>();
|
||||||
|
addOffset(parameters);
|
||||||
|
addLimit(parameters);
|
||||||
parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
||||||
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
|
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
|
||||||
|
|
||||||
|
@ -984,22 +1106,35 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
return runQueryTemplate(name, "");
|
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
|
@Override
|
||||||
public <E extends Entity> List<E> runQueryTemplate(String name)
|
public String runQueryTemplate(String name)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String ret = runQueryTemplateGetString(name);
|
String ret = runQueryTemplateGetString(name);
|
||||||
JavaType type = ElementMapper.getObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Entity.class);
|
return ret;
|
||||||
return ElementMapper.getObjectMapper().readValue(ret, type);
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate)
|
public String runQueryTemplate(QueryTemplate queryTemplate)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||||
return runQueryTemplate(queryTemplate.getName());
|
return runQueryTemplate(queryTemplate.getName());
|
||||||
}
|
}
|
||||||
|
@ -1037,7 +1172,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends Entity> List<E> runQueryTemplate(String name, JsonNode jsonNode)
|
public String runQueryTemplate(String name, JsonNode jsonNode)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
@ -1052,7 +1187,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends Entity> List<E> runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
|
public String runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
|
||||||
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||||
return runQueryTemplate(queryTemplate.getName(), jsonNode);
|
return runQueryTemplate(queryTemplate.getName(), jsonNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
||||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||||
|
import org.gcube.common.keycloak.KeycloakClientHelper;
|
||||||
import org.gcube.common.keycloak.model.TokenResponse;
|
import org.gcube.common.keycloak.model.TokenResponse;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class ContextTest {
|
public class ContextTest {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||||
|
@ -40,14 +39,13 @@ public class ContextTest {
|
||||||
public static final String NEXTNEXT;
|
public static final String NEXTNEXT;
|
||||||
public static final String DEVSEC;
|
public static final String DEVSEC;
|
||||||
public static final String DEVVRE;
|
public static final String DEVVRE;
|
||||||
|
|
||||||
protected static final Properties properties;
|
protected static final Properties properties;
|
||||||
|
|
||||||
protected static final String CLIENT_ID_PROPERTY_KEY = "client_id";
|
public static final String TYPE_PROPERTY_KEY = "type";
|
||||||
protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret";
|
public static final String USERNAME_PROPERTY_KEY = "username";
|
||||||
|
public static final String PASSWORD_PROPERTY_KEY = "password";
|
||||||
protected static final String clientID;
|
public static final String CLIENT_ID_PROPERTY_KEY = "clientId";
|
||||||
protected static final String clientSecret;
|
|
||||||
|
|
||||||
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
|
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
|
||||||
public static final String RESOURCE_REGISTRY_URL;
|
public static final String RESOURCE_REGISTRY_URL;
|
||||||
|
@ -69,9 +67,6 @@ public class ContextTest {
|
||||||
// load the properties file
|
// load the properties file
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
|
|
||||||
clientID = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
|
||||||
clientSecret = properties.getProperty(CLIENT_SECRET_PROPERTY_KEY);
|
|
||||||
|
|
||||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -80,6 +75,10 @@ public class ContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum Type{
|
||||||
|
USER, CLIENT_ID
|
||||||
|
};
|
||||||
|
|
||||||
public static void set(Secret secret) throws Exception {
|
public static void set(Secret secret) throws Exception {
|
||||||
SecretManagerProvider.instance.reset();
|
SecretManagerProvider.instance.reset();
|
||||||
SecretManager secretManager = new SecretManager();
|
SecretManager secretManager = new SecretManager();
|
||||||
|
@ -89,15 +88,56 @@ public class ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setContextByName(String fullContextName) throws Exception {
|
public static void setContextByName(String fullContextName) throws Exception {
|
||||||
|
logger.debug("Going to set credentials for context {}", fullContextName);
|
||||||
Secret secret = getSecretByContextName(fullContextName);
|
Secret secret = getSecretByContextName(fullContextName);
|
||||||
set(secret);
|
set(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||||
ScopeProvider.instance.set(context);
|
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
|
||||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
|
||||||
return tr;
|
TokenResponse tr = null;
|
||||||
|
|
||||||
|
int index = context.indexOf('/', 1);
|
||||||
|
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return tr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Secret getSecretByContextName(String context) throws Exception {
|
public static Secret getSecretByContextName(String context) throws Exception {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,16 +3,20 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.informationsystem.resourceregistry.client;
|
package org.gcube.informationsystem.resourceregistry.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
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.base.reference.Direction;
|
||||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
||||||
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
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.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
|
@ -20,6 +24,9 @@ import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
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.types.reference.Type;
|
||||||
import org.gcube.informationsystem.utils.UUIDManager;
|
import org.gcube.informationsystem.utils.UUIDManager;
|
||||||
import org.gcube.informationsystem.utils.UUIDUtility;
|
import org.gcube.informationsystem.utils.UUIDUtility;
|
||||||
|
@ -30,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.EService;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
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.Service;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.resources.VirtualService;
|
||||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -60,16 +68,82 @@ public class ResourceRegistryClientTest extends ContextTest {
|
||||||
logger.trace(res);
|
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
|
@Test
|
||||||
public void testGetFacetSchema() throws SchemaNotFoundException, ResourceRegistryException {
|
public void testGetFacetSchema() throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
List<Type> typeDefinitions = resourceRegistryClient.getType(ContactFacet.class, true);
|
List<Type> types = resourceRegistryClient.getType(ContactFacet.class, true);
|
||||||
logger.trace("{}", typeDefinitions);
|
logger.trace("List size {}\n{}", types.size(), getTypeNames(types));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetResourceSchema() throws SchemaNotFoundException, ResourceRegistryException {
|
public void testGetResourceSchema() throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
List<Type> typeDefinitions = resourceRegistryClient.getType(HostingNode.class, true);
|
List<Type> types = resourceRegistryClient.getType(HostingNode.class, true);
|
||||||
logger.trace("{}", typeDefinitions);
|
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 {
|
interface Aux extends Service {
|
||||||
|
@ -210,4 +284,32 @@ public class ResourceRegistryClientTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue