Compare commits
79 Commits
Author | SHA1 | Date |
---|---|---|
Luca Frosini | 45f837ae61 | |
Luca Frosini | 94e11b2665 | |
Luca Frosini | 8bccea574f | |
luca.frosini | c171876186 | |
luca.frosini | 7d4bb7d70f | |
luca.frosini | fdf33f87a1 | |
luca.frosini | 85cb4a4e55 | |
luca.frosini | c26b70520a | |
luca.frosini | 848d1ee835 | |
luca.frosini | 5189194b5e | |
luca.frosini | 384a7bdaf7 | |
luca.frosini | 2113a6ee97 | |
luca.frosini | 30eac775f6 | |
luca.frosini | 660f0ea4a5 | |
luca.frosini | b17edcb160 | |
luca.frosini | 3b125dfa15 | |
luca.frosini | 9eceb98059 | |
luca.frosini | 0cc1ead630 | |
luca.frosini | 29b559a71a | |
luca.frosini | 164be53064 | |
luca.frosini | de47918497 | |
luca.frosini | 5128f4ad63 | |
Luca Frosini | 1f0835775b | |
Luca Frosini | cb7bd04bc2 | |
Luca Frosini | 5df6c19a24 | |
Luca Frosini | c933cc3f85 | |
Luca Frosini | 047e0d448d | |
Luca Frosini | 34a2dd7959 | |
Luca Frosini | b04623028e | |
Luca Frosini | 75b5acb932 | |
Luca Frosini | 3faac2a236 | |
Luca Frosini | 484a467d55 | |
Luca Frosini | bb9e1fdd93 | |
Luca Frosini | 037d119697 | |
Luca Frosini | faa0642224 | |
Luca Frosini | ac164abb46 | |
Luca Frosini | fdf9e71068 | |
Luca Frosini | e9611dcafc | |
Luca Frosini | 6639589e9e | |
Luca Frosini | 022b3acc8b | |
Luca Frosini | 91a03750a0 | |
Luca Frosini | d4ba9022d4 | |
Luca Frosini | a0dd4422b0 | |
Luca Frosini | 59f4abda63 | |
Luca Frosini | 46091ad285 | |
Luca Frosini | ee9344cee1 | |
Luca Frosini | 9b84168926 | |
Luca Frosini | 196907d4de | |
Luca Frosini | 91e3f790cd | |
Luca Frosini | 973d60eb04 | |
Luca Frosini | 836d66bec4 | |
Luca Frosini | 85ed707f44 | |
Luca Frosini | 888d666b79 | |
Luca Frosini | 2c75dde1b8 | |
Luca Frosini | d3d92cbbf7 | |
Luca Frosini | c63dc4c4c8 | |
Luca Frosini | 3b06356a26 | |
Luca Frosini | f115e9b4b9 | |
Luca Frosini | ec50b30abc | |
Luca Frosini | b3c254161c | |
Luca Frosini | 5744607834 | |
Luca Frosini | 9a856a68f8 | |
Luca Frosini | 8a4a70673c | |
Luca Frosini | 0121657b4b | |
Luca Frosini | 4d2f87e83c | |
Luca Frosini | 8ead38f561 | |
Luca Frosini | e907c029f9 | |
Luca Frosini | 57d0a5dbc4 | |
Luca Frosini | 5914112a5f | |
Luca Frosini | ac2cd3edd7 | |
Luca Frosini | 11a79f3724 | |
Luca Frosini | 1c40bf3515 | |
Luca Frosini | f9a2a599d9 | |
Luca Frosini | ac1f23c36e | |
Luca Frosini | 9909a87644 | |
Luca Frosini | 4cb760f4c3 | |
Luca Frosini | 79f4fe330b | |
Luca Frosini | 192bb0adf5 | |
Luca Frosini | 34fca63cc2 |
|
@ -1,3 +1,5 @@
|
|||
target
|
||||
.classpath
|
||||
.project
|
||||
/.DS_Store
|
||||
/bin/
|
||||
|
|
32
CHANGELOG.md
32
CHANGELOG.md
|
@ -2,16 +2,48 @@ 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]
|
||||
- Moved Direction class in information-system-model
|
||||
- Added support for context names included in header among UUIDs [#22090]
|
||||
- Added JSON Query API [#22047][#22815]
|
||||
- Added QueryTemplate safe APIs [#22091][#22815]
|
||||
- Client gets service URL using resource-registry-api lib utility [#23658]
|
||||
|
||||
|
||||
## [v4.1.0]
|
||||
|
||||
- Used ContextCache to make the client more efficient
|
||||
- Added APIs to get instance contexts [#20013]
|
||||
- Added support to request contexts in instances header [#20012]
|
||||
|
||||
|
||||
## [v4.0.0] [r4.26.0] - 2020-11-11
|
||||
|
||||
- Switched JSON management to gcube-jackson [#19116]
|
||||
|
||||
|
||||
## [v3.0.0] [r4.21.0] - 2020-03-30
|
||||
|
||||
- Refactored code to support IS Model reorganization (e.g naming, packages)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# Acknowledgments
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
|
||||
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
|
||||
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
|
||||
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
|
||||
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
|
||||
- the H2020 research and innovation programme
|
||||
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
|
||||
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
|
||||
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
|
||||
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
|
||||
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
|
||||
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
|
||||
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
|
||||
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
|
||||
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
|
||||
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
|
||||
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
|
||||
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
|
||||
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);
|
24
README.md
24
README.md
|
@ -45,26 +45,4 @@ open-source software toolkit used for building and operating Hybrid Data
|
|||
Infrastructures enabling the dynamic deployment of Virtual Research Environments
|
||||
by favouring the realisation of reuse oriented policies.
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- DILIGENT (grant no. 004260).
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- D4Science (grant no. 212488);
|
||||
- D4Science-II (grant no.239019);
|
||||
- ENVRI (grant no. 283465);
|
||||
- iMarine(grant no. 283644);
|
||||
- EUBrazilOpenBio (grant no. 288754).
|
||||
- the H2020 research and innovation programme
|
||||
- SoBigData (grant no. 654024);
|
||||
- PARTHENOS (grant no. 654119);
|
||||
- EGIEngage (grant no. 654142);
|
||||
- ENVRIplus (grant no. 654182);
|
||||
- BlueBRIDGE (grant no. 675680);
|
||||
- PerformFish (grant no. 727610);
|
||||
- AGINFRAplus (grant no. 731001);
|
||||
- DESIRA (grant no. 818194);
|
||||
- ARIADNEplus (grant no. 823914);
|
||||
- RISIS2 (grant no. 824091);
|
||||
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)
|
||||
|
|
18
pom.xml
18
pom.xml
|
@ -9,7 +9,7 @@
|
|||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-client</artifactId>
|
||||
<version>4.1.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.0.1</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>
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public enum Direction {
|
||||
|
||||
IN, OUT, BOTH;
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,50 +2,164 @@ package org.gcube.informationsystem.resourceregistry.client;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
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;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
||||
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 interface ResourceRegistryClient extends RequestInfo {
|
||||
|
||||
public <IE extends IdentifiableElement> boolean exists(Class<IE> clazz, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
/**
|
||||
* Use {@link #includeContexts()} instead
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isIncludeContextsInHeader();
|
||||
|
||||
public boolean exists(String type, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
/**
|
||||
* Use {@link #includeContexts(boolean)} instead
|
||||
* @param includeContextsInHeader
|
||||
*/
|
||||
@Deprecated
|
||||
public void setIncludeContextsInHeader(boolean includeContexts);
|
||||
|
||||
public <IE extends IdentifiableElement> IE getInstance(Class<IE> clazz, UUID uuid)
|
||||
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;
|
||||
|
||||
public Context getContext(String uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
public ModelKnowledge<Type, TypeInformation> getModelKnowledge();
|
||||
|
||||
public void renewModelKnowledge();
|
||||
|
||||
public boolean existType(String typeName) throws ResourceRegistryException;
|
||||
|
||||
public <ME extends ModelElement> boolean existType(Class<ME> clazz) throws ResourceRegistryException;
|
||||
|
||||
public String getType(String typeName, 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)
|
||||
throws ResourceRegistryException;
|
||||
|
||||
public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException;
|
||||
|
||||
public <ERElem extends ERElement> boolean existInstance(Class<ERElem> clazz, UUID uuid)
|
||||
throws AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public boolean existInstance(String type, UUID uuid)
|
||||
throws AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <ERElem extends ERElement> ERElem getInstance(Class<ERElem> clazz, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public String getInstance(String type, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement, R extends Resource> List<R> getInstances(Class<IE> clazz, Boolean polymorphic)
|
||||
throws ResourceRegistryException;
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException;
|
||||
public <ERElem extends ERElement> Map<UUID, String> getInstanceContexts(Class<ERElem> clazz, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, String> getInstanceContexts(String type, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
public List<QueryTemplate> getAllQueryTemplates() throws ResourceRegistryException;
|
||||
|
||||
public boolean existQueryTemplate(QueryTemplate queryTemplate) throws ResourceRegistryException;
|
||||
|
||||
public boolean existQueryTemplate(String queryTemplateName) throws ResourceRegistryException;
|
||||
|
||||
public QueryTemplate readQueryTemplate(QueryTemplate queryTemplate)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public QueryTemplate readQueryTemplate(String queryTemplateName)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String readQueryTemplateAsString(String queryTemplateName)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String runQueryTemplateGetString(String name)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String runQueryTemplate(String name)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String runQueryTemplate(QueryTemplate queryTemplate)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String runQueryTemplate(String name, String params)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String runQueryTemplate(String name, JsonNode jsonNode)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String runQueryTemplate(QueryTemplate queryTemplate, JsonNode jsonNode)
|
||||
throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
public <R extends Resource, C extends ConsistsOf<?, ?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
|
||||
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, F referenceFacet,
|
||||
boolean polymorphic) throws ResourceRegistryException;
|
||||
Class<R> resourceClass, Class<C> consistsOfClass, F referenceFacet, boolean polymorphic)
|
||||
throws ResourceRegistryException;
|
||||
|
||||
public <R extends Resource, C extends ConsistsOf<?, ?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
|
||||
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, UUID referenceFacetUUID,
|
||||
|
@ -54,28 +168,25 @@ public interface ResourceRegistryClient {
|
|||
public String getResourcesFromReferenceFacet(String resourceType, String consistsOfType, String facetType,
|
||||
UUID referenceFacetUUID, boolean polymorphic) throws ResourceRegistryException;
|
||||
|
||||
|
||||
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> map) throws ResourceRegistryException;
|
||||
Map<String, String> facetConstraint) throws ResourceRegistryException;
|
||||
|
||||
public String getFilteredResources(String resourceType, String consistsOfType, String facetType,
|
||||
boolean polymorphic, Map<String,String> map) throws ResourceRegistryException;
|
||||
|
||||
boolean polymorphic, Map<String, String> facetConstraint) throws ResourceRegistryException;
|
||||
|
||||
public <R extends Resource, I extends IsRelatedTo<?, ?>, RR extends Resource> List<R> getRelatedResourcesFromReferenceResource(
|
||||
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> referenceResourceClass, RR referenceResource,
|
||||
Direction direction, boolean polymorphic) throws ResourceRegistryException;
|
||||
Class<R> resourceClass, Class<I> isRelatedToClass, RR referenceResource, Direction direction,
|
||||
boolean polymorphic) throws ResourceRegistryException;
|
||||
|
||||
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;
|
||||
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> referenceResourceClass,
|
||||
UUID referenceResourceUUID, Direction direction, boolean polymorphic) throws ResourceRegistryException;
|
||||
|
||||
public String getRelatedResourcesFromReferenceResource(String resourceType, String isRelatedToType,
|
||||
String referenceResourceType, UUID referenceResourceUUID, Direction direction, boolean polymorphic)
|
||||
throws ResourceRegistryException;
|
||||
|
||||
|
||||
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;
|
||||
|
@ -83,46 +194,20 @@ public interface ResourceRegistryClient {
|
|||
public String getRelatedResources(String resourceType, String isRelatedToType, String referenceResourceType,
|
||||
Direction direction, boolean polymorphic) throws ResourceRegistryException;
|
||||
|
||||
/*
|
||||
public <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,Object> map) throws ResourceRegistryException;
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
public String getRelated(String entityType, String relationType, String referenceEntityType, Direction direction,
|
||||
boolean polymorphic, Map<String,Object> map) throws ResourceRegistryException;
|
||||
|
||||
public <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;
|
||||
|
||||
public <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;
|
||||
|
||||
public String getRelated(String entityType, String relationType, String referenceEntityType, UUID referenceEntity,
|
||||
Direction direction, boolean polymorphic) throws ResourceRegistryException;
|
||||
*/
|
||||
|
||||
|
||||
public String query(final String query, final int limit, final String fetchPlan)
|
||||
public String jsonQuery(final String query)
|
||||
throws InvalidQueryException, ResourceRegistryException;
|
||||
|
||||
public String query(final String query, final int limit, final String fetchPlan, boolean raw)
|
||||
public <E extends Entity> List<E> jsonQuery(final JsonNode jsonNode)
|
||||
throws InvalidQueryException, ResourceRegistryException;
|
||||
|
||||
public <E extends Element> List<Type> getSchema(Class<E> clazz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException;
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||
public String rawQuery(final String query)
|
||||
throws InvalidQueryException, ResourceRegistryException;
|
||||
|
||||
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<Context> getAllContext() throws ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement> Set<UUID> getInstanceContexts(Class<IE> clazz, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public Set<UUID> getInstanceContexts(String type, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
public String rawQuery(final String query, boolean raw)
|
||||
throws InvalidQueryException, ResourceRegistryException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.resourceregistry.api.Constants;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.ServiceInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -22,129 +12,25 @@ public class ResourceRegistryClientFactory {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryClientFactory.class);
|
||||
|
||||
protected static boolean HIERARCHICAL_MODE;
|
||||
|
||||
protected static boolean isHierarchicalMode() {
|
||||
return ResourceRegistryClientFactory.HIERARCHICAL_MODE;
|
||||
public static String getResourceRegistryURL() {
|
||||
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists*
|
||||
* @param hierarchicalMode
|
||||
*/
|
||||
public static void setHierarchicalMode(boolean hierarchicalMode) {
|
||||
ResourceRegistryClientFactory.HIERARCHICAL_MODE = hierarchicalMode;
|
||||
}
|
||||
|
||||
protected static boolean INCLUDE_CONTEXTS_IN_INSTANCES_HEADER;
|
||||
|
||||
protected static boolean includeContextsInInstanceHeader() {
|
||||
return ResourceRegistryClientFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER;
|
||||
}
|
||||
|
||||
/**
|
||||
* The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists*
|
||||
* @param includeContextsInInstancesHeader
|
||||
*/
|
||||
public static void includeContextsInInstanceHeader(boolean includeContextsInInstancesHeader) {
|
||||
ResourceRegistryClientFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER = includeContextsInInstancesHeader;
|
||||
}
|
||||
|
||||
|
||||
protected static List<String> addresses;
|
||||
|
||||
static {
|
||||
addresses = new ArrayList<>();
|
||||
}
|
||||
|
||||
private static String FORCED_URL = null;
|
||||
|
||||
protected static void forceToURL(String url){
|
||||
FORCED_URL = url;
|
||||
HIERARCHICAL_MODE = false;
|
||||
}
|
||||
|
||||
private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'";
|
||||
private static String nameFormat = "$resource/Profile/ServiceName/text() eq '%1s'";
|
||||
private static String statusFormat = "$resource/Profile/DeploymentData/Status/text() eq 'ready'";
|
||||
private static String containsFormat = "$entry/@EntryName eq '%1s'";
|
||||
|
||||
|
||||
private static String serviceEndpointCategoryFormat = "$resource/Profile/Category/text() eq '%1s'";
|
||||
private static String serviceEndpointNameFormat = "$resource/Profile/Name/text() eq '%1s'";
|
||||
private static String serviceEndpointstatusFormat = "$resource/Profile/RunTime/Status/text() eq 'READY'";
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private static SimpleQuery queryForService(){
|
||||
return ICFactory.queryFor(GCoreEndpoint.class)
|
||||
.addCondition(String.format(classFormat, Constants.SERVICE_CLASS))
|
||||
.addCondition(String.format(nameFormat, Constants.SERVICE_NAME))
|
||||
.addCondition(String.format(statusFormat))
|
||||
.addVariable("$entry","$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint")
|
||||
.addCondition(String.format(containsFormat, Constants.SERVICE_ENTRY_NAME))
|
||||
.setResult("$entry/text()");
|
||||
}
|
||||
|
||||
private static SimpleQuery queryForProxy(){
|
||||
return ICFactory.queryFor(ServiceEndpoint.class)
|
||||
.addCondition(String.format(serviceEndpointCategoryFormat, Constants.SERVICE_CLASS))
|
||||
.addCondition(String.format(serviceEndpointNameFormat, Constants.SERVICE_NAME))
|
||||
.addCondition(String.format(serviceEndpointstatusFormat))
|
||||
.addVariable("$entry","$resource/Profile/AccessPoint/Interface/Endpoint")
|
||||
.addCondition(String.format(containsFormat, Constants.SERVICE_ENTRY_NAME))
|
||||
.setResult("$entry/text()");
|
||||
}
|
||||
|
||||
|
||||
protected static List<String> getAddresses(){
|
||||
List<String> addresses = new ArrayList<>();
|
||||
|
||||
try {
|
||||
SimpleQuery proxyQuery = queryForProxy();
|
||||
addresses = ICFactory.client().submit(proxyQuery);
|
||||
if(addresses==null || addresses.isEmpty()){
|
||||
throw new Exception("No ResourceRegistry Proxy Found");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("{}. Looking for RunningInstance.", e.getMessage());
|
||||
SimpleQuery serviceQuery = queryForService();
|
||||
addresses = ICFactory.client().submit(serviceQuery);
|
||||
}
|
||||
|
||||
return addresses;
|
||||
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 = null;
|
||||
|
||||
if(FORCED_URL!=null){
|
||||
address = FORCED_URL;
|
||||
}else {
|
||||
|
||||
if(addresses==null || addresses.isEmpty()) {
|
||||
addresses = getAddresses();
|
||||
}
|
||||
|
||||
if(addresses==null || addresses.isEmpty()){
|
||||
String error = String.format("No %s:%s found in the current context %s", Constants.SERVICE_CLASS, Constants.SERVICE_NAME, getCurrentContextFullName());
|
||||
throw new RuntimeException(error);
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
int index = random.nextInt(addresses.size());
|
||||
address = addresses.get(index);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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,91 +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";
|
||||
|
||||
protected static final String REGISTRY_PROPERTIES_FILENAME = "registry.properties";
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
||||
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
|
||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
|
||||
|
||||
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
|
||||
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 {
|
||||
TokenResponse tr = getJWTAccessToken(context);
|
||||
Secret secret = new JWTSecret(tr.getAccessToken());
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static void setContext(String token) throws Exception {
|
||||
Secret secret = getSecret(token);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
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 {
|
||||
setContextByName(DEFAULT_TEST_SCOPE);
|
||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
logger.error("Unable to retrieve user. {} will be used", user);
|
||||
}
|
||||
|
||||
|
||||
Properties registryProperties = new Properties();
|
||||
input = ContextTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME);
|
||||
try {
|
||||
// load the properties file
|
||||
registryProperties.load(input);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
RESOURCE_REGISTRY_URL = registryProperties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
|
||||
if(RESOURCE_REGISTRY_URL!=null){
|
||||
ResourceRegistryClientFactory.forceToURL(RESOURCE_REGISTRY_URL);
|
||||
}
|
||||
}
|
||||
|
||||
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 void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
||||
String token = ContextTest.properties.getProperty(fullContextName);
|
||||
setContext(token);
|
||||
}
|
||||
|
||||
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));
|
||||
return user;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -116,8 +173,7 @@ public class ContextTest {
|
|||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
SecretManagerProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,23 +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.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||
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.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.schema.SchemaNotFoundException;
|
||||
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;
|
||||
|
@ -27,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;
|
||||
|
@ -43,25 +54,96 @@ public class ResourceRegistryClientTest extends ContextTest {
|
|||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public ResourceRegistryClientTest() {
|
||||
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.query("SELECT FROM V", 0, null);
|
||||
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 testGetFacetSchema() throws SchemaNotFoundException, ResourceRegistryException {
|
||||
List<Type> typeDefinitions = resourceRegistryClient.getSchema(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.getSchema(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 {
|
||||
|
@ -70,7 +152,7 @@ public class ResourceRegistryClientTest extends ContextTest {
|
|||
|
||||
@Test(expected = SchemaNotFoundException.class)
|
||||
public void testException() throws SchemaNotFoundException, ResourceRegistryException {
|
||||
resourceRegistryClient.getSchema(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
|
||||
|
@ -80,25 +162,25 @@ public class ResourceRegistryClientTest extends ContextTest {
|
|||
// @Test
|
||||
public void testExists() throws ResourceRegistryException {
|
||||
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
||||
resourceRegistryClient.exists(EService.NAME, uuid);
|
||||
resourceRegistryClient.existInstance(EService.NAME, uuid);
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testExistsByClass() throws ResourceRegistryException {
|
||||
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
||||
resourceRegistryClient.exists(EService.class, uuid);
|
||||
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);
|
||||
}
|
||||
|
@ -123,13 +205,14 @@ 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.class, hostingNode, Direction.OUT, true);
|
||||
IsRelatedTo.class, hostingNode, Direction.OUT, true);
|
||||
logger.trace("{}", eServices);
|
||||
}
|
||||
|
||||
|
@ -149,11 +232,10 @@ 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);
|
||||
List<EService> eServices = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class,
|
||||
SoftwareFacet.class, softwareFacet, true);
|
||||
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));
|
||||
}
|
||||
|
@ -170,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;
|
||||
|
@ -185,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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,244 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.Direction;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
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;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ResourceRegistryClientTestWikiExamples extends ContextTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ResourceRegistryClientTestWikiExamples.class);
|
||||
|
||||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public ResourceRegistryClientTestWikiExamples() {
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
}else {
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample1() throws ResourceRegistryException {
|
||||
List<EService> list = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, null);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample1Alt() throws ResourceRegistryException, Exception {
|
||||
String jsonString = resourceRegistryClient.getFilteredResources("EService", "IsIdentifiedBy", "SoftwareFacet", true, null);
|
||||
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
@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 = 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 = 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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample3() throws ResourceRegistryException, Exception{
|
||||
Map<String, String> facetConstraints = new HashMap<>();
|
||||
facetConstraints.put("group", "VREManagement");
|
||||
facetConstraints.put("name", "WhnManager");
|
||||
|
||||
List<EService> list = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, facetConstraints);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample3Alt() throws ResourceRegistryException, Exception{
|
||||
Map<String, String> facetConstraints = new HashMap<>();
|
||||
facetConstraints.put("group", "VREManagement");
|
||||
facetConstraints.put("name", "WhnManager");
|
||||
|
||||
String jsonString = resourceRegistryClient.getFilteredResources("EService", "IsIdentifiedBy", "SoftwareFacet", true, facetConstraints);
|
||||
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample4() throws ResourceRegistryException {
|
||||
List<Resource> list = resourceRegistryClient.getFilteredResources(Resource.class, IsIdentifiedBy.class, ContactFacet.class, true, null);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample4Alt() throws ResourceRegistryException, Exception {
|
||||
String jsonString = resourceRegistryClient.getFilteredResources("Resource", "IsIdentifiedBy", "ContactFacet", true, null);
|
||||
List<Resource> list = ElementMapper.unmarshalList(Resource.class, jsonString);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExample5() throws ResourceRegistryException {
|
||||
List<Resource> list = resourceRegistryClient.getFilteredResources(Resource.class, ConsistsOf.class, ContactFacet.class, true, null);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample5Alt() throws ResourceRegistryException, Exception {
|
||||
String jsonString = resourceRegistryClient.getFilteredResources("Resource", "ConsistsOf", "ContactFacet", true, null);
|
||||
List<Resource> list = ElementMapper.unmarshalList(Resource.class, jsonString);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample6() throws ResourceRegistryException, Exception{
|
||||
Map<String, String> facetConstraints = new HashMap<>();
|
||||
facetConstraints.put("name", "Luca");
|
||||
facetConstraints.put("surname", "Frosini");
|
||||
|
||||
List<Resource> list = resourceRegistryClient.getFilteredResources(Resource.class, ConsistsOf.class, ContactFacet.class, true, facetConstraints);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample6Alt() throws ResourceRegistryException, Exception{
|
||||
Map<String, String> facetConstraints = new HashMap<>();
|
||||
facetConstraints.put("name", "Luca");
|
||||
facetConstraints.put("surname", "Frosini");
|
||||
|
||||
String jsonString = resourceRegistryClient.getFilteredResources("Resource", "ConsistsOf", "ContactFacet", true, facetConstraints);
|
||||
List<Resource> list = ElementMapper.unmarshalList(Resource.class, jsonString);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExample7() throws ResourceRegistryException {
|
||||
List<EService> list = resourceRegistryClient.getRelatedResources(EService.class, Hosts.class, HostingNode.class, Direction.IN, true);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
@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
|
||||
@Ignore
|
||||
public void testExample8Alt() throws Exception{
|
||||
HostingNode hostingNodeInstance = new HostingNodeImpl();
|
||||
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
|
||||
@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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rawQueryExample1() throws ResourceRegistryException, Exception{
|
||||
String jsonString = resourceRegistryClient.rawQuery("SELECT FROM SoftwareFacet", true);
|
||||
logger.debug("{}", jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rawQueryExample2() throws ResourceRegistryException, Exception{
|
||||
String jsonString = resourceRegistryClient.rawQuery("SELECT FROM SoftwareFacet");
|
||||
List<SoftwareFacet> list = ElementMapper.unmarshalList(SoftwareFacet.class, jsonString);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonQueryExample1() throws ResourceRegistryException, Exception{
|
||||
String jsonQuery = "{\n"
|
||||
+ " \"" + Element.TYPE_PROPERTY + "\": \"EService\",\n"
|
||||
+ " \"consistsOf\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"" + Element.TYPE_PROPERTY + "\": \"IsIdentifiedBy\",\n"
|
||||
+ " \"target\": {\n"
|
||||
+ " \"" + Element.TYPE_PROPERTY + "\": \"SoftwareFacet\",\n"
|
||||
+ " \"group\": \"DataTransfer\",\n"
|
||||
+ " \"name\": \"data-transfer-service\"\n"
|
||||
+ " }\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"" + Element.TYPE_PROPERTY + "\": \"ConsistsOf\",\n"
|
||||
+ " \"target\": {\n"
|
||||
+ " \"" + Element.TYPE_PROPERTY + "\": \"StateFacet\",\n"
|
||||
+ " \"value\": \"down\"\n"
|
||||
+ " }\n"
|
||||
+ " }\n"
|
||||
+ " \n"
|
||||
+ " ]\n"
|
||||
+ "}";
|
||||
|
||||
String jsonString = resourceRegistryClient.jsonQuery(jsonQuery);
|
||||
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
||||
logger.debug("{}", list);
|
||||
}
|
||||
}
|
|
@ -6,3 +6,4 @@
|
|||
/registry.properties.empty
|
||||
/registry.properties.redirect-test
|
||||
/registry.properties.test
|
||||
/config.ini
|
||||
|
|
Loading…
Reference in New Issue