Compare commits
78 Commits
Author | SHA1 | Date |
---|---|---|
Luca Frosini | 2aa2909e4e | |
Luca Frosini | 489eed2787 | |
Luca Frosini | 483826685c | |
luca.frosini | 179013ec5b | |
luca.frosini | 88ef977959 | |
luca.frosini | 3670c234a4 | |
luca.frosini | dbfa2901c0 | |
luca.frosini | 1af4a41fe5 | |
Luca Frosini | caf354617a | |
Luca Frosini | cff16573dd | |
Luca Frosini | d8947f2814 | |
Luca Frosini | fd7948bd7c | |
Luca Frosini | 64ec6c94d5 | |
Luca Frosini | 6b8b2e780a | |
Luca Frosini | 22a6538683 | |
Luca Frosini | b8c80b122d | |
Luca Frosini | af2ef0ccb5 | |
Luca Frosini | 83deeb649b | |
Luca Frosini | 05279d72fa | |
Luca Frosini | c9c6c59c5c | |
Luca Frosini | b8d3fac55f | |
Luca Frosini | 02abe7e89f | |
Luca Frosini | 1011c5a68d | |
Luca Frosini | 9a465edb19 | |
Luca Frosini | bef7068964 | |
Luca Frosini | 8f3c8d21a1 | |
Luca Frosini | 99d26ded6c | |
Luca Frosini | 981fe278c6 | |
Luca Frosini | 0d07a471ff | |
Luca Frosini | 59b55953bd | |
Luca Frosini | 40df50ed76 | |
Luca Frosini | c8518b5951 | |
Luca Frosini | 031372c497 | |
Luca Frosini | e7b6f7c889 | |
Luca Frosini | 6c74d0f0fd | |
Luca Frosini | 7401c46e4d | |
Luca Frosini | cdeeae7bda | |
Luca Frosini | 3ad57330b9 | |
Luca Frosini | d1f7fe0fb0 | |
Luca Frosini | 40acf5f865 | |
Luca Frosini | acdd43f7ef | |
Luca Frosini | ea2156d0d5 | |
Luca Frosini | a7c042bf2e | |
Luca Frosini | c67acadce7 | |
Luca Frosini | f711e95e7e | |
Luca Frosini | e9d110e5a1 | |
Luca Frosini | 621f1abaaa | |
Luca Frosini | 9721a504b4 | |
Luca Frosini | 824e2eabf3 | |
Luca Frosini | 7ebebdda11 | |
Luca Frosini | 19c674a350 | |
Luca Frosini | 82f4bdeb94 | |
Luca Frosini | cef2da3f8f | |
Luca Frosini | 096fc46dbf | |
Luca Frosini | 882f26ac12 | |
Luca Frosini | 351500e701 | |
Luca Frosini | 6068c366ed | |
Luca Frosini | abc185f7a5 | |
Luca Frosini | 0c866bced8 | |
Luca Frosini | d09fbdbf69 | |
Luca Frosini | 487ab87d99 | |
Luca Frosini | 242d41f07b | |
Luca Frosini | bee21362e2 | |
Luca Frosini | c76c983b7c | |
Luca Frosini | 352709f9dc | |
Luca Frosini | 268b9939c8 | |
Luca Frosini | 13973f9dc4 | |
Luca Frosini | 76a573a43f | |
Luca Frosini | 35aa1071a4 | |
Luca Frosini | 229c07ca2d | |
Luca Frosini | 59477e011a | |
Luca Frosini | 5703717da0 | |
Luca Frosini | ced0133b92 | |
Luca Frosini | 54715a0783 | |
Luca Frosini | 32f02d057f | |
Luca Frosini | 8b61afdec3 | |
Luca Frosini | d43d734712 | |
Luca Frosini | 1be6393f26 |
|
@ -1,3 +1,5 @@
|
|||
target
|
||||
.classpath
|
||||
.project
|
||||
/.DS_Store
|
||||
/bin/
|
||||
|
|
31
CHANGELOG.md
31
CHANGELOG.md
|
@ -2,12 +2,43 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Resource Registry Publisher
|
||||
|
||||
## [v4.5.0-SNAPSHOT]
|
||||
|
||||
- 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 code to Luca Frosini dissertation theory
|
||||
- Add/Remove to/from Context return the list of affected instances and not just success or failure code [#20555]
|
||||
- Aligned client with changes of Sharing REST collection redesign [#20530][#20555]
|
||||
- Aligned overrided APIs [#21979]
|
||||
- Getting all the relations of a type it is returned a list of relations and not the list of Resources sources of such relation [#22003]
|
||||
- Added check for reserved UUID
|
||||
- Added support for context names included in header among UUIDs [#22090]
|
||||
- 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]
|
||||
|
|
|
@ -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)
|
||||
|
|
27
pom.xml
27
pom.xml
|
@ -9,7 +9,7 @@
|
|||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-publisher</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<version>4.5.0-SNAPSHOT</version>
|
||||
<name>Resource Registry Publisher</name>
|
||||
<description>Resource Registry Publisher is a library designed to interact with Resource Registry Instances 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,10 +74,21 @@
|
|||
<artifactId>gcube-model</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-client</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,285 +1,331 @@
|
|||
package org.gcube.informationsystem.resourceregistry.publisher;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.model.reference.ERElement;
|
||||
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.resourceregistry.api.contexts.ContextCache;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
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.entity.facet.FacetAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface ResourceRegistryPublisher {
|
||||
public interface ResourceRegistryPublisher extends RequestInfo {
|
||||
|
||||
/**
|
||||
* Use {@link #includeContexts()} instead
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isIncludeContextsInHeader();
|
||||
|
||||
public <IE extends IdentifiableElement> IE create(IE er)
|
||||
throws AlreadyPresentException, ResourceRegistryException;
|
||||
/**
|
||||
* Use {@link #includeContexts(boolean)} instead
|
||||
* @param includeContextsInHeader
|
||||
*/
|
||||
@Deprecated
|
||||
public void setIncludeContextsInHeader(boolean includeContexts);
|
||||
|
||||
public String create(String json) throws AlreadyPresentException, ResourceRegistryException;
|
||||
public void addHeader(String name, String value);
|
||||
|
||||
public ContextCache getContextCache();
|
||||
|
||||
public <IE extends IdentifiableElement> boolean exists(Class<IE> clazz, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
/**
|
||||
* Use {@link #getContexts()} instead
|
||||
* @return an array containing all contexts definition
|
||||
* @throws ResourceRegistryException if fails
|
||||
*/
|
||||
@Deprecated
|
||||
public List<Context> getAllContext() throws ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement> boolean exists(IE identifiableElement)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
/**
|
||||
* @return an array containing all contexts definition
|
||||
* @throws ResourceRegistryException if fails
|
||||
*/
|
||||
public List<Context> getContexts() throws ResourceRegistryException;
|
||||
|
||||
public boolean exists(String type, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <IE extends IdentifiableElement> IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException;
|
||||
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <IE extends IdentifiableElement> IE update(IE identifiableElement)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public String update(String type, String json) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public String update(String json) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <IE extends IdentifiableElement> boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean delete(String type, UUID uuid) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
/* ----- */
|
||||
|
||||
public <ERElem extends ERElement> List<ERElem> list(Class<ERElem> clazz, Boolean polymorphic)
|
||||
throws ResourceRegistryException;
|
||||
|
||||
public String list(String type, Boolean polymorphic)
|
||||
throws ResourceRegistryException;
|
||||
|
||||
|
||||
public <ERElem extends ERElement> ERElem create(ERElem er)
|
||||
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String create(String json)
|
||||
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <ERElem extends ERElement> boolean exist(ERElem er)
|
||||
throws AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz, UUID uuid)
|
||||
throws AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public boolean exist(String type, UUID uuid)
|
||||
throws AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <ERElem extends ERElement> ERElem read(ERElem er)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <ERElem extends ERElement> ERElem read(Class<ERElem> clazz, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public String read(String type, UUID uuid)
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <ERElem extends ERElement> ERElem update(ERElem er)
|
||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
|
||||
|
||||
public String update(String json)
|
||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
|
||||
|
||||
public String update(String type, String json)
|
||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
|
||||
|
||||
public String update(String type, String json, UUID uuid)
|
||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <ERElem extends ERElement> boolean delete(ERElem er)
|
||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean delete(String type, UUID uuid)
|
||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
public <F extends Facet> F createFacet(F facet)
|
||||
throws FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <F extends Facet> F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
|
||||
throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createFacet(String facet)
|
||||
throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> F readFacet(F facet)
|
||||
throws FacetNotFoundException, FacetAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public String readFacet(String facetType, UUID uuid)
|
||||
throws FacetNotFoundException, FacetAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <F extends Facet> F updateFacet(F facet)
|
||||
throws FacetNotFoundException, ResourceRegistryException;
|
||||
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException;
|
||||
public String updateFacet(String facet)
|
||||
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
|
||||
public <F extends Facet> boolean deleteFacet(F facet)
|
||||
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
|
||||
public boolean deleteFacet(String facetType, UUID uuid)
|
||||
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
|
||||
|
||||
public <R extends Resource> R createResource(R resource)
|
||||
throws ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <R extends Resource> R readResource(R resource)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
public String createResource(String resource)
|
||||
throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String readResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> R readResource(R resource)
|
||||
throws ResourceNotFoundException, ResourceAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public String readResource(String resourceType, UUID uuid)
|
||||
throws ResourceNotFoundException, ResourceAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> R updateResource(R resource)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String updateResource(String resource)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> boolean deleteResource(R resource)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean deleteResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
public boolean deleteResource(String resourceType, UUID uuid)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
|
||||
C consistsOf) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(C consistsOf)
|
||||
throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String createConsistsOf(String consistsOf)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C readConsistsOf(
|
||||
C consistsOf) throws NotFoundException, ResourceRegistryException;
|
||||
throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C readConsistsOf(C consistsOf)
|
||||
throws ConsistsOfNotFoundException, ConsistsOfAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public String readConsistsOf(String consistsOfType, UUID uuid)
|
||||
throws ConsistsOfNotFoundException, ConsistsOfAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C updateConsistsOf(C consistsOf)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String updateConsistsOf(String consistsOf)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf)
|
||||
throws ResourceRegistryException;
|
||||
throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException;
|
||||
public boolean deleteConsistsOf(String consistsOfType, UUID uuid)
|
||||
throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
|
||||
I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(I isRelatedTo)
|
||||
throws SchemaViolationException, IsRelatedToAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String createIsRelatedTo(String isRelatedTo)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I readIsRelatedTo(
|
||||
I isRelatedTo) throws NotFoundException, ResourceRegistryException;
|
||||
throws SchemaViolationException, IsRelatedToAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String readIsRelatedTo(String isRelatedToType, UUID uuid) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I readIsRelatedTo(I isRelatedTo)
|
||||
throws IsRelatedToNotFoundException, IsRelatedToAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public String readIsRelatedTo(String isRelatedToType, UUID uuid)
|
||||
throws IsRelatedToNotFoundException, IsRelatedToAvailableInAnotherContextException, ResourceRegistryException;
|
||||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I updateIsRelatedTo(I isRelatedTo)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
throws SchemaViolationException, IsRelatedToNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String updateIsRelatedTo(String isRelatedTo)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
throws SchemaViolationException, IsRelatedToNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
|
||||
throws ResourceRegistryException;
|
||||
throws IsRelatedToNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException;
|
||||
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid)
|
||||
throws IsRelatedToNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
public List<ERElement> addToContext(String type, UUID instanceUUID, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> addToContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> addToCurrentContext(String type, UUID instanceUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> addToCurrentContext(ERElement er, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> removeFromContext(String type, UUID instanceUUID, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> removeFromCurrentContext(String type, UUID instanceUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> removeFromCurrentContext(ERElement er, Boolean dryRun)
|
||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID)
|
||||
public Map<UUID, String> getElementContexts(String type, UUID instanceUUID)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement> boolean addToContext(IE identifiableElement, UUID contextUUID)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean addToCurrentContext(String type, UUID instanceUUID)
|
||||
public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement> boolean removeFromContext(IE identifiableElement, UUID contextUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean removeFromCurrentContext(String type, UUID instanceUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Set<UUID> getElementContexts(String type, UUID instanceUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <IE extends IdentifiableElement> Set<UUID> getElementContexts(IE identifiableElement)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
|
||||
public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public List<ERElement> addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> boolean addResourceToCurrentContext(R resource)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public <R extends Resource> List<ERElement> addResourceToContext(R resource, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public List<ERElement> addResourceToCurrentContext(String resourceType, UUID resourceUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public <R extends Resource> List<ERElement> addResourceToCurrentContext(R resource, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> boolean removeResourceFromCurrentContext(R resource)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Set<UUID> getResourceContexts(String resourceType, UUID resourceUUID)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public List<ERElement> removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> List<ERElement> removeResourceFromContext(R resource, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> removeResourceFromCurrentContext(String resourceType, UUID resourceUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> List<ERElement> removeResourceFromCurrentContext(R resource, Boolean dryRun)
|
||||
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, String> getResourceContexts(String resourceType, UUID resourceUUID)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> Map<UUID, String> getResourceContexts(R resource)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> Set<UUID> getResourceContexts(R resource)
|
||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
|
||||
public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> boolean addFacetToContext(F facet, UUID contextUUID)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean addFacetToCurrentContext(String facetType, UUID facetUUID)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public List<ERElement> addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> boolean addFacetToCurrentContext(F facet)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public <F extends Facet> List<ERElement> addFacetToContext(F facet, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public List<ERElement> addFacetToCurrentContext(String facetType, UUID facetUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> boolean removeFacetFromCurrentContext(F facet)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Set<UUID> getFacetContexts(String facetType, UUID facetUUID)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
public <F extends Facet> List<ERElement> addFacetToCurrentContext(F facet, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> List<ERElement> removeFacetFromContext(F facet, UUID contextUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<ERElement> removeFacetFromCurrentContext(String facetType, UUID facetUUID, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> List<ERElement> removeFacetFromCurrentContext(F facet, Boolean dryRun)
|
||||
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, String> getFacetContexts(String facetType, UUID facetUUID)
|
||||
throws FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> Map<UUID, String> getFacetContexts(F facet)
|
||||
throws FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> Set<UUID> getFacetContexts(F facet)
|
||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
/* ----- */
|
||||
|
||||
|
||||
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<Context> getAllContext() throws ResourceRegistryException;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
package org.gcube.informationsystem.resourceregistry.publisher;
|
||||
|
||||
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,128 +12,25 @@ public class ResourceRegistryPublisherFactory {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherFactory.class);
|
||||
|
||||
protected static boolean HIERARCHICAL_MODE;
|
||||
|
||||
public static boolean isHierarchicalMode() {
|
||||
return ResourceRegistryPublisherFactory.HIERARCHICAL_MODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The affected methods are {@link ResourceRegistryPublisher} safe methods i.e. read* and exists*
|
||||
* @param hierarchicalMode
|
||||
*/
|
||||
public static void setHierarchicalMode(boolean hierarchicalMode) {
|
||||
ResourceRegistryPublisherFactory.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 ResourceRegistryPublisherFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER;
|
||||
}
|
||||
|
||||
/**
|
||||
* The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists*
|
||||
* @param hierarchicalMode
|
||||
*/
|
||||
public static void includeContextsInInstanceHeader(boolean includeContextsInInstancesHeader) {
|
||||
ResourceRegistryPublisherFactory.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 ResourceRegistryPublisher 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 ResourceRegistryPublisherImpl(address);
|
||||
}
|
||||
|
||||
public static ResourceRegistryPublisher create(String context) {
|
||||
String address = getResourceRegistryURL(context);
|
||||
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
|
||||
return new ResourceRegistryPublisherImpl(address);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +0,0 @@
|
|||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
public class ResourceRegistryClientFactorySetter {
|
||||
|
||||
public static void forceToURL(String url) {
|
||||
ResourceRegistryClientFactory.forceToURL(url);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,15 +7,14 @@ 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.informationsystem.resourceregistry.client.ResourceRegistryClientFactorySetter;
|
||||
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.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -23,92 +22,143 @@ 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);
|
||||
} 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){
|
||||
ResourceRegistryPublisherFactory.forceToURL(RESOURCE_REGISTRY_URL);
|
||||
ResourceRegistryClientFactorySetter.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 = "UNKNOWN";
|
||||
try {
|
||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to retrieve user. {} will be used", user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -118,8 +168,7 @@ public class ContextTest {
|
|||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
SecretManagerProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,179 @@
|
|||
package org.gcube.informationsystem.resourceregistry.publisher;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
||||
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.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.UUIDManager;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
||||
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.RunningPlugin;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class InvalidOperationTest extends ERManagementTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class);
|
||||
|
||||
public static final String ACTIVATES = "{\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"" + Element.TYPE_PROPERTY + "\":\"Activates\",\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Configuration\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"CONFIGURATION_UUID\"},\"target\":{\"" + IdentifiableElement.ID_PROPERTY + "\":\"ESERVICE_UUID\",\"" + Element.TYPE_PROPERTY + "\":\"EService\"}}";
|
||||
public static final String ACTOR = "{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null,\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"remove\":\"cascade\",\"delete\":\"cascade\",\"add\":\"propagate\"},\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null},\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"ContactFacet\",\"metadata\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void createInvalidIsRealtedTo() throws Exception {
|
||||
Configuration configuration = createConfiguration();
|
||||
EService eService = createEService();
|
||||
|
||||
try {
|
||||
/*
|
||||
* Trying to create a relation activates between a Configuration and EService
|
||||
* The creation MUST fails raising SchemaViolationException because the
|
||||
* Activates relation is between two Service isntaces
|
||||
*
|
||||
* The only way to try to create it is using static string because Java classes
|
||||
* already deny to create and instance of Activates
|
||||
*
|
||||
* Here we want to test how the service behave if a client does not behave properly
|
||||
*/
|
||||
|
||||
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getID().toString());
|
||||
json = json.replace("ESERVICE_UUID", eService.getID().toString());
|
||||
|
||||
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Activates.NAME, json, UUIDManager.getInstance().generateValidUUID());
|
||||
|
||||
}finally {
|
||||
resourceRegistryPublisher.delete(configuration);
|
||||
resourceRegistryPublisher.delete(eService);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateStandAloneFacet() throws Exception {
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
|
||||
resourceRegistryPublisher.create(cpuFacet);
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateInvalidRunningPlugin() throws Exception {
|
||||
RunningPlugin runningPlugin = new RunningPluginImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("information-system");
|
||||
softwareFacet.setName("is-exporter-se-plugin");
|
||||
softwareFacet.setVersion("1.0.0");
|
||||
|
||||
IsIdentifiedBy<RunningPlugin, SoftwareFacet> isIdentifiedBy = new IsIdentifiedByImpl<>(runningPlugin, softwareFacet);
|
||||
runningPlugin.addFacet(isIdentifiedBy);
|
||||
|
||||
resourceRegistryPublisher.create(runningPlugin);
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateAbstractEntity() throws Exception {
|
||||
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Actor.NAME, ACTOR, UUIDManager.getInstance().generateValidUUID());
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
|
||||
ERManagementTest erManagementTest = new ERManagementTest();
|
||||
Map<String, Resource> map = erManagementTest.createHostingNodeAndEService();
|
||||
EService eService = (EService) map.get(EService.NAME);
|
||||
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
|
||||
try {
|
||||
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
|
||||
ConsistsOf<EService, Facet> consistsOf = new ConsistsOfImpl<>(eService, shared);
|
||||
consistsOf = resourceRegistryPublisher.create(consistsOf);
|
||||
|
||||
logger.debug("Created : {}", consistsOf);
|
||||
|
||||
} finally {
|
||||
resourceRegistryPublisher.delete(eService);
|
||||
resourceRegistryPublisher.delete(hostingNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateEServiceAndDeleteRequiredConsistsOf() throws Exception {
|
||||
EService eService = null;
|
||||
try {
|
||||
ERManagementTest erManagementTest = new ERManagementTest();
|
||||
eService = erManagementTest.createEService();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
||||
resourceRegistryPublisher.delete(isIdentifiedBy);
|
||||
}finally {
|
||||
resourceRegistryPublisher.delete(eService);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateEServiceAndDeleteRequiredFacet() throws Exception {
|
||||
ERManagementTest erManagementTest = new ERManagementTest();
|
||||
EService eService = erManagementTest.createEService();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
||||
SoftwareFacet softwareFacet = isIdentifiedBy.getTarget();
|
||||
try {
|
||||
resourceRegistryPublisher.delete(softwareFacet);
|
||||
}finally {
|
||||
resourceRegistryPublisher.delete(eService);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateConsistsOfBeetweenResources() throws Exception {
|
||||
ERManagementTest erManagementTest = new ERManagementTest();
|
||||
Map<String, Resource> map = erManagementTest.createHostingNodeAndEService();
|
||||
|
||||
UUID hostingNodeUUID = map.get(HostingNode.NAME).getID();
|
||||
UUID eServiceUUID = map.get(EService.NAME).getID();
|
||||
|
||||
HostingNode hostingNode = new HostingNodeImpl();
|
||||
hostingNode.setID(hostingNodeUUID);
|
||||
|
||||
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
|
||||
fakeEServiceAsSimpleFacet.setID(eServiceUUID);
|
||||
|
||||
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
|
||||
|
||||
try {
|
||||
String json = ElementMapper.marshal(consistsOf);
|
||||
json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
|
||||
|
||||
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(ConsistsOf.NAME, json, UUIDManager.getInstance().generateValidUUID());
|
||||
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
|
||||
} finally {
|
||||
resourceRegistryPublisher.delete(map.get(EService.NAME));
|
||||
resourceRegistryPublisher.delete(map.get(HostingNode.NAME));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.publisher;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* To properly use thois test you must comment
|
||||
* gcube-model dependency
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class NoGcubeModelTest extends ContextTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(NoGcubeModelTest.class);
|
||||
|
||||
public static final String GROUP = "InformationSystem";
|
||||
public static final String NAME = "resource-registry";
|
||||
public static final String VERSION = "1.0.0";
|
||||
public static final String NEW_VERSION = "2.0.0";
|
||||
|
||||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
|
||||
public NoGcubeModelTest() {
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
}
|
||||
resourceRegistryPublisher.setIncludeMeta(true);
|
||||
resourceRegistryPublisher.setAllMeta(true);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testCreateResourceFromJson() throws Exception {
|
||||
String json = "{\"type\":\"VirtualService\",\"consistsOf\":[{\"type\":\"IsIdentifiedBy\",\"target\":{\"name\":\"aaaaaa\",\"optional\":\"true\",\"group\":\"xxxxx\",\"description\":\"\",\"version\":\"cvcvvv\",\"qualifier\":\"\",\"type\":\"SoftwareFacet\",\"aaaa\":\"dddddd\"}}]}";
|
||||
String ret = resourceRegistryPublisher.createResource(json);
|
||||
logger.info(ret);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.publisher;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class RRClientTest extends ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EntityManagementTest.class);
|
||||
|
||||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public RRClientTest(){
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
logger.trace("{} and {} created",
|
||||
ResourceRegistryPublisher.class.getSimpleName(),
|
||||
ResourceRegistryClient.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFacet() throws FacetNotFoundException, ResourceRegistryException{
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
|
||||
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
|
||||
|
||||
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
|
||||
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
||||
|
||||
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
||||
|
||||
Facet f = resourceRegistryClient.getInstance(Facet.class, uuid);
|
||||
Assert.assertTrue(f instanceof CPUFacet);
|
||||
|
||||
CPUFacet readCpuFacet = (CPUFacet) f;
|
||||
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
|
||||
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
||||
|
||||
|
||||
readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
|
||||
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
|
||||
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
||||
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResource() throws ResourceNotFoundException, ResourceRegistryException{
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
|
||||
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedByESSF = new IsIdentifiedByImpl<>(eService, softwareFacet, null);
|
||||
eService.addFacet(isIdentifiedByESSF);
|
||||
|
||||
EService createdEService = resourceRegistryPublisher.createResource(eService);
|
||||
|
||||
List<? extends Facet> idenficationFacets = createdEService.getIdentificationFacets();
|
||||
Assert.assertTrue(idenficationFacets!=null);
|
||||
Assert.assertTrue(idenficationFacets.size()==1);
|
||||
Facet f = idenficationFacets.get(0);
|
||||
Assert.assertTrue(f!=null);
|
||||
Assert.assertTrue(f instanceof SoftwareFacet);
|
||||
SoftwareFacet createdSoftwareFacet = (SoftwareFacet) f;
|
||||
Assert.assertTrue(createdSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
|
||||
Assert.assertTrue(createdSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
|
||||
Assert.assertTrue(createdSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
|
||||
|
||||
|
||||
Resource resource = resourceRegistryClient.getInstance(Resource.class, createdEService.getHeader().getUUID());
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
|
||||
Assert.assertTrue(resource instanceof EService);
|
||||
|
||||
EService readEService = resourceRegistryClient.getInstance(EService.class, createdEService.getHeader().getUUID());
|
||||
Assert.assertTrue(readEService.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
|
||||
List<? extends Facet> idFacets = readEService.getIdentificationFacets();
|
||||
Assert.assertTrue(idFacets!=null);
|
||||
Assert.assertTrue(idFacets.size()==1);
|
||||
f = idFacets.get(0);
|
||||
Assert.assertTrue(f!=null);
|
||||
Assert.assertTrue(f instanceof SoftwareFacet);
|
||||
SoftwareFacet readSoftwareFacet = (SoftwareFacet) f;
|
||||
Assert.assertTrue(readSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
|
||||
Assert.assertTrue(readSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
|
||||
Assert.assertTrue(readSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
|
||||
Assert.assertTrue(readSoftwareFacet.getHeader().getUUID().compareTo(createdSoftwareFacet.getHeader().getUUID())==0);
|
||||
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(createdEService);
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,672 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.publisher.old;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
import org.gcube.informationsystem.base.reference.Direction;
|
||||
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ERManagementTest extends ContextTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class);
|
||||
|
||||
public static final String PASSWORD = "PASSWORD";
|
||||
|
||||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public ERManagementTest() {
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncrypted() throws Exception {
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
URL endpoint = new URL("https://d4science.org:443");
|
||||
accessPointFacet.setEndpoint(endpoint.toURI());
|
||||
Encrypted encrypted = new EncryptedImpl();
|
||||
encrypted.setValue(StringEncrypter.getEncrypter().encrypt("1"));
|
||||
accessPointFacet.setAdditionalProperty(PASSWORD, encrypted);
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
|
||||
IsIdentifiedBy<Resource,Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(eService, softwareFacet,
|
||||
null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
EService receivedEservice = resourceRegistryPublisher.create(eService);
|
||||
|
||||
AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
|
||||
UUID eServiceUUID = receivedEservice.getID();
|
||||
UUID facetUUID = receivedFacet.getID();
|
||||
|
||||
logger.debug("Created {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
|
||||
|
||||
for(int i=0; i<10; i++) {
|
||||
try {
|
||||
if(i%2==0) {
|
||||
receivedEservice = resourceRegistryPublisher.update(receivedEservice);
|
||||
logger.debug("Updated {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
|
||||
}else {
|
||||
receivedEservice = resourceRegistryPublisher.read(receivedEservice);
|
||||
logger.debug("Read {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
|
||||
}
|
||||
UUID receivedEServiceUUID = receivedEservice.getID();
|
||||
Assert.assertTrue(eServiceUUID.compareTo(receivedEServiceUUID)==0);
|
||||
|
||||
receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
|
||||
UUID receivedFacetUUID = receivedFacet.getID();
|
||||
Assert.assertTrue(facetUUID.compareTo(receivedFacetUUID)==0);
|
||||
|
||||
Encrypted receivedEncrypted = (Encrypted) receivedFacet.getAdditionalProperty(PASSWORD);
|
||||
Assert.assertTrue(encrypted.getValue().compareTo(receivedEncrypted.getValue())==0);
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.delete(receivedEservice);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDeleteEService() throws Exception {
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
|
||||
null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||
accessPointFacet.setEntryName("port1");
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
||||
licenseFacet.setName("EUPL");
|
||||
licenseFacet.setTextURL(
|
||||
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
||||
eService.addFacet(licenseFacet);
|
||||
|
||||
eService = resourceRegistryPublisher.createResource(eService);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(eService);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUpdateDeleteEService() throws Exception {
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
|
||||
null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||
accessPointFacet.setEntryName("port1");
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
||||
licenseFacet.setName("EUPL");
|
||||
licenseFacet.setTextURL(
|
||||
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
||||
eService.addFacet(licenseFacet);
|
||||
|
||||
eService = resourceRegistryPublisher.createResource(eService);
|
||||
|
||||
eService.getFacets(SoftwareFacet.class).get(0).setVersion("1.2.0");
|
||||
|
||||
eService = resourceRegistryPublisher.updateResource(eService);
|
||||
|
||||
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo("1.2.0") == 0);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(eService);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEServiceAsJsonString() throws Exception {
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
|
||||
null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||
accessPointFacet.setEntryName("port1");
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
||||
licenseFacet.setName("EUPL");
|
||||
licenseFacet.setTextURL(
|
||||
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
||||
eService.addFacet(licenseFacet);
|
||||
|
||||
String json = ElementMapper.marshal(eService);
|
||||
|
||||
String createdString = resourceRegistryPublisher.createResource(json);
|
||||
|
||||
EService created = ElementMapper.unmarshal(EService.class, createdString);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(created);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUpdateDeleteEServiceAsJsonString() throws Exception {
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
|
||||
null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||
accessPointFacet.setEntryName("port1");
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
||||
licenseFacet.setName("EUPL");
|
||||
licenseFacet.setTextURL(
|
||||
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
||||
eService.addFacet(licenseFacet);
|
||||
|
||||
eService = resourceRegistryPublisher.createResource(eService);
|
||||
|
||||
eService.getFacets(SoftwareFacet.class).get(0).setVersion("1.2.0");
|
||||
|
||||
eService = resourceRegistryPublisher.updateResource(eService);
|
||||
|
||||
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo("1.2.0") == 0);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(eService);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
public Map<String,Resource> createHostingNodeAndEService() throws Exception {
|
||||
Map<String,Resource> map = new HashMap<>();
|
||||
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
|
||||
IsIdentifiedBy<Resource,Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(eService, softwareFacet,
|
||||
null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||
accessPointFacet.setEntryName("port1");
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
eService = resourceRegistryPublisher.createResource(eService);
|
||||
map.put(EService.NAME, eService);
|
||||
|
||||
// networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet);
|
||||
// logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet);
|
||||
|
||||
HostingNode hostingNode = new HostingNodeImpl();
|
||||
|
||||
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
|
||||
networkingFacet.setIPAddress("146.48.87.183");
|
||||
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
|
||||
networkingFacet.setDomainName("isti.cnr.it");
|
||||
networkingFacet.setMask("255.255.248.0");
|
||||
networkingFacet.setBroadcastAddress("146.48.87.255");
|
||||
|
||||
isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null);
|
||||
hostingNode.addFacet(isIdentifiedBy);
|
||||
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
hostingNode.addFacet(cpuFacet);
|
||||
|
||||
MemoryFacet ram = new MemoryFacetImpl();
|
||||
ram.setSize(8);
|
||||
ram.setUnit(MemoryUnit.GB);
|
||||
ram.setUsed(2);
|
||||
|
||||
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory =
|
||||
new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(hostingNode, ram, null);
|
||||
hostingNode.addFacet(hasVolatileMemory);
|
||||
|
||||
|
||||
MemoryFacet disk = new MemoryFacetImpl();
|
||||
disk.setSize(256);
|
||||
disk.setUnit(MemoryUnit.GB);
|
||||
disk.setUsed(120);
|
||||
|
||||
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory =
|
||||
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
|
||||
hostingNode.addFacet(hasPersistentMemory);
|
||||
|
||||
StateFacet hnStateFacet = new StateFacetImpl();
|
||||
hnStateFacet.setValue("certified");
|
||||
hostingNode.addFacet(hnStateFacet);
|
||||
|
||||
EventFacet hnEventFacet = new EventFacetImpl();
|
||||
hnEventFacet.setDate(Calendar.getInstance().getTime());
|
||||
hnEventFacet.setEvent("Created");
|
||||
hostingNode.addFacet(hnEventFacet);
|
||||
|
||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
|
||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
|
||||
|
||||
Activates<HostingNode,EService> activates = new ActivatesImpl<HostingNode,EService>(hostingNode, eService,
|
||||
propagationConstraint);
|
||||
hostingNode.attachResource(activates);
|
||||
|
||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
||||
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
||||
map.put(HostingNode.NAME, hostingNode);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateHostingNodeAndEService() throws Exception {
|
||||
Map<String,Resource> map = createHostingNodeAndEService();
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
|
||||
Map<String,Resource> map = createHostingNodeAndEService();
|
||||
|
||||
EService eService = (EService) map.get(EService.NAME);
|
||||
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
|
||||
|
||||
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
|
||||
UUID sharedFacetUUID = shared.getID();
|
||||
|
||||
try {
|
||||
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
|
||||
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
|
||||
} catch (SchemaViolationException e) {
|
||||
logger.debug("As expected ", e);
|
||||
} finally {
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
try {
|
||||
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
|
||||
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.debug("Shared Facet was not found as expected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAll() throws Exception {
|
||||
Map<String,List<Resource>> resources = new HashMap<>();
|
||||
|
||||
final int MAX = 5;
|
||||
int typeNumber = 0;
|
||||
|
||||
for(int i = 0; i < MAX; i++) {
|
||||
Map<String,Resource> map = createHostingNodeAndEService();
|
||||
if(typeNumber == 0) {
|
||||
typeNumber = map.size();
|
||||
}
|
||||
for(String key : map.keySet()) {
|
||||
if(!resources.containsKey(key)) {
|
||||
resources.put(key, new ArrayList<Resource>());
|
||||
}
|
||||
resources.get(key).add(map.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
/* Getting all instances of created specific Resources */
|
||||
for(String key : resources.keySet()) {
|
||||
String instances = resourceRegistryClient.getInstances(key, false);
|
||||
List<Resource> list = ElementMapper.unmarshalList(Resource.class, instances);
|
||||
logger.debug("{} are {} : {} ", key, list.size(), list);
|
||||
Assert.assertTrue(list.size() == MAX);
|
||||
}
|
||||
|
||||
/* Getting all Resources polymorphic and non polymorphic */
|
||||
List<Resource> list = resourceRegistryClient.getInstances(Resource.class, true);
|
||||
logger.debug("{} are {} : {} ", Resource.NAME, list.size(), list);
|
||||
Assert.assertTrue(list.size() == (MAX * typeNumber));
|
||||
|
||||
list = resourceRegistryClient.getInstances(Resource.class, false);
|
||||
Assert.assertTrue(list.size() == 0);
|
||||
|
||||
/* Getting all IsRelatedTo polymorphic and non polymorphic */
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<IsRelatedTo> resourcesList = resourceRegistryClient.getInstances(IsRelatedTo.class, true);
|
||||
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, resourcesList.size(), resourcesList);
|
||||
Assert.assertTrue(resourcesList.size() == MAX);
|
||||
|
||||
resourcesList = resourceRegistryClient.getInstances(IsRelatedTo.class, false);
|
||||
Assert.assertTrue(resourcesList.size() == 0);
|
||||
|
||||
/* Getting all ConsistsOf polymorphic and non polymorphic */
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<ConsistsOf> consistsOfPolimorphicList = resourceRegistryClient.getInstances(ConsistsOf.class, true);
|
||||
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfPolimorphicList.size(), consistsOfPolimorphicList);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<ConsistsOf> consistsOfNonPolimorphicList = resourceRegistryClient.getInstances(ConsistsOf.class, false);
|
||||
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfNonPolimorphicList.size(),
|
||||
consistsOfNonPolimorphicList);
|
||||
|
||||
Assert.assertTrue(consistsOfPolimorphicList.size() >= consistsOfNonPolimorphicList.size());
|
||||
|
||||
/* Removing created Entity and Relation to have a clean DB */
|
||||
|
||||
List<Resource> resourceList = resources.get(HostingNode.NAME);
|
||||
for(Resource r : resourceList) {
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(r);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllFrom() throws Exception {
|
||||
Map<String,Resource> map = createHostingNodeAndEService();
|
||||
|
||||
EService eService = (EService) map.get(EService.NAME);
|
||||
UUID eServiceUUID = eService.getID();
|
||||
|
||||
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
|
||||
UUID hostingNodeUUID = hostingNode.getID();
|
||||
|
||||
/* EService */
|
||||
List<Resource> resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.BOTH, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
Resource resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getID().compareTo(hostingNodeUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.OUT, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getID().compareTo(hostingNodeUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.IN, true);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.BOTH, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.OUT, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.IN, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
/* END EService */
|
||||
|
||||
/* Hosting Node */
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.OUT, true);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.IN, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.OUT, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.IN, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
/* END HostingNode */
|
||||
|
||||
Facet identificationFacet = eService.getIdentificationFacets().get(0);
|
||||
UUID identificationFacetUUID = identificationFacet.getID();
|
||||
|
||||
|
||||
/* Eservice with Software Facet as Identification Facet */
|
||||
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
resource = resourceList.get(0);
|
||||
Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0);
|
||||
Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
|
||||
Assert.assertTrue(targetIdentificationFacet.getID().compareTo(identificationFacetUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
/* END Eservice with Software Facet as Identification Facet */
|
||||
|
||||
|
||||
|
||||
/* END SoftwareFacet of Eservice */
|
||||
/* Support removed
|
||||
List<Facet> facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
Facet facet = facets.get(0);
|
||||
Assert.assertTrue(facet.getUUID().compareTo(identificationFacetUUID) == 0);
|
||||
|
||||
facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
*/
|
||||
/* END SoftwareFacet of Eservice */
|
||||
|
||||
/* Removing created Entity and Relation to have a clean DB */
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateHostingNodeThenActivatesWithEService() throws Exception {
|
||||
|
||||
HostingNode hostingNode = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidHostingNode();
|
||||
|
||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
||||
|
||||
/* -------- */
|
||||
|
||||
EService eService = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidEService();
|
||||
|
||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
|
||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
|
||||
|
||||
Activates<HostingNode,EService> activates = new ActivatesImpl<HostingNode,EService>(hostingNode, eService,
|
||||
propagationConstraint);
|
||||
|
||||
activates = resourceRegistryPublisher.createIsRelatedTo(activates);
|
||||
hostingNode.attachResource(activates);
|
||||
|
||||
logger.debug("Created {} is {}", Activates.NAME, ElementMapper.marshal(activates));
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.publisher;
|
||||
package org.gcube.informationsystem.resourceregistry.publisher.old;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -9,7 +9,11 @@ import java.util.UUID;
|
|||
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.utils.ElementMapper;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
|
@ -25,7 +29,6 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNo
|
|||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -39,10 +42,15 @@ public class EntityManagementTest extends ContextTest {
|
|||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
|
||||
public EntityManagementTest(){
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testCreateUpdateDeleteFacet() throws Exception {
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
|
@ -55,7 +63,7 @@ public class EntityManagementTest extends ContextTest {
|
|||
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
||||
|
||||
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
||||
UUID uuid = createdCpuFacet.getID();
|
||||
|
||||
String newVendor = "Intel";
|
||||
String newClockSpeed = "2 GHz";
|
||||
|
@ -71,13 +79,13 @@ public class EntityManagementTest extends ContextTest {
|
|||
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
|
||||
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
|
||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
|
||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID())==0);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testCreateUpdateDeleteFacetStringAPI() throws Exception {
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
|
@ -92,7 +100,7 @@ public class EntityManagementTest extends ContextTest {
|
|||
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
||||
|
||||
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
||||
UUID uuid = createdCpuFacet.getID();
|
||||
|
||||
String newVendor = "Intel";
|
||||
String newClockSpeed = "2 GHz";
|
||||
|
@ -110,13 +118,13 @@ public class EntityManagementTest extends ContextTest {
|
|||
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
|
||||
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
|
||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
|
||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID())==0);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testCreateDeleteResources() throws Exception {
|
||||
|
||||
EService eService = new EServiceImpl();
|
||||
|
@ -191,7 +199,7 @@ public class EntityManagementTest extends ContextTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testCreateAndDeleteEntitiesAndRelations() throws Exception {
|
||||
EService eService = new EServiceImpl();
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.publisher;
|
||||
package org.gcube.informationsystem.resourceregistry.publisher.old;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
@ -10,8 +10,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.reference.ERElement;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
|
@ -19,6 +20,11 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
|
||||
|
@ -29,7 +35,6 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl
|
|||
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||
|
@ -45,7 +50,6 @@ import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFace
|
|||
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
||||
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
|
@ -68,9 +72,14 @@ public class MultiContextTest extends ContextTest {
|
|||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public MultiContextTest() throws Exception {
|
||||
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,15 +94,13 @@ public class MultiContextTest extends ContextTest {
|
|||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
accessPointFacet.setEndpoint(new URI("http://localhost"));
|
||||
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||
accessPointFacet.setEntryName("port1");
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
ValueSchema event = new ValueSchemaImpl();
|
||||
event.setValue("Created");
|
||||
eventFacet.setEvent(event);
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
|
@ -120,7 +127,6 @@ public class MultiContextTest extends ContextTest {
|
|||
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(hostingNode, networkingFacet, null);
|
||||
hostingNode.addFacet(isIdentifiedByHNNF);
|
||||
|
||||
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
|
@ -147,28 +153,34 @@ public class MultiContextTest extends ContextTest {
|
|||
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
|
||||
hostingNode.addFacet(hasPersistentMemory);
|
||||
|
||||
StateFacet hnStateFacet = new StateFacetImpl();
|
||||
hnStateFacet.setValue("certified");
|
||||
hostingNode.addFacet(hnStateFacet);
|
||||
|
||||
EventFacet hnEventFacet = new EventFacetImpl();
|
||||
hnEventFacet.setDate(Calendar.getInstance().getTime());
|
||||
hnEventFacet.setEvent("Created");
|
||||
hostingNode.addFacet(hnEventFacet);
|
||||
|
||||
|
||||
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, createdEService, null);
|
||||
hostingNode.attachResource(activates);
|
||||
|
||||
HostingNode createdHN = resourceRegistryPublisher.createResource(hostingNode);
|
||||
logger.debug("Created : {}", createdHN);
|
||||
|
||||
|
||||
UUID hostingNodeUUID = createdHN.getID();
|
||||
UUID eServiceUUID = createdEService.getID();
|
||||
|
||||
UUID alternativeContextUUID = ContextCache.getInstance().getUUIDByFullName(ALTERNATIVE_TEST_SCOPE);
|
||||
|
||||
|
||||
logger.debug("Changing token to test add to scope");
|
||||
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
|
||||
|
||||
|
||||
UUID hostingNodeUUID = createdHN.getHeader().getUUID();
|
||||
UUID eServiceUUID = createdEService.getHeader().getUUID();
|
||||
resourceRegistryPublisher.addResourceToContext(createdHN, alternativeContextUUID, false);
|
||||
|
||||
logger.debug("Changing token to test add to scope");
|
||||
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
|
||||
|
||||
try {
|
||||
resourceRegistryClient.exists(EService.class, eServiceUUID);
|
||||
resourceRegistryClient.existInstance(EService.class, eServiceUUID);
|
||||
} catch (NotFoundException e) {
|
||||
throw e;
|
||||
} catch (AvailableInAnotherContextException e) {
|
||||
|
@ -179,7 +191,7 @@ public class MultiContextTest extends ContextTest {
|
|||
|
||||
|
||||
try {
|
||||
resourceRegistryClient.exists(HostingNode.class, hostingNodeUUID);
|
||||
resourceRegistryClient.existInstance(HostingNode.class, hostingNodeUUID);
|
||||
} catch (NotFoundException e) {
|
||||
throw e;
|
||||
} catch (AvailableInAnotherContextException e) {
|
||||
|
@ -189,11 +201,12 @@ public class MultiContextTest extends ContextTest {
|
|||
}
|
||||
|
||||
|
||||
boolean addedToContext = resourceRegistryPublisher.addResourceToCurrentContext(createdHN);
|
||||
Assert.assertTrue(addedToContext);
|
||||
List<ERElement> affectedInstances = resourceRegistryPublisher.addResourceToCurrentContext(createdHN, false);
|
||||
logger.debug("{} added to context. Affected instances are {}", createdHN, affectedInstances);
|
||||
//Assert.assertTrue(addedToContext);
|
||||
|
||||
try {
|
||||
resourceRegistryClient.exists(EService.class, eServiceUUID);
|
||||
resourceRegistryClient.existInstance(EService.class, eServiceUUID);
|
||||
}catch(AvailableInAnotherContextException e){
|
||||
logger.debug("Resource with {} Available in another Context as Expected", eServiceUUID.toString());
|
||||
}
|
||||
|
@ -211,8 +224,8 @@ public class MultiContextTest extends ContextTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllContexts() throws Exception {
|
||||
List<Context> contexts = resourceRegistryPublisher.getAllContext();
|
||||
public void testGetContexts() throws Exception {
|
||||
List<Context> contexts = resourceRegistryPublisher.getContexts();
|
||||
logger.debug("{}", contexts);
|
||||
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
|
@ -221,11 +234,11 @@ public class MultiContextTest 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;
|
||||
|
@ -236,9 +249,9 @@ public class MultiContextTest 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +259,7 @@ public class MultiContextTest extends ContextTest {
|
|||
logger.debug("Current context : {}", currentContext);
|
||||
|
||||
for(Context c : contexts) {
|
||||
UUID uuid = c.getHeader().getUUID();
|
||||
UUID uuid = c.getID();
|
||||
Context context = resourceRegistryPublisher.getContext(uuid);
|
||||
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
|
||||
logger.debug("{} - {} : {}", uuid, fullName, context);
|
|
@ -0,0 +1,22 @@
|
|||
type=USER
|
||||
#type=CLIENT_ID
|
||||
|
||||
username=luca.frosini
|
||||
password=Pupp4M3l0
|
||||
|
||||
#username=grsf.publisher
|
||||
#password=grsfcambiami
|
||||
|
||||
#clientId=grsf-publisher
|
||||
#/gcube=54cc7454-1a84-11ee-be56-0242ac120002
|
||||
#/pred4s=de293f60-e004-45ce-b64f-20de77fad888
|
||||
#/d4science.research-infrastructures.eu=
|
||||
|
||||
#client_id=junit.tests.luca.frosini
|
||||
#/gcube=6b0d0222-3130-41f1-a86d-6b23993547be
|
||||
|
||||
|
||||
#clientId=gcat
|
||||
#/gcube=712add63-c642-4a6a-8ddc-283dc978120a
|
||||
#/pred4s=4e35a122-8f25-48f9-9788-8588ee86633f
|
||||
#/d4science.research-infrastructures.eu=
|
Loading…
Reference in New Issue