Compare commits

...

77 Commits

Author SHA1 Message Date
Luca Frosini 8bccea574f Fixed API interface 2024-01-24 16:10:42 +01:00
luca.frosini c171876186 Generalised runQueryTempalte function 2023-11-29 16:17:01 +01:00
luca.frosini 7d4bb7d70f Fixed changelog 2023-11-16 11:20:14 +01:00
luca.frosini fdf33f87a1 Added test 2023-11-16 11:20:02 +01:00
luca.frosini 85cb4a4e55 Fixing getAllContextsFromServer() 2023-11-09 19:04:12 +01:00
luca.frosini c26b70520a Improved contexts limit offset 2023-11-09 18:56:02 +01:00
luca.frosini 848d1ee835 Improved limit offset request for contexts 2023-11-09 18:52:54 +01:00
luca.frosini 5189194b5e Fixed changelog 2023-11-09 18:03:11 +01:00
luca.frosini 384a7bdaf7 Added limit offset support for instances listing 2023-10-31 16:57:08 +01:00
luca.frosini 2113a6ee97 Added cache for ModelKnowledge 2023-10-31 15:59:26 +01:00
luca.frosini 30eac775f6 Added renew for TypesKnowledge 2023-10-31 15:51:06 +01:00
luca.frosini 660f0ea4a5 Improved test 2023-10-30 17:47:03 +01:00
luca.frosini b17edcb160 Fixed changelog 2023-10-30 17:11:42 +01:00
luca.frosini 3b125dfa15 Added full support for ModelKnowledge 2023-10-30 17:08:46 +01:00
luca.frosini 9eceb98059 fixing issue 2023-10-27 18:15:38 +02:00
luca.frosini 0cc1ead630 Adding support for types as tree using ModelKnowledge as cache 2023-10-27 18:14:16 +02:00
luca.frosini 29b559a71a Added getContextCache() to be able to get Context as Tree 2023-10-27 15:05:44 +02:00
luca.frosini 164be53064 Extended BaseRequestInfo to get new query parameters management for free 2023-09-13 18:42:25 +02:00
luca.frosini de47918497 Removed -SNAPSHOT for release 2023-07-21 14:24:22 +02:00
luca.frosini 5128f4ad63 Ignored MacOs File 2023-06-21 11:44:52 +02:00
Luca Frosini 1f0835775b Fixed tests 2023-05-17 18:11:56 +02:00
Luca Frosini cb7bd04bc2 Fixed sent query parameters 2023-05-15 16:48:40 +02:00
Luca Frosini 5df6c19a24 Added missing query parameters to request 2023-05-05 12:12:30 +02:00
Luca Frosini c933cc3f85 Using RequestInfo 2023-05-02 17:24:03 +02:00
Luca Frosini 047e0d448d Removed wrong comment 2023-04-28 14:53:17 +02:00
Luca Frosini 34a2dd7959 Fixed code to comply with uuid property rename to id 2023-04-28 11:45:23 +02:00
Luca Frosini b04623028e Refactored due to is-model constant name change 2023-04-27 10:42:22 +02:00
Luca Frosini 75b5acb932 Getting type indication property from constant 2023-04-26 21:44:40 +02:00
Luca Frosini 3faac2a236 Fixed changelog 2023-04-26 09:37:01 +02:00
Luca Frosini 484a467d55 Fixed changelog 2023-04-26 09:35:33 +02:00
Luca Frosini bb9e1fdd93 Maintaining backward compatibility 2023-04-26 09:31:43 +02:00
Luca Frosini 037d119697 Enhanced version 2023-04-26 09:22:13 +02:00
Luca Frosini faa0642224 Reorganized utilities and their usage 2023-04-21 15:57:08 +02:00
Luca Frosini ac164abb46 Porting code to redesigned E/R format 2023-04-19 11:37:12 +02:00
Luca Frosini fdf9e71068 Redesigning E/R instance definition 2023-04-18 17:51:47 +02:00
Luca Frosini e9611dcafc Removed -SNAPSHOT to release the component 2023-03-03 12:06:18 +01:00
Luca Frosini 6639589e9e Added facilities to use the client outside of container 2023-03-02 14:51:22 +01:00
Luca Frosini 022b3acc8b Removed wrong TODO comment 2023-03-01 20:09:11 +01:00
Luca Frosini 91a03750a0 Added addHeader in the interface 2023-03-01 14:23:11 +01:00
Luca Frosini d4ba9022d4 Fixed changelog 2023-02-27 18:53:21 +01:00
Luca Frosini a0dd4422b0 Added the possibility to create a client instance by context 2023-02-27 18:52:23 +01:00
Luca Frosini 59f4abda63 Added the possibility for a client to add additional HTTP headers 2023-02-27 18:20:12 +01:00
Luca Frosini 46091ad285 common-utility 1.X.X has been renamed to common-utility-sg3 2023-02-24 14:56:47 +01:00
Luca Frosini ee9344cee1 Added usage of common-utility 2023-02-22 15:14:18 +01:00
Luca Frosini 9b84168926 authorization-utils added as test dependency 2023-02-16 15:57:47 +01:00
Luca Frosini 196907d4de Fixed ContextTest 2023-02-09 17:57:59 +01:00
Luca Frosini 91e3f790cd Enhanced gcube-bom version and migrated code to new is-model version 2023-02-09 17:07:58 +01:00
Luca Frosini 973d60eb04 Removed -SNAPSHOT to release the component 2022-10-19 11:53:36 +02:00
Luca Frosini 836d66bec4 Fixed tests root class 2022-07-25 11:21:27 +02:00
Luca Frosini 85ed707f44 Removed force URL in factory 2022-07-25 11:07:32 +02:00
Luca Frosini 888d666b79 Fixed typo 2022-07-22 10:34:48 +02:00
Luca Frosini 2c75dde1b8 Fixed CHANGELOG 2022-07-22 10:09:38 +02:00
Luca Frosini d3d92cbbf7 Added missing @Override annotations 2022-07-21 17:04:00 +02:00
Luca Frosini c63dc4c4c8 The parameters hierarchicalMode and includeContextsInHeader are now
instance based
2022-07-21 16:55:22 +02:00
Luca Frosini 3b06356a26 Reorganized query and path parameters constants 2022-07-20 12:09:20 +02:00
Luca Frosini f115e9b4b9 Removed uneeded parameters 2022-07-19 14:04:26 +02:00
Luca Frosini ec50b30abc Removed uneeded parameters 2022-07-18 16:34:56 +02:00
Luca Frosini b3c254161c ignored ini file 2022-07-18 15:48:48 +02:00
Luca Frosini 5744607834 Set log to trace 2022-07-15 10:26:00 +02:00
Luca Frosini 9a856a68f8 Using the right query parameter 2022-07-14 15:51:24 +02:00
Luca Frosini 8a4a70673c Added example used in wiki in tests 2022-02-09 15:15:00 +01:00
Luca Frosini 0121657b4b Added changes in CHANGELOG 2022-02-09 15:14:41 +01:00
Luca Frosini 4d2f87e83c Added missing APIs and aligned API names 2022-02-09 13:20:48 +01:00
Luca Frosini 8ead38f561 Refactoring due to package renaming in resource-regsitry-api 2022-02-01 16:46:03 +01:00
Luca Frosini e907c029f9 Added support for context names included in header among UUIDs refs
#22090
2021-10-28 11:19:50 +02:00
Luca Frosini 57d0a5dbc4 Fixed import due to packages renaming 2021-10-25 11:38:58 +02:00
Luca Frosini 5914112a5f Fixed import due to package renaming 2021-10-25 10:59:44 +02:00
Luca Frosini ac2cd3edd7 Fixed CHANGELOG 2021-10-21 16:59:06 +02:00
Luca Frosini 11a79f3724 Moved Direction in ISModel 2021-10-15 17:29:30 +02:00
Luca Frosini 1c40bf3515 Aligned APIs refs #22011 2021-09-15 11:45:05 +02:00
Luca Frosini f9a2a599d9 Aligned APIs with the rr-publisher APIs 2021-09-14 16:34:20 +02:00
Luca Frosini ac1f23c36e Added the examples of the wiki page
https://gcube.wiki.gcube-system.org/gcube/Resource_Registry_Service_-_Query_&_Access
2021-07-07 19:39:33 +02:00
Luca Frosini 9909a87644 Improving client 2021-07-07 17:35:49 +02:00
Luca Frosini 4cb760f4c3 Added a _ prefix for query parameters to avoid constraint clashes 2021-07-07 11:24:40 +02:00
Luca Frosini 79f4fe330b Reordered methods 2021-07-05 17:32:29 +02:00
Luca Frosini 192bb0adf5 Updated gcube-bom version 2021-06-29 18:14:10 +02:00
Luca Frosini 34fca63cc2 Aligned distro files with new specification 2021-06-29 18:14:00 +02:00
14 changed files with 1590 additions and 561 deletions

2
.gitignore vendored
View File

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

View File

@ -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)

26
FUNDING.md Normal file
View File

@ -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);

View File

@ -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)

22
pom.xml
View File

@ -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>
@ -57,6 +49,10 @@
<groupId>org.gcube.common</groupId>
<artifactId>gxHTTP</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-utility-sg3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -78,5 +74,11 @@
<artifactId>gcube-model</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,14 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.client;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public enum Direction {
IN, OUT, BOTH;
}

View File

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

View File

@ -2,127 +2,212 @@ 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 {
/**
* Use {@link #includeContexts()} instead
* @return
*/
@Deprecated
public boolean isIncludeContextsInHeader();
/**
* Use {@link #includeContexts(boolean)} instead
* @param includeContextsInHeader
*/
@Deprecated
public void setIncludeContextsInHeader(boolean includeContexts);
public <IE extends IdentifiableElement> boolean exists(Class<IE> clazz, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
public void addHeader(String name, String value);
public boolean exists(String type, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
public <IE extends IdentifiableElement> IE getInstance(Class<IE> 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 <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;
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, UUID referenceFacetUUID,
boolean polymorphic) throws ResourceRegistryException;
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;
public String getFilteredResources(String resourceType, String consistsOfType, String facetType,
boolean polymorphic, Map<String,String> map) 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;
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;
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;
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)
throws InvalidQueryException, ResourceRegistryException;
public String query(final String query, final int limit, final String fetchPlan, boolean raw)
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 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 ContextCache getContextCache();
public Set<UUID> getInstanceContexts(String type, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
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 <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, 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,
boolean polymorphic) throws ResourceRegistryException;
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> facetConstraint) throws ResourceRegistryException;
public String getFilteredResources(String resourceType, String consistsOfType, String facetType,
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, 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;
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;
public String getRelatedResources(String resourceType, String isRelatedToType, String referenceResourceType,
Direction direction, boolean polymorphic) throws ResourceRegistryException;
/* ---------------------------------------------------------------------- */
public String jsonQuery(final String query)
throws InvalidQueryException, ResourceRegistryException;
public <E extends Entity> List<E> jsonQuery(final JsonNode jsonNode)
throws InvalidQueryException, ResourceRegistryException;
/* ---------------------------------------------------------------------- */
public String rawQuery(final String query)
throws InvalidQueryException, ResourceRegistryException;
public String rawQuery(final String query, boolean raw)
throws InvalidQueryException, ResourceRegistryException;
}

View File

@ -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;
}
/**
* 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;
public static String getResourceRegistryURL() {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
return address;
}
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);
}

View File

@ -7,14 +7,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.KeycloakClientHelper;
import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@ -22,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);
} 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";
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
try {
setContextByName(DEFAULT_TEST_SCOPE);
} catch(Exception e) {
throw new RuntimeException(e);
}
Properties registryProperties = new Properties();
input = ContextTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME);
try {
// load the properties file
registryProperties.load(input);
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
} catch (IOException e) {
throw new RuntimeException(e);
}
RESOURCE_REGISTRY_URL = registryProperties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
}
private enum Type{
USER, CLIENT_ID
};
public static void set(Secret secret) throws Exception {
SecretManagerProvider.instance.reset();
SecretManager secretManager = new SecretManager();
secretManager.addSecret(secret);
SecretManagerProvider.instance.set(secretManager);
SecretManagerProvider.instance.get().set();
}
public static void setContextByName(String fullContextName) throws Exception {
logger.debug("Going to set credentials for context {}", fullContextName);
Secret secret = getSecretByContextName(fullContextName);
set(secret);
}
private static TokenResponse getJWTAccessToken(String context) throws Exception {
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
if(RESOURCE_REGISTRY_URL!=null){
ResourceRegistryClientFactory.forceToURL(RESOURCE_REGISTRY_URL);
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 String getCurrentScope(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context);
return context;
public static Secret getSecretByContextName(String context) throws Exception {
TokenResponse tr = getJWTAccessToken(context);
Secret secret = new JWTSecret(tr.getAccessToken());
return secret;
}
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
String token = ContextTest.properties.getProperty(fullContextName);
setContext(token);
public static void setContext(String token) throws Exception {
Secret secret = getSecret(token);
set(secret);
}
private static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
ClientInfo clientInfo = authorizationEntry.getClientInfo();
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
String qualifier = authorizationEntry.getQualifier();
Caller caller = new Caller(clientInfo, qualifier);
AuthorizationProvider.instance.set(caller);
ScopeProvider.instance.set(getCurrentScope(token));
private static Secret getSecret(String token) throws Exception {
Secret secret = SecretUtility.getSecretByTokenString(token);
return secret;
}
public static String getUser() {
String user = Metadata.UNKNOWN_USER;
try {
user = SecretManagerProvider.instance.get().getUser().getUsername();
} catch(Exception e) {
logger.error("Unable to retrieve user. {} will be used", user);
}
return user;
}
@BeforeClass
@ -116,8 +173,7 @@ public class ContextTest {
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
SecretManagerProvider.instance.reset();
}
}

View File

@ -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() {
resourceRegistryClient = ResourceRegistryClientFactory.create();
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);
}
}

View File

@ -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);
}
}

View File

@ -6,3 +6,4 @@
/registry.properties.empty
/registry.properties.redirect-test
/registry.properties.test
/config.ini