Merge branch '#22686'
# Conflicts: # geoportal-client/CHANGELOG.md # geoportal-client/pom.xml
This commit is contained in:
commit
703ef65f66
|
@ -2,6 +2,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for org.gcube.spatial.data.gcube-sdi-suite
|
||||
|
||||
## [v1.0.2] - 2021-02-24
|
||||
-Introduced module sdi-plugins
|
||||
-Introduced module notifications-plugins
|
||||
-Introduced module dataminer-plugins
|
||||
-Introduced module images-plugins
|
||||
-Introduced module ckan-plugin
|
||||
|
||||
## [v1.0.1] - 2021-12-07
|
||||
- Introduced cms-plugin-framework
|
||||
- Introduced concessioni use case
|
||||
|
|
26
README.md
26
README.md
|
@ -1,7 +1,27 @@
|
|||
gCube CMS Suite
|
||||
--------------------------------------------------
|
||||
|
||||
gCube CMS Suite is a set of components designed to manage complex space-temporal Documents defined by metadata Profiles.
|
||||
gCube CMS Suite is a distributed full stack application for publication management in a gCube Hybrid e-infrastructure. Check wiki [here](https://sublime-and-sphinx-guide.readthedocs.io)
|
||||
|
||||
[<img src="https://gcube.wiki.gcube-system.org/images_gcube/e/e4/Geo_Portale%281%29.png">](https://www.sphinx-doc.org/en/master/)
|
||||
|
||||
|
||||
Rationale :
|
||||
|
||||
Publication involves lots of common features as well as custom behaviour and formats. The service implements the basic common logic, delegating to installed plugin both cutom and configurable functions ranging from validation, data manifestazion, indexing and lifecycle management.
|
||||
Lifecycle management is itself an extension allowing for both common and complex ad-hoc workflows.
|
||||
High modularity of plugins allows for the composition of ad hoc use cases with maximized re-usability.
|
||||
|
||||
The suite comes with a set of pre-built plugins and GUIs that communities can easily extend and / or reuse.
|
||||
|
||||
|
||||
## Documentation
|
||||
* [Dedicated Wiki](https://sublime-and-sphinx-guide.readthedocs.io) - TBD Powered by [Sphynx](https://www.sphinx-doc.org/en/master/)
|
||||
* [Service Interactive API]() -TBD Powered by [Enunciate](http://enunciate.webcohesion.com/)
|
||||
* [Gcube System Wiki](https://gcube.wiki.gcube-system.org/gcube/GeoPortal).
|
||||
* [Guide Notebooks](use-cases) - Powered by [Jupyter](https://jupyter.org/)
|
||||
* [Service Wiki src](use-cases/src/site/suite.rst)
|
||||
|
||||
|
||||
## Built with
|
||||
* [gCube SmartGears] (https://gcube.wiki.gcube-system.org/gcube/SmartGears) - The gCube SmartGears framework
|
||||
|
@ -9,10 +29,8 @@ gCube CMS Suite is a set of components designed to manage complex space-temporal
|
|||
* [JAX-RS](https://github.com/eclipse-ee4j/jaxrs-api) - Java™ API for RESTful Web Services
|
||||
* [Jersey](https://jersey.github.io/) - JAX-RS runtime
|
||||
* [Maven](https://maven.apache.org/) - Dependency Management
|
||||
* [Enunciate] (http://enunciate.webcohesion.com/) - API Documentation
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation can be found [here](https://gcube.wiki.gcube-system.org/gcube/GeoPortal_Service).
|
||||
|
||||
## Change log
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
# Changelog for org.gcube.application.cms.ckan-plugin
|
||||
|
||||
This library contains gcube-cms plugins for ckan materializations
|
||||
|
||||
## [v1.0.0] - 2022-02-24
|
||||
- First release
|
|
@ -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);
|
|
@ -0,0 +1,312 @@
|
|||
# European Union Public Licence V. 1.1
|
||||
|
||||
|
||||
EUPL © the European Community 2007
|
||||
|
||||
|
||||
This European Union Public Licence (the “EUPL”) applies to the Work or Software
|
||||
(as defined below) which is provided under the terms of this Licence. Any use of
|
||||
the Work, other than as authorised under this Licence is prohibited (to the
|
||||
extent such use is covered by a right of the copyright holder of the Work).
|
||||
|
||||
The Original Work is provided under the terms of this Licence when the Licensor
|
||||
(as defined below) has placed the following notice immediately following the
|
||||
copyright notice for the Original Work:
|
||||
|
||||
Licensed under the EUPL V.1.1
|
||||
|
||||
or has expressed by any other mean his willingness to license under the EUPL.
|
||||
|
||||
|
||||
|
||||
## 1. Definitions
|
||||
|
||||
In this Licence, the following terms have the following meaning:
|
||||
|
||||
- The Licence: this Licence.
|
||||
|
||||
- The Original Work or the Software: the software distributed and/or
|
||||
communicated by the Licensor under this Licence, available as Source Code and
|
||||
also as Executable Code as the case may be.
|
||||
|
||||
- Derivative Works: the works or software that could be created by the Licensee,
|
||||
based upon the Original Work or modifications thereof. This Licence does not
|
||||
define the extent of modification or dependence on the Original Work required
|
||||
in order to classify a work as a Derivative Work; this extent is determined by
|
||||
copyright law applicable in the country mentioned in Article 15.
|
||||
|
||||
- The Work: the Original Work and/or its Derivative Works.
|
||||
|
||||
- The Source Code: the human-readable form of the Work which is the most
|
||||
convenient for people to study and modify.
|
||||
|
||||
- The Executable Code: any code which has generally been compiled and which is
|
||||
meant to be interpreted by a computer as a program.
|
||||
|
||||
- The Licensor: the natural or legal person that distributes and/or communicates
|
||||
the Work under the Licence.
|
||||
|
||||
- Contributor(s): any natural or legal person who modifies the Work under the
|
||||
Licence, or otherwise contributes to the creation of a Derivative Work.
|
||||
|
||||
- The Licensee or “You”: any natural or legal person who makes any usage of the
|
||||
Software under the terms of the Licence.
|
||||
|
||||
- Distribution and/or Communication: any act of selling, giving, lending,
|
||||
renting, distributing, communicating, transmitting, or otherwise making
|
||||
available, on-line or off-line, copies of the Work or providing access to its
|
||||
essential functionalities at the disposal of any other natural or legal
|
||||
person.
|
||||
|
||||
|
||||
|
||||
## 2. Scope of the rights granted by the Licence
|
||||
|
||||
The Licensor hereby grants You a world-wide, royalty-free, non-exclusive,
|
||||
sub-licensable licence to do the following, for the duration of copyright vested
|
||||
in the Original Work:
|
||||
|
||||
- use the Work in any circumstance and for all usage, reproduce the Work, modify
|
||||
- the Original Work, and make Derivative Works based upon the Work, communicate
|
||||
- to the public, including the right to make available or display the Work or
|
||||
- copies thereof to the public and perform publicly, as the case may be, the
|
||||
- Work, distribute the Work or copies thereof, lend and rent the Work or copies
|
||||
- thereof, sub-license rights in the Work or copies thereof.
|
||||
|
||||
Those rights can be exercised on any media, supports and formats, whether now
|
||||
known or later invented, as far as the applicable law permits so.
|
||||
|
||||
In the countries where moral rights apply, the Licensor waives his right to
|
||||
exercise his moral right to the extent allowed by law in order to make effective
|
||||
the licence of the economic rights here above listed.
|
||||
|
||||
The Licensor grants to the Licensee royalty-free, non exclusive usage rights to
|
||||
any patents held by the Licensor, to the extent necessary to make use of the
|
||||
rights granted on the Work under this Licence.
|
||||
|
||||
|
||||
|
||||
## 3. Communication of the Source Code
|
||||
|
||||
The Licensor may provide the Work either in its Source Code form, or as
|
||||
Executable Code. If the Work is provided as Executable Code, the Licensor
|
||||
provides in addition a machine-readable copy of the Source Code of the Work
|
||||
along with each copy of the Work that the Licensor distributes or indicates, in
|
||||
a notice following the copyright notice attached to the Work, a repository where
|
||||
the Source Code is easily and freely accessible for as long as the Licensor
|
||||
continues to distribute and/or communicate the Work.
|
||||
|
||||
|
||||
|
||||
## 4. Limitations on copyright
|
||||
|
||||
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
||||
any exception or limitation to the exclusive rights of the rights owners in the
|
||||
Original Work or Software, of the exhaustion of those rights or of other
|
||||
applicable limitations thereto.
|
||||
|
||||
|
||||
|
||||
## 5. Obligations of the Licensee
|
||||
|
||||
The grant of the rights mentioned above is subject to some restrictions and
|
||||
obligations imposed on the Licensee. Those obligations are the following:
|
||||
|
||||
Attribution right: the Licensee shall keep intact all copyright, patent or
|
||||
trademarks notices and all notices that refer to the Licence and to the
|
||||
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
||||
copy of the Licence with every copy of the Work he/she distributes and/or
|
||||
communicates. The Licensee must cause any Derivative Work to carry prominent
|
||||
notices stating that the Work has been modified and the date of modification.
|
||||
|
||||
Copyleft clause: If the Licensee distributes and/or communicates copies of the
|
||||
Original Works or Derivative Works based upon the Original Work, this
|
||||
Distribution and/or Communication will be done under the terms of this Licence
|
||||
or of a later version of this Licence unless the Original Work is expressly
|
||||
distributed only under this version of the Licence. The Licensee (becoming
|
||||
Licensor) cannot offer or impose any additional terms or conditions on the Work
|
||||
or Derivative Work that alter or restrict the terms of the Licence.
|
||||
|
||||
Compatibility clause: If the Licensee Distributes and/or Communicates Derivative
|
||||
Works or copies thereof based upon both the Original Work and another work
|
||||
licensed under a Compatible Licence, this Distribution and/or Communication can
|
||||
be done under the terms of this Compatible Licence. For the sake of this clause,
|
||||
“Compatible Licence” refers to the licences listed in the appendix attached to
|
||||
this Licence. Should the Licensee’s obligations under the Compatible Licence
|
||||
conflict with his/her obligations under this Licence, the obligations of the
|
||||
Compatible Licence shall prevail.
|
||||
|
||||
Provision of Source Code: When distributing and/or communicating copies of the
|
||||
Work, the Licensee will provide a machine-readable copy of the Source Code or
|
||||
indicate a repository where this Source will be easily and freely available for
|
||||
as long as the Licensee continues to distribute and/or communicate the Work.
|
||||
|
||||
Legal Protection: This Licence does not grant permission to use the trade names,
|
||||
trademarks, service marks, or names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the copyright notice.
|
||||
|
||||
|
||||
|
||||
## 6. Chain of Authorship
|
||||
|
||||
The original Licensor warrants that the copyright in the Original Work granted
|
||||
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
||||
power and authority to grant the Licence.
|
||||
|
||||
Each Contributor warrants that the copyright in the modifications he/she brings
|
||||
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
||||
power and authority to grant the Licence.
|
||||
|
||||
Each time You accept the Licence, the original Licensor and subsequent
|
||||
Contributors grant You a licence to their contributions to the Work, under the
|
||||
terms of this Licence.
|
||||
|
||||
|
||||
|
||||
## 7. Disclaimer of Warranty
|
||||
|
||||
The Work is a work in progress, which is continuously improved by numerous
|
||||
contributors. It is not a finished work and may therefore contain defects or
|
||||
“bugs” inherent to this type of software development.
|
||||
|
||||
For the above reason, the Work is provided under the Licence on an “as is” basis
|
||||
and without warranties of any kind concerning the Work, including without
|
||||
limitation merchantability, fitness for a particular purpose, absence of defects
|
||||
or errors, accuracy, non-infringement of intellectual property rights other than
|
||||
copyright as stated in Article 6 of this Licence.
|
||||
|
||||
This disclaimer of warranty is an essential part of the Licence and a condition
|
||||
for the grant of any rights to the Work.
|
||||
|
||||
|
||||
|
||||
## 8. Disclaimer of Liability
|
||||
|
||||
Except in the cases of wilful misconduct or damages directly caused to natural
|
||||
persons, the Licensor will in no event be liable for any direct or indirect,
|
||||
material or moral, damages of any kind, arising out of the Licence or of the use
|
||||
of the Work, including without limitation, damages for loss of goodwill, work
|
||||
stoppage, computer failure or malfunction, loss of data or any commercial
|
||||
damage, even if the Licensor has been advised of the possibility of such
|
||||
damage. However, the Licensor will be liable under statutory product liability
|
||||
laws as far such laws apply to the Work.
|
||||
|
||||
|
||||
|
||||
## 9. Additional agreements
|
||||
|
||||
While distributing the Original Work or Derivative Works, You may choose to
|
||||
conclude an additional agreement to offer, and charge a fee for, acceptance of
|
||||
support, warranty, indemnity, or other liability obligations and/or services
|
||||
consistent with this Licence. However, in accepting such obligations, You may
|
||||
act only on your own behalf and on your sole responsibility, not on behalf of
|
||||
the original Licensor or any other Contributor, and only if You agree to
|
||||
indemnify, defend, and hold each Contributor harmless for any liability incurred
|
||||
by, or claims asserted against such Contributor by the fact You have accepted
|
||||
any such warranty or additional liability.
|
||||
|
||||
|
||||
|
||||
## 10. Acceptance of the Licence
|
||||
|
||||
The provisions of this Licence can be accepted by clicking on an icon “I agree”
|
||||
placed under the bottom of a window displaying the text of this Licence or by
|
||||
affirming consent in any other similar way, in accordance with the rules of
|
||||
applicable law. Clicking on that icon indicates your clear and irrevocable
|
||||
acceptance of this Licence and all of its terms and conditions.
|
||||
|
||||
Similarly, you irrevocably accept this Licence and all of its terms and
|
||||
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
||||
such as the use of the Work, the creation by You of a Derivative Work or the
|
||||
Distribution and/or Communication by You of the Work or copies thereof.
|
||||
|
||||
|
||||
|
||||
## 11. Information to the public
|
||||
|
||||
In case of any Distribution and/or Communication of the Work by means of
|
||||
electronic communication by You (for example, by offering to download the Work
|
||||
from a remote location) the distribution channel or media (for example, a
|
||||
website) must at least provide to the public the information requested by the
|
||||
applicable law regarding the Licensor, the Licence and the way it may be
|
||||
accessible, concluded, stored and reproduced by the Licensee.
|
||||
|
||||
|
||||
|
||||
## 12. Termination of the Licence
|
||||
|
||||
The Licence and the rights granted hereunder will terminate automatically upon
|
||||
any breach by the Licensee of the terms of the Licence.
|
||||
|
||||
Such a termination will not terminate the licences of any person who has
|
||||
received the Work from the Licensee under the Licence, provided such persons
|
||||
remain in full compliance with the Licence.
|
||||
|
||||
|
||||
|
||||
## 13. Miscellaneous
|
||||
|
||||
Without prejudice of Article 9 above, the Licence represents the complete
|
||||
agreement between the Parties as to the Work licensed hereunder.
|
||||
|
||||
If any provision of the Licence is invalid or unenforceable under applicable
|
||||
law, this will not affect the validity or enforceability of the Licence as a
|
||||
whole. Such provision will be construed and/or reformed so as necessary to make
|
||||
it valid and enforceable.
|
||||
|
||||
The European Commission may publish other linguistic versions and/or new
|
||||
versions of this Licence, so far this is required and reasonable, without
|
||||
reducing the scope of the rights granted by the Licence. New versions of the
|
||||
Licence will be published with a unique version number.
|
||||
|
||||
All linguistic versions of this Licence, approved by the European Commission,
|
||||
have identical value. Parties can take advantage of the linguistic version of
|
||||
their choice.
|
||||
|
||||
|
||||
|
||||
## 14. Jurisdiction
|
||||
|
||||
Any litigation resulting from the interpretation of this License, arising
|
||||
between the European Commission, as a Licensor, and any Licensee, will be
|
||||
subject to the jurisdiction of the Court of Justice of the European Communities,
|
||||
as laid down in article 238 of the Treaty establishing the European Community.
|
||||
|
||||
Any litigation arising between Parties, other than the European Commission, and
|
||||
resulting from the interpretation of this License, will be subject to the
|
||||
exclusive jurisdiction of the competent court where the Licensor resides or
|
||||
conducts its primary business.
|
||||
|
||||
|
||||
|
||||
## 15. Applicable Law
|
||||
|
||||
This Licence shall be governed by the law of the European Union country where
|
||||
the Licensor resides or has his registered office.
|
||||
|
||||
This licence shall be governed by the Belgian law if:
|
||||
|
||||
- a litigation arises between the European Commission, as a Licensor, and any
|
||||
- Licensee; the Licensor, other than the European Commission, has no residence
|
||||
- or registered office inside a European Union country.
|
||||
|
||||
|
||||
|
||||
## Appendix
|
||||
|
||||
|
||||
|
||||
“Compatible Licences” according to article 5 EUPL are:
|
||||
|
||||
|
||||
- GNU General Public License (GNU GPL) v. 2
|
||||
|
||||
- Open Software License (OSL) v. 2.1, v. 3.0
|
||||
|
||||
- Common Public License v. 1.0
|
||||
|
||||
- Eclipse Public License v. 1.0
|
||||
|
||||
- Cecill v. 2.0
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
gCube CMS Suite
|
||||
--------------------------------------------------
|
||||
|
||||
gCube CMS Suite is a set of components designed to manage complex space-temporal Documents defined by metadata Profiles.
|
||||
|
||||
## Built with
|
||||
* [gCube SmartGears] (https://gcube.wiki.gcube-system.org/gcube/SmartGears) - The gCube SmartGears framework
|
||||
* [OpenJDK](https://openjdk.java.net/) - The JDK used
|
||||
* [JAX-RS](https://github.com/eclipse-ee4j/jaxrs-api) - Java™ API for RESTful Web Services
|
||||
* [Jersey](https://jersey.github.io/) - JAX-RS runtime
|
||||
* [Maven](https://maven.apache.org/) - Dependency Management
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation can be found [here](https://gcube.wiki.gcube-system.org/gcube/GeoPortal_Service).
|
||||
|
||||
## Change log
|
||||
|
||||
See [CHANGELOG.md](CHANGELOG.md).
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the EUPL V.1.1 License - see the [LICENSE.md](LICENSE.md) file for details.
|
||||
|
||||
## About the gCube Framework
|
||||
This software is part of the [gCubeFramework](https://www.gcube-system.org/ "gCubeFramework"): an
|
||||
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);
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ckan-plugins</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>gCube CMS - CKAN Plugins</name>
|
||||
|
||||
|
||||
<parent>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>gcube-cms-suite</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
|
||||
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gcube-cms-suite</connection>
|
||||
<developerConnection>scm:git:${gitBaseUrl}/gcube-cms-suite</developerConnection>
|
||||
<url>${gitBaseUrl}/gcube-cms-suite</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>${gcube-smartgears-bom-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>cms-plugin-framework</artifactId>
|
||||
<version>${plugin-framework-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>cms-plugin-framework</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>cms-test-commons</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-uberjar</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>make-servicearchive</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,2 @@
|
|||
public class CkanPlugin {
|
||||
}
|
|
@ -2,5 +2,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for org.gcube.application.cms-plugin-framework
|
||||
|
||||
## [v1.0.1] 2022-01-17
|
||||
- Serialization Features
|
||||
|
||||
## [v1.0.0] 2021-09-20
|
||||
- First release
|
|
@ -4,19 +4,18 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cms-plugin-framework</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>gcube-cms-suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
<sis.version>1.0</sis.version>
|
||||
|
||||
</properties>
|
||||
|
||||
|
||||
|
@ -28,16 +27,92 @@
|
|||
</scm>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>${gcube-smartgears-bom-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- TO REMOVE WHEN LEGACY SUPPORT IS REMOVED -->
|
||||
<!-- DEPRECATED LEGACY LOGIC SUPPORT -->
|
||||
|
||||
<!-- POSTGRES DRIVERS -->
|
||||
<dependency>
|
||||
<groupId>net.postgis</groupId>
|
||||
<artifactId>postgis-jdbc</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SDI -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.spatial.data</groupId>
|
||||
<artifactId>gis-interface</artifactId>
|
||||
<version>[2.4.6,3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- DT -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>data-transfer-library</artifactId>
|
||||
<version>[1.2.1,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>geoportal-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Storage HUB -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/de.grundid.opendatalab/geojson-jackson -->
|
||||
<dependency>
|
||||
<groupId>de.grundid.opendatalab</groupId>
|
||||
<artifactId>geojson-jackson</artifactId>
|
||||
<version>1.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Common - basic -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<!-- <version>2.3.0</version>-->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,40 @@
|
|||
package org.gcube.application.cms.caches;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||
|
||||
@Slf4j
|
||||
/**
|
||||
* TTL Map Context -> T
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractScopedMap<T> extends TimedMap<String,T> implements Engine<T>{
|
||||
|
||||
public AbstractScopedMap(@NonNull String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getObject() throws ConfigurationException {
|
||||
return get(ContextUtils.getCurrentScope());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init() {}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
log.warn(name + ": shutting down");
|
||||
scopeMap.forEach((String s,TTLObject<T> o)->{
|
||||
try{if(o!=null&&o.getTheObject()!=null)
|
||||
dispose(o.getTheObject());
|
||||
}catch(Throwable t) {
|
||||
log.warn(name +": unable to dispose ",t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.application.cms.caches;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
public interface Cache<K,V>{
|
||||
|
||||
public V get(K key) throws ConfigurationException;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.gcube.application.cms.caches;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
|
||||
public interface Engine <T> {
|
||||
|
||||
public void init();
|
||||
public void shutdown();
|
||||
|
||||
public T getObject() throws ConfigurationException;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.application.cms.caches;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
public interface ObjectManager<T>{
|
||||
|
||||
public T insert(T object) throws ConfigurationException;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.application.geoportal.service.engine.providers;
|
||||
package org.gcube.application.cms.caches;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
|
@ -0,0 +1,55 @@
|
|||
package org.gcube.application.cms.caches;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public abstract class TimedMap <K,V> implements Cache<K,V> {
|
||||
|
||||
protected ConcurrentHashMap<K, TTLObject<V>> scopeMap=new ConcurrentHashMap<K,TTLObject<V>>();
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
protected TemporalAmount TTL=null;
|
||||
|
||||
@NonNull
|
||||
protected String name;
|
||||
|
||||
@Override
|
||||
public V get(K key) throws ConfigurationException {
|
||||
log.trace(name+" : obtaining object by "+key);
|
||||
|
||||
TTLObject<V> found=scopeMap.get(key);
|
||||
|
||||
if(found== null){
|
||||
log.debug(name+" : init object for key "+key);
|
||||
TTLObject<V> toPut=new TTLObject<V>(LocalDateTime.now(),retrieveObject(key));
|
||||
scopeMap.put(key, toPut);
|
||||
return toPut.getTheObject();
|
||||
}
|
||||
|
||||
if(getTTL()!=null) {
|
||||
if(found.getCreationTime().plus(getTTL()).isBefore(LocalDateTime.now())) {
|
||||
log.debug(name+" : elapsed TTL, disposing..");
|
||||
dispose(found.getTheObject());
|
||||
TTLObject<V> newer=new TTLObject<V>(LocalDateTime.now(),retrieveObject(key));
|
||||
scopeMap.put(key, newer);
|
||||
found=scopeMap.get(key);
|
||||
}
|
||||
}else {log.trace(name+" : TTL is null, never disposing..");}
|
||||
log.trace(name+"Returning {} ",found);
|
||||
return found.getTheObject();
|
||||
}
|
||||
|
||||
protected abstract V retrieveObject(K key) throws ConfigurationException;
|
||||
protected void dispose(V toDispose){};
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package org.gcube.application.cms.implementations;
|
||||
|
||||
import org.gcube.application.cms.caches.Engine;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||
import org.gcube.application.geoportal.common.utils.ISUtils;
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultISProvider implements ISInterface, Engine<ISInterface> {
|
||||
|
||||
|
||||
@Override
|
||||
public DatabaseConnection queryForDatabase(String category, String platform, String flagName, String flagValue) throws ConfigurationException {
|
||||
return ISUtils.performQueryForDB(category, platform, flagName, flagValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceEndpoint.AccessPoint> performGetAP(String category, String platform, String flagName, String flagValue) {
|
||||
return ISUtils.performGetAP(category, platform, flagName, flagValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decryptString(String toDecrypt) {
|
||||
return ISUtils.decryptString(toDecrypt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encryptString(String toEncrypt) {
|
||||
return ISUtils.encryptString(toEncrypt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GenericResource> getGenericResource(String secondaryType,String name) {
|
||||
return ISUtils.getGenericResources(secondaryType,name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericResource createUpdateGR(GenericResource resource) {
|
||||
return ISUtils.writeGR(resource);
|
||||
}
|
||||
|
||||
// ** ENGINE
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISInterface getObject() throws ConfigurationException {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.gcube.application.cms.implementations;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ISInterface {
|
||||
|
||||
public DatabaseConnection queryForDatabase(String category, String platform,String flagName, String flagValue) throws ConfigurationException;
|
||||
public List<ServiceEndpoint.AccessPoint> performGetAP(String category, String platform, String flagName, String flagValue);
|
||||
public String decryptString(String toDecrypt);
|
||||
public String encryptString(String toEncrypt);
|
||||
|
||||
public List<GenericResource> getGenericResource(String secondaryType,String name);
|
||||
|
||||
|
||||
public GenericResource createUpdateGR(GenericResource res);
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package org.gcube.application.cms.implementations;
|
||||
|
||||
|
||||
import lombok.Synchronized;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.caches.Engine;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class ImplementationProvider {
|
||||
|
||||
private static ImplementationProvider instance=null;
|
||||
|
||||
@Synchronized
|
||||
public static ImplementationProvider get() {
|
||||
if(instance==null) {
|
||||
instance=new ImplementationProvider();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public <T> T getProvidedObjectByClass(Class<T> clazz) throws ConfigurationException {
|
||||
return (T) implementationsRegistry.get(clazz).getObject();
|
||||
}
|
||||
|
||||
public <T> Engine<T> getEngineByManagedClass(Class<T> clazz) throws ConfigurationException {
|
||||
return implementationsRegistry.get(clazz);
|
||||
}
|
||||
|
||||
private ConcurrentHashMap<Class,Engine> implementationsRegistry=new ConcurrentHashMap<>();
|
||||
|
||||
public <T> void setEngine(Engine<T> engine, Class<T> clazz){
|
||||
implementationsRegistry.put(clazz,engine);
|
||||
}
|
||||
|
||||
private ImplementationProvider(){
|
||||
//Defaults
|
||||
setEngine(new DefaultISProvider(),ISInterface.class);
|
||||
setEngine(new StorageHubProvider(), StorageHubClient.class);
|
||||
}
|
||||
public Map<Class,String> getManagerList(){
|
||||
HashMap<Class,String> toReturn=new HashMap<>();
|
||||
implementationsRegistry.forEach(
|
||||
(aClass, engine) -> {toReturn.put(engine.getClass(),aClass.getCanonicalName());}
|
||||
);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private boolean isInit=false;
|
||||
|
||||
@Synchronized
|
||||
public void initEngines(){
|
||||
if(!isInit) {
|
||||
log.info("INITIALIZING ENGINES. Size : {} ", implementationsRegistry.size());
|
||||
HashSet<Class> failed = new HashSet<>();
|
||||
implementationsRegistry.forEach((aClass, engine) -> {
|
||||
log.info("Init : {} -> {}", engine.getClass().toGenericString(), aClass.getCanonicalName());
|
||||
try {
|
||||
engine.init();
|
||||
} catch (Throwable t) {
|
||||
failed.add(engine.getClass());
|
||||
log.error("Unable to start engine {} ", engine.getClass(), t);
|
||||
}
|
||||
});
|
||||
if (failed.isEmpty())
|
||||
log.info("INIT OK");
|
||||
else {
|
||||
log.warn("!!!!! Following Engines FAILED INIT :");
|
||||
failed.forEach(aClass -> log.warn(String.valueOf(aClass)));
|
||||
}
|
||||
isInit = true;
|
||||
}else log.info("Received Init request but Engines already started");
|
||||
}
|
||||
|
||||
public void shutdownEngines(){
|
||||
log.info("SHUTTING DOWN ENGINES. Size : {} ",implementationsRegistry.size());
|
||||
HashSet<Class> failed= new HashSet<>();
|
||||
implementationsRegistry.forEach((aClass, engine) -> {
|
||||
log.info("ShotDown : {} -> {}",engine.getClass().toGenericString(),aClass.getCanonicalName());
|
||||
try{
|
||||
engine.shutdown();
|
||||
}catch (Throwable t){
|
||||
failed.add(engine.getClass());
|
||||
log.error("Unable to shutdown engine {} ",engine.getClass(),t);
|
||||
}
|
||||
});
|
||||
if(failed.isEmpty())
|
||||
log.info("SHUTDOWN OK");
|
||||
else {
|
||||
log.warn("!!!!! Following Engines FAILED SHUTDOWN :");
|
||||
failed.forEach(aClass->log.warn(String.valueOf(aClass)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.application.cms.implementations;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.implementations.faults.InvalidUserRoleException;
|
||||
import org.gcube.application.cms.implementations.faults.ProjectNotFoundException;
|
||||
import org.gcube.application.cms.implementations.faults.RegistrationException;
|
||||
import org.gcube.application.cms.implementations.faults.UnauthorizedAccess;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProjectAccess {
|
||||
|
||||
|
||||
public Project getById(String ucid,String id) throws RegistrationException, ConfigurationException, InvalidUserRoleException, ProjectNotFoundException, UnauthorizedAccess;
|
||||
|
||||
public Iterable<Document> query(String ucid, QueryRequest query) throws RegistrationException, ConfigurationException, InvalidUserRoleException;
|
||||
|
||||
public List<RelationshipNavigationObject> getRelations(String ucid, String id, String relation,Boolean deep) throws InvalidUserRoleException, RegistrationException, ProjectNotFoundException, ConfigurationException, UnauthorizedAccess;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.gcube.application.cms.implementations;
|
||||
|
||||
import org.gcube.application.cms.caches.Engine;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
|
||||
public class StorageHubProvider implements Engine<StorageHubClient> {
|
||||
|
||||
|
||||
@Override
|
||||
public StorageHubClient getObject() throws ConfigurationException {
|
||||
return new StorageHubClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {}
|
||||
@Override
|
||||
public void shutdown() { }
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package org.gcube.application.cms.implementations;
|
||||
|
||||
public interface WSInterface {
|
||||
}
|
|
@ -1,18 +1,16 @@
|
|||
package org.gcube.application.geoportal.service.engine;
|
||||
package org.gcube.application.cms.implementations;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.geoportal.common.faults.PathException;
|
||||
import org.gcube.application.geoportal.common.model.legacy.WorkspaceContent;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Archive;
|
||||
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFile;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Slf4j
|
||||
|
@ -22,6 +20,7 @@ public class WorkspaceManager {
|
|||
|
||||
|
||||
private StorageHubClient sgClient=null;
|
||||
@Getter
|
||||
private FolderContainer appBase=null;
|
||||
|
||||
@Getter
|
||||
|
@ -29,7 +28,7 @@ public class WorkspaceManager {
|
|||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public static class FolderOptions{
|
||||
@NotNull
|
||||
@NonNull
|
||||
private String folderName;
|
||||
private String folderDescription;
|
||||
private FolderContainer parent;
|
||||
|
@ -40,7 +39,7 @@ public class WorkspaceManager {
|
|||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public static class FileOptions{
|
||||
@NotNull
|
||||
@NonNull
|
||||
private String fileName;
|
||||
@NonNull
|
||||
private InputStream is;
|
||||
|
@ -50,9 +49,14 @@ public class WorkspaceManager {
|
|||
|
||||
}
|
||||
|
||||
public Archive getConfiguration(){
|
||||
Archive toReturn = new Archive("W-STORAGE");
|
||||
toReturn.put("folder_id",appBase.getId());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public WorkspaceManager() throws ConfigurationException, StorageHubException {
|
||||
sgClient= ImplementationProvider.get().getSHubProvider().getObject();
|
||||
sgClient= ImplementationProvider.get().getProvidedObjectByClass(StorageHubClient.class);
|
||||
appBase=getApplicationBaseFolder(sgClient);
|
||||
}
|
||||
|
||||
|
@ -75,6 +79,19 @@ public class WorkspaceManager {
|
|||
}
|
||||
|
||||
public FolderContainer getSubFolder(FolderContainer parentFolder,String path) throws StorageHubException {
|
||||
return getSubFolder(parentFolder,path,"");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns sub folder. Creates it if missing
|
||||
*
|
||||
* @param parentFolder
|
||||
* @param path
|
||||
* @return
|
||||
* @throws StorageHubException
|
||||
*/
|
||||
public FolderContainer getSubFolder(FolderContainer parentFolder,String path, String description) throws StorageHubException {
|
||||
try{
|
||||
return parentFolder.openByRelativePath(path).asFolder();
|
||||
}catch(StorageHubException e) {
|
||||
|
@ -87,27 +104,48 @@ public class WorkspaceManager {
|
|||
targetParent=getSubFolder(parentFolder,parent);
|
||||
targetName=path.substring(path.lastIndexOf("/")+1);
|
||||
}
|
||||
log.debug("Creating "+targetName);
|
||||
return createFolder(new FolderOptions(targetName,"",targetParent));
|
||||
FolderOptions opts = new FolderOptions(targetName,description,targetParent);
|
||||
log.debug("Creating FOLDER {}", opts);
|
||||
return createFolder(opts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public WorkspaceContent storeToWS(FileOptions opts) throws FileNotFoundException, StorageHubException {
|
||||
// public WorkspaceContent storeToWS(FileOptions opts) throws FileNotFoundException, StorageHubException {
|
||||
// FileContainer item=createFileRoutine(opts);
|
||||
// item=sgClient.open(item.getId()).asFile();
|
||||
//
|
||||
// WorkspaceContent content=new WorkspaceContent();
|
||||
// content.setLink(item.getPublicLink().toString());
|
||||
// content.setMimetype(item.get().getContent().getMimeType());
|
||||
// content.setStorageID(item.getId());
|
||||
// content.setName(item.get().getName());
|
||||
// return content;
|
||||
//
|
||||
// }
|
||||
|
||||
public RegisteredFile registerFile(FileOptions opts) throws StorageHubException {
|
||||
FileContainer item=createFileRoutine(opts);
|
||||
item=sgClient.open(item.getId()).asFile();
|
||||
|
||||
WorkspaceContent content=new WorkspaceContent();
|
||||
content.setLink(item.getPublicLink().toString());
|
||||
content.setMimetype(item.get().getContent().getMimeType());
|
||||
content.setStorageID(item.getId());
|
||||
content.setName(item.get().getName());
|
||||
return content;
|
||||
RegisteredFile file=new RegisteredFile();
|
||||
|
||||
|
||||
file.setLink(item.getPublicLink().toString());
|
||||
file.setMimetype(item.get().getContent().getMimeType());
|
||||
file.setStorageID(item.getId());
|
||||
file.setName(item.get().getName());
|
||||
return file;
|
||||
|
||||
}
|
||||
|
||||
public void deleteFromWS(WorkspaceContent toDelete) throws StorageHubException {
|
||||
sgClient.open(toDelete.getStorageID()).asFile().forceDelete();
|
||||
|
||||
// public void deleteFromWS(WorkspaceContent toDelete) throws StorageHubException {
|
||||
// sgClient.open(toDelete.getStorageID()).asFile().forceDelete();
|
||||
// }
|
||||
|
||||
public void deleteItem(String itemId)throws StorageHubException{
|
||||
sgClient.open(itemId).asItem().forceDelete();
|
||||
}
|
||||
|
||||
// STATIC SYNCH METHODS
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.application.geoportal.service.model.internal.faults;
|
||||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class DataParsingException extends Exception {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.application.geoportal.service.model.internal.faults;
|
||||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class DeletionException extends Exception {
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class InvalidLockException extends Exception{
|
||||
public InvalidLockException() {
|
||||
}
|
||||
|
||||
public InvalidLockException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidLockException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidLockException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidLockException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.application.geoportal.service.model.internal.faults;
|
||||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class InvalidStateException extends Exception {
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class InvalidUserRoleException extends Exception {
|
||||
|
||||
public InvalidUserRoleException() {
|
||||
}
|
||||
|
||||
public InvalidUserRoleException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidUserRoleException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidUserRoleException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidUserRoleException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class ProjectLockedException extends Exception{
|
||||
public ProjectLockedException() {
|
||||
}
|
||||
|
||||
public ProjectLockedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ProjectLockedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ProjectLockedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ProjectLockedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class ProjectNotFoundException extends Exception {
|
||||
public ProjectNotFoundException() {
|
||||
}
|
||||
|
||||
public ProjectNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ProjectNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ProjectNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ProjectNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class RegistrationException extends Exception {
|
||||
|
||||
public RegistrationException() {
|
||||
}
|
||||
|
||||
public RegistrationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public RegistrationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public RegistrationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public RegistrationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.application.cms.implementations.faults;
|
||||
|
||||
public class UnauthorizedAccess extends Exception {
|
||||
|
||||
public UnauthorizedAccess() {
|
||||
}
|
||||
|
||||
public UnauthorizedAccess(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnauthorizedAccess(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public UnauthorizedAccess(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public UnauthorizedAccess(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
public interface IndexerPluginInterface extends InitializablePlugin{
|
||||
|
||||
public IndexDocumentReport index(IndexDocumentRequest request) throws InvalidPluginRequestException;
|
||||
public IndexDocumentReport deindex(IndexDocumentRequest request) throws InvalidPluginRequestException;
|
||||
|
||||
public Index getIndex(BaseRequest request) throws ConfigurationException;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,14 +1,24 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.faults.StepException;
|
||||
import org.gcube.application.cms.plugins.reports.ExecutionReport;
|
||||
import org.gcube.application.cms.plugins.faults.*;
|
||||
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
|
||||
public interface LifecycleManager extends InitializablePlugin{
|
||||
|
||||
// Lifecycle operations
|
||||
|
||||
public ExecutionReport performStep(StepExecutionRequest request)throws StepException;
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException, InvalidProfileException, ConfigurationException, InsufficientPrivileges;
|
||||
|
||||
public Configuration getCurrentConfiguration(BaseRequest request) throws ConfigurationException;
|
||||
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException;
|
||||
|
||||
public void setPluginManager(PluginManagerInterface manager);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.faults.MaterializationException;
|
||||
import org.gcube.application.cms.plugins.reports.MaterializationReport;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
|
||||
public interface MaterializationPlugin extends InitializablePlugin{
|
||||
|
||||
public MaterializationReport materialize(MaterializationRequest request) throws MaterializationException, InvalidPluginRequestException;
|
||||
|
||||
public MaterializationReport dematerialize(MaterializationRequest request) throws MaterializationException, InvalidPluginRequestException;
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
|
||||
|
||||
public interface Plugin {
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PluginManagerInterface {
|
||||
|
||||
public Plugin getById(String pluginID) throws ConfigurationException;
|
||||
public Map<String,Plugin> getByType(String type) throws ConfigurationException;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class PluginsReflections {
|
||||
|
||||
/** Loads Plugin implementation classes. It should only be accessed once by Plugin Manager
|
||||
* Plugins shouldn't access this class unless for testing purposes.
|
||||
* @return
|
||||
*/
|
||||
public static Map<String,Plugin> load(){
|
||||
Map<String,Plugin> toReturn=new HashMap<>();
|
||||
log.warn("WARNING!! LOADING PLUGIN CLASSES : THIS SHOULD HAPPEN ONLY ONCE");
|
||||
Reflections reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.forPackage("org.gcube.application.cms")
|
||||
.filterInputsBy(new FilterBuilder().includePackage("org.gcube.application.cms")));
|
||||
|
||||
reflections.getSubTypesOf(Plugin.class).iterator().forEachRemaining(pluginClass->{
|
||||
log.trace("Evaluating class {}",pluginClass);
|
||||
if(!pluginClass.isInterface() && !Modifier.isAbstract(pluginClass.getModifiers())){
|
||||
try {
|
||||
log.debug("Found implementation {} ",pluginClass);
|
||||
Plugin plugin = pluginClass.newInstance();
|
||||
log.debug("Loading {} description : {}", plugin, plugin.getDescriptor());
|
||||
|
||||
toReturn.put(plugin.getDescriptor().getId(), plugin);
|
||||
|
||||
|
||||
}catch (Throwable t){
|
||||
log.warn("Unable to instantiate Plugin "+pluginClass,t);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return toReturn;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class EventException extends PluginExecutionException{
|
||||
|
||||
public EventException() {
|
||||
}
|
||||
|
||||
public EventException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public EventException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EventException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public EventException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class IndexingException extends PluginExecutionException{
|
||||
public IndexingException() {
|
||||
}
|
||||
|
||||
public IndexingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public IndexingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IndexingException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public IndexingException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class InitializationException extends Exception{
|
||||
public class InitializationException extends PluginExecutionException{
|
||||
|
||||
public InitializationException() {
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class InsufficientPrivileges extends Exception {
|
||||
public InsufficientPrivileges() {
|
||||
}
|
||||
|
||||
public InsufficientPrivileges(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InsufficientPrivileges(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InsufficientPrivileges(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InsufficientPrivileges(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class InvalidPluginRequestException extends PluginExecutionException {
|
||||
public InvalidPluginRequestException() {
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class InvalidProfileException extends Exception {
|
||||
public InvalidProfileException() {
|
||||
}
|
||||
|
||||
public InvalidProfileException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidProfileException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidProfileException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidProfileException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class MaterializationException extends PluginExecutionException {
|
||||
|
||||
public MaterializationException() {
|
||||
}
|
||||
|
||||
public MaterializationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MaterializationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public MaterializationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public MaterializationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class PluginExecutionException extends Exception{
|
||||
public PluginExecutionException() {
|
||||
}
|
||||
|
||||
public PluginExecutionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PluginExecutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PluginExecutionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public PluginExecutionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class StepException extends Exception {
|
||||
public class StepException extends PluginExecutionException {
|
||||
|
||||
public StepException() {
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class UnrecognizedEventException extends EventException{
|
||||
public UnrecognizedEventException() {
|
||||
}
|
||||
|
||||
public UnrecognizedEventException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnrecognizedEventException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public UnrecognizedEventException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public UnrecognizedEventException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class UnrecognizedStepException extends StepException{
|
||||
public UnrecognizedStepException() {
|
||||
}
|
||||
|
||||
public UnrecognizedStepException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnrecognizedStepException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public UnrecognizedStepException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public UnrecognizedStepException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
package org.gcube.application.cms.plugins.implementations;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.implementations.ProjectAccess;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.PluginManagerInterface;
|
||||
import org.gcube.application.cms.plugins.faults.*;
|
||||
import org.gcube.application.cms.plugins.implementations.executions.GuardedEventManager;
|
||||
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
|
||||
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
|
||||
import org.gcube.application.cms.plugins.reports.InitializationReport;
|
||||
import org.gcube.application.cms.plugins.reports.Report;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.TriggeredEvents;
|
||||
import org.gcube.application.geoportal.common.model.plugins.LifecycleManagerDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractLifeCycleManager extends AbstractPlugin implements LifecycleManager {
|
||||
|
||||
protected static class Events{
|
||||
public static final OperationDescriptor INIT=new OperationDescriptor(EventExecutionRequest.Events.ON_INIT_DOCUMENT,"Sets defaults and validate");
|
||||
public static final OperationDescriptor UPDATE=new OperationDescriptor(EventExecutionRequest.Events.ON_UPDATE_DOCUMENT,"Sets defaults and validate");
|
||||
public static final OperationDescriptor DELETE=new OperationDescriptor(EventExecutionRequest.Events.ON_DELETE_DOCUMENT,"No op");
|
||||
public static final OperationDescriptor DELETE_FS=new OperationDescriptor(EventExecutionRequest.Events.ON_DELETE_FILESET,"No op");
|
||||
}
|
||||
|
||||
@Setter
|
||||
protected PluginManagerInterface pluginManager;
|
||||
|
||||
@Setter
|
||||
protected ProjectAccess projectAccess;
|
||||
|
||||
|
||||
private Map<String, GuardedStepExecution> registeredSteps=new HashMap<>();
|
||||
private Map<String, GuardedEventManager> registeredEvent=new HashMap<>();
|
||||
|
||||
|
||||
protected void setEvent(GuardedEventManager m){
|
||||
OperationDescriptor op= m.getOp();
|
||||
DESCRIPTOR.getSupportedEvents().put(op.getId(),op);
|
||||
registeredEvent.put(op.getId(),m);
|
||||
}
|
||||
protected void setStep(GuardedStepExecution e){
|
||||
OperationDescriptor op= e.getOp();
|
||||
DESCRIPTOR.getSupportedSteps().put(op.getId(),op);
|
||||
registeredSteps.put(op.getId(),e);
|
||||
}
|
||||
|
||||
public AbstractLifeCycleManager() {
|
||||
DESCRIPTOR.setSupportedSteps(new HashMap<>());
|
||||
DESCRIPTOR.setSupportedEvents(new HashMap<>());
|
||||
registerEvents();
|
||||
registerSteps();
|
||||
}
|
||||
|
||||
protected EventExecutionReport onDeleteDocument(EventExecutionReport report) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {return report;}
|
||||
protected EventExecutionReport onDeleteFileSet(EventExecutionReport report) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {return report;}
|
||||
protected EventExecutionReport onUpdateDocument(EventExecutionReport report){
|
||||
report = validate(report);
|
||||
report = setDefault(report);
|
||||
return report;
|
||||
}
|
||||
protected EventExecutionReport onInitDocument(EventExecutionReport report) throws InvalidPluginRequestException {
|
||||
report = validate(report);
|
||||
report = setDefault(report);
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void registerEvents(){
|
||||
setEvent(new GuardedEventManager(Events.INIT) {
|
||||
@Override
|
||||
protected EventExecutionReport run() throws Exception {
|
||||
return onInitDocument(theReport);
|
||||
}
|
||||
});
|
||||
setEvent(new GuardedEventManager(Events.UPDATE) {
|
||||
@Override
|
||||
protected EventExecutionReport run() throws Exception {
|
||||
return onUpdateDocument(theReport);
|
||||
}
|
||||
});
|
||||
setEvent(new GuardedEventManager(Events.DELETE) {
|
||||
@Override
|
||||
protected EventExecutionReport run() throws Exception {
|
||||
return onDeleteDocument(theReport);
|
||||
}
|
||||
});
|
||||
setEvent(new GuardedEventManager(Events.DELETE_FS) {
|
||||
@Override
|
||||
protected EventExecutionReport run() throws Exception {
|
||||
return onDeleteFileSet(theReport);
|
||||
}
|
||||
});
|
||||
}
|
||||
protected void registerSteps(){}
|
||||
|
||||
|
||||
protected LifecycleManagerDescriptor DESCRIPTOR=new LifecycleManagerDescriptor(";;;");
|
||||
|
||||
|
||||
@Override
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException, InvalidProfileException, ConfigurationException, InsufficientPrivileges {
|
||||
log.info("Serving Request {}",request);
|
||||
|
||||
log.debug("Checking is STEP {} is supported by {}",request.getStep(),DESCRIPTOR.getId());
|
||||
if(!registeredSteps.containsKey(request.getStep()))
|
||||
throw new UnrecognizedStepException(("Invalid Step " + request.getStep()));
|
||||
|
||||
HandlerDeclaration handlerDeclaration= getConfigurationFromProfile(request.getUseCaseDescriptor());
|
||||
log.debug("Checking user role {} against config {} ",request.getCaller(),handlerDeclaration);
|
||||
if(!canInvokeStep(request.getStep(),request.getCaller(), handlerDeclaration))
|
||||
throw new InsufficientPrivileges("User is not allowed to invoke "+request.getStep());
|
||||
|
||||
StepExecutionReport report=new StepExecutionReport(request);
|
||||
LifecycleInformation info=report.getToSetLifecycleInformation();
|
||||
report.setStatus(Report.Status.OK);
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||
info.setLastInvokedStep(request.getStep());
|
||||
|
||||
try {
|
||||
GuardedStepExecution exec=registeredSteps.get(request.getStep());
|
||||
exec.setTheReport(report);
|
||||
exec.setHandlerConfiguration(handlerDeclaration);
|
||||
log.debug("Actually executing Step with {} ",exec);
|
||||
return exec.execute();
|
||||
}catch (StepException | InvalidPluginRequestException e){
|
||||
throw e;
|
||||
}catch (Throwable t) {
|
||||
log.error("Unable to perform step " + request.getStep(), t);
|
||||
String msg = "Unable to execute Step " + request.getStep() + ". Error was " + t.getMessage();
|
||||
report.setStatus(Report.Status.ERROR);
|
||||
report.putMessage(msg);
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
|
||||
info.addErrorMessage(msg);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
protected boolean canInvokeStep(String stepID, User u, HandlerDeclaration config) throws ConfigurationException {
|
||||
return new RoleManager(config).canInvokeStep(stepID,u);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InitializationReport initInContext() throws InitializationException {
|
||||
InitializationReport report = new InitializationReport();
|
||||
try{
|
||||
report.setStatus(Report.Status.OK);
|
||||
} catch (Throwable e) {
|
||||
log.error("Unable to initialize plugins in {} ", ContextUtils.getCurrentScope(),e);
|
||||
report.setStatus(Report.Status.WARNING);
|
||||
report.putMessage("Unable to initialize plugins in "+ ContextUtils.getCurrentScope()+" : "+e.getMessage());
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitializationReport init() throws InitializationException {
|
||||
InitializationReport report = new InitializationReport();
|
||||
try{
|
||||
report.setStatus(Report.Status.OK);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error("Unable to initialize plugins ",e);
|
||||
report.setStatus(Report.Status.WARNING);
|
||||
report.putMessage("Unable to initialize plugins : "+e.getMessage());
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PluginDescriptor getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException {
|
||||
log.info("Executing Event {}",request);
|
||||
EventExecutionReport report=new EventExecutionReport(request);
|
||||
report.getToSetLifecycleInformation().addEventReport(new TriggeredEvents());
|
||||
TriggeredEvents info = report.getToSetLifecycleInformation().getLastEvent();
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||
info.setEvent(request.getEvent());
|
||||
try {
|
||||
if(!registeredEvent.containsKey(request.getEvent()))
|
||||
throw new UnrecognizedEventException("Unexpected Event "+request.getEvent());
|
||||
|
||||
return registeredEvent.get(request.getEvent()).setTheReport(report).execute();
|
||||
|
||||
}catch (EventException e){
|
||||
throw e;
|
||||
}catch (Throwable t){
|
||||
log.error("Unable to execute on event "+request.getEvent(),t);
|
||||
String msg = "Unable to execute on event "+request.getEvent()+". Error was "+t.getMessage();
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
|
||||
info.addErrorMessage(msg);
|
||||
report.setStatus(Report.Status.ERROR);
|
||||
report.putMessage(msg);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override this method for programmatic default values management
|
||||
*
|
||||
* @param currentReport
|
||||
* @return
|
||||
*/
|
||||
public EventExecutionReport setDefault(EventExecutionReport currentReport){
|
||||
// Default implementation is no op
|
||||
return currentReport;
|
||||
}
|
||||
|
||||
public EventExecutionReport validate(EventExecutionReport currentReport){
|
||||
// Default implementation is no op
|
||||
return currentReport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() throws ShutDownException {}
|
||||
|
||||
@Override
|
||||
public Configuration getCurrentConfiguration(BaseRequest request) throws ConfigurationException {
|
||||
return new Configuration();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.gcube.application.cms.plugins.implementations;
|
||||
|
||||
import org.gcube.application.cms.plugins.Plugin;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidProfileException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractPlugin implements Plugin {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected HandlerDeclaration getConfigurationFromProfile(UseCaseDescriptor useCaseDescriptor) throws InvalidProfileException{
|
||||
return getMultipleDeclarationsFromProfile(useCaseDescriptor).get(0);
|
||||
}
|
||||
|
||||
protected List<HandlerDeclaration> getMultipleDeclarationsFromProfile(UseCaseDescriptor p)throws InvalidProfileException {
|
||||
Map<String,List<HandlerDeclaration>> map = p.getHandlersMapByID();
|
||||
if(map.containsKey(getDescriptor().getId()))
|
||||
return map.get(getDescriptor().getId());
|
||||
else throw new InvalidProfileException("No Configuration found for "+getDescriptor().getId()+" in "+p.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
package org.gcube.application.cms.plugins.implementations;
|
||||
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
||||
import org.gcube.application.cms.plugins.faults.EventException;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.faults.MaterializationException;
|
||||
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
|
||||
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
|
||||
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Slf4j
|
||||
public class Default3PhaseManager extends SimpleLifeCycleManager implements LifecycleManager {
|
||||
|
||||
protected static class Phases {
|
||||
public static final String PENDING_APPROVAL="Pending Approval";
|
||||
public static final String PUBLISHED="Published";
|
||||
|
||||
}
|
||||
|
||||
protected static class STEPS{
|
||||
public static final OperationDescriptor SUBMIT=new OperationDescriptor("SUBMIT-FOR-REVIEW","Submits the Draft for reviewing");
|
||||
public static final OperationDescriptor REJECT=new OperationDescriptor("REJECT-DRAFT","Rejects the submitted Draft");
|
||||
public static final OperationDescriptor APPROVE=new OperationDescriptor("APPROVE-SUBMITTED","Approves the submitted Draft");
|
||||
|
||||
static {
|
||||
SUBMIT.setAppliableToPhases(Collections.singletonList(LifecycleInformation.CommonPhases.DRAFT_PHASE));
|
||||
REJECT.setAppliableToPhases(Collections.singletonList(Phases.PENDING_APPROVAL));
|
||||
APPROVE.setAppliableToPhases(Collections.singletonList(Phases.PENDING_APPROVAL));
|
||||
}
|
||||
}
|
||||
|
||||
private static class PARAMETERS{
|
||||
public static final String NOTES="notes";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected EventExecutionReport onDeleteDocument(EventExecutionReport report) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
||||
report = super.onDeleteDocument(report);
|
||||
for(IndexerPluginInterface indexer : getIndexers(report.getTheRequest()))
|
||||
report= deIndex(report,indexer,getInternalIndexParams(report.getTheRequest()));
|
||||
return report;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
||||
theReport = super.onDeleteFileSet(theReport);
|
||||
String phase = theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase();
|
||||
Document parameters = null;
|
||||
if(phase.equals(Phases.PENDING_APPROVAL))
|
||||
parameters =getInternalIndexParams(theReport.getTheRequest());
|
||||
if(phase.equals(Phases.PUBLISHED))
|
||||
parameters = getPublicIndexParams(theReport.getTheRequest());
|
||||
if(parameters!= null)
|
||||
for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest()))
|
||||
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||
return theReport;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerSteps() {
|
||||
// register steps
|
||||
setStep(new GuardedStepExecution(STEPS.SUBMIT) {
|
||||
@Override
|
||||
protected StepExecutionReport run() throws Exception {
|
||||
return executeSubmit(theReport);
|
||||
}
|
||||
});
|
||||
setStep(new GuardedStepExecution(STEPS.APPROVE) {
|
||||
@Override
|
||||
protected StepExecutionReport run() throws Exception {
|
||||
return executeApprove(theReport);
|
||||
}
|
||||
});
|
||||
setStep(new GuardedStepExecution(STEPS.REJECT) {
|
||||
@Override
|
||||
protected StepExecutionReport run() throws Exception {
|
||||
return executeReject(theReport);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Default3PhaseManager() {
|
||||
DESCRIPTOR.setId("DEFAULT-3PHASE");
|
||||
DESCRIPTOR.setDescription("Default 3-phase lifecycle manager. This plugin supports a simple moderated publication lifecycle.");
|
||||
DESCRIPTOR.setVersion(new Semver("1.0.0"));
|
||||
DESCRIPTOR.setLabel("Default 3-Phase");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Configuration getCurrentConfiguration(BaseRequest req) throws ConfigurationException {
|
||||
Configuration toReturn = super.getCurrentConfiguration(req);
|
||||
|
||||
IndexerPluginInterface indexerPlugin;
|
||||
indexerPlugin = (IndexerPluginInterface) pluginManager.getById("SDI-Indexer-Plugin");
|
||||
BaseRequest indexRequest = new BaseRequest(req.getUseCaseDescriptor(),req.getCaller(),req.getContext());
|
||||
|
||||
// Info on internal_index
|
||||
try {
|
||||
indexRequest.setCallParameters(getInternalIndexParams(req));
|
||||
Index internalIndex = indexerPlugin.getIndex(indexRequest);
|
||||
internalIndex.put("flag", "internal");
|
||||
toReturn.getIndexes().add(internalIndex);
|
||||
}catch(ConfigurationException e){
|
||||
toReturn.addErrorMessage("Unable to gather information on internal GIS Centroids Index : "+e.getMessage());
|
||||
log.error("Unable to gather information on internal GIS Centroids Index",e);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
protected Document getInternalIndexParams(BaseRequest req){
|
||||
Document callParameters = new Document();
|
||||
|
||||
callParameters.put("workspace", Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName()));
|
||||
callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName()+"_centroids"));
|
||||
return callParameters;
|
||||
}
|
||||
|
||||
protected StepExecutionReport executeSubmit(StepExecutionReport theReport) throws Exception {
|
||||
// Materialize
|
||||
|
||||
for(MaterializationPlugin mat : getMaterializers(theReport.getTheRequest()))
|
||||
theReport = materializeDocument(theReport,mat,getMaterializationParameters(theReport.getTheRequest()));
|
||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
|
||||
// Index
|
||||
for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest()))
|
||||
theReport = index(theReport,indexer,getInternalIndexParams(theReport.getTheRequest()));
|
||||
// setPhase
|
||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||
theReport.getToSetLifecycleInformation().setPhase(Phases.PENDING_APPROVAL);
|
||||
}
|
||||
return theReport;
|
||||
}
|
||||
|
||||
protected StepExecutionReport executeApprove(StepExecutionReport theReport) throws Exception {
|
||||
// Index
|
||||
for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest()))
|
||||
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||
// setPhase
|
||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||
theReport.getToSetLifecycleInformation().setPhase(Phases.PUBLISHED);
|
||||
return theReport;
|
||||
}
|
||||
|
||||
protected StepExecutionReport executeReject(StepExecutionReport theReport) throws Exception {
|
||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||
theReport.getToSetLifecycleInformation().setPhase(LifecycleInformation.CommonPhases.DRAFT_PHASE);
|
||||
return theReport;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package org.gcube.application.cms.plugins.implementations;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@ToString
|
||||
public class RoleManager {
|
||||
|
||||
HashMap<String,StepAccess> accessMap=new HashMap<>();
|
||||
|
||||
|
||||
public RoleManager(HandlerDeclaration config) throws ConfigurationException {
|
||||
log.debug("Instantiating for configuration {}",config);
|
||||
List l =config.getConfiguration().get("step_access", List.class);
|
||||
if(l==null|| l.isEmpty()) throw new ConfigurationException("Missing Role management in UCD");
|
||||
for (Object o : l) {
|
||||
StepAccess a= Serialization.convert(o, StepAccess.class);
|
||||
accessMap.put(a.getStepId(),a);
|
||||
}
|
||||
log.debug("Access Map is {}",accessMap);
|
||||
}
|
||||
|
||||
public boolean canInvokeStep(String stepID,User u) throws ConfigurationException {
|
||||
if(!accessMap.containsKey(stepID)) throw new ConfigurationException("Missing step "+stepID+" access definition");
|
||||
|
||||
List<String> roles=accessMap.get(stepID).getRoles();
|
||||
if(roles.isEmpty()) return true;
|
||||
|
||||
for (String role : roles)
|
||||
if (u.getRoles().contains(role))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public static class StepAccess {
|
||||
|
||||
public static final String STEP="STEP";
|
||||
public static final String ROLES="roles";
|
||||
|
||||
|
||||
@JsonProperty(STEP)
|
||||
private String stepId;
|
||||
|
||||
@JsonProperty(ROLES)
|
||||
private List<String> roles;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,307 @@
|
|||
package org.gcube.application.cms.plugins.implementations;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.implementations.faults.InvalidUserRoleException;
|
||||
import org.gcube.application.cms.implementations.faults.ProjectNotFoundException;
|
||||
import org.gcube.application.cms.implementations.faults.RegistrationException;
|
||||
import org.gcube.application.cms.implementations.faults.UnauthorizedAccess;
|
||||
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
||||
import org.gcube.application.cms.plugins.faults.EventException;
|
||||
import org.gcube.application.cms.plugins.faults.IndexingException;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.faults.MaterializationException;
|
||||
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
|
||||
import org.gcube.application.cms.plugins.reports.*;
|
||||
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.application.geoportal.common.model.plugins.IndexerPluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.MaterializerPluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements LifecycleManager {
|
||||
|
||||
public static final String PLUGIN_ID="DEFAULT-SINGLE-STEP";
|
||||
|
||||
|
||||
public SimpleLifeCycleManager() {
|
||||
DESCRIPTOR.setId(PLUGIN_ID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class Steps {
|
||||
public static final OperationDescriptor PUBLISH = new OperationDescriptor("PUBLISH","Materialize & index project");
|
||||
|
||||
static{
|
||||
PUBLISH.setAppliableToPhases(Collections.singletonList(LifecycleInformation.CommonPhases.DRAFT_PHASE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Configuration getCurrentConfiguration(BaseRequest req) throws ConfigurationException {
|
||||
Configuration toReturn = super.getCurrentConfiguration(req);
|
||||
toReturn.setIndexes(new ArrayList<>());
|
||||
|
||||
IndexerPluginInterface indexerPlugin;
|
||||
indexerPlugin = (IndexerPluginInterface) pluginManager.getById("SDI-Indexer-Plugin");
|
||||
BaseRequest indexRequest = new BaseRequest(req.getUseCaseDescriptor(),req.getCaller(),req.getContext());
|
||||
|
||||
// Info on Public index
|
||||
try {
|
||||
indexRequest.setCallParameters(getPublicIndexParams(req));
|
||||
Index publicIndex = indexerPlugin.getIndex(indexRequest);
|
||||
publicIndex.put("flag", "public");
|
||||
toReturn.getIndexes().add(publicIndex);
|
||||
}catch(ConfigurationException e){
|
||||
toReturn.addErrorMessage("Unable to gather information on public GIS Centroids Index : "+e.getMessage());
|
||||
log.error("Unable to gather information on public GIS Centroids Index",e);
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
protected Document getPublicIndexParams(BaseRequest req){
|
||||
Document callParameters = new Document();
|
||||
callParameters.put("workspace",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName()));
|
||||
callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName()+"_centroids"));
|
||||
return callParameters;
|
||||
}
|
||||
|
||||
|
||||
protected Document getMaterializationParameters(BaseRequest request){
|
||||
Document params = new Document();
|
||||
String workspace = request.getUseCaseDescriptor().getId() + request.getContext().getId();
|
||||
params.put("workspace", Files.fixFilename(workspace));
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void registerSteps() {
|
||||
setStep(new GuardedStepExecution(Steps.PUBLISH) {
|
||||
@Override
|
||||
protected StepExecutionReport run() throws Exception {
|
||||
//Check Performed by Guarded Step Execution
|
||||
// if(!theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE))
|
||||
// throw new StepException("Document is not in "+LifecycleInformation.CommonPhases.DRAFT_PHASE+" phase");
|
||||
|
||||
// Materialize
|
||||
for(MaterializationPlugin mat : getMaterializers(theReport.getTheRequest()))
|
||||
theReport = materializeDocument(theReport, mat, getMaterializationParameters(theReport.getTheRequest()));
|
||||
|
||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
|
||||
// Index
|
||||
for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest()))
|
||||
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||
// setPhase
|
||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||
theReport.getToSetLifecycleInformation().setPhase("PUBLISHED");
|
||||
}
|
||||
return theReport;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void blockNonDraft(EventExecutionReport report) throws InvalidPluginRequestException {
|
||||
Boolean force = false;
|
||||
try {
|
||||
force = Boolean.parseBoolean(report.getTheRequest().getCallParameters().get("force").toString());
|
||||
}catch(Throwable t){}
|
||||
|
||||
if(!report.getTheRequest().getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE) && ! force)
|
||||
throw new InvalidPluginRequestException("Document is not in "+LifecycleInformation.CommonPhases.DRAFT_PHASE+" phase");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventExecutionReport onInitDocument(EventExecutionReport report) throws InvalidPluginRequestException {
|
||||
blockNonDraft(report);
|
||||
return super.onInitDocument(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventExecutionReport onUpdateDocument(EventExecutionReport report) {
|
||||
return super.onUpdateDocument(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventExecutionReport onDeleteDocument(EventExecutionReport report) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
||||
// Block non draft only if not force
|
||||
Boolean force=Boolean.parseBoolean(report.getTheRequest().getWithDefault("force","false"));
|
||||
log.debug("ON DELETE for {} : force is {}",report.getTheRequest().getDocument().getId(),force);
|
||||
if(!force) blockNonDraft(report);
|
||||
// dematerialize all
|
||||
JSONPathWrapper wrapper = new JSONPathWrapper(report.getTheRequest().getDocument().getTheDocument().toJson());
|
||||
for (String s : wrapper.getMatchingPaths("$..[?(@." + RegisteredFileSet.PAYLOADS + ")]")){
|
||||
log.info("Requesting dematerialization for {} ",s);
|
||||
for(MaterializationPlugin mat : getMaterializers(report.getTheRequest()))
|
||||
report = deMaterialize(report,mat,new Document("fileSetPath",s));
|
||||
if(!report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||
break;
|
||||
}
|
||||
if(report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) {
|
||||
for(IndexerPluginInterface indexer : getIndexers(report.getTheRequest()))
|
||||
report = deIndex(report,indexer,getPublicIndexParams(report.getTheRequest()));
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
||||
// dematerialize selected
|
||||
blockNonDraft(theReport);
|
||||
for(MaterializationPlugin mat : getMaterializers(theReport.getTheRequest()))
|
||||
deMaterialize(theReport,mat,
|
||||
theReport.getTheRequest().getCallParameters());
|
||||
// de index
|
||||
for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest()))
|
||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||
deIndex(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||
return theReport;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void registerEvents() {
|
||||
super.registerEvents();
|
||||
}
|
||||
|
||||
|
||||
protected List<IndexerPluginInterface> getIndexers(BaseRequest request) throws ConfigurationException {
|
||||
log.trace("Looking for Indexers for {}",request);
|
||||
ArrayList<IndexerPluginInterface> toReturn=new ArrayList<>();
|
||||
UseCaseDescriptor desc = request.getUseCaseDescriptor();
|
||||
List<HandlerDeclaration> indexers = desc.getHandlersByType(IndexerPluginDescriptor.INDEXER);
|
||||
log.debug("Found UCD [{}] Indexers : {}",desc.getId(),indexers.size());
|
||||
for (HandlerDeclaration handlerDeclaration : indexers)
|
||||
toReturn.add((IndexerPluginInterface) pluginManager.getById(handlerDeclaration.getId()));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
protected List<MaterializationPlugin> getMaterializers(BaseRequest request) throws ConfigurationException {
|
||||
log.trace("Looking for materializers for {}",request);
|
||||
ArrayList<MaterializationPlugin> toReturn=new ArrayList<>();
|
||||
UseCaseDescriptor desc = request.getUseCaseDescriptor();
|
||||
List<HandlerDeclaration> materializers = desc.getHandlersByType(MaterializerPluginDescriptor.MATERIALIZER);
|
||||
log.debug("Found UCD [{}] Materializers : {}",desc.getId(),materializers.size());
|
||||
for (HandlerDeclaration handlerDeclaration : materializers) {
|
||||
toReturn.add((MaterializationPlugin) pluginManager.getById(handlerDeclaration.getId()));
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
protected <T extends DocumentHandlingReport> T deIndex(T report, IndexerPluginInterface indexer, Document parameters) throws InvalidPluginRequestException {
|
||||
BaseExecutionRequest request = report.getTheRequest();
|
||||
IndexDocumentRequest indexRequest = new IndexDocumentRequest(
|
||||
request.getUseCaseDescriptor(),request.getCaller(), request.getContext(),request.getDocument());
|
||||
|
||||
indexRequest.setCallParameters(parameters);
|
||||
IndexDocumentReport indexReport = indexer.deindex(indexRequest);
|
||||
|
||||
return handleReport(indexReport,report);
|
||||
|
||||
}
|
||||
|
||||
protected <T extends DocumentHandlingReport> T deMaterialize(T report, MaterializationPlugin plugin, Document parameters) throws InvalidPluginRequestException, MaterializationException {
|
||||
BaseExecutionRequest request = report.getTheRequest();
|
||||
MaterializationRequest matReq =
|
||||
new MaterializationRequest(request.getUseCaseDescriptor(),request.getCaller(), request.getContext(), request.getDocument());
|
||||
|
||||
Document params = new Document();
|
||||
String workspace = request.getUseCaseDescriptor().getId() + request.getContext().getId();
|
||||
params.put("workspace", Files.fixFilename(workspace));
|
||||
|
||||
matReq.setCallParameters(params);
|
||||
MaterializationReport matRep = plugin.dematerialize(matReq);
|
||||
|
||||
return handleReport(matRep,report);
|
||||
}
|
||||
|
||||
protected <T extends DocumentHandlingReport> T index(T report, IndexerPluginInterface indexer, Document parameters) throws InvalidPluginRequestException {
|
||||
BaseExecutionRequest request = report.getTheRequest();
|
||||
IndexDocumentRequest indexRequest = new IndexDocumentRequest(
|
||||
request.getUseCaseDescriptor(),request.getCaller(), request.getContext(),request.getDocument());
|
||||
|
||||
indexRequest.setCallParameters(parameters);
|
||||
|
||||
IndexDocumentReport indexReport = null;
|
||||
try {
|
||||
indexRequest.setCallParameters(evaluateAdditionalIndexParameters(indexRequest));
|
||||
indexReport = indexer.index(indexRequest);
|
||||
}catch (IndexingException e){
|
||||
log.error("Unable to serve index request.",e);
|
||||
indexReport = new IndexDocumentReport(indexRequest);
|
||||
indexReport.setStatus(Report.Status.ERROR);
|
||||
indexReport.setMessages(new ArrayList<>());
|
||||
indexReport.getMessages().add("Unable to evaluate centroids : "+e.getMessage());
|
||||
}
|
||||
return handleReport(indexReport,report);
|
||||
|
||||
}
|
||||
|
||||
protected Document evaluateAdditionalIndexParameters(IndexDocumentRequest request) throws IndexingException {return request.getCallParameters();}
|
||||
|
||||
|
||||
protected <T extends DocumentHandlingReport> T materializeDocument(T report,MaterializationPlugin plugin,Document parameters) throws InvalidPluginRequestException, MaterializationException {
|
||||
BaseExecutionRequest request = report.getTheRequest();
|
||||
MaterializationRequest matReq =
|
||||
new MaterializationRequest(request.getUseCaseDescriptor(),request.getCaller(), request.getContext(), request.getDocument());
|
||||
|
||||
matReq.setCallParameters(parameters);
|
||||
MaterializationReport matRep = plugin.materialize(matReq);
|
||||
|
||||
return handleReport(matRep,report);
|
||||
}
|
||||
|
||||
|
||||
private <T extends DocumentHandlingReport> T handleReport(DocumentHandlingReport toHandle, T toUpdate){
|
||||
toUpdate.setResultingDocument(toHandle.getResultingDocument());
|
||||
LifecycleInformation info = toUpdate.getToSetLifecycleInformation();
|
||||
switch(toHandle.getStatus()){
|
||||
case OK : {
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||
if(toHandle instanceof IndexDocumentReport)
|
||||
toUpdate.setToSetIdentificationReferences(((IndexDocumentReport)toHandle).getToSetIdentificationReferences());
|
||||
// Propagate changes for further processings
|
||||
toUpdate.getTheRequest().getDocument().setTheDocument(toHandle.getResultingDocument());
|
||||
toUpdate.setToSetLifecycleInformation(toHandle.getToSetLifecycleInformation());
|
||||
|
||||
// if(toHandle instanceof MaterializationReport)
|
||||
// toUpdate.setToSetSpatialReference(((IndexDocumentReport)toHandle).getToSetSpatialReference());
|
||||
break;
|
||||
}
|
||||
case ERROR : {
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
|
||||
toHandle.getMessages().forEach(s -> info.addErrorMessage(s));
|
||||
break;
|
||||
}
|
||||
case WARNING : {
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.WARNING);
|
||||
toHandle.getMessages().forEach(s -> info.addWarningMessage(s));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return toUpdate;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.gcube.application.cms.plugins.implementations.executions;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||
|
||||
@Slf4j
|
||||
public abstract class GuardedEventManager extends GuardedExecution<EventExecutionRequest,EventExecutionReport>{
|
||||
|
||||
|
||||
public GuardedEventManager(@NonNull OperationDescriptor op) {
|
||||
super(op);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package org.gcube.application.cms.plugins.implementations.executions;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
||||
import org.gcube.application.cms.plugins.faults.StepException;
|
||||
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public abstract class GuardedExecution<R extends BaseExecutionRequest,T extends DocumentHandlingReport> {
|
||||
|
||||
@Getter
|
||||
protected T result = null;
|
||||
|
||||
|
||||
@NonNull
|
||||
@Getter
|
||||
private OperationDescriptor op;
|
||||
|
||||
|
||||
protected T theReport;
|
||||
|
||||
protected void checks() throws ConfigurationException, InsufficientPrivileges {
|
||||
if(theReport.getTheRequest()==null) throw new RuntimeException("Unexpected state : request cannot be null");
|
||||
|
||||
// Check document phase
|
||||
if(op.getAppliableToPhases()!=null&&!op.getAppliableToPhases().isEmpty()) {
|
||||
String currentPhase = theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase();
|
||||
if(!op.getAppliableToPhases().contains(currentPhase))
|
||||
new StepException("Document must be in one of the following phases : "+ op.getAppliableToPhases());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public T execute() throws Exception {
|
||||
log.trace("Executing {} ",theReport.getTheRequest());
|
||||
|
||||
checks();
|
||||
|
||||
result = run();
|
||||
log.trace("Report is {} ",theReport);
|
||||
return result;
|
||||
}
|
||||
|
||||
public T getResult() {
|
||||
return result;
|
||||
}
|
||||
protected abstract T run() throws Exception;
|
||||
|
||||
public GuardedExecution<R, T> setTheReport(T theReport) {
|
||||
this.theReport = theReport;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HandlerDeclaration config=null;
|
||||
|
||||
public void setHandlerConfiguration(HandlerDeclaration config){
|
||||
this.config=config;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.gcube.application.cms.plugins.implementations.executions;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
||||
import org.gcube.application.cms.plugins.implementations.RoleManager;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
public abstract class GuardedStepExecution extends GuardedExecution<StepExecutionRequest, StepExecutionReport>{
|
||||
|
||||
|
||||
public GuardedStepExecution(@NonNull OperationDescriptor op) {
|
||||
super(op);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checks() throws ConfigurationException, InsufficientPrivileges {
|
||||
super.checks();
|
||||
RoleManager r = new RoleManager(config);
|
||||
if(!r.canInvokeStep(theReport.getTheRequest().getStep(),theReport.getTheRequest().getCaller()))
|
||||
throw new InsufficientPrivileges("User is not allowed to execute "+theReport.getTheRequest().getStep());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.application.geoportal.common.model.document;
|
||||
package org.gcube.application.cms.plugins.model;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -22,14 +22,7 @@ package org.gcube.application.geoportal.common.model.document;
|
|||
import lombok.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
|
@ -1,26 +0,0 @@
|
|||
package org.gcube.application.cms.plugins.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.gcube.application.geoportal.common.model.document.ComparableVersion;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PluginDescriptor {
|
||||
|
||||
public static class BaseTypes{
|
||||
public static final String LIFECYCLE_MANAGER="LifecycleManagement";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String id;
|
||||
@NonNull
|
||||
private String type;
|
||||
private String label;
|
||||
private String description;
|
||||
private ComparableVersion version;
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
|
||||
@Slf4j
|
||||
public class DocumentHandlingReport<T extends BaseExecutionRequest> extends Report{
|
||||
|
||||
@NonNull
|
||||
T theRequest;
|
||||
Document resultingDocument;
|
||||
LifecycleInformation toSetLifecycleInformation;
|
||||
|
||||
protected List<IdentificationReference> toSetIdentificationReferences=null;
|
||||
|
||||
public DocumentHandlingReport<T> addIdentificationReference(IdentificationReference toAdd){
|
||||
if(toSetIdentificationReferences == null) toSetIdentificationReferences = new ArrayList<>();
|
||||
toSetIdentificationReferences.add(toAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public DocumentHandlingReport(@NonNull T theRequest) throws InvalidPluginRequestException {
|
||||
theRequest.validate();
|
||||
this.theRequest = theRequest;
|
||||
this.setStatus(Status.OK);
|
||||
toSetLifecycleInformation=theRequest.getDocument().getLifecycleInformation();
|
||||
resultingDocument = theRequest.getDocument().getTheDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws PluginExecutionException {
|
||||
super.validate();
|
||||
if (resultingDocument==null) {
|
||||
log.warn("NULL resulting document in report {} ", this);
|
||||
throw new PluginExecutionException("Invalid report : Resulting document cannot be null");
|
||||
}
|
||||
if(toSetLifecycleInformation == null) {
|
||||
log.warn("NULL lifecycleinformation in report {} ",this);
|
||||
throw new PluginExecutionException("Invalid report : Lifecycle information cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
public Project prepareResult() throws JsonProcessingException, PluginExecutionException {
|
||||
log.trace("Preparing document ID {} from report ... ",theRequest.getDocument().getId());
|
||||
this.validate();
|
||||
|
||||
Project toReturn = theRequest.getDocument();
|
||||
toReturn.setTheDocument(resultingDocument);
|
||||
toReturn.setLifecycleInformation(toSetLifecycleInformation);
|
||||
|
||||
// Force Report status into info
|
||||
log.trace("Report status is {} ",getStatus());
|
||||
LifecycleInformation info = toReturn.getLifecycleInformation();
|
||||
switch (getStatus()){
|
||||
case ERROR: {
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
|
||||
this.getMessages().forEach(s -> info.addErrorMessage(s));
|
||||
break;
|
||||
}
|
||||
case WARNING:{
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.WARNING);
|
||||
this.getMessages().forEach(s -> info.addWarningMessage(s));
|
||||
break;
|
||||
}
|
||||
case OK: {
|
||||
if(info.getLastOperationStatus()==null)
|
||||
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(toSetIdentificationReferences!=null)
|
||||
toReturn.setIdentificationReferences(toSetIdentificationReferences);
|
||||
return toReturn;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
|
||||
@ToString(callSuper = true)
|
||||
@Slf4j
|
||||
public class EventExecutionReport extends DocumentHandlingReport<EventExecutionRequest>{
|
||||
|
||||
public EventExecutionReport(EventExecutionRequest req) throws InvalidPluginRequestException {
|
||||
super(req);
|
||||
try{
|
||||
if(theRequest.getDocument().getLifecycleInformation()!=null)
|
||||
this.setToSetLifecycleInformation(theRequest.getDocument().getLifecycleInformation().cleanState());
|
||||
else theRequest.getDocument().setLifecycleInformation(new LifecycleInformation().cleanState());
|
||||
}catch(Throwable t){
|
||||
log.warn("Cannot to clean state for lifecycle information {} in {} : {}",
|
||||
theRequest.getDocument().getLifecycleInformation(),
|
||||
theRequest.getDocument().getProfileID(),
|
||||
theRequest.getDocument().getId(),
|
||||
t);
|
||||
}
|
||||
this.getToSetLifecycleInformation().setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setToSetLifecycleInformation(LifecycleInformation toSetLifecycleInformation) {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.Data;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
|
||||
@Data
|
||||
public class ExecutionReport extends Report{
|
||||
|
||||
StepExecutionRequest request;
|
||||
|
||||
ProfiledDocument result;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class IndexDocumentReport extends DocumentHandlingReport<IndexDocumentRequest> {
|
||||
|
||||
// protected List<IdentificationReference> toSetIndexReferences=new ArrayList<>();
|
||||
|
||||
|
||||
public IndexDocumentReport(@NonNull IndexDocumentRequest theRequest) throws InvalidPluginRequestException {
|
||||
super(theRequest);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Project prepareResult() throws JsonProcessingException, PluginExecutionException {
|
||||
// Project toReturn= super.prepareResult();
|
||||
// if(toSetSpatialReference != null) toReturn.setSpatialReference(toSetSpatialReference);
|
||||
// if(toSetTemporalReference != null) toReturn.setTemporalReference(toSetTemporalReference);
|
||||
// return toReturn;
|
||||
// }
|
||||
}
|
|
@ -1,6 +1,11 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
public class InitializationReport {
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class InitializationReport extends Report{
|
||||
|
||||
public InitializationReport(Status status, String... messages) {
|
||||
super(status, messages);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
|
||||
|
||||
public class MaterializationReport extends DocumentHandlingReport<MaterializationRequest>{
|
||||
|
||||
public MaterializationReport(@NonNull MaterializationRequest theRequest) throws InvalidPluginRequestException {
|
||||
super(theRequest);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,16 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Report {
|
||||
|
||||
public static enum Status {
|
||||
|
@ -13,4 +19,24 @@ public class Report {
|
|||
|
||||
private Status status;
|
||||
private List<String> messages;
|
||||
|
||||
public Report(Status status,String ... messages) {
|
||||
this.status = status;
|
||||
this.messages=new ArrayList<>();
|
||||
for (String s : messages)
|
||||
this.messages.add(s);
|
||||
}
|
||||
|
||||
public Report putMessage(String msg){
|
||||
if(messages==null)messages=new ArrayList<>();
|
||||
messages.add(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void validate()throws PluginExecutionException {
|
||||
if(status == null) throw new PluginExecutionException("Status is null");
|
||||
if(!status.equals(Status.OK))
|
||||
if(messages==null || messages.isEmpty()) throw new PluginExecutionException("Messages are mandatory for status != OK ");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class StepExecutionReport extends DocumentHandlingReport<StepExecutionRequest>{
|
||||
|
||||
public StepExecutionReport(@NonNull StepExecutionRequest theRequest) throws InvalidPluginRequestException {
|
||||
|
||||
super(theRequest);
|
||||
this.getToSetLifecycleInformation().cleanState();
|
||||
this.getToSetLifecycleInformation().setLastInvokedStep(theRequest.getStep());
|
||||
}
|
||||
|
||||
List<EventExecutionRequest> toTriggerEvents;
|
||||
|
||||
List<StepExecutionRequest> cascadeSteps;
|
||||
|
||||
|
||||
|
||||
|
||||
public StepExecutionReport addToTriggerEvent(EventExecutionRequest req){
|
||||
if(toTriggerEvents==null) toTriggerEvents = new ArrayList<>();
|
||||
toTriggerEvents.add(req);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public StepExecutionReport addCascadeStep(StepExecutionRequest req){
|
||||
if(cascadeSteps == null ) cascadeSteps = new ArrayList<>();
|
||||
cascadeSteps.add(req);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project prepareResult() throws JsonProcessingException, PluginExecutionException {
|
||||
Project toReturn= super.prepareResult();
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class BaseExecutionRequest extends BaseRequest{
|
||||
|
||||
|
||||
Project document;
|
||||
|
||||
public BaseExecutionRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document) {
|
||||
super(useCaseDescriptor, caller, context);
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
public BaseExecutionRequest validate() throws InvalidPluginRequestException {
|
||||
super.validate();
|
||||
if(document==null) throw new InvalidPluginRequestException("Document cannot be null");
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.*;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
@RequiredArgsConstructor
|
||||
public class BaseRequest {
|
||||
|
||||
@NonNull
|
||||
UseCaseDescriptor useCaseDescriptor;
|
||||
@NonNull
|
||||
User caller;
|
||||
@NonNull
|
||||
Context context;
|
||||
|
||||
|
||||
Document callParameters;
|
||||
|
||||
public final String getMandatory(String param) throws InvalidPluginRequestException {
|
||||
return getMandatory(param,callParameters);
|
||||
}
|
||||
|
||||
public final String getWithDefault(String param,String defaultValue) {
|
||||
try{
|
||||
return getMandatory(param,callParameters);
|
||||
}catch (InvalidPluginRequestException e){
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String getMandatory(String param,Document params) throws InvalidPluginRequestException {
|
||||
if(params==null || params.isEmpty()|| !params.containsKey(param)) throw new InvalidPluginRequestException("Missing mandatory parameter "+param);
|
||||
return Serialization.convert(params.get(param),String.class);
|
||||
}
|
||||
|
||||
public BaseRequest validate() throws InvalidPluginRequestException {
|
||||
if(useCaseDescriptor ==null)throw new InvalidPluginRequestException("UseCaseDescriptor cannot be null ");
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseRequest setParameter(String key,Object value){
|
||||
if(callParameters==null) callParameters=new Document();
|
||||
callParameters.put(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class EventExecutionRequest extends BaseExecutionRequest{
|
||||
|
||||
public static class Events{
|
||||
public static final String ON_INIT_DOCUMENT="INIT_DOCUMENT";
|
||||
public static final String ON_UPDATE_DOCUMENT="UPDATE_DOCUMENT";
|
||||
public static final String ON_DELETE_DOCUMENT="DELETE_DOCUMENT";
|
||||
public static final String ON_DELETE_FILESET="DELETE_FILESET";
|
||||
}
|
||||
|
||||
public EventExecutionRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document, String event) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
String event;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@ToString(callSuper = true)
|
||||
public class IndexDocumentRequest extends BaseExecutionRequest{
|
||||
public IndexDocumentRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@ToString(callSuper = true)
|
||||
public class MaterializationRequest extends BaseExecutionRequest{
|
||||
public MaterializationRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
}
|
||||
}
|
|
@ -1,28 +1,25 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.Data;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Data
|
||||
public class StepExecutionRequest {
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class StepExecutionRequest extends BaseExecutionRequest{
|
||||
|
||||
public static class Steps{
|
||||
public static final String ON_INIT_DOCUMENT="@@@INIT_DOCUMENT@@";
|
||||
public static final String ON_UPDATE_DOCUMENT="@@@UPDATE_DOCUMENT@@";
|
||||
public static final String ON_DELETE_DOCUMENT="@@@DELETE_DOCUMENT@@";
|
||||
|
||||
public static final String ON_MATERIALIZE_DOCUMENT="@@@MATERIALIZE_DOCUMENT@@";
|
||||
public static final String ON_DEMATERIALIZE_DOCUMENT="@@@DEMATERIALIZE_DOCUMENT@@";
|
||||
|
||||
public static final String ON_INDEX_DOCUMENT="@@@INDEX_DOCUMENT@@";
|
||||
public static final String ON_DEINDEX_DOCUMENT="@@@DEINDEX_DOCUMENT@@";
|
||||
public StepExecutionRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document, String step) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
|
||||
Profile profile;
|
||||
ProfiledDocument document;
|
||||
String step;
|
||||
Document callParameters;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.application.cms.serialization;
|
||||
|
||||
import com.jayway.jsonpath.Configuration;
|
||||
import com.jayway.jsonpath.Option;
|
||||
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
|
||||
import com.jayway.jsonpath.spi.json.JsonProvider;
|
||||
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
|
||||
import com.jayway.jsonpath.spi.mapper.MappingProvider;
|
||||
import org.gcube.application.geoportal.common.JSONSerializationProvider;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class JacksonProvider implements JSONSerializationProvider {
|
||||
|
||||
|
||||
@Override
|
||||
public void setJSONWrapperDefaults() {
|
||||
Configuration.setDefaults(new Configuration.Defaults() {
|
||||
private JsonProvider jacksonProvider = new JacksonJsonProvider(Serialization.mapper);
|
||||
|
||||
private final MappingProvider mappingProvider = new JacksonMappingProvider(Serialization.mapper);
|
||||
@Override
|
||||
public JsonProvider jsonProvider() {
|
||||
return jacksonProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Option> options() {
|
||||
return EnumSet.noneOf(Option.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingProvider mappingProvider() {
|
||||
return mappingProvider;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
package org.gcube.application.cms.serialization;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.gcube.application.cms.plugins.model.ComparableVersion;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Iterator;
|
||||
|
||||
@Slf4j
|
||||
public class Serialization {
|
||||
|
||||
public static final DateTimeFormatter FULL_FORMATTER=DateTimeFormatter.ofPattern("uuuuMMdd_HH-mm-ss");
|
||||
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper=new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
|
||||
SimpleModule s=new SimpleModule();
|
||||
s.addDeserializer(ObjectId.class,new ObjectIdDeserializer());
|
||||
s.addSerializer(ObjectId.class,new ObjectIdSerializer());
|
||||
|
||||
// s.addDeserializer(ComparableVersion.class,new ComparableVersionDeserializer());
|
||||
// s.addSerializer(ComparableVersion.class,new ComparableVersionSerializer());
|
||||
|
||||
s.addDeserializer(Semver.class,new SemverDeserializer());
|
||||
s.addSerializer(Semver.class,new SemverSerializer());
|
||||
|
||||
mapper.registerModule(s);
|
||||
}
|
||||
|
||||
public static <T> T read(String jsonString,Class<T> clazz) throws JsonProcessingException, IOException {
|
||||
return mapper.readerFor(clazz).readValue(jsonString);
|
||||
}
|
||||
|
||||
public static <T> Iterator<T> readCollection(String jsonString, Class<T> clazz) throws IOException {
|
||||
return mapper.readerFor(clazz).readValues(jsonString);
|
||||
}
|
||||
|
||||
|
||||
public static String write(Object toWrite) throws JsonProcessingException {
|
||||
String toReturn= mapper.writeValueAsString(toWrite);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static QueryRequest parseQuery(String queryString) throws IOException {
|
||||
log.trace("Parsing query Request {} ",queryString);
|
||||
Document queryDocument = Document.parse(queryString);
|
||||
log.trace("Document is ",queryDocument.toJson());
|
||||
QueryRequest req = new QueryRequest();
|
||||
if (queryDocument.getOrDefault("ordering",null)!=null)
|
||||
req.setOrdering(Serialization.read(((Document) queryDocument.get("ordering")).toJson(), QueryRequest.OrderedRequest.class));
|
||||
if (queryDocument.getOrDefault("paging",null)!=null)
|
||||
req.setPaging(Serialization.read(((Document) queryDocument.get("paging")).toJson(), QueryRequest.PagedRequest.class));
|
||||
req.setProjection(queryDocument.get("projection", Document.class));
|
||||
req.setFilter(queryDocument.get("filter", Document.class));
|
||||
return req;
|
||||
}
|
||||
|
||||
|
||||
//**** PROFILED DOCUMENTS
|
||||
|
||||
public static final <T> T convert(Object d,Class<T> clazz){
|
||||
return mapper.convertValue(d,clazz);
|
||||
}
|
||||
|
||||
public static final Document asDocument(Object obj) throws JsonProcessingException {
|
||||
return Document.parse(mapper.writeValueAsString(obj));
|
||||
}
|
||||
|
||||
public static final Document asDocumentWithId(Project doc) throws JsonProcessingException {
|
||||
Document toReturn =Document.parse(mapper.writeValueAsString(doc));
|
||||
if(doc.getId()!=null)
|
||||
toReturn.put(Project.ID,new ObjectId(doc.getId()));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
// ***** Serialization Exceptions
|
||||
|
||||
// OBJECT ID
|
||||
private static class ObjectIdSerializer extends JsonSerializer<ObjectId> {
|
||||
@Override
|
||||
public void serialize(ObjectId objectId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
||||
if (objectId == null) jsonGenerator.writeNull();
|
||||
else jsonGenerator.writeString(objectId.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ObjectId> handledType() {
|
||||
return ObjectId.class;
|
||||
}
|
||||
}
|
||||
private static class ObjectIdDeserializer extends JsonDeserializer<ObjectId> {
|
||||
|
||||
@Override
|
||||
public ObjectId deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||
String value=jsonParser.getValueAsString();
|
||||
if(value==null || value.isEmpty() || value.equals("null"))
|
||||
return null;
|
||||
else return new ObjectId(value);
|
||||
}
|
||||
@Override
|
||||
public Class<ObjectId> handledType() {
|
||||
return ObjectId.class;
|
||||
}
|
||||
}
|
||||
|
||||
//Comparable Version
|
||||
private static class ComparableVersionSerializer extends JsonSerializer<ComparableVersion> {
|
||||
@Override
|
||||
public void serialize(ComparableVersion comparableVersion, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
||||
if (comparableVersion == null) jsonGenerator.writeNull();
|
||||
else jsonGenerator.writeString(comparableVersion.getCanonical());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ComparableVersion> handledType() {
|
||||
return ComparableVersion.class;
|
||||
}
|
||||
}
|
||||
private static class ComparableVersionDeserializer extends JsonDeserializer<ComparableVersion> {
|
||||
|
||||
@Override
|
||||
public ComparableVersion deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||
String value=jsonParser.getValueAsString();
|
||||
if(value==null || value.isEmpty() || value.equals("null"))
|
||||
return null;
|
||||
else return new ComparableVersion(value);
|
||||
}
|
||||
@Override
|
||||
public Class<ComparableVersion> handledType() {
|
||||
return ComparableVersion.class;
|
||||
}
|
||||
}
|
||||
|
||||
//Sem Version
|
||||
private static class SemverSerializer extends JsonSerializer<Semver> {
|
||||
@Override
|
||||
public void serialize(Semver semver, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
||||
if (semver == null) jsonGenerator.writeNull();
|
||||
else jsonGenerator.writeString(semver.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Semver> handledType() {
|
||||
return Semver.class;
|
||||
}
|
||||
}
|
||||
private static class SemverDeserializer extends JsonDeserializer<Semver> {
|
||||
|
||||
@Override
|
||||
public Semver deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||
String value=jsonParser.getValueAsString();
|
||||
if(value==null || value.isEmpty() || value.equals("null"))
|
||||
return null;
|
||||
else return new Semver(value);
|
||||
}
|
||||
@Override
|
||||
public Class<Semver> handledType() {
|
||||
return Semver.class;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
public class SimpleLifecycleTests {
|
||||
|
||||
// NB cannot use test commons, need to separate modules
|
||||
// extends
|
||||
// BasicPluginTest {
|
||||
//
|
||||
// @Test
|
||||
// public void testFullCycle(){
|
||||
// SimpleLifeCycleManager manager = plugins.get(SimpleLifeCycleManager.PLUGIN_ID);
|
||||
//
|
||||
// StepExecutionRequest request = new StepExecutionRequest();
|
||||
//
|
||||
// Project p = null;
|
||||
//
|
||||
// EventExecutionRequest eventRequest = new EventExecutionRequest();
|
||||
//
|
||||
// manager.onEvent()
|
||||
//
|
||||
// manager.performStep()
|
||||
// }
|
||||
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
# Changelog for org.gcube.application.cms.cms-test-commons
|
||||
|
||||
## [v1.0.2] - 2022-01-17
|
||||
- Profiles
|
||||
|
||||
## [v1.0.1] - 2021-09-11
|
||||
- Introduced profiled documents
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cms-test-commons</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
<name>CMS Test Commons</name>
|
||||
|
||||
|
||||
<parent>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>gcube-cms-suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
</parent>
|
||||
|
||||
|
||||
|
@ -33,14 +33,14 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>${gcube-bom-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>${gcube-smartgears-bom-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -48,6 +48,7 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>geoportal-common</artifactId>
|
||||
|
@ -62,6 +63,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>cms-plugin-framework</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -82,6 +84,61 @@
|
|||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j18-impl</artifactId>
|
||||
<version>2.13.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Missing in JDK 11 -->
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,71 +0,0 @@
|
|||
package org.gcube.application.cms.tests;
|
||||
|
||||
import ch.qos.logback.core.net.SyslogOutputStream;
|
||||
import org.gcube.application.cms.plugins.InitializablePlugin;
|
||||
import org.gcube.application.cms.plugins.Plugin;
|
||||
import org.gcube.application.cms.plugins.faults.InitializationException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
|
||||
import java.rmi.ServerError;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class BasicPluginTest {
|
||||
|
||||
static List<Plugin> plugins;
|
||||
|
||||
@BeforeClass
|
||||
public static void checkPluginRegistration() {
|
||||
|
||||
|
||||
Reflections reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.forPackage("org.gcube.application.cms")
|
||||
.filterInputsBy(new FilterBuilder().includePackage("org.gcube.application.cms")));
|
||||
|
||||
reflections.getSubTypesOf(Plugin.class).iterator().forEachRemaining(pluginClass->{
|
||||
if(!pluginClass.isInterface()){
|
||||
try {
|
||||
Plugin plugin = pluginClass.newInstance();
|
||||
plugins.add(plugin);
|
||||
}catch (Throwable t){
|
||||
t.printStackTrace(System.err);
|
||||
Assert.fail("Unable to Load "+pluginClass);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
Assert.assertFalse(plugins.isEmpty());
|
||||
System.out.println("Plugin Loading OK");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void basicChecks(){
|
||||
plugins.forEach(p->{
|
||||
System.out.println("INIT Plugin "+p.getClass());
|
||||
Assert.assertNotNull(p.getDescriptor());
|
||||
Assert.assertNotNull(p.getDescriptor().getId());
|
||||
Assert.assertNotNull(p.getDescriptor().getType());
|
||||
Assert.assertNotNull(p.getDescriptor().getVersion());
|
||||
if(p instanceof InitializablePlugin){
|
||||
InitializablePlugin ip=(InitializablePlugin)p;
|
||||
try {
|
||||
ip.init();
|
||||
} catch (InitializationException e) {
|
||||
e.printStackTrace(System.err);
|
||||
Assert.fail("Unable to Init "+p.getDescriptor().getId());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.gcube.application.cms.tests;
|
||||
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TestDocuments {
|
||||
public static File BASE_FOLDER =new File("../test-data/profiledDocuments");
|
||||
public static final HashMap<String, Project> documentMap =new HashMap<>();
|
||||
|
||||
static{
|
||||
|
||||
for(File f:BASE_FOLDER.listFiles()){
|
||||
try {
|
||||
if(!f.isDirectory()) {
|
||||
Project p = Serialization.read(
|
||||
Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()), Project.class);
|
||||
documentMap.put(f.getName(), p);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("WARN : Unable to read file "+f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.gcube.application.cms.tests;
|
||||
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TestProfiles {
|
||||
|
||||
|
||||
public static File BASE_FOLDER =new File("../test-data/profiledDocuments/profiles");
|
||||
public static final HashMap<String, UseCaseDescriptor> profiles =new HashMap<>();
|
||||
|
||||
static{
|
||||
|
||||
for(File f:BASE_FOLDER.listFiles()){
|
||||
try {
|
||||
UseCaseDescriptor p =Serialization.read(
|
||||
Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()), UseCaseDescriptor.class);
|
||||
profiles.put(p.getId(), p);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.gcube.application.cms.tests;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TestSchemas {
|
||||
|
||||
|
||||
|
||||
public static File BASE_FOLDER =new File("../test-data/profiledDocuments/schemas");
|
||||
public static final HashMap<String, Document> schemas =new HashMap<>();
|
||||
|
||||
static{
|
||||
|
||||
for(File f:BASE_FOLDER.listFiles()){
|
||||
try {
|
||||
schemas.put(f.getName(), Document.parse(Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset())));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.gcube.application.cms.tests;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Tests {
|
||||
|
||||
public static File BASE_FOLDER =new File("../test-data");
|
||||
public static File FOLDER_CONCESSIONI =new File("../test-data/concessioni");
|
||||
}
|
|
@ -1,9 +1,19 @@
|
|||
package org.gcube.application.cms.tests;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||
import org.gcube.common.authorization.utils.secret.GCubeSecret;
|
||||
import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
|
@ -16,18 +26,37 @@ public class TokenSetter {
|
|||
try {
|
||||
props.load(TokenSetter.class.getResourceAsStream("/tokens.properties"));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("YOU NEED TO SET TOKEN FILE IN CONFIGURATION");
|
||||
throw new RuntimeException("YOU NEED TO SET TOKEN FILE IN CONFIGURATION",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void set(String scope){
|
||||
try{
|
||||
SecretManagerProvider.instance.set(new SecretManager());
|
||||
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
|
||||
SecurityTokenProvider.instance.set(props.getProperty(scope));
|
||||
}catch(Throwable e){
|
||||
log.warn("Unable to set token for scope "+scope,e);
|
||||
}
|
||||
ScopeProvider.instance.set(scope);
|
||||
// Secret secret = SecretUtility. getSecretByTokenString(token); // se non sai con che token hai a che fare;
|
||||
// oppure
|
||||
String toSet= props.getProperty(scope);
|
||||
log.debug("Setting secret "+toSet);
|
||||
|
||||
Secret secret = null;
|
||||
if(toSet.length()>50)
|
||||
secret = new JWTSecret(toSet); // se nuovo token
|
||||
else
|
||||
secret = new GCubeSecret(toSet); // se vecchio token
|
||||
|
||||
|
||||
SecretManagerProvider.instance.get().addSecret(secret);
|
||||
try{
|
||||
SecretManagerProvider.instance.get().set();
|
||||
}catch(Exception e ){throw new RuntimeException("Unable to set secret for context "+scope,e);}
|
||||
}
|
||||
//
|
||||
// public static void setUma() throws IOException {
|
||||
// File umaFile = new File("uma.json");
|
||||
// String uma= Files.readFileAsString(umaFile.getAbsolutePath(), Charset.defaultCharset());
|
||||
// AccessTokenProvider.instance.set(uma);
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
package org.gcube.application.cms.tests.model;
|
||||
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.access.Access;
|
||||
import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.application.geoportal.common.model.plugins.LifecycleManagerDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.DataAccessPolicy;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public class BasicTests extends GCubeTest {
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void initContext(){
|
||||
assumeTrue(isTestInfrastructureEnabled());
|
||||
TokenSetter.set(getContext());
|
||||
}
|
||||
|
||||
protected User getCurrentUser(){
|
||||
User u= new User();
|
||||
u.setUsername("fake-user");
|
||||
return u;
|
||||
}
|
||||
|
||||
protected UseCaseDescriptor getUCD(){
|
||||
return initUCD(getContextObject(),getCurrentUser());
|
||||
}
|
||||
|
||||
protected Document getBasicDocument(){
|
||||
return new Document();
|
||||
}
|
||||
|
||||
protected Project getBasicProject(){
|
||||
return initProject(getBasicDocument(),getUCD(), getCurrentUser(), getContextObject());
|
||||
}
|
||||
|
||||
protected Context getContextObject(){
|
||||
Context toReturn = new Context();
|
||||
toReturn.setName("My Fake Vre");
|
||||
toReturn.setId("FAKE-VRE");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
protected PublicationInfo getCurrentInfo(){
|
||||
return initPublicationInfo(getUCD(),getContextObject(),getCurrentUser());
|
||||
}
|
||||
|
||||
protected static PublicationInfo initPublicationInfo(UseCaseDescriptor ucd, Context ctx, User user){
|
||||
PublicationInfo toReturn = new PublicationInfo();
|
||||
|
||||
// TODO Set Access From UseCaseDescriptor
|
||||
Access access=new Access();
|
||||
access.setLicense("");
|
||||
access.setPolicy(AccessPolicy.OPEN);
|
||||
toReturn.setAccess(access);
|
||||
|
||||
toReturn.setCreationInfo(initAccountingInfo(ctx,user));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
protected static AccountingInfo initAccountingInfo(Context ctx, User user){
|
||||
AccountingInfo accInfo = new AccountingInfo();
|
||||
accInfo.setInstant(LocalDateTime.now());
|
||||
accInfo.setContext(ctx);
|
||||
accInfo.setUser(user);
|
||||
return accInfo;
|
||||
}
|
||||
|
||||
protected static Project initProject(Document doc, UseCaseDescriptor ucd,User user, Context ctx){
|
||||
Project p = new Project();
|
||||
|
||||
p.setId(UUID.randomUUID().toString());
|
||||
p.setInfo(initPublicationInfo(ucd,ctx,user));
|
||||
|
||||
p.setProfileID(ucd.getId());
|
||||
p.setProfileVersion(ucd.getVersion());
|
||||
p.setVersion(new Semver("1.0.0"));
|
||||
|
||||
LifecycleInformation draftInfo=new LifecycleInformation().cleanState();
|
||||
draftInfo.setPhase(LifecycleInformation.CommonPhases.DRAFT_PHASE);
|
||||
draftInfo.setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||
p.setLifecycleInformation(draftInfo);
|
||||
return p;
|
||||
}
|
||||
|
||||
protected static UseCaseDescriptor initUCD(Context ctx, User u){
|
||||
UseCaseDescriptor ucd = new UseCaseDescriptor();
|
||||
ucd.setName("Test UCD");
|
||||
ucd.setId("test-ucd");
|
||||
ucd.setDescription("Just a test dummy profile");
|
||||
ucd.setCreationInfo(initAccountingInfo(ctx,u));
|
||||
|
||||
ucd.setVersion(new Semver("1.0.0"));
|
||||
HandlerDeclaration h= new HandlerDeclaration();
|
||||
h.setType(LifecycleManagerDescriptor.LIFECYCLE_MANAGER_TYPE);
|
||||
h.setId(UUID.randomUUID().toString());
|
||||
ucd.setHandlers(Collections.singletonList(h));
|
||||
|
||||
DataAccessPolicy p =new DataAccessPolicy();
|
||||
p.setPolicy(new DataAccessPolicy.Policy());
|
||||
p.getPolicy().setRead(DataAccessPolicy.Policy.Type.any);
|
||||
p.getPolicy().setWrite(DataAccessPolicy.Policy.Type.any);
|
||||
ucd.setDataAccessPolicies(Collections.singletonList(p));
|
||||
return ucd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void validate (Project doc){
|
||||
assertTrue(doc!=null);
|
||||
assertTrue(doc.getId()!=null);
|
||||
assertTrue(doc.getLifecycleInformation().getPhase()!=null);
|
||||
assertTrue(doc.getLifecycleInformation().getLastOperationStatus()!=null);
|
||||
if(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.ERROR))
|
||||
assertTrue(doc.getLifecycleInformation().getErrorMessages().size()>0);
|
||||
if(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.WARNING))
|
||||
assertTrue(doc.getLifecycleInformation().getWarningMessages().size()>0);
|
||||
|
||||
if(doc.getLifecycleInformation().getTriggeredEvents()!=null)
|
||||
doc.getLifecycleInformation().getTriggeredEvents().forEach(triggeredEvents -> {
|
||||
assertTrue(triggeredEvents.getEvent()!=null);
|
||||
assertTrue(triggeredEvents.getLastOperationStatus()!=null);
|
||||
if(triggeredEvents.getLastOperationStatus().equals(LifecycleInformation.Status.ERROR))
|
||||
assertTrue(triggeredEvents.getErrorMessages().size()>0);
|
||||
if(triggeredEvents.getLastOperationStatus().equals(LifecycleInformation.Status.WARNING))
|
||||
assertTrue(triggeredEvents.getWarningMessages().size()>0);
|
||||
});
|
||||
|
||||
|
||||
assertTrue(doc.getInfo()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo().getContext()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo().getContext().getId()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo().getContext().getName()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo().getInstant()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo().getInstant()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo().getUser()!=null);
|
||||
assertTrue(doc.getInfo().getCreationInfo().getUser().getUsername()!=null);
|
||||
|
||||
assertTrue(doc.getTheDocument()!=null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package org.gcube.application.cms.tests.model;
|
||||
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
||||
import org.gcube.application.cms.plugins.PluginManagerInterface;
|
||||
import org.gcube.application.cms.plugins.faults.*;
|
||||
import org.gcube.application.cms.plugins.reports.*;
|
||||
import org.gcube.application.cms.plugins.requests.*;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
|
||||
public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, MaterializationPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public IndexDocumentReport index(IndexDocumentRequest request) throws InvalidPluginRequestException {
|
||||
return new IndexDocumentReport(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexDocumentReport deindex(IndexDocumentRequest request) throws InvalidPluginRequestException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Index getIndex(BaseRequest request) throws ConfigurationException {
|
||||
return new Index("Dummy index");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitializationReport initInContext() throws InitializationException {
|
||||
return new InitializationReport(Report.Status.WARNING,"DUMB");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitializationReport init() throws InitializationException {
|
||||
return new InitializationReport(Report.Status.WARNING,"DUMB");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() throws ShutDownException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException {
|
||||
request.validate();
|
||||
return new StepExecutionReport(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getCurrentConfiguration(BaseRequest ucd) throws ConfigurationException {
|
||||
return new Configuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException {
|
||||
return new EventExecutionReport(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPluginManager(PluginManagerInterface manager) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterializationReport materialize(MaterializationRequest request) throws MaterializationException, InvalidPluginRequestException {
|
||||
return new MaterializationReport(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterializationReport dematerialize(MaterializationRequest request) throws MaterializationException, InvalidPluginRequestException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginDescriptor getDescriptor() {
|
||||
return new PluginDescriptor("DUMMY-PLUGIN","DUMMY-TYPE","Dummy","No op plugin", new Semver("1.0.0"));
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package org.gcube.application.cms.tests.model.concessioni;
|
||||
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TestConcessioniFilters {
|
||||
|
||||
public static final HashMap<String,String> filters=new HashMap<>();
|
||||
|
||||
static{
|
||||
|
||||
for(File f:new File(TestConcessioniModel.getBaseFolder(),"filters").listFiles()){
|
||||
try {
|
||||
filters.put(f.getName(), Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package org.gcube.application.cms.tests.model.concessioni;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.gcube.application.geoportal.common.model.legacy.*;
|
||||
|
||||
public class TestConcessioniModel {
|
||||
|
||||
public static File getBaseFolder(){
|
||||
File toReturn =new File("../test-data/concessioni");
|
||||
if(!toReturn.exists()) toReturn = new File("test-data/concessioni");
|
||||
if(!toReturn.exists()) throw new RuntimeException("Unable to find test data");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static Concessione prepareEmptyConcessione() {
|
||||
Concessione concessione=new Concessione();
|
||||
|
||||
// Generic fields
|
||||
|
||||
// Concessione fields
|
||||
concessione.setNome("MONGO Italia, forse, ma su ");
|
||||
concessione.setIntroduzione("This is my MONGO project");
|
||||
concessione.setDescrizioneContenuto("It contains this and that");
|
||||
|
||||
concessione.setAuthors(Arrays.asList(new String[] {"Some one","Some, oneelse"}));
|
||||
|
||||
concessione.setContributore("Contrib 1");
|
||||
concessione.setTitolari(Arrays.asList(new String[] {"Some one","Some, oneelse"}));
|
||||
concessione.setResponsabile("Someone");
|
||||
concessione.setEditore("Editore");
|
||||
|
||||
concessione.setFontiFinanziamento(Arrays.asList(new String[] {"Big pharma","Pentagon"}));
|
||||
|
||||
|
||||
concessione.setSoggetto(Arrays.asList(new String[] {"Research Excavation","Archeology"}));
|
||||
|
||||
|
||||
concessione.setDataInizioProgetto(LocalDateTime.now());
|
||||
concessione.setDataFineProgetto(LocalDateTime.now());
|
||||
|
||||
concessione.setLicenzaID("CC-BY");
|
||||
|
||||
concessione.setTitolareLicenza(Arrays.asList(new String[] {"Qualcun altro"}));
|
||||
concessione.setTitolareCopyright(Arrays.asList(new String[] {"Chiedilo in giro"}));
|
||||
|
||||
concessione.setParoleChiaveLibere(Arrays.asList(new String[] {"Robba","Stuff"}));
|
||||
concessione.setParoleChiaveICCD(Arrays.asList(new String[] {"vattelapesca","somthing something"}));
|
||||
|
||||
|
||||
// concessione.setCentroidLat(43.0); //N-S
|
||||
// concessione.setCentroidLong(9.0); //E-W
|
||||
//
|
||||
return concessione;
|
||||
}
|
||||
|
||||
public static final Concessione setIds(Concessione c) {
|
||||
// c.setMongo_id(rnd());
|
||||
c.getRelazioneScavo().setMongo_id(rnd());
|
||||
c.getPosizionamentoScavo().setMongo_id(rnd());
|
||||
c.getPianteFineScavo().forEach((LayerConcessione l)->{l.setMongo_id(rnd());});
|
||||
c.getImmaginiRappresentative().forEach((UploadedImage i)->{i.setMongo_id(rnd());});
|
||||
return c;
|
||||
}
|
||||
|
||||
public static final String rnd() {
|
||||
return new ObjectId().toHexString();
|
||||
}
|
||||
|
||||
|
||||
public static Concessione prepareConcessione() {
|
||||
return prepareConcessione(4,2);
|
||||
}
|
||||
|
||||
public static Concessione prepareConcessione(int pianteCount ,int imgsCount) {
|
||||
|
||||
Concessione concessione=prepareEmptyConcessione();
|
||||
|
||||
|
||||
|
||||
// Attachments
|
||||
// Relazione scavo
|
||||
RelazioneScavo relScavo=new RelazioneScavo();
|
||||
relScavo.setResponsabili(concessione.getAuthors());
|
||||
concessione.setRelazioneScavo(relScavo);
|
||||
|
||||
//Abstract
|
||||
AbstractRelazione abstractRelazione=new AbstractRelazione();
|
||||
abstractRelazione.setAbstractIta("Il mio abstract");
|
||||
abstractRelazione.setAbstractEng("My abstract");
|
||||
concessione.setAbstractRelazione(abstractRelazione);
|
||||
|
||||
|
||||
//Immagini rappresentative
|
||||
ArrayList<UploadedImage> imgs=new ArrayList<>();
|
||||
for(int i=0;i<imgsCount;i++) {
|
||||
UploadedImage img=new UploadedImage();
|
||||
img.setTitolo("My image number "+i);
|
||||
img.setDidascalia("You can see my image number "+i);
|
||||
img.setFormat("TIFF");
|
||||
img.setCreationTime(LocalDateTime.now());
|
||||
img.setResponsabili(concessione.getAuthors());
|
||||
imgs.add(img);
|
||||
}
|
||||
concessione.setImmaginiRappresentative(imgs);
|
||||
//Posizionamento
|
||||
LayerConcessione posizionamento=new LayerConcessione();
|
||||
posizionamento.setValutazioneQualita("Secondo me si");
|
||||
posizionamento.setMetodoRaccoltaDati("Fattobbene");
|
||||
posizionamento.setScalaAcquisizione("1:10000");
|
||||
posizionamento.setAuthors(concessione.getAuthors());
|
||||
concessione.setPosizionamentoScavo(posizionamento);
|
||||
|
||||
// Piante fine scavo
|
||||
ArrayList<LayerConcessione> piante=new ArrayList<LayerConcessione>();
|
||||
for(int i=0;i<pianteCount;i++) {
|
||||
LayerConcessione pianta=new LayerConcessione();
|
||||
pianta.setValutazioneQualita("Secondo me si");
|
||||
pianta.setMetodoRaccoltaDati("Fattobbene");
|
||||
pianta.setScalaAcquisizione("1:10000");
|
||||
pianta.setAuthors(concessione.getAuthors());
|
||||
pianta.setPolicy(AccessPolicy.RESTRICTED);
|
||||
piante.add(pianta);
|
||||
}
|
||||
concessione.setPianteFineScavo(piante);
|
||||
|
||||
return concessione;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package org.gcube.application.cms.tests.model.concessioni;
|
||||
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TestConcessioniQueries {
|
||||
|
||||
public static final HashMap<String,String> queries =new HashMap<>();
|
||||
|
||||
static{
|
||||
|
||||
for(File f:new File(TestConcessioniModel.getBaseFolder(),"queries").listFiles()){
|
||||
try {
|
||||
queries.put(f.getName(), Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package org.gcube.application.cms.tests.plugins;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.Plugin;
|
||||
import org.gcube.application.cms.plugins.faults.*;
|
||||
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.common.model.plugins.LifecycleManagerDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class BasicLCPluginTest extends BasicPluginTest{
|
||||
|
||||
@Test
|
||||
public void testLifeCycle(){
|
||||
for (Map.Entry<String, Plugin> entry : plugins.entrySet()) {
|
||||
String s = entry.getKey();
|
||||
Plugin p = entry.getValue();
|
||||
if (p.getDescriptor().getType().equals(LifecycleManagerDescriptor.LIFECYCLE_MANAGER_TYPE)) {
|
||||
System.out.println("Testing LC Manager " + p.getDescriptor());
|
||||
LifecycleManager ip = (LifecycleManager) p;
|
||||
try {
|
||||
LifecycleManagerDescriptor descriptor =(LifecycleManagerDescriptor)p.getDescriptor();
|
||||
log.info("EVENTS ARE {}",descriptor.getSupportedEvents());
|
||||
for(Map.Entry<String, OperationDescriptor> e : descriptor.getSupportedEvents().entrySet()){
|
||||
EventExecutionRequest req = prepareEventRequest(e.getKey());
|
||||
log.info("Launching request {} ",req);
|
||||
EventExecutionReport rep = testEvent(ip,req);
|
||||
log.info("Report is {} ",rep);
|
||||
}
|
||||
|
||||
if(descriptor.getSupportedSteps()!=null) {
|
||||
log.info("STEPS ARE {}", descriptor.getSupportedEvents());
|
||||
for (Map.Entry<String, OperationDescriptor> e : descriptor.getSupportedSteps().entrySet()) {
|
||||
StepExecutionRequest req = prepareStepRequest(e.getKey());
|
||||
log.info("Launching request {} ", req);
|
||||
StepExecutionReport rep = testStep(ip, req);
|
||||
log.info("Report is {} ", rep);
|
||||
}
|
||||
}
|
||||
|
||||
ip.init().validate();
|
||||
|
||||
if (GCubeTest.isTestInfrastructureEnabled()) {
|
||||
TokenSetter.set(GCubeTest.getContext());
|
||||
ip.initInContext().validate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
Assert.fail("Unable to Init " + p.getDescriptor().getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected StepExecutionRequest prepareStepRequest(String stepId){
|
||||
return new StepExecutionRequest(getUCD(),getCurrentUser(),getContextObject(),getBasicProject(),stepId);
|
||||
};
|
||||
|
||||
protected EventExecutionRequest prepareEventRequest(String event){
|
||||
return new EventExecutionRequest(getUCD(),getCurrentUser(),getContextObject(),getBasicProject(),event);
|
||||
};
|
||||
|
||||
|
||||
protected EventExecutionReport testEvent(LifecycleManager lc, EventExecutionRequest r) throws InvalidPluginRequestException, EventException {
|
||||
return lc.onEvent(r);
|
||||
}
|
||||
protected StepExecutionReport testStep(LifecycleManager lc, StepExecutionRequest r) throws InvalidPluginRequestException, StepException, InvalidProfileException, StepException, ConfigurationException, InsufficientPrivileges {
|
||||
return lc.performStep(r);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package org.gcube.application.cms.tests.plugins;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.caches.Engine;
|
||||
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||
import org.gcube.application.cms.plugins.Plugin;
|
||||
import org.gcube.application.cms.plugins.PluginsReflections;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.cms.tests.model.BasicTests;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public abstract class BasicPluginTest extends BasicTests {
|
||||
|
||||
|
||||
|
||||
protected Context getTestContext(){
|
||||
Context toReturn = new Context();
|
||||
String contextId =GCubeTest.getContext();
|
||||
toReturn.setId(contextId);
|
||||
toReturn.setName(contextId.substring(contextId.lastIndexOf("/")));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
protected static Map<String,Plugin> plugins=new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void checkPluginRegistration() {
|
||||
plugins.putAll(PluginsReflections.load());
|
||||
plugins.forEach((s,p) -> System.out.println(s+" "+p.getDescriptor()));
|
||||
|
||||
Assert.assertFalse(plugins.isEmpty());
|
||||
|
||||
plugins.forEach(PluginCheks.descriptor);
|
||||
plugins.forEach(PluginCheks.init);
|
||||
System.out.println("Plugin Loading OK");
|
||||
|
||||
|
||||
ImplementationProvider.get().setEngine(new Engine<StorageUtils>() {
|
||||
@Override
|
||||
public void init() {}
|
||||
|
||||
@Override
|
||||
public void shutdown() {}
|
||||
|
||||
@Override
|
||||
public StorageUtils getObject() throws ConfigurationException {
|
||||
TokenSetter.set(GCubeTest.getContext());
|
||||
return new StorageUtils();
|
||||
}
|
||||
|
||||
},StorageUtils.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.gcube.application.cms.tests.plugins;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.plugins.*;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.common.model.plugins.IndexerPluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.LifecycleManagerDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.plugins.MaterializerPluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
public class PluginCheks {
|
||||
|
||||
static BiConsumer<String, Plugin> init= (s,p)->{
|
||||
if(p instanceof InitializablePlugin){
|
||||
log.info("INIT Plugin "+p.getDescriptor());
|
||||
InitializablePlugin ip=(InitializablePlugin)p;
|
||||
try {
|
||||
ip.init().validate();
|
||||
|
||||
if(GCubeTest.isTestInfrastructureEnabled()){
|
||||
log.info("INIT Plugin "+p.getDescriptor()+" under "+GCubeTest.getContext());
|
||||
TokenSetter.set(GCubeTest.getContext());
|
||||
ip.initInContext().validate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unable to init {} ",p,e);
|
||||
Assert.fail("Unable to Init "+p.getDescriptor().getId());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static BiConsumer<String, Plugin> descriptor= (s,p)->{
|
||||
log.info("Checking Plugin Descriptor "+p.getClass());
|
||||
Assert.assertNotNull(p.getDescriptor());
|
||||
Assert.assertNotNull(p.getDescriptor().getId());
|
||||
Assert.assertNotNull(p.getDescriptor().getType());
|
||||
switch(p.getDescriptor().getType()){
|
||||
case LifecycleManagerDescriptor.LIFECYCLE_MANAGER_TYPE:{
|
||||
assertTrue(p instanceof LifecycleManager);
|
||||
break; }
|
||||
case MaterializerPluginDescriptor.MATERIALIZER:{
|
||||
assertTrue(p instanceof MaterializationPlugin);
|
||||
break; }
|
||||
case IndexerPluginDescriptor.INDEXER:{
|
||||
assertTrue(p instanceof IndexerPluginInterface);
|
||||
break; }
|
||||
default:{}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.gcube.application.cms.commons.model;
|
||||
|
||||
import org.gcube.application.cms.tests.plugins.BasicPluginTest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DummyTest extends BasicPluginTest {
|
||||
|
||||
@Test
|
||||
public void myTest(){}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.gcube.application.cms.commons.model;
|
||||
|
||||
import org.gcube.application.cms.tests.TestProfiles;
|
||||
import org.gcube.application.cms.tests.model.BasicTests;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
|
||||
public class RolesTesting extends BasicTests {
|
||||
|
||||
|
||||
|
||||
public UseCaseDescriptor getUcd() {
|
||||
return TestProfiles.profiles.get("profiledConcessioni");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkRoles(){
|
||||
User u = getCurrentUser();
|
||||
UseCaseDescriptor ucd = getUcd();
|
||||
u.setRoles(Collections.emptySet());
|
||||
assertNotNull(ucd.getMatching(u));
|
||||
|
||||
u.setRoles(Collections.singleton("FakeUser"));
|
||||
assertNotNull(ucd.getMatching(u));
|
||||
u.setRoles(Collections.singleton("FakeAdmin"));
|
||||
assertNotNull(ucd.getMatching(u));
|
||||
u.setRoles(Collections.singleton("FakeEditor"));
|
||||
assertNotNull(ucd.getMatching(u));
|
||||
u.setRoles(Collections.singleton("FakeMember"));
|
||||
assertNotNull(ucd.getMatching(u));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
package org.gcube.application.cms.commons.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Serialization {
|
||||
|
||||
@Test
|
||||
public void testSerializations(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package org.gcube.application.cms.commons.model.concessioni;
|
||||
|
||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniFilters;
|
||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class Models {
|
||||
|
||||
@Test
|
||||
public void checkFilters(){
|
||||
assertTrue(TestConcessioniFilters.filters.size()>0);
|
||||
TestConcessioniFilters.filters.keySet().forEach(f -> {
|
||||
System.out.println(f);});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkConcessione(){
|
||||
Concessione c= TestConcessioniModel.prepareConcessione(3,5);
|
||||
assertTrue(c.getPianteFineScavo().size()==3);
|
||||
assertTrue(c.getImmaginiRappresentative().size()==5);
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package org.gcube.application.cms.commons.model.concessioni;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
|
||||
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
|
||||
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class PathsTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void embeddedPaths() {
|
||||
Concessione c= TestConcessioniModel.prepareConcessione();
|
||||
c= TestConcessioniModel.setIds(c);
|
||||
|
||||
|
||||
|
||||
LayerConcessione p=(LayerConcessione) c.getContentByPath(Paths.POSIZIONAMENTO);
|
||||
Assert.assertEquals(c.getPosizionamentoScavo(), p);
|
||||
|
||||
RelazioneScavo rel=(RelazioneScavo) c.getContentByPath(Paths.RELAZIONE);
|
||||
Assert.assertEquals(c.getRelazioneScavo(), rel);
|
||||
|
||||
for(int i=0;i<c.getPianteFineScavo().size();i++) {
|
||||
LayerConcessione l=(LayerConcessione) c.getContentByPath(Paths.piantaByIndex(i));
|
||||
Assert.assertEquals(c.getPianteFineScavo().get(i),l);
|
||||
}
|
||||
|
||||
for(int i=0;i<c.getImmaginiRappresentative().size();i++) {
|
||||
UploadedImage l=(UploadedImage) c.getContentByPath(Paths.imgByIndex(i));
|
||||
Assert.assertEquals(c.getImmaginiRappresentative().get(i),l);
|
||||
}
|
||||
|
||||
|
||||
for(int i=0;i<c.getPianteFineScavo().size();i++) {
|
||||
LayerConcessione layer=c.getPianteFineScavo().get(i);
|
||||
LayerConcessione l=(LayerConcessione) c.getContentByPath(Paths.piantaById(layer.getMongo_id()));
|
||||
Assert.assertEquals(layer,l);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(int i=0;i<c.getImmaginiRappresentative().size();i++) {
|
||||
UploadedImage layer=c.getImmaginiRappresentative().get(i);
|
||||
UploadedImage l=(UploadedImage) c.getContentByPath(Paths.imgById(layer.getMongo_id()));
|
||||
Assert.assertEquals(layer,l);
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package org.gcube.application.cms.commons.model.concessioni;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||
import org.gcube.application.geoportal.common.model.legacy.AccessPolicy;
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SerializationTest {
|
||||
|
||||
|
||||
private static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
static {
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
|
||||
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
|
||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void readProfile() throws JsonProcessingException, IOException {
|
||||
|
||||
Profile concessione=mapper.readerFor(Profile.class).readValue(new File(TestConcessioniModel.getBaseFolder(),"ProfileConcessioni.json"));
|
||||
|
||||
System.out.println("Profile is "+mapper.writeValueAsString(concessione));
|
||||
|
||||
//Assert.assertTrue(concessione .getFields().size()>0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readConcessione() throws JsonProcessingException, IOException {
|
||||
Concessione concessione=mapper.readerFor(Concessione.class).readValue(new File(TestConcessioniModel.getBaseFolder(),"Concessione.json"));
|
||||
System.out.println("Concessione is "+concessione.toString());
|
||||
|
||||
concessione.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED);
|
||||
assertEquals(AccessPolicy.EMBARGOED,concessione.getRelazioneScavo().getPolicy());
|
||||
|
||||
concessione=mapper.readerFor(Concessione.class).readValue(mapper.writeValueAsString(concessione));
|
||||
assertEquals(AccessPolicy.EMBARGOED,concessione.getRelazioneScavo().getPolicy());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generic() throws JsonProcessingException, IOException {
|
||||
Concessione conc= TestConcessioniModel.prepareConcessione();
|
||||
conc.validate();
|
||||
full(conc);
|
||||
}
|
||||
|
||||
|
||||
public void full(Object obj) throws JsonProcessingException, IOException {
|
||||
String asString=mapper.writeValueAsString(obj);
|
||||
Object other=mapper.readerFor(obj.getClass()).readValue(asString);
|
||||
|
||||
}
|
||||
}
|
|
@ -4,5 +4,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
This library contains custom extensions for the support of GNA "concessioni" use case
|
||||
|
||||
## [v1.0.1] - 2022-01-17
|
||||
- Serialization adaptation
|
||||
|
||||
## [v1.0.0] - 2021-12-15
|
||||
- First release
|
||||
|
|
|
@ -3,16 +3,15 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>concessioni-lifecycle</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1</version>
|
||||
<name>GNA Concessioni Lifecycle</name>
|
||||
|
||||
|
||||
<parent>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>gcube-cms-suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@ -28,6 +27,18 @@
|
|||
</scm>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>cms-plugin-framework</artifactId>
|
||||
<version>${plugin-framework-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -35,16 +46,53 @@
|
|||
<artifactId>cms-plugin-framework</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>concessioni-model</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– SDI –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.gcube.spatial.data</groupId>-->
|
||||
<!-- <artifactId>gis-interface</artifactId>-->
|
||||
<!-- <version>[2.4.6,3.0.0)</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- DT -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>data-transfer-library</artifactId>
|
||||
<version>[1.2.1,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>cms-test-commons</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>concessioni-model</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-uberjar</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>make-servicearchive</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue