diff --git a/CHANGELOG.md b/CHANGELOG.md index f853a66..a08b31e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,5 +2,10 @@ 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.1] - 2021-12-07 +- Introduced cms-plugin-framework +- Introduced concessioni use case +- Fixed internal group ids + ## [v1.0.0] - 2021-2-11 -First release +- First release diff --git a/cms-plugin-framework/CHANGELOG.md b/cms-plugin-framework/CHANGELOG.md new file mode 100644 index 0000000..7e9289e --- /dev/null +++ b/cms-plugin-framework/CHANGELOG.md @@ -0,0 +1,6 @@ +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +# Changelog for org.gcube.application.cms-plugin-framework + +## [v1.0.0] 2021-09-20 +- First release \ No newline at end of file diff --git a/cms-plugin-framework/FUNDING.md b/cms-plugin-framework/FUNDING.md new file mode 100644 index 0000000..9e48b94 --- /dev/null +++ b/cms-plugin-framework/FUNDING.md @@ -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); diff --git a/cms-plugin-framework/LICENSE.md b/cms-plugin-framework/LICENSE.md new file mode 100644 index 0000000..3af0507 --- /dev/null +++ b/cms-plugin-framework/LICENSE.md @@ -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 + diff --git a/cms-plugin-framework/README.md b/cms-plugin-framework/README.md new file mode 100644 index 0000000..1fd3533 --- /dev/null +++ b/cms-plugin-framework/README.md @@ -0,0 +1,53 @@ +CMS - Plugin Framework +-------------------------------------------------- + +CMS Plugin Framework is a library containing the definition of Java interfaces that plugins should implement + +## Built with +* [gCube SDI] (https://gcube.wiki.gcube-system.org/gcube/) - The gCube SDI +* [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). + +## 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); + diff --git a/cms-plugin-framework/pom.xml b/cms-plugin-framework/pom.xml new file mode 100644 index 0000000..99f0dd0 --- /dev/null +++ b/cms-plugin-framework/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + cms-plugin-framework + 1.0.0 + + + org.gcube.application.cms + gcube-cms-suite + 1.0.1 + + + + + https://code-repo.d4science.org/gCubeSystem + 1.0 + + + + + + + scm:git:${gitBaseUrl}/gcube-cms-suite + scm:git:${gitBaseUrl}/gcube-cms-suite + ${gitBaseUrl}/gcube-cms-suite + + + + + + org.gcube.application.cms + geoportal-common + + + + org.projectlombok + lombok + + + + \ No newline at end of file diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/InitializablePlugin.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/InitializablePlugin.java new file mode 100644 index 0000000..9a4e502 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/InitializablePlugin.java @@ -0,0 +1,28 @@ +package org.gcube.application.cms.plugins; + +import org.gcube.application.cms.plugins.faults.InitializationException; +import org.gcube.application.cms.plugins.faults.ShutDownException; +import org.gcube.application.cms.plugins.reports.InitializationReport; + +public interface InitializablePlugin extends Plugin{ + /** + * To be called once per context + * @return + * @throws InitializationException + */ + + public InitializationReport initInContext()throws InitializationException; + + /** + * To be called for static initialization + * @return + * @throws InitializationException + */ + public InitializationReport init()throws InitializationException; + + /** + * To be called at application shutdown + * @throws ShutDownException + */ + public void shutdown() throws ShutDownException; +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/LifecycleManager.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/LifecycleManager.java new file mode 100644 index 0000000..ad59b66 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/LifecycleManager.java @@ -0,0 +1,14 @@ +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.requests.StepExecutionRequest; +import org.gcube.application.geoportal.common.model.document.ProfiledDocument; + +public interface LifecycleManager extends InitializablePlugin{ + + // Lifecycle operations + + public ExecutionReport performStep(StepExecutionRequest request)throws StepException; + +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/Plugin.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/Plugin.java new file mode 100644 index 0000000..cac99a9 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/Plugin.java @@ -0,0 +1,8 @@ +package org.gcube.application.cms.plugins; + +import org.gcube.application.cms.plugins.model.PluginDescriptor; + +public interface Plugin { + + public PluginDescriptor getDescriptor(); +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/InitializationException.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/InitializationException.java new file mode 100644 index 0000000..177e5d6 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/InitializationException.java @@ -0,0 +1,23 @@ +package org.gcube.application.cms.plugins.faults; + +public class InitializationException extends Exception{ + + public InitializationException() { + } + + public InitializationException(String message) { + super(message); + } + + public InitializationException(String message, Throwable cause) { + super(message, cause); + } + + public InitializationException(Throwable cause) { + super(cause); + } + + public InitializationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/ShutDownException.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/ShutDownException.java new file mode 100644 index 0000000..c3584b1 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/ShutDownException.java @@ -0,0 +1,23 @@ +package org.gcube.application.cms.plugins.faults; + +public class ShutDownException extends Exception { + + public ShutDownException() { + } + + public ShutDownException(String message) { + super(message); + } + + public ShutDownException(String message, Throwable cause) { + super(message, cause); + } + + public ShutDownException(Throwable cause) { + super(cause); + } + + public ShutDownException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/StepException.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/StepException.java new file mode 100644 index 0000000..39e5302 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/faults/StepException.java @@ -0,0 +1,23 @@ +package org.gcube.application.cms.plugins.faults; + +public class StepException extends Exception { + + public StepException() { + } + + public StepException(String message) { + super(message); + } + + public StepException(String message, Throwable cause) { + super(message, cause); + } + + public StepException(Throwable cause) { + super(cause); + } + + public StepException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/model/PluginDescriptor.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/model/PluginDescriptor.java new file mode 100644 index 0000000..b05ef30 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/model/PluginDescriptor.java @@ -0,0 +1,26 @@ +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; + +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/ExecutionReport.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/ExecutionReport.java new file mode 100644 index 0000000..ea0d69e --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/ExecutionReport.java @@ -0,0 +1,13 @@ +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; +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/InitializationReport.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/InitializationReport.java new file mode 100644 index 0000000..58638ae --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/InitializationReport.java @@ -0,0 +1,6 @@ +package org.gcube.application.cms.plugins.reports; + +public class InitializationReport { + + +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/Report.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/Report.java new file mode 100644 index 0000000..58b9755 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/Report.java @@ -0,0 +1,16 @@ +package org.gcube.application.cms.plugins.reports; + +import lombok.Data; + +import java.util.List; + +@Data +public class Report { + + public static enum Status { + ERROR,WARNING,OK + } + + private Status status; + private List messages; +} diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/requests/StepExecutionRequest.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/requests/StepExecutionRequest.java new file mode 100644 index 0000000..41fef59 --- /dev/null +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/requests/StepExecutionRequest.java @@ -0,0 +1,28 @@ +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; + +@Data +public class StepExecutionRequest { + + 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@@"; + } + + + Profile profile; + ProfiledDocument document; + String step; + Document callParameters; +} diff --git a/cms-test-commons/CHANGELOG.md b/cms-test-commons/CHANGELOG.md index 7a0cba8..883bfa2 100644 --- a/cms-test-commons/CHANGELOG.md +++ b/cms-test-commons/CHANGELOG.md @@ -1,5 +1,8 @@ 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.1] - 2021-09-11 +- Introduced profiled documents + ## [v1.0.0] - 2021-09-11 -First release \ No newline at end of file +- First release \ No newline at end of file diff --git a/cms-test-commons/pom.xml b/cms-test-commons/pom.xml index 601fc78..eec1913 100644 --- a/cms-test-commons/pom.xml +++ b/cms-test-commons/pom.xml @@ -5,14 +5,14 @@ 4.0.0 cms-test-commons - 1.0.0 + 1.0.1 CMS Test Commons org.gcube.application.cms gcube-cms-suite - 1.0.0 + 1.0.1 @@ -49,10 +49,21 @@ - org.gcube.application + org.gcube.application.cms geoportal-common + + + org.reflections + reflections + + + + org.gcube.application.cms + cms-plugin-framework + + ch.qos.logback logback-classic diff --git a/cms-test-commons/src/main/java/org/gcube/application/cms/tests/BasicPluginTest.java b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/BasicPluginTest.java new file mode 100644 index 0000000..6780630 --- /dev/null +++ b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/BasicPluginTest.java @@ -0,0 +1,71 @@ +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 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()); + } + } + }); + } +} diff --git a/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestFilters.java b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniFilters.java similarity index 50% rename from cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestFilters.java rename to cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniFilters.java index ac55535..b998b87 100644 --- a/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestFilters.java +++ b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniFilters.java @@ -1,33 +1,20 @@ -package org.gcube.application.cms.tests.model; +package org.gcube.application.cms.tests.model.concessioni; import org.gcube.application.geoportal.common.utils.Files; -import sun.misc.IOUtils; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLDecoder; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; -import java.util.Enumeration; import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.stream.Stream; -public class TestFilters { +public class TestConcessioniFilters { public static final HashMap filters=new HashMap<>(); static{ - for(File f:new File(TestModel.getBaseFolder(),"filters").listFiles()){ + for(File f:new File(TestConcessioniModel.getBaseFolder(),"filters").listFiles()){ try { filters.put(f.getName(), Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset())); } catch (IOException e) { diff --git a/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestModel.java b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniModel.java similarity index 97% rename from cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestModel.java rename to cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniModel.java index 541f8b8..27ae3c5 100644 --- a/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestModel.java +++ b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniModel.java @@ -1,4 +1,4 @@ -package org.gcube.application.cms.tests.model; +package org.gcube.application.cms.tests.model.concessioni; import java.io.File; import java.time.LocalDateTime; @@ -8,7 +8,7 @@ import java.util.Arrays; import org.bson.types.ObjectId; import org.gcube.application.geoportal.common.model.legacy.*; -public class TestModel { +public class TestConcessioniModel { public static File getBaseFolder(){ File toReturn =new File("../test-data/concessioni"); diff --git a/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestQueries.java b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniQueries.java similarity index 72% rename from cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestQueries.java rename to cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniQueries.java index b633bcd..8be7fa6 100644 --- a/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/TestQueries.java +++ b/cms-test-commons/src/main/java/org/gcube/application/cms/tests/model/concessioni/TestConcessioniQueries.java @@ -1,21 +1,19 @@ -package org.gcube.application.cms.tests.model; +package org.gcube.application.cms.tests.model.concessioni; import org.gcube.application.geoportal.common.utils.Files; -import sun.misc.IOUtils; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.nio.charset.Charset; import java.util.HashMap; -public class TestQueries { +public class TestConcessioniQueries { public static final HashMap queries =new HashMap<>(); static{ - for(File f:new File(TestModel.getBaseFolder(),"queries").listFiles()){ + for(File f:new File(TestConcessioniModel.getBaseFolder(),"queries").listFiles()){ try { queries.put(f.getName(), Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset())); } catch (IOException e) { diff --git a/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/Serialization.java b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/Serialization.java new file mode 100644 index 0000000..1f50d09 --- /dev/null +++ b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/Serialization.java @@ -0,0 +1,6 @@ +package org.gcube.application.cms.commons.model; + +public class Serialization { + + +} diff --git a/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/Models.java b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/Models.java index e8aab7d..d1694ca 100644 --- a/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/Models.java +++ b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/Models.java @@ -1,7 +1,7 @@ package org.gcube.application.cms.commons.model.concessioni; -import org.gcube.application.cms.tests.model.TestFilters; -import org.gcube.application.cms.tests.model.TestModel; +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; @@ -11,14 +11,14 @@ public class Models { @Test public void checkFilters(){ - assertTrue(TestFilters.filters.size()>0); - TestFilters.filters.keySet().forEach(f -> { + assertTrue(TestConcessioniFilters.filters.size()>0); + TestConcessioniFilters.filters.keySet().forEach(f -> { System.out.println(f);}); } @Test public void checkConcessione(){ - Concessione c= TestModel.prepareConcessione(3,5); + Concessione c= TestConcessioniModel.prepareConcessione(3,5); assertTrue(c.getPianteFineScavo().size()==3); assertTrue(c.getImmaginiRappresentative().size()==5); } diff --git a/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/PathsTest.java b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/PathsTest.java index 3f3d0ca..203e8d1 100644 --- a/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/PathsTest.java +++ b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/PathsTest.java @@ -2,7 +2,7 @@ package org.gcube.application.cms.commons.model.concessioni; import static org.junit.Assert.assertEquals; -import org.gcube.application.cms.tests.model.TestModel; +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; @@ -17,8 +17,8 @@ public class PathsTest { @Test public void embeddedPaths() { - Concessione c= TestModel.prepareConcessione(); - c=TestModel.setIds(c); + Concessione c= TestConcessioniModel.prepareConcessione(); + c= TestConcessioniModel.setIds(c); diff --git a/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/SerializationTest.java b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/SerializationTest.java index 6f4fb33..494a1a8 100644 --- a/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/SerializationTest.java +++ b/cms-test-commons/src/test/java/org/gcube/application/cms/commons/model/concessioni/SerializationTest.java @@ -3,10 +3,10 @@ package org.gcube.application.cms.commons.model.concessioni; import java.io.File; import java.io.IOException; -import org.gcube.application.cms.tests.model.TestModel; +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.gcube.application.geoportal.common.utils.Files; import org.junit.Assert; import org.junit.Test; @@ -17,6 +17,8 @@ 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 { @@ -35,24 +37,30 @@ public class SerializationTest { @Test public void readProfile() throws JsonProcessingException, IOException { - Profile concessione=mapper.readerFor(Profile.class).readValue(new File(TestModel.getBaseFolder(),"ProfileConcessioni.json")); + 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); + //Assert.assertTrue(concessione .getFields().size()>0); } @Test public void readConcessione() throws JsonProcessingException, IOException { - Concessione concessione=mapper.readerFor(Concessione.class).readValue(new File(TestModel.getBaseFolder(),"Concessione.json")); - System.out.println("Concessione is "+concessione.toString()); - + 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= TestModel.prepareConcessione(); + Concessione conc= TestConcessioniModel.prepareConcessione(); conc.validate(); full(conc); } diff --git a/concessioni-lifecycle/CHANGELOG.md b/concessioni-lifecycle/CHANGELOG.md new file mode 100644 index 0000000..078a9e4 --- /dev/null +++ b/concessioni-lifecycle/CHANGELOG.md @@ -0,0 +1,8 @@ +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +# Changelog for org.gcube.application.cms.concessioni-lifecycle + +This library contains custom extensions for the support of GNA "concessioni" use case + +## [v1.0.0] - 2021-12-15 +- First release diff --git a/concessioni-lifecycle/FUNDING.md b/concessioni-lifecycle/FUNDING.md new file mode 100644 index 0000000..9e48b94 --- /dev/null +++ b/concessioni-lifecycle/FUNDING.md @@ -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); diff --git a/concessioni-lifecycle/LICENSE.md b/concessioni-lifecycle/LICENSE.md new file mode 100644 index 0000000..3af0507 --- /dev/null +++ b/concessioni-lifecycle/LICENSE.md @@ -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 + diff --git a/concessioni-lifecycle/README.md b/concessioni-lifecycle/README.md new file mode 100644 index 0000000..85dd719 --- /dev/null +++ b/concessioni-lifecycle/README.md @@ -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); + diff --git a/concessioni-lifecycle/pom.xml b/concessioni-lifecycle/pom.xml new file mode 100644 index 0000000..c62a2e8 --- /dev/null +++ b/concessioni-lifecycle/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + concessioni-lifecycle + 1.0.0 + GNA Concessioni Lifecycle + + + + org.gcube.application.cms + gcube-cms-suite + 1.0.1 + + + + https://code-repo.d4science.org/gCubeSystem + + + + + + scm:git:${gitBaseUrl}/gcube-cms-suite + scm:git:${gitBaseUrl}/gcube-cms-suite + ${gitBaseUrl}/gcube-cms-suite + + + + + + + org.gcube.application.cms + cms-plugin-framework + + + + org.gcube.application.cms + cms-test-commons + test + + + org.gcube.application.cms + concessioni-model + + + + + \ No newline at end of file diff --git a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java new file mode 100644 index 0000000..b94d603 --- /dev/null +++ b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java @@ -0,0 +1,102 @@ +package org.gcube.application.cms.concessioni.plugins; + +import lombok.extern.slf4j.Slf4j; +import org.bson.Document; +import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione; +import org.gcube.application.cms.plugins.LifecycleManager; +import org.gcube.application.cms.plugins.faults.InitializationException; +import org.gcube.application.cms.plugins.faults.ShutDownException; +import org.gcube.application.cms.plugins.faults.StepException; +import org.gcube.application.cms.plugins.model.PluginDescriptor; +import org.gcube.application.cms.plugins.reports.ExecutionReport; +import org.gcube.application.cms.plugins.reports.InitializationReport; +import org.gcube.application.cms.plugins.reports.Report; +import org.gcube.application.cms.plugins.requests.StepExecutionRequest; +import org.gcube.application.geoportal.common.model.document.ComparableVersion; +import org.gcube.application.geoportal.common.model.document.ProfiledDocument; +import org.gcube.application.geoportal.common.utils.JSONPathWrapper; + +@Slf4j +public class ConcessioniLifeCycleManager implements LifecycleManager { + + private static final PluginDescriptor DESCRIPTOR=new PluginDescriptor("GNA-CONCESSIONI-LC", PluginDescriptor.BaseTypes.LIFECYCLE_MANAGER); + static { + DESCRIPTOR.setDescription("GNA Concessioni. This plugin supports custom lifecycle management for the GNA Concessioni UseCase."); + DESCRIPTOR.setVersion(new ComparableVersion("1.0.0")); + } + + + @Override + public InitializationReport initInContext() throws InitializationException { + return null; + } + + @Override + public InitializationReport init() throws InitializationException { + return null; + } + + @Override + public void shutdown() throws ShutDownException { + + } + + @Override + public ExecutionReport performStep(StepExecutionRequest request) throws StepException { + log.info("Serving Request {}",request); + ExecutionReport report=new ExecutionReport(); + report.setRequest(request); + report.setStatus(Report.Status.OK); + try { + switch (request.getStep()) { + case StepExecutionRequest.Steps.ON_INIT_DOCUMENT: + // Set Defaults as for on update + case StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT: { + ProfiledDocument doc = request.getDocument(); + + break; + } + case StepExecutionRequest.Steps.ON_MATERIALIZE_DOCUMENT: { + break; + } + case StepExecutionRequest.Steps.ON_DEMATERIALIZE_DOCUMENT: { + break; + } + case StepExecutionRequest.Steps.ON_DEINDEX_DOCUMENT: { + break; + } + case StepExecutionRequest.Steps.ON_INDEX_DOCUMENT: { + break; + } + case StepExecutionRequest.Steps.ON_DELETE_DOCUMENT: { + break; + } + default: + throw new StepException("Invalid Step " + request.getStep()); + } + }catch (StepException e){ + throw e; + }catch (Throwable t){ + log.error("Unable to perform step "+request.getStep(),t); + report.setStatus(Report.Status.ERROR); + report.getMessages().add("Unable to execute Step "+request.getStep()+". Error was "+t.getMessage()); + } + return report; + } + + @Override + public PluginDescriptor getDescriptor() { + return DESCRIPTOR; + } + + + // STATIC ROUTINES + + private static final ProfiledDocument setDefaults(ProfiledDocument document){ + ProfiledConcessione c =(ProfiledConcessione) document; + c.setDefaults(); + return c; + } + + +} diff --git a/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/Tests.java b/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/Tests.java new file mode 100644 index 0000000..b297ce4 --- /dev/null +++ b/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/Tests.java @@ -0,0 +1,13 @@ +package org.gcube.application.cms.concessioni.plugins; + +import org.gcube.application.cms.tests.BasicPluginTest; +import org.junit.Assert; +import org.junit.Test; + +public class Tests extends BasicPluginTest { + + @Test + public void testLoad(){ + Assert.assertTrue(true); + } +} diff --git a/concessioni-model/CHANGELOG.md b/concessioni-model/CHANGELOG.md new file mode 100644 index 0000000..6c54d43 --- /dev/null +++ b/concessioni-model/CHANGELOG.md @@ -0,0 +1,8 @@ +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +# Changelog for org.gcube.application.cms.concessioni-model + +This library contains custom BEANS for the support of GNA "concessioni" use case + +## [v1.0.0-SNAPSHOT] - 2021-12-15 +- First release diff --git a/concessioni-model/FUNDING.md b/concessioni-model/FUNDING.md new file mode 100644 index 0000000..9e48b94 --- /dev/null +++ b/concessioni-model/FUNDING.md @@ -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); diff --git a/concessioni-model/LICENSE.md b/concessioni-model/LICENSE.md new file mode 100644 index 0000000..3af0507 --- /dev/null +++ b/concessioni-model/LICENSE.md @@ -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 + diff --git a/concessioni-model/README.md b/concessioni-model/README.md new file mode 100644 index 0000000..85dd719 --- /dev/null +++ b/concessioni-model/README.md @@ -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); + diff --git a/concessioni-model/pom.xml b/concessioni-model/pom.xml new file mode 100644 index 0000000..b3dc4af --- /dev/null +++ b/concessioni-model/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + org.gcube.application.cms + concessioni-model + 1.0.0 + GNA Concessioni Model + + + + org.gcube.application.cms + gcube-cms-suite + 1.0.1 + + + + https://code-repo.d4science.org/gCubeSystem + + + + + + scm:git:${gitBaseUrl}/gcube-cms-suite + scm:git:${gitBaseUrl}/gcube-cms-suite + ${gitBaseUrl}/gcube-cms-suite + + + + + + + org.gcube.application.cms + geoportal-common + + + + org.gcube.application.cms + cms-test-commons + test + + + + \ No newline at end of file diff --git a/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/DefaultLogicHolder.java b/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/DefaultLogicHolder.java new file mode 100644 index 0000000..2938ad0 --- /dev/null +++ b/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/DefaultLogicHolder.java @@ -0,0 +1,7 @@ +package org.gcube.application.cms.custom.gna.concessioni.model; + +public interface DefaultLogicHolder { + + public void setDefaults(); + +} diff --git a/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/DocumentedRelazioneScavo.java b/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/DocumentedRelazioneScavo.java new file mode 100644 index 0000000..eeb4187 --- /dev/null +++ b/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/DocumentedRelazioneScavo.java @@ -0,0 +1,11 @@ +package org.gcube.application.cms.custom.gna.concessioni.model; + +import org.bson.Document; + +public class DocumentedRelazioneScavo extends Document implements DefaultLogicHolder{ + + @Override + public void setDefaults() { + + } +} diff --git a/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/ProfiledConcessione.java b/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/ProfiledConcessione.java new file mode 100644 index 0000000..cee48e6 --- /dev/null +++ b/concessioni-model/src/main/java/org/gcube/application/cms/custom/gna/concessioni/model/ProfiledConcessione.java @@ -0,0 +1,118 @@ +package org.gcube.application.cms.custom.gna.concessioni.model; + +import org.bson.BsonDocument; +import org.bson.BsonString; +import org.bson.BsonValue; +import org.bson.Document; +import org.gcube.application.geoportal.common.model.document.Access; +import org.gcube.application.geoportal.common.model.document.AccessPolicy; +import org.gcube.application.geoportal.common.model.document.ProfiledDocument; +import org.gcube.application.geoportal.common.model.document.RegisteredFileSet; +import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione; +import org.gcube.application.geoportal.common.model.legacy.report.Check; +import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck; + +import java.util.List; + + +public class ProfiledConcessione extends ProfiledDocument { + + public static final String NOME="nome"; + //Introduzione (descrizione del progetto) + public final static String INTRODUZIONE = "introduzione"; + //Descrizione del contenuto + public final static String DSCRIZIONE_CONTENUTO ="descrizioneContenuto"; + //Autori + public final static String AUTHORS= "authors"; + //Soggetto che materialmente invia i dati. + public final static String CONTRIBUTORE ="contributore"; + + //Indicare il nome del titolare/i dei dati contenuti nel dataset e/o per sue specifiche parti. + public final static String TITOLARI="titolari"; + + public final static String RESPONSABILE="responsabile"; + public final static String EDITORS ="editore"; + + public final static String FONTI_FINANZIAMENTO="fontiFinanziamento"; + //Research Excavation; Archaeology (valori di default) + public final static String SOGGETTO="soggetto"; + + //Referenze bibliografiche, DOI (se esistenti) di risorse correlate all’indagine in oggetto + public final static String RISORSE_CORRELATE="risorseCorrelate"; + + public final static String DATA_INZIO_PROGETTO="dataInizioProgetto"; + public final static String DATA_FINE_PROGETTO="dataFineProgetto"; + + public final static String TITOLARE_LICENZA="titolareLicenza"; + public final static String TITOLARE_COPYRIGHT="titolareCopyright"; + + public final static String PAROLE_CHIAVE_LIBERE="paroleChiaveLibere"; + public final static String PAREOLE_CHIAVE_ICCD="paroleChiaveICCD"; + + public final static String RELAZIONE_SCAVO="relazioneScavo"; + public final static String ABSTRACT_RELAZIONE ="abstractRelazione"; + public final static String IMMAGINI_RAPPRESENTATIVE="immaginiRappresentative"; + public final static String POSIZIONAMENTO_SCAVO = "posizionamentoScavo"; + public final static String PIANTE_FINE_SCAVO = "pianteFineScavo"; + public final static String GENERIC_CONTENT= "genericContent"; + + public static class Sections{ + public static final String TITOLO="titolo"; + } + public static class Relazione{ + + public static final String RESPONSABILI= "responsabili"; + + } + + @Override + public void setDefaults() { + Document doc=this.getTheDocument(); + doc.putIfAbsent(SOGGETTO,new String[]{"Research Excavation","Archaeology"}); + + doc.putIfAbsent(DSCRIZIONE_CONTENUTO,"Relazione di fine scavo e relativo abstract; selezione di immagini rappresentative;" + + " posizionamento topografico dell'area indagata, pianta di fine scavo."); + + // Super Section + this.getInfo().getAccess().setLicense( + ConstraintCheck.defaultFor(getInfo().getAccess().getLicense(), "CC0-1.0").evaluate()); + + + //RELAZIONE + doc.putIfAbsent(RELAZIONE_SCAVO,new RegisteredFileSet()); + Document rel=doc.get(RELAZIONE_SCAVO,Document.class); + rel.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" relazione di scavo"); + rel.putIfAbsent(SOGGETTO,doc.get(SOGGETTO)); + rel.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo()); + rel.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess()); + Access relAccess=rel.get(RegisteredFileSet.ACCESS,Access.class); + relAccess.setLicense(ConstraintCheck.defaultFor(relAccess.getLicense(),"CC-BY-4.0").evaluate()); + relAccess.setPolicy(ConstraintCheck.defaultFor(relAccess.getPolicy(), AccessPolicy.OPEN).evaluate()); + + //ABSTRACT Relazione + doc.putIfAbsent(ABSTRACT_RELAZIONE,new RegisteredFileSet()); + Document abs=doc.get(ABSTRACT_RELAZIONE,Document.class); + abs.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" abstract relazione di scavo"); + abs.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo()); + abs.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess()); + Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class); + absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate()); + absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate()); + + //IMMAGINI RAPPRESENTATIVE + + +// if(doc.containsKey(IMMAGINI_RAPPRESENTATIVE)) { +// for (BsonValue bsonValue : doc.toBsonDocument(null, null). +// getArray(IMMAGINI_RAPPRESENTATIVE)) { +// BsonDocument imgDocument = bsonValue.asDocument(); +// imgDocument.putIfAbsent(SOGGETTO,new BsonString(doc.getString(SOGGETTO)); +// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,new BsonDocument(this.getInfo().getCreationInfo()); +// imgDocument.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess()); +// Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class); +// absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate()); +// absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate()); +// } +// } + } +} diff --git a/geoportal-client/CHANGELOG.md b/geoportal-client/CHANGELOG.md index 6a01b3c..5b1585a 100644 --- a/geoportal-client/CHANGELOG.md +++ b/geoportal-client/CHANGELOG.md @@ -2,26 +2,28 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for org.gcube.application.geoportal-client +## [v1.0.6] - 2021-09-20 +- Changed artifact dependencies +- Default Profiled Documents client + ## [v1.0.5] - 2021-09-20 -Refactored repositories +- Refactored repositories ## [v1.0.4-SNAPSHOT] - 2020-11-11 -Serialization utils -Queries & Filters support -Test Reports -UseCases -Fixes #21897 +- Serialization utils +- Queries & Filters support +- Test Reports +- UseCases +- Fixes #21897 ## [v1.0.3] - 2020-11-11 -Stateful Concessioni Manager client over mongo +- Stateful Concessioni Manager client over mongo ## [v1.0.2] - 2020-11-11 -Fixed dulicate dependency declaration +- Fixed dulicate dependency declaration ## [v1.0.1] - 2020-11-11 -Excluded common-calls 1.2.0 - +-Excluded common-calls 1.2.0 ## [v1.0.0] - 2020-11-11 - -First release \ No newline at end of file +- First release \ No newline at end of file diff --git a/geoportal-client/pom.xml b/geoportal-client/pom.xml index 82ca912..35d70b8 100644 --- a/geoportal-client/pom.xml +++ b/geoportal-client/pom.xml @@ -4,14 +4,14 @@ 4.0.0 org.gcube.application geoportal-client - 1.0.5 + 1.0.6 Geoportal Client org.gcube.application.cms gcube-cms-suite - 1.0.0 + 1.0.1 @@ -32,7 +32,7 @@ - org.gcube.application + org.gcube.application.cms geoportal-common diff --git a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProfiledConcessioni.java b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProfiledConcessioni.java new file mode 100644 index 0000000..7102c15 --- /dev/null +++ b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProfiledConcessioni.java @@ -0,0 +1,93 @@ +package org.gcube.application.geoportal.client; + +import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest; +import org.gcube.application.geoportal.common.model.rest.Configuration; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.rest.MongoConcessioni; + +import java.util.Iterator; + +public class DefaultProfiledConcessioni implements MongoConcessioni { + + + @Override + public Concessione createNew(Concessione c) throws Exception { + return null; + } + + @Override + public void deleteById(String id) throws Exception { + + } + + @Override + public void deleteById(String id, Boolean force) throws Exception { + + } + + @Override + public Concessione getById(String id) throws Exception { + return null; + } + + @Override + public Iterator getList() throws Exception { + return null; + } + + @Override + public Concessione publish(String id) throws Exception { + return null; + } + + @Override + public Concessione registerFileSet(String id, AddSectionToConcessioneRequest request) throws Exception { + return null; + } + + @Override + public Concessione cleanFileSet(String id, String path) throws Exception { + return null; + } + + @Override + public Concessione update(String id, String jsonUpdate) throws Exception { + return null; + } + + @Override + public Concessione replace(Concessione replacement) throws Exception { + return null; + } + + @Override + public void unPublish(String id) throws Exception { + + } + + @Override + public Configuration getCurrentConfiguration() throws Exception { + return null; + } + + @Override + public Iterator search(String filter) throws Exception { + return null; + } + + @Override + public Iterator query(QueryRequest request) throws Exception { + return null; + } + + @Override + public String queryForJSON(QueryRequest request) throws Exception { + return null; + } + + @Override + public Iterator queryForType(QueryRequest request, Class clazz) throws Exception { + return null; + } +} diff --git a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProfiledDocuments.java b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProfiledDocuments.java new file mode 100644 index 0000000..df7e07f --- /dev/null +++ b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProfiledDocuments.java @@ -0,0 +1,62 @@ +package org.gcube.application.geoportal.client; + + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.bson.Document; +import org.gcube.application.geoportal.common.model.document.ProfiledDocument; +import org.gcube.application.geoportal.common.model.rest.Configuration; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.rest.ProfiledDocumentsI; +import org.gcube.common.clients.delegates.ProxyDelegate; + +import javax.ws.rs.client.WebTarget; +import java.rmi.RemoteException; +import java.util.Iterator; + +@RequiredArgsConstructor +public class DefaultProfiledDocuments implements ProfiledDocumentsI { + + @NonNull + private final ProxyDelegate delegate; + + @Override + public ProfiledDocument createNew(Document toCreate) throws RemoteException { + return null; + } + + @Override + public void deleteById(String id) throws RemoteException { + + } + + @Override + public void deleteById(String id, Boolean force) throws RemoteException { + + } + + @Override + public ProfiledDocument getById(String id) throws RemoteException { + return null; + } + + @Override + public Configuration getConfiguration() throws RemoteException { + return null; + } + + @Override + public Iterator query(QueryRequest request) throws RemoteException { + return null; + } + + @Override + public String querForJSON(QueryRequest request) throws RemoteException { + return null; + } + + @Override + public ProfiledDocument performStep(String id, String step, Document request) { + return null; + } +} diff --git a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProjects.java b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProjects.java deleted file mode 100644 index 37415f2..0000000 --- a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultProjects.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.gcube.application.geoportal.client; - -import java.rmi.RemoteException; -import java.util.Iterator; - -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import org.gcube.application.geoportal.common.model.project.Project; -import org.gcube.application.geoportal.common.rest.ProjectsI; -import org.gcube.common.clients.Call; -import org.gcube.common.clients.delegates.ProxyDelegate; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class DefaultProjects implements ProjectsI{ - - @NonNull - private final ProxyDelegate delegate; - - @Override - public void deleteById(String profileId, String projectId) throws RemoteException { - deleteById(profileId,projectId,false); - } - @Override - public void deleteById(String profileId, String projectId,Boolean force) throws RemoteException { -// Call call= new Call() { -// -// @Override -// public String call(WebTarget endpoint) throws Exception { -// endpoint.path(profileId).path(projectId).request(MediaType.APPLICATION_JSON).delete(); -// } -// }; -// try{ -// delegate.make(call); -// }catch(Exception e) { -//// throw new RemoteException(e); -// } - } - - @Override - public Iterator getAll() throws RemoteException { - Call> call=new Call>(){ - @Override - public Iterator call(WebTarget endpoint) throws Exception { - throw new Exception("Client method not ready"); - } - }; - try{ - return delegate.make(call); - }catch(Exception e) { - throw new RemoteException(e.getMessage()); - } - } - - @Override - public Iterator getByFilter(String filter) throws RemoteException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Iterator getByFilter(String filter, String profileId) throws RemoteException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Project getById(String profileId, String id) throws RemoteException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Iterator getByProfile(String profileId) throws RemoteException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Project registrNew(String profileId, String jsonDocument) throws RemoteException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Project update(String profileId, String projectId, String jsonDocument) throws RemoteException { - // TODO Auto-generated method stub - return null; - } -} diff --git a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/ProjectsPlugin.java b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/ProjectsPlugin.java index aaa17a5..53637e4 100644 --- a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/ProjectsPlugin.java +++ b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/ProjectsPlugin.java @@ -6,14 +6,14 @@ import javax.xml.transform.dom.DOMResult; import javax.xml.ws.EndpointReference; import org.gcube.application.geoportal.common.rest.InterfaceConstants; -import org.gcube.application.geoportal.common.rest.ProjectsI; +import org.gcube.application.geoportal.common.rest.ProfiledDocumentsI; import org.gcube.common.calls.jaxrs.GcubeService; import org.gcube.common.calls.jaxrs.TargetFactory; import org.gcube.common.clients.config.ProxyConfig; import org.gcube.common.clients.delegates.ProxyDelegate; import org.w3c.dom.Node; -public class ProjectsPlugin extends GeoportalAbstractPlugin{ +public class ProjectsPlugin extends GeoportalAbstractPlugin{ @Override @@ -22,8 +22,8 @@ public class ProjectsPlugin extends GeoportalAbstractPlugin delegate) { - return new DefaultProjects(delegate); + public ProfiledDocumentsI newProxy(ProxyDelegate delegate) { + return new DefaultProfiledDocuments(delegate); } @Override diff --git a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/ConcessioniManagerI.java b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/ConcessioniManagerI.java index 97ef9f9..986e2c4 100644 --- a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/ConcessioniManagerI.java +++ b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/ConcessioniManagerI.java @@ -7,6 +7,7 @@ import org.gcube.application.geoportal.common.rest.TempFile; public interface ConcessioniManagerI extends MongoConcessioni{ + public Concessione getCurrent(); public Concessione addImmagineRappresentativa(UploadedImage toAdd,TempFile f) throws Exception; public Concessione addPiantaFineScavo(LayerConcessione toAdd,TempFile...files)throws Exception; public Concessione setPosizionamento(LayerConcessione toSet,TempFile...files)throws Exception; diff --git a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/StatefulMongoConcessioni.java b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/StatefulMongoConcessioni.java index 7a7a578..70bb6af 100644 --- a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/StatefulMongoConcessioni.java +++ b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/legacy/StatefulMongoConcessioni.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import javax.ws.rs.client.WebTarget; +import lombok.Getter; import org.gcube.application.geoportal.client.DefaultMongoConcessioni; import org.gcube.application.geoportal.common.model.legacy.*; import org.gcube.application.geoportal.common.utils.FileSets; @@ -21,97 +22,98 @@ public class StatefulMongoConcessioni extends DefaultMongoConcessioni implements super(delegate); } - private Concessione currentC=null; + @Getter + private Concessione current =null; private StorageUtils storage=new StorageUtils(); // Override methods to handle state @Override public Concessione createNew(Concessione c) throws Exception { - currentC=super.createNew(c); - return currentC; + current =super.createNew(c); + return current; } @Override public Concessione getById(String id) throws Exception { - currentC= super.getById(id); - return currentC; + current = super.getById(id); + return current; } @Override public Concessione publish() throws Exception { - if(currentC==null) throw new Exception("Invalid operation : current Concessione is null."); - currentC=super.publish(currentC.getMongo_id()); - return currentC; + if(current ==null) throw new Exception("Invalid operation : current Concessione is null."); + current =super.publish(current.getMongo_id()); + return current; } @Override public void delete() throws Exception { - if(currentC==null) throw new Exception("Invalid operation : current Concessione is null."); - super.deleteById(currentC.getMongo_id()); - currentC=null; + if(current ==null) throw new Exception("Invalid operation : current Concessione is null."); + super.deleteById(current.getMongo_id()); + current =null; } @Override public Concessione addImmagineRappresentativa(UploadedImage toAdd, TempFile f) throws Exception { - if(currentC==null) throw new Exception("Invalid operation : current Concessione is null."); - if(currentC.getImmaginiRappresentative()==null) currentC.setImmaginiRappresentative(new ArrayList()); - currentC.getImmaginiRappresentative().add(toAdd); - currentC=replace(currentC); + if(current ==null) throw new Exception("Invalid operation : current Concessione is null."); + if(current.getImmaginiRappresentative()==null) current.setImmaginiRappresentative(new ArrayList()); + current.getImmaginiRappresentative().add(toAdd); + current =replace(current); - currentC=super.registerFileSet(currentC.getMongo_id(), - FileSets.build(Paths.imgByIndex(currentC.getImmaginiRappresentative().size()-1),f).getTheRequest()); - return currentC; + current =super.registerFileSet(current.getMongo_id(), + FileSets.build(Paths.imgByIndex(current.getImmaginiRappresentative().size()-1),f).getTheRequest()); + return current; } @Override public Concessione addPiantaFineScavo(LayerConcessione toAdd, TempFile... files) throws Exception { - if(currentC==null) throw new Exception("Invalid operation : current Concessione is null."); - if(currentC.getPianteFineScavo()==null) currentC.setPianteFineScavo(new ArrayList<>()); - currentC.getPianteFineScavo().add(toAdd); - currentC=replace(currentC); + if(current ==null) throw new Exception("Invalid operation : current Concessione is null."); + if(current.getPianteFineScavo()==null) current.setPianteFineScavo(new ArrayList<>()); + current.getPianteFineScavo().add(toAdd); + current =replace(current); - currentC=super.registerFileSet(currentC.getMongo_id(), - FileSets.build(Paths.piantaByIndex(currentC.getPianteFineScavo().size()-1),files).getTheRequest()); - return currentC; + current =super.registerFileSet(current.getMongo_id(), + FileSets.build(Paths.piantaByIndex(current.getPianteFineScavo().size()-1),files).getTheRequest()); + return current; } @Override public Concessione setPosizionamento(LayerConcessione toSet, TempFile... files) throws Exception { - if(currentC==null) throw new Exception("Invalid operation : current Concessione is null."); - currentC.setPosizionamentoScavo(toSet); - currentC=replace(currentC); + if(current ==null) throw new Exception("Invalid operation : current Concessione is null."); + current.setPosizionamentoScavo(toSet); + current =replace(current); - currentC=super.registerFileSet(currentC.getMongo_id(), + current =super.registerFileSet(current.getMongo_id(), FileSets.build(Paths.POSIZIONAMENTO,files).getTheRequest()); - return currentC; + return current; } @Override public Concessione setRelazioneScavo(RelazioneScavo toSet, TempFile... files) throws Exception { - if(currentC==null) throw new Exception("Invalid operation : current Concessione is null."); - currentC.setRelazioneScavo(toSet); - currentC=replace(currentC); + if(current ==null) throw new Exception("Invalid operation : current Concessione is null."); + current.setRelazioneScavo(toSet); + current =replace(current); - currentC=super.registerFileSet(currentC.getMongo_id(), + current =super.registerFileSet(current.getMongo_id(), FileSets.build(Paths.RELAZIONE,files).getTheRequest()); - return currentC; + return current; } @Override public Concessione setAbstractRelazioneScavo(AbstractRelazione toSet, TempFile... files) throws Exception { - if(currentC==null) throw new Exception("Invalid operation : current Concessione is null."); - currentC.setAbstractRelazione(toSet); - currentC=replace(currentC); + if(current ==null) throw new Exception("Invalid operation : current Concessione is null."); + current.setAbstractRelazione(toSet); + current =replace(current); - currentC=super.registerFileSet(currentC.getMongo_id(), + current =super.registerFileSet(current.getMongo_id(), FileSets.build(Paths.ABSTRACT_RELAZIONE,files).getTheRequest()); - return currentC; + return current; } diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/StorageTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/StorageTests.java index 5056c64..87f4801 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/StorageTests.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/StorageTests.java @@ -2,7 +2,7 @@ package org.gcube.application.geoportal; import org.apache.commons.io.IOUtils; import org.gcube.application.cms.tests.TokenSetter; -import org.gcube.application.cms.tests.model.TestModel; + import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportal.common.utils.Files; import org.gcube.application.geoportal.common.utils.StorageUtils; diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java index 4110a1e..4016eb1 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java @@ -7,8 +7,9 @@ public class BasicVreTests { @BeforeClass public static void setScope(){ -// TokenSetter.set("/gcube/devNext/NextNext"); - TokenSetter.set("/gcube/devsec/devVRE"); +// TokenSetter.set("/pred4s/preprod/preVRE"); + // TokenSetter.set("/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype"); + TokenSetter.set("/gcube/devsec/devVRE"); } diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatefulClientTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatefulClientTests.java index 9bfe465..f8e861b 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatefulClientTests.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatefulClientTests.java @@ -7,13 +7,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import org.gcube.application.cms.tests.model.TestModel; + +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI; import org.gcube.application.geoportal.client.utils.Serialization; -import org.gcube.application.geoportal.common.model.legacy.Concessione; -import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor; -import org.gcube.application.geoportal.common.model.legacy.LayerConcessione; -import org.gcube.application.geoportal.common.model.legacy.UploadedImage; +import org.gcube.application.geoportal.common.model.legacy.*; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportal.common.utils.Files; @@ -31,55 +29,66 @@ public class StatefulClientTests extends BasicVreTests{ StorageUtils storage=new StorageUtils(); - Concessione toRegister= TestModel.prepareEmptyConcessione(); + Concessione toRegister= TestConcessioniModel.prepareEmptyConcessione(); toRegister.setNome("Mock module"); manager.createNew(toRegister); - Concessione source=TestModel.prepareConcessione(); + + + + Concessione source=TestConcessioniModel.prepareConcessione(); UploadedImage toRegisterImg= source.getImmaginiRappresentative().get(0); // TEMP Files are hosted in INFRASTRUCTURE's VOLATILE AREA TempFile toUpload=storage.putOntoStorage( - new File(TestModel.getBaseFolder(),"immagine.png"), "immagine.png"); + new File(TestConcessioniModel.getBaseFolder(),"immagine1.png"), "immagine.png"); manager.addImmagineRappresentativa(toRegisterImg, toUpload); //Alternative Method InputStreamDescriptor isDesc= - new InputStreamDescriptor(new FileInputStream(new File(TestModel.getBaseFolder(), - "immagine.png")), "San Mauro_drone totale.JPG"); + new InputStreamDescriptor(new FileInputStream(new File(TestConcessioniModel.getBaseFolder(), + "immagine1.png")), "San Mauro_drone totale.JPG"); manager.addImmagineRappresentativa(toRegisterImg, isDesc); + source.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED); + assertEquals(AccessPolicy.EMBARGOED,source.getRelazioneScavo().getPolicy()); //Relazione manager.setRelazioneScavo(source.getRelazioneScavo(), - storage.putOntoStorage(new File(TestModel.getBaseFolder(),"relazione.pdf"), "relazione_it.pdf"), - storage.putOntoStorage(new File(TestModel.getBaseFolder(),"relazione.pdf"), "relazione_en.pdf")); + storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "relazione_it.pdf"), + storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "relazione_en.pdf")); + assertEquals(AccessPolicy.EMBARGOED,manager.getCurrent().getRelazioneScavo().getPolicy()); //Abstract manager.setAbstractRelazioneScavo( source.getAbstractRelazione(), - storage.putOntoStorage(new File(TestModel.getBaseFolder(),"relazione.pdf"), "abstract_relazione_it.pdf"), - storage.putOntoStorage(new File(TestModel.getBaseFolder(),"relazione.pdf"), "abstract_relazione_en.pdf")); + storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "abstract_relazione_it.pdf"), + storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "abstract_relazione_en.pdf")); + // Posizionamento scavo manager.setPosizionamento(source.getPosizionamentoScavo(), storage.putOntoStorage( - new File(TestModel.getBaseFolder(),"pos.shp"),"pos.shp")); + new File(TestConcessioniModel.getBaseFolder(),"pos.shp"),"pos.shp")); // Piante manager.addPiantaFineScavo(source.getPianteFineScavo().get(0), storage.putOntoStorage( - new File(TestModel.getBaseFolder(),"pianta.shp"),"pianta.shp")); + new File(TestConcessioniModel.getBaseFolder(),"pianta.shp"),"pianta.shp")); // new File("/Users/fabioisti/Documents/invio_08_05/Montalto di Castro (VT)_Vulci_Indagini non invasive_Doc. paragr._Va/CONSEGNA_WGS84") // .listFiles((file,name)->{return name.startsWith("Mag_anomalies_WGS84");}))); - - return manager.publish(); + + + + Concessione toReturn=manager.publish(); + assertEquals(AccessPolicy.EMBARGOED,toReturn.getRelazioneScavo().getPolicy()); + return toReturn; } @@ -110,7 +119,7 @@ public class StatefulClientTests extends BasicVreTests{ ConcessioniManagerI manager=statefulMongoConcessioni().build(); StorageUtils storage=new StorageUtils(); - manager.createNew(TestModel.prepareEmptyConcessione()); + manager.createNew(TestConcessioniModel.prepareEmptyConcessione()); manager.delete(); } diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatelessClientTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatelessClientTests.java index 15f9ff6..c9f953b 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatelessClientTests.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/StatelessClientTests.java @@ -11,14 +11,17 @@ import java.util.Collections; import java.util.Iterator; import java.util.concurrent.atomic.AtomicLong; -import org.gcube.application.cms.tests.model.TestFilters; -import org.gcube.application.cms.tests.model.TestModel; -import org.gcube.application.cms.tests.model.TestQueries; +import org.bson.Document; +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniFilters; +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniQueries; import org.gcube.application.geoportal.client.utils.Queries; +import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.model.legacy.*; import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus; import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.utils.FileSets; import org.gcube.application.geoportal.common.utils.Files; @@ -37,22 +40,28 @@ public class StatelessClientTests extends BasicVreTests{ @Test public void searches() throws Exception { - TestFilters.filters.forEach((k,v)->{ + TestConcessioniFilters.filters.forEach((k, v)->{ try { System.out.println("Count for " + k + "\t" + count(client.search(v))); }catch (Exception e){ throw new RuntimeException(e); } }); + + } @Test public void query() throws Exception { + + System.out.println("FRA "+ count(client.query( + Queries.parse(TestConcessioniQueries.queries.get("emptyresult.json"))))); + // No Transformation System.out.print("First Registered \t"); Iterator queriedDocuments=client.query( - Queries.parse(TestQueries.queries.get("firstRegistered.json"))); + Queries.parse(TestConcessioniQueries.queries.get("firstRegistered.json"))); // Expected one result assertTrue(count(queriedDocuments)==1); @@ -61,7 +70,7 @@ public class StatelessClientTests extends BasicVreTests{ System.out.print("Last Registered \t"); // Expected one result queriedDocuments=client.query( - Queries.parse(TestQueries.queries.get("lastRegistered.json"))); + Queries.parse(TestConcessioniQueries.queries.get("lastRegistered.json"))); assertTrue(count(queriedDocuments)==1); queriedDocuments.forEachRemaining((Concessione c)->{System.out.println(c.getNome());}); @@ -70,11 +79,11 @@ public class StatelessClientTests extends BasicVreTests{ // Transformations System.out.println( client.queryForJSON( - Queries.parse(TestQueries.queries.get("lastNameRegisteredByFabio.json")))); + Queries.parse(TestConcessioniQueries.queries.get("lastNameRegisteredByFabio.json")))); System.out.println( client.queryForJSON( - Queries.parse(TestQueries.queries.get("publicationWarningMessages.json")))); + Queries.parse(TestConcessioniQueries.queries.get("publicationWarningMessages.json")))); // String query=Files.readFileAsString(filterFile.getAbsolutePath(), Charset.defaultCharset()); // System.out.println("Count for "+filterFile.getName()+"\t"+ count(client.search(query))); @@ -91,14 +100,14 @@ public class StatelessClientTests extends BasicVreTests{ @Test public void testCreateNew() throws Exception { - Concessione c= client.createNew(TestModel.prepareEmptyConcessione()); + Concessione c= client.createNew(TestConcessioniModel.prepareEmptyConcessione()); assertNotNull(c); assertNotNull(c.getMongo_id()); } @Test public void testReplace() throws Exception { - Concessione testObject= client.createNew(TestModel.prepareEmptyConcessione()); + Concessione testObject= client.createNew(TestConcessioniModel.prepareEmptyConcessione()); String title="My new shiny Title"; testObject.setNome(title); Concessione c1=client.replace(testObject); @@ -107,11 +116,11 @@ public class StatelessClientTests extends BasicVreTests{ @Test public void testUploadFileSet() throws Exception { - Concessione testObject= client.createNew(TestModel.prepareConcessione()); + Concessione testObject= client.createNew(TestConcessioniModel.prepareConcessione()); AddSectionToConcessioneRequest request= -// FileSets.prepareRequest(new StorageUtils(),Paths.RELAZIONE,new File(TestModel.getBaseFolder(),"relazione.pdf")); +// FileSets.prepareRequest(new StorageUtils(),Paths.RELAZIONE,new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf")); FileSets.build(Paths.ABSTRACT_RELAZIONE).add( - new StorageUtils().putOntoStorage(new File(TestModel.getBaseFolder(),"relazione.pdf"),"San Mauro_drone totale.JPG")) + new StorageUtils().putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"),"San Mauro_drone totale.JPG")) .getTheRequest(); testObject= client.registerFileSet(testObject.getMongo_id(), request); @@ -124,13 +133,13 @@ public class StatelessClientTests extends BasicVreTests{ @Test public void testDeleteById() throws Exception { - Concessione c= client.createNew(TestModel.prepareEmptyConcessione()); + Concessione c= client.createNew(TestConcessioniModel.prepareEmptyConcessione()); client.deleteById(c.getMongo_id()); } @Test - public void testPublsh() throws Exception { + public void testPublish() throws Exception { Concessione c=prepare(); assertTrue(c.getReport().getStatus().equals(ValidationStatus.PASSED)); @@ -171,34 +180,46 @@ public class StatelessClientTests extends BasicVreTests{ private Concessione prepare() throws Exception { int numImgs=1; - Concessione c= client.createNew(TestModel.prepareConcessione(1,numImgs)); + Concessione c= client.createNew(TestConcessioniModel.prepareConcessione(1,numImgs)); StorageUtils storage = new StorageUtils(); + c.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED); String mongoId=c.getMongo_id(); + c=client.update(mongoId, Serialization.write(c)); - client.registerFileSet(mongoId, - FileSets.prepareRequest(storage,Paths.RELAZIONE,new File(TestModel.getBaseFolder(),"relazione.pdf"))); + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); - client.registerFileSet(mongoId, - FileSets.prepareRequest(storage,Paths.RELAZIONE,new File(TestModel.getBaseFolder(),"relazione.pdf"))); + c=client.registerFileSet(mongoId, + FileSets.prepareRequest(storage,Paths.RELAZIONE,new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"))); + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); + c=client.registerFileSet(mongoId, + FileSets.prepareRequest(storage,Paths.ABSTRACT_RELAZIONE,new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"))); + + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); for(int i=0;i 4.0.0 - org.gcube.application geoportal-common - 1.0.7 + 1.0.8 Geoportal Common org.gcube.application.cms gcube-cms-suite - 1.0.0 + 1.0.1 @@ -42,6 +41,11 @@ authorization-client + + com.jayway.jsonpath + json-path + 2.4.0 + diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Access.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Access.java new file mode 100644 index 0000000..c265269 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Access.java @@ -0,0 +1,18 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class Access { + + public static final String POLICY="policy"; + public static final String LICENSE="license"; + + private AccessPolicy policy; + private String license; + +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/AccessPolicy.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/AccessPolicy.java new file mode 100644 index 0000000..cb04ae1 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/AccessPolicy.java @@ -0,0 +1,7 @@ +package org.gcube.application.geoportal.common.model.document; + +public enum AccessPolicy { + + OPEN,RESTRICTED,EMBARGOED; + +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/AccountingInfo.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/AccountingInfo.java new file mode 100644 index 0000000..4f25379 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/AccountingInfo.java @@ -0,0 +1,21 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class AccountingInfo { + + public static final String USER="user"; + public static final String CONTEXT="context"; + public static final String INSTANT="instant"; + + private User user; + private Context context; + private LocalDateTime instant; +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/ComparableVersion.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/ComparableVersion.java new file mode 100644 index 0000000..56a340d --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/ComparableVersion.java @@ -0,0 +1,840 @@ +package org.gcube.application.geoportal.common.model.document; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +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; + +/** + *

+ * Generic implementation of version comparison. + *

+ * + * Features: + *
    + *
  • mixing of '-' (hyphen) and '.' (dot) separators,
  • + *
  • transition between characters and digits also constitutes a separator: + * 1.0alpha1 => [1, 0, alpha, 1]
  • + *
  • unlimited number of version components,
  • + *
  • version components in the text can be digits or strings,
  • + *
  • strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering. + * Well-known qualifiers (case insensitive) are:
      + *
    • alpha or a
    • + *
    • beta or b
    • + *
    • milestone or m
    • + *
    • rc or cr
    • + *
    • snapshot
    • + *
    • (the empty string) or ga or final
    • + *
    • sp
    • + *
    + * Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive), + *
  • + *
  • a hyphen usually precedes a qualifier, and is always less important than something preceded with a dot.
  • + *
+ * + * @see "Versioning" on Maven Wiki + * @author Kenney Westerhof + * @author Hervé Boutemy + */ + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class ComparableVersion + implements Comparable +{ + private static final int MAX_INTITEM_LENGTH = 9; + + private static final int MAX_LONGITEM_LENGTH = 18; + + private String value; + + private String canonical; + + private ListItem items; + + private interface Item + { + int INT_ITEM = 3; + int LONG_ITEM = 4; + int BIGINTEGER_ITEM = 0; + int STRING_ITEM = 1; + int LIST_ITEM = 2; + + int compareTo( Item item ); + + int getType(); + + boolean isNull(); + } + + /** + * Represents a numeric item in the version item list that can be represented with an int. + */ + private static class IntItem + implements Item + { + private final int value; + + public static final IntItem ZERO = new IntItem(); + + private IntItem() + { + this.value = 0; + } + + IntItem( String str ) + { + this.value = Integer.parseInt( str ); + } + + @Override + public int getType() + { + return INT_ITEM; + } + + @Override + public boolean isNull() + { + return value == 0; + } + + @Override + public int compareTo( Item item ) + { + if ( item == null ) + { + return ( value == 0 ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + } + + switch ( item.getType() ) + { + case INT_ITEM: + int itemValue = ( (IntItem) item ).value; + return Integer.compare( value, itemValue ); + case LONG_ITEM: + case BIGINTEGER_ITEM: + return -1; + + case STRING_ITEM: + return 1; // 1.1 > 1-sp + + case LIST_ITEM: + return 1; // 1.1 > 1-1 + + default: + throw new IllegalStateException( "invalid item: " + item.getClass() ); + } + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + IntItem intItem = (IntItem) o; + + return value == intItem.value; + + } + + @Override + public int hashCode() + { + return value; + } + + @Override + public String toString() + { + return Integer.toString( value ); + } + } + + /** + * Represents a numeric item in the version item list that can be represented with a long. + */ + private static class LongItem + implements Item + { + private final long value; + + LongItem( String str ) + { + this.value = Long.parseLong( str ); + } + + @Override + public int getType() + { + return LONG_ITEM; + } + + @Override + public boolean isNull() + { + return value == 0; + } + + @Override + public int compareTo( Item item ) + { + if ( item == null ) + { + return ( value == 0 ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + } + + switch ( item.getType() ) + { + case INT_ITEM: + return 1; + case LONG_ITEM: + long itemValue = ( (LongItem) item ).value; + return Long.compare( value, itemValue ); + case BIGINTEGER_ITEM: + return -1; + + case STRING_ITEM: + return 1; // 1.1 > 1-sp + + case LIST_ITEM: + return 1; // 1.1 > 1-1 + + default: + throw new IllegalStateException( "invalid item: " + item.getClass() ); + } + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + LongItem longItem = (LongItem) o; + + return value == longItem.value; + + } + + @Override + public int hashCode() + { + return (int) ( value ^ ( value >>> 32 ) ); + } + + @Override + public String toString() + { + return Long.toString( value ); + } + } + + /** + * Represents a numeric item in the version item list. + */ + private static class BigIntegerItem + implements Item + { + private final BigInteger value; + + BigIntegerItem( String str ) + { + this.value = new BigInteger( str ); + } + + @Override + public int getType() + { + return BIGINTEGER_ITEM; + } + + @Override + public boolean isNull() + { + return BigInteger.ZERO.equals( value ); + } + + @Override + public int compareTo( Item item ) + { + if ( item == null ) + { + return BigInteger.ZERO.equals( value ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + } + + switch ( item.getType() ) + { + case INT_ITEM: + case LONG_ITEM: + return 1; + + case BIGINTEGER_ITEM: + return value.compareTo( ( (BigIntegerItem) item ).value ); + + case STRING_ITEM: + return 1; // 1.1 > 1-sp + + case LIST_ITEM: + return 1; // 1.1 > 1-1 + + default: + throw new IllegalStateException( "invalid item: " + item.getClass() ); + } + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + BigIntegerItem that = (BigIntegerItem) o; + + return value.equals( that.value ); + + } + + @Override + public int hashCode() + { + return value.hashCode(); + } + + public String toString() + { + return value.toString(); + } + } + + /** + * Represents a string in the version item list, usually a qualifier. + */ + private static class StringItem + implements Item + { + private static final List QUALIFIERS = + Arrays.asList( "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" ); + + private static final Properties ALIASES = new Properties(); + static + { + ALIASES.put( "ga", "" ); + ALIASES.put( "final", "" ); + ALIASES.put( "release", "" ); + ALIASES.put( "cr", "rc" ); + } + + /** + * A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes + * the version older than one without a qualifier, or more recent. + */ + private static final String RELEASE_VERSION_INDEX = String.valueOf( QUALIFIERS.indexOf( "" ) ); + + private final String value; + + StringItem( String value, boolean followedByDigit ) + { + if ( followedByDigit && value.length() == 1 ) + { + // a1 = alpha-1, b1 = beta-1, m1 = milestone-1 + switch ( value.charAt( 0 ) ) + { + case 'a': + value = "alpha"; + break; + case 'b': + value = "beta"; + break; + case 'm': + value = "milestone"; + break; + default: + } + } + this.value = ALIASES.getProperty( value , value ); + } + + @Override + public int getType() + { + return STRING_ITEM; + } + + @Override + public boolean isNull() + { + return ( comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ) == 0 ); + } + + /** + * Returns a comparable value for a qualifier. + * + * This method takes into account the ordering of known qualifiers then unknown qualifiers with lexical + * ordering. + * + * just returning an Integer with the index here is faster, but requires a lot of if/then/else to check for -1 + * or QUALIFIERS.size and then resort to lexical ordering. Most comparisons are decided by the first character, + * so this is still fast. If more characters are needed then it requires a lexical sort anyway. + * + * @param qualifier + * @return an equivalent value that can be used with lexical comparison + */ + public static String comparableQualifier( String qualifier ) + { + int i = QUALIFIERS.indexOf( qualifier ); + + return i == -1 ? ( QUALIFIERS.size() + "-" + qualifier ) : String.valueOf( i ); + } + + @Override + public int compareTo( Item item ) + { + if ( item == null ) + { + // 1-rc < 1, 1-ga > 1 + return comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ); + } + switch ( item.getType() ) + { + case INT_ITEM: + case LONG_ITEM: + case BIGINTEGER_ITEM: + return -1; // 1.any < 1.1 ? + + case STRING_ITEM: + return comparableQualifier( value ).compareTo( comparableQualifier( ( (StringItem) item ).value ) ); + + case LIST_ITEM: + return -1; // 1.any < 1-1 + + default: + throw new IllegalStateException( "invalid item: " + item.getClass() ); + } + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + StringItem that = (StringItem) o; + + return value.equals( that.value ); + + } + + @Override + public int hashCode() + { + return value.hashCode(); + } + + public String toString() + { + return value; + } + } + + /** + * Represents a version list item. This class is used both for the global item list and for sub-lists (which start + * with '-(number)' in the version specification). + */ + private static class ListItem + extends ArrayList + implements Item + { + @Override + public int getType() + { + return LIST_ITEM; + } + + @Override + public boolean isNull() + { + return ( size() == 0 ); + } + + void normalize() + { + for ( int i = size() - 1; i >= 0; i-- ) + { + Item lastItem = get( i ); + + if ( lastItem.isNull() ) + { + // remove null trailing items: 0, "", empty list + remove( i ); + } + else if ( !( lastItem instanceof ListItem ) ) + { + break; + } + } + } + + @Override + public int compareTo( Item item ) + { + if ( item == null ) + { + if ( size() == 0 ) + { + return 0; // 1-0 = 1- (normalize) = 1 + } + // Compare the entire list of items with null - not just the first one, MNG-6964 + for ( Item i : this ) + { + int result = i.compareTo( null ); + if ( result != 0 ) + { + return result; + } + } + return 0; + } + switch ( item.getType() ) + { + case INT_ITEM: + case LONG_ITEM: + case BIGINTEGER_ITEM: + return -1; // 1-1 < 1.0.x + + case STRING_ITEM: + return 1; // 1-1 > 1-sp + + case LIST_ITEM: + Iterator left = iterator(); + Iterator right = ( (ListItem) item ).iterator(); + + while ( left.hasNext() || right.hasNext() ) + { + Item l = left.hasNext() ? left.next() : null; + Item r = right.hasNext() ? right.next() : null; + + // if this is shorter, then invert the compare and mul with -1 + int result = l == null ? ( r == null ? 0 : -1 * r.compareTo( l ) ) : l.compareTo( r ); + + if ( result != 0 ) + { + return result; + } + } + + return 0; + + default: + throw new IllegalStateException( "invalid item: " + item.getClass() ); + } + } + + @Override + public String toString() + { + StringBuilder buffer = new StringBuilder(); + for ( Item item : this ) + { + if ( buffer.length() > 0 ) + { + buffer.append( ( item instanceof ListItem ) ? '-' : '.' ); + } + buffer.append( item ); + } + return buffer.toString(); + } + + /** + * Return the contents in the same format that is used when you call toString() on a List. + */ + private String toListString() + { + StringBuilder buffer = new StringBuilder(); + buffer.append( "[" ); + for ( Item item : this ) + { + if ( buffer.length() > 1 ) + { + buffer.append( ", " ); + } + if ( item instanceof ListItem ) + { + buffer.append( ( (ListItem ) item ).toListString() ); + } + else + { + buffer.append( item ); + } + } + buffer.append( "]" ); + return buffer.toString(); + } + } + + public ComparableVersion( String version ) + { + parseVersion( version ); + } + + @SuppressWarnings( "checkstyle:innerassignment" ) + public final void parseVersion( String version ) + { + this.value = version; + + items = new ListItem(); + + version = version.toLowerCase( Locale.ENGLISH ); + + ListItem list = items; + + Deque stack = new ArrayDeque<>(); + stack.push( list ); + + boolean isDigit = false; + + int startIndex = 0; + + for ( int i = 0; i < version.length(); i++ ) + { + char c = version.charAt( i ); + + if ( c == '.' ) + { + if ( i == startIndex ) + { + list.add( IntItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + } + else if ( c == '-' ) + { + if ( i == startIndex ) + { + list.add( IntItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + + list.add( list = new ListItem() ); + stack.push( list ); + } + else if ( Character.isDigit( c ) ) + { + if ( !isDigit && i > startIndex ) + { + list.add( new StringItem( version.substring( startIndex, i ), true ) ); + startIndex = i; + + list.add( list = new ListItem() ); + stack.push( list ); + } + + isDigit = true; + } + else + { + if ( isDigit && i > startIndex ) + { + list.add( parseItem( true, version.substring( startIndex, i ) ) ); + startIndex = i; + + list.add( list = new ListItem() ); + stack.push( list ); + } + + isDigit = false; + } + } + + if ( version.length() > startIndex ) + { + list.add( parseItem( isDigit, version.substring( startIndex ) ) ); + } + + while ( !stack.isEmpty() ) + { + list = (ListItem) stack.pop(); + list.normalize(); + } + } + + private static Item parseItem( boolean isDigit, String buf ) + { + if ( isDigit ) + { + buf = stripLeadingZeroes( buf ); + if ( buf.length() <= MAX_INTITEM_LENGTH ) + { + // lower than 2^31 + return new IntItem( buf ); + } + else if ( buf.length() <= MAX_LONGITEM_LENGTH ) + { + // lower than 2^63 + return new LongItem( buf ); + } + return new BigIntegerItem( buf ); + } + return new StringItem( buf, false ); + } + + private static String stripLeadingZeroes( String buf ) + { + if ( buf == null || buf.isEmpty() ) + { + return "0"; + } + for ( int i = 0; i < buf.length(); ++i ) + { + char c = buf.charAt( i ); + if ( c != '0' ) + { + return buf.substring( i ); + } + } + return buf; + } + + @Override + public int compareTo( ComparableVersion o ) + { + return items.compareTo( o.items ); + } + + @Override + public String toString() + { + return value; + } + + public String getCanonical() + { + if ( canonical == null ) + { + canonical = items.toString(); + } + return canonical; + } + + @Override + public boolean equals( Object o ) + { + return ( o instanceof ComparableVersion ) && items.equals( ( (ComparableVersion) o ).items ); + } + + @Override + public int hashCode() + { + return items.hashCode(); + } + + // CHECKSTYLE_OFF: LineLength + /** + * Main to test version parsing and comparison. + *

+ * To check how "1.2.7" compares to "1.2-SNAPSHOT", for example, you can issue + *

java -jar ${maven.repo.local}/org/apache/maven/maven-artifact/${maven.version}/maven-artifact-${maven.version}.jar "1.2.7" "1.2-SNAPSHOT"
+ * command to command line. Result of given command will be something like this: + *
+     * Display parameters as parsed by Maven (in canonical form) and comparison result:
+     * 1. 1.2.7 == 1.2.7
+     *    1.2.7 > 1.2-SNAPSHOT
+     * 2. 1.2-SNAPSHOT == 1.2-snapshot
+     * 
+ * + * @param args the version strings to parse and compare. You can pass arbitrary number of version strings and always + * two adjacent will be compared + */ + // CHECKSTYLE_ON: LineLength + public static void main( String... args ) + { + System.out.println( "Display parameters as parsed by Maven (in canonical form and as a list of tokens) and" + + " comparison result:" ); + if ( args.length == 0 ) + { + return; + } + + ComparableVersion prev = null; + int i = 1; + for ( String version : args ) + { + ComparableVersion c = new ComparableVersion( version ); + + if ( prev != null ) + { + int compare = prev.compareTo( c ); + System.out.println( " " + prev.toString() + ' ' + + ( ( compare == 0 ) ? "==" : ( ( compare < 0 ) ? "<" : ">" ) ) + ' ' + version ); + } + + System.out.println( ( i++ ) + ". " + version + " -> " + c.getCanonical() + + "; tokens: " + c.items.toListString() ); + + prev = c; + } + } +} + diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Context.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Context.java new file mode 100644 index 0000000..b0e7feb --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Context.java @@ -0,0 +1,17 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class Context { + public static final String ID="id"; + public static final String NAME = "name"; + + + private String id; + private String name; +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/LifecycleInformation.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/LifecycleInformation.java new file mode 100644 index 0000000..d6fc700 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/LifecycleInformation.java @@ -0,0 +1,31 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class LifecycleInformation { + + public static final String PHASE="phase"; + public static final String LAST_OPERATION_STATUS="lastOperationStatus"; + public static final String ERROR_MESSAGES="errorMessages"; + public static final String WARNING_MESSAGES="warningMEssages"; + public static final String CHILDREN="children"; + + public static enum Status{ + PASSED,ERROR,WARNING + } + + + private String phase; + private Status lastOperationStatus; + private List errorMessages; + private List warningMessages; + private List children; + +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/ProfiledDocument.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/ProfiledDocument.java new file mode 100644 index 0000000..3a081d9 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/ProfiledDocument.java @@ -0,0 +1,52 @@ +package org.gcube.application.geoportal.common.model.document; + +import com.mongodb.client.model.geojson.GeoJsonObjectType; +import lombok.*; +import org.bson.Document; + + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class ProfiledDocument { + + public static final String _ID="_id"; + public static final String VERSION="version"; + public static final String INFO="info"; + public static final String PROFILE_ID="profileID"; + public static final String PROFILE_VERSION="profileVersion"; + public static final String LIFECYCLE_INFORMATION="lifecycleInformation"; + public static final String RELATIONSHIPS="relationships"; + public static final String SPATIAL_REFERENCE="spatialReference"; + public static final String TEMPORAL_REFERENCE="temporalReference"; + public static final String THE_DOCUMENT="theDocument"; + + // CORE METADATA + + private String _id; + private ComparableVersion version; + + // Publication Info + private PublicationInfo info; + + // Profile reference + private String profileID; + private ComparableVersion profileVersion; + + private LifecycleInformation lifecycleInformation; + + private Relationship[] relationships; + + private GeoJsonObjectType spatialReference; + + private TemporalReference temporalReference; + + private Document theDocument; + + public void setDefaults(){ + // TODO APPLY DEFAULTS ?? + + }; +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/PublicationInfo.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/PublicationInfo.java new file mode 100644 index 0000000..c48add5 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/PublicationInfo.java @@ -0,0 +1,23 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; +import org.gcube.application.geoportal.common.model.legacy.AccessPolicy; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class PublicationInfo { + + public static final String CREATION_INFO="creationInfo"; + public static final String LAST_EDIT_INFO="lastEditInfo"; + public static final String ACCESS = "access"; + + + private AccountingInfo creationInfo; + private AccountingInfo lastEditInfo; + private Access access; + + +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/RegisteredFile.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/RegisteredFile.java new file mode 100644 index 0000000..1844eca --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/RegisteredFile.java @@ -0,0 +1,21 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class RegisteredFile { + + public static String MIMETYPE="mimetype"; + public static String STORAGE_ID="storageID"; + public static String LINK="link"; + public static String NAME="NAME"; + + private String mimetype; + private String storageID; + private String link; + private String name; +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/RegisteredFileSet.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/RegisteredFileSet.java new file mode 100644 index 0000000..376999d --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/RegisteredFileSet.java @@ -0,0 +1,25 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; +import org.bson.Document; + +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class RegisteredFileSet { + + public static final String CREATION_INFO="creationInfo"; + public static final String ACCESS="access"; + public static final String FOLDER_ID="folderID"; + public static final String PAYLOADS="payloads"; + + private AccountingInfo creationInfo; + private Access access; + private String folderID; + + private List payloads; +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Relationship.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Relationship.java new file mode 100644 index 0000000..caa0c93 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Relationship.java @@ -0,0 +1,18 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class Relationship { + + public static final String RELATIONSHIP_NAME="relationshipName"; + public static final String TARGET_ID="targetID"; + + private String relationshipName; + private String targetID; + +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/TemporalReference.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/TemporalReference.java new file mode 100644 index 0000000..889db6e --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/TemporalReference.java @@ -0,0 +1,13 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class TemporalReference { + + private String field; +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/User.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/User.java new file mode 100644 index 0000000..fda76a3 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/User.java @@ -0,0 +1,17 @@ +package org.gcube.application.geoportal.common.model.document; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class User { + + public static final String USERNAME="username"; + + + private String username; + +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/Concessione.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/Concessione.java index 0a67088..45c97b7 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/Concessione.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/Concessione.java @@ -218,7 +218,7 @@ public class Concessione extends Record{ validator.setObjectName("Concessione"); - setPolicy(AccessPolicy.OPEN); + // setPolicy(AccessPolicy.OPEN); @@ -258,18 +258,6 @@ public class Concessione extends Record{ validator.addChild(abstractRelazione.validateForInsertion()); } -// if(immaginiRappresentative!=null) -// -// for(UploadedImage img : immaginiRappresentative) { -// validator.setDefault(img.getSoggetto(),getSoggetto()); -// validator.setDefault(img.getCreationTime(),getCreationTime()); -// validator.setDefault(img.getPolicy(), getPolicy()); -// validator.setDefault(img.getLicenzaID(), getLicenzaID()); -// -// validator.addChild(img.validateForInsertion()); -// } -// - if(validator.checkMandatory(posizionamentoScavo, "Posizionamento scavo")) { ValidationReport posReport=posizionamentoScavo.validateForInsertion(); @@ -282,15 +270,11 @@ public class Concessione extends Record{ for(OtherContent content:genericContent) validator.addChild(content.validateForInsertion()); - if(validator.checkMandatory(pianteFineScavo,"Piante fine scavo")) + if(pianteFineScavo!=null) for(LayerConcessione l:pianteFineScavo) { validator.addChild(l.validateForInsertion()); } - - - - - + return validator; } @@ -317,15 +301,15 @@ public class Concessione extends Record{ relazioneScavo.setTitolo(ConstraintCheck.defaultFor(relazioneScavo.getTitolo(),getNome()+" relazione di scavo").evaluate()); relazioneScavo.setSoggetto(ConstraintCheck.defaultFor(relazioneScavo.getSoggetto(),getSoggetto()).evaluate()); relazioneScavo.setCreationTime(ConstraintCheck.defaultFor(relazioneScavo.getCreationTime(),getCreationTime()).evaluate()); - relazioneScavo.setLicenseID(ConstraintCheck.defaultFor(getLicenzaID(), "CC-BY-4.0").evaluate()); - relazioneScavo.setPolicy(getPolicy()); + relazioneScavo.setLicenseID(ConstraintCheck.defaultFor(relazioneScavo.getLicenseID(), "CC-BY-4.0").evaluate()); + relazioneScavo.setPolicy(ConstraintCheck.defaultFor(relazioneScavo.getPolicy(),AccessPolicy.OPEN).evaluate()); if(abstractRelazione == null) abstractRelazione = new AbstractRelazione(); abstractRelazione.setTitolo(ConstraintCheck.defaultFor(abstractRelazione.getTitolo(),getNome()+" abstract relazione di scavo").evaluate()); abstractRelazione.setCreationTime(ConstraintCheck.defaultFor(abstractRelazione.getCreationTime(),getCreationTime()).evaluate()); - abstractRelazione.setLicenseID(ConstraintCheck.defaultFor(getLicenzaID(), "CC-BY-4.0").evaluate()); - abstractRelazione.setPolicy(getPolicy()); + abstractRelazione.setLicenseID(ConstraintCheck.defaultFor(abstractRelazione.getLicenseID(), "CC-BY-4.0").evaluate()); + abstractRelazione.setPolicy(ConstraintCheck.defaultFor(abstractRelazione.getPolicy(),AccessPolicy.OPEN).evaluate()); if(immaginiRappresentative!=null) diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/report/ConstraintCheck.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/report/ConstraintCheck.java index 558d108..211c73e 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/report/ConstraintCheck.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/legacy/report/ConstraintCheck.java @@ -7,9 +7,11 @@ import java.util.List; import lombok.Getter; import lombok.Setter; +import lombok.extern.slf4j.Slf4j; @Getter @Setter +@Slf4j public class ConstraintCheck { public static ConstraintCheck defaultFor(T toCheck,T defaultValue){ @@ -55,6 +57,8 @@ public class ConstraintCheck { T result=theObject; if(isError()) { result=theDefault; + log.debug("Applying default {} for current value {}",theDefault,theObject); + if(theDefault!=null && theDefault instanceof Collection) { Collection defaultCollection=(Collection) theDefault; ArrayList target=new ArrayList(defaultCollection); diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/DefaultCompiler.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/DefaultCompiler.java deleted file mode 100644 index 019f08a..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/DefaultCompiler.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.gcube.application.geoportal.common.model.profile; - -public class DefaultCompiler { - - - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Field.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Field.java deleted file mode 100644 index dd59a37..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Field.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.gcube.application.geoportal.common.model.profile; - -import lombok.Getter; - -@Getter -public class Field { - - - - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/FieldMapping.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/FieldMapping.java deleted file mode 100644 index be913ee..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/FieldMapping.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.gcube.application.geoportal.common.model.profile; - -public class FieldMapping { - - - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/HandlerDeclaration.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/HandlerDeclaration.java new file mode 100644 index 0000000..3f70dae --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/HandlerDeclaration.java @@ -0,0 +1,12 @@ +package org.gcube.application.geoportal.common.model.profile; + +import lombok.Data; +import org.bson.Document; + +@Data +public class HandlerDeclaration { + + private String id; + private String type; + private Document configuration; +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/IndexDefinition.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/IndexDefinition.java deleted file mode 100644 index 67ee4dd..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/IndexDefinition.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.gcube.application.geoportal.common.model.profile; - -public class IndexDefinition { - - - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/IsoMapper.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/IsoMapper.java deleted file mode 100644 index 1cbd4b8..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/IsoMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.gcube.application.geoportal.common.model.profile; - -public class IsoMapper { - - private String className; - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Profile.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Profile.java index 258c5ab..c1f96bb 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Profile.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Profile.java @@ -1,24 +1,46 @@ package org.gcube.application.geoportal.common.model.profile; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlRootElement; +import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; +import org.bson.Document; +import org.gcube.application.geoportal.common.model.document.AccountingInfo; +import org.gcube.application.geoportal.common.model.document.ComparableVersion; -@Getter +@Data @NoArgsConstructor @XmlRootElement public class Profile{ - private String name; private String id; - private List fields; - - private List defaultCompilers; - private List validators; - private IsoMapper isoMapper; - private List centroidsMapping; - private List indexes; + private ComparableVersion version; + + private String name; + private String description; + private AccountingInfo creationInfo; + + private Document schema; + + private List handlers; + + /** + * Returns map Type -> Handler Declaration + * @return + */ + public Map> getHandlersMap(){ + HashMap> toReturn=new HashMap<>(); + handlers.forEach(h->{ + if(!toReturn.containsKey(h.getType())) + toReturn.put(h.getType(),new ArrayList<>()); + toReturn.get(h.getType()).add(h); + }); + return toReturn; + } } diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Validator.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Validator.java deleted file mode 100644 index d161f5d..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Validator.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.gcube.application.geoportal.common.model.profile; - -public class Validator { - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Centroid.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Centroid.java deleted file mode 100644 index ee752e9..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Centroid.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.gcube.application.geoportal.common.model.project; - -public class Centroid { - - private Double x; - private Double y; - private Double z; - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Project.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Project.java deleted file mode 100644 index c1801f8..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Project.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.gcube.application.geoportal.common.model.project; - -import org.gcube.application.geoportal.common.model.BasicJSONObject; - -import lombok.NoArgsConstructor; - -@NoArgsConstructor -public class Project { - - -/** - * Project{ - _id: - profile_id: - publication :{ - creation_time: - creation_user: - last_update_time: - last_update_user: - version : - license : - policy : - status : VALID, - PUBLISHED,INVALID - document : {.....} - centroid : { - x: - y: - z:} - } - - * - */ - - private String _id; - private String profile_id; - private Status status; - private Object document; - private Centroid centroid; - private PublicationDetails publication; - - private String json; -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/PublicationDetails.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/PublicationDetails.java deleted file mode 100644 index 3656a12..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/PublicationDetails.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.gcube.application.geoportal.common.model.project; - -import java.time.LocalDateTime; - -import lombok.Data; - -@Data -public class PublicationDetails { - - public static enum Policy{ - OPEN,RESTRICTED,EMBARGOED; - } - - private LocalDateTime creation_time; - private String creation_user; - private LocalDateTime last_update_time; - private String last_update_user; - private String version; - private String license; - private String policy; - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Status.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Status.java deleted file mode 100644 index 0783b0a..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/Status.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.gcube.application.geoportal.common.model.project; - -import java.util.List; - -public class Status { - - - private StatusPhase phase; - private List messages; - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/StatusPhase.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/StatusPhase.java deleted file mode 100644 index 522532c..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/StatusPhase.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.gcube.application.geoportal.common.model.project; - -public enum StatusPhase { - - DRAFT, - UNDER_VALIDATION, - INVALID, - VALID, - UNDER_PUBLICATION, - PUBLICATION_ERROR, - PUBLISHED - -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/StoredFile.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/StoredFile.java deleted file mode 100644 index 1309362..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/project/StoredFile.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.gcube.application.geoportal.common.model.project; - - - diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java index 3ed42f4..1dac42a 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java @@ -13,6 +13,7 @@ public class InterfaceConstants { public static final String PROFILES="profiles"; public static final String SECTIONS="sections"; public static final String PROJECTS="projects"; + public static final String CONCESSIONI="concessioni"; public static final String MONGO_CONCESSIONI="mongo-concessioni"; diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/ProfiledDocumentsI.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/ProfiledDocumentsI.java new file mode 100644 index 0000000..c7aaabd --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/ProfiledDocumentsI.java @@ -0,0 +1,28 @@ +package org.gcube.application.geoportal.common.rest; + +import org.bson.Document; +import org.gcube.application.geoportal.common.model.document.ProfiledDocument; +import org.gcube.application.geoportal.common.model.rest.Configuration; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; + +import java.rmi.RemoteException; +import java.util.Iterator; + +public interface ProfiledDocumentsI

{ + + // CRUD + public P createNew(Document toCreate)throws RemoteException; + public void deleteById(String id) throws RemoteException; + public void deleteById(String id,Boolean force) throws RemoteException; + public P getById(String id) throws RemoteException; + + // CONFIG + public Configuration getConfiguration() throws RemoteException; + + // QUERY + public Iterator

query (QueryRequest request) throws RemoteException; + public String querForJSON(QueryRequest request)throws RemoteException; + + //Execution + public P performStep(String id, String step, Document request); +} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/ProjectsI.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/ProjectsI.java deleted file mode 100644 index 6ff8a00..0000000 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/ProjectsI.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.gcube.application.geoportal.common.rest; - -import org.gcube.application.geoportal.common.model.project.Project; - -import java.util.Iterator; - -public interface ProjectsI { - - - public Iterator getAll() throws Exception; - public Iterator getByProfile(String profileId) throws Exception; - public Project getById(String profileId,String id) throws Exception; - public Iterator getByFilter(String filter)throws Exception; - public Iterator getByFilter(String filter, String profileId)throws Exception; - public Project registrNew(String profileId, String jsonDocument)throws Exception; - public Project update(String profileId, String projectId,String jsonDocument) throws Exception; - public void deleteById(String profileId, String projectId)throws Exception; - public void deleteById(String profileId, String projectId, Boolean force)throws Exception; -} diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/Files.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/Files.java index 1bb66bd..fc04d6b 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/Files.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/Files.java @@ -85,6 +85,8 @@ public class Files { } public static String fixFilename(String toFix) { + if(toFix.startsWith("\\.")) + toFix=toFix.replaceFirst("\\.","_"); String extension=""; if(toFix.contains(".")) { //preserve extension diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/JSONPathWrapper.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/JSONPathWrapper.java new file mode 100644 index 0000000..3b0cfdf --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/JSONPathWrapper.java @@ -0,0 +1,34 @@ +package org.gcube.application.geoportal.common.utils; + +import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.Option; +import lombok.Getter; + +import java.util.List; + +public class JSONPathWrapper { + + public static Configuration JSON_PATH_ALWAYS_LIST_CONFIG=null; + public static Configuration JSON_PATH_PATHS_CONFIGURATION=null; + + static { + JSON_PATH_ALWAYS_LIST_CONFIG= Configuration.builder().options(Option.ALWAYS_RETURN_LIST,Option.SUPPRESS_EXCEPTIONS,Option.DEFAULT_PATH_LEAF_TO_NULL).build(); + JSON_PATH_PATHS_CONFIGURATION = Configuration.builder().options(Option.AS_PATH_LIST,Option.SUPPRESS_EXCEPTIONS,Option.DEFAULT_PATH_LEAF_TO_NULL).build(); + } + + + @Getter + DocumentContext ctx=null; + + public JSONPathWrapper(String json) { + ctx=JsonPath.using(JSON_PATH_ALWAYS_LIST_CONFIG).parse(json); + } + + public List getByPath(String path){ + throw new RuntimeException("TO IMPLEMENT"); + } + + +} diff --git a/geoportal-common/src/test/java/org/gcube/application/geoportal/common/legacy/DefaultsTests.java b/geoportal-common/src/test/java/org/gcube/application/geoportal/common/legacy/DefaultsTests.java new file mode 100644 index 0000000..61549c1 --- /dev/null +++ b/geoportal-common/src/test/java/org/gcube/application/geoportal/common/legacy/DefaultsTests.java @@ -0,0 +1,43 @@ +package org.gcube.application.geoportal.common.legacy; + +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.legacy.RelazioneScavo; +import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck; +import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class DefaultsTests { + + @Test + public void checkConstraints(){ + assertEquals(AccessPolicy.OPEN,ConstraintCheck.defaultFor(null,AccessPolicy.OPEN).evaluate()); + assertEquals(AccessPolicy.EMBARGOED,ConstraintCheck.defaultFor(AccessPolicy.EMBARGOED,AccessPolicy.OPEN).evaluate()); + } + + + @Test + public void checkDefaults(){ + + Concessione c= new Concessione(); + + c.setDefaults(); + c.validate(); + System.out.println(c.getReport()); + // Mandatory fields without defaults + assertEquals(ValidationReport.ValidationStatus.ERROR,c.getReport().getStatus()); + + c=new Concessione(); + c.setRelazioneScavo(new RelazioneScavo()); + c.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED); + c.setPolicy(AccessPolicy.OPEN); + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); + c.setDefaults(); + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); + } + + + +} diff --git a/geoportal-service/CHANGELOG.md b/geoportal-service/CHANGELOG.md index b09f888..d89cf4e 100644 --- a/geoportal-service/CHANGELOG.md +++ b/geoportal-service/CHANGELOG.md @@ -2,36 +2,40 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for org.gcube.application.geoportal-service +## [v1.0.8] 2021-09-20 +- Logging +- Fixes [#22193](https://support.d4science.org/issues/22193) +- Fixes [#22280](https://support.d4science.org/issues/22280) +- Fixes [#20755](https://support.d4science.org/issues/20755) +- Profiled Documents + + ## [v1.0.6] 2021-09-20 -Refactored repositories -Fixes #22193 -Fixes #22217 +- Refactored repositories +- Fixes #22193 +- Fixes #22217 ## [v1.0.5-SNAPSHOT] 2021-07-23 -Upgrade to gcube-smartgears-bom 2.1.0 -Fix register postgis table layer -Added PostgisIndexRecordManager +- Upgrade to gcube-smartgears-bom 2.1.0 +- Fix register postgis table layer +- Added PostgisIndexRecordManager ## [v1.0.4] 2020-11-11 -Mongo integration with Concessione -Project interface -TempFile management -WorkspaceContent and publication for Concessioni-over-mongo +- Mongo integration with Concessione +- Project interface +- TempFile management +- WorkspaceContent and publication for Concessioni-over-mongo ## [v1.0.3] 2020-11-11 -Fixed HTTP method +- Fixed HTTP method ## [v1.0.2] 2020-11-11 -Delete method -Excluded upper bound release gCube 5 +- Delete method +- Excluded upper bound release gCube 5 ## [v1.0.1] 2020-11-11 - -Project interface +- Project interface ## [v1.0.0] 2020-11-11 - -First release - - +- First release \ No newline at end of file diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index 4c95743..b837b74 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -4,14 +4,14 @@ 4.0.0 org.gcube.application geoportal-service - 1.0.6 + 1.0.8 Geoportal Service war org.gcube.application.cms gcube-cms-suite - 1.0.0 + 1.0.1 @@ -83,10 +83,15 @@ - org.gcube.application + org.gcube.application.cms geoportal-common + + org.gcube.application.cms + cms-plugin-framework + + @@ -185,6 +190,11 @@ jackson-datatype-jsr310 + + org.reflections + reflections + + org.gcube.contentmanagement @@ -203,6 +213,12 @@ test + + org.gcube.application.cms + concessioni-lifecycle + test + + junit junit diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index 7fb5902..d06a0f5 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -3,8 +3,9 @@ package org.gcube.application.geoportal.service; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.service.rest.ConcessioniOverMongo; -import org.gcube.application.geoportal.service.rest.Profiles; -import org.gcube.application.geoportal.service.rest.Projects; + + +import org.gcube.application.geoportal.service.rest.ProfiledDocuments; import org.gcube.application.geoportal.service.rest.Sections; import org.gcube.application.geoportal.service.utils.Serialization; import org.glassfish.jersey.server.ResourceConfig; @@ -21,9 +22,9 @@ public class GeoPortalService extends ResourceConfig{ //Register interrfaces // registerClasses(Concessioni.class); registerClasses(ConcessioniOverMongo.class); - registerClasses(Projects.class); + registerClasses(ProfiledDocuments.class); registerClasses(Sections.class); - registerClasses(Profiles.class); + diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/ImplementationProvider.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/ImplementationProvider.java index 3f62f97..1494cd9 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/ImplementationProvider.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/ImplementationProvider.java @@ -6,6 +6,7 @@ package org.gcube.application.geoportal.service.engine; import lombok.Getter; import lombok.Setter; import lombok.Synchronized; +import org.gcube.application.cms.plugins.Plugin; import org.gcube.application.geoportal.service.engine.providers.*; public class ImplementationProvider { @@ -38,25 +39,29 @@ public class ImplementationProvider { @Setter private ISProvider isProvider=new ISProvider(); -// @Getter -// @Setter -// private EMFProvider emfProvider=new ScopedEMFProvider(); - + @Getter + @Setter + private ProfileMapCache profiles=new ProfileMapCache(); + + @Getter + @Setter + private PluginManager pluginManager=new PluginManager(); @Getter @Setter private StorageHubProvider sHubProvider=new StorageHubProvider(); - public void shutdown() { - // Stop JPA -// AbstractRecordManager.shutdown(); - - mongoClientProvider.shutdown(); - } - - public void startup() { -// AbstractRecordManager.setDefaultProvider(emfProvider); - - mongoClientProvider.init(); - } +// public void shutdown() { +// // Stop JPA +//// AbstractRecordManager.shutdown(); +// +// mongoClientProvider.shutdown(); +// pluginManager.shutdown(); +// } +// +// public void startup() { +//// AbstractRecordManager.setDefaultProvider(emfProvider); +// pluginManager.init(); +// mongoClientProvider.init(); +// } } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/handlers/SimpleLifeCycleManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/handlers/SimpleLifeCycleManager.java new file mode 100644 index 0000000..689bd5b --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/handlers/SimpleLifeCycleManager.java @@ -0,0 +1,77 @@ +package org.gcube.application.geoportal.service.engine.handlers; + +import com.google.protobuf.DescriptorProtos; +import lombok.extern.slf4j.Slf4j; +import org.gcube.application.cms.plugins.LifecycleManager; +import org.gcube.application.cms.plugins.faults.InitializationException; +import org.gcube.application.cms.plugins.faults.ShutDownException; +import org.gcube.application.cms.plugins.faults.StepException; +import org.gcube.application.cms.plugins.model.PluginDescriptor; +import org.gcube.application.cms.plugins.reports.ExecutionReport; +import org.gcube.application.cms.plugins.reports.InitializationReport; +import org.gcube.application.cms.plugins.requests.StepExecutionRequest; +import org.gcube.application.geoportal.common.model.document.ComparableVersion; + +@Slf4j +public class SimpleLifeCycleManager implements LifecycleManager { + + + private static final PluginDescriptor DESCRIPTOR=new PluginDescriptor("SIMPLE-LIFECYCLE", "Simple Lifecycle manager"); + static { + DESCRIPTOR.setDescription("Simple Lifecycle Management. This plugin supports a simple publication lifecycle."); + DESCRIPTOR.setVersion(new ComparableVersion("1.0.0")); + } + + @Override + public InitializationReport initInContext() throws InitializationException { + return null; + } + + @Override + public InitializationReport init() throws InitializationException { + return null; + } + + @Override + public void shutdown() throws ShutDownException { + + } + + @Override + public ExecutionReport performStep(StepExecutionRequest request) throws StepException { + log.info("Received Request "); + + switch(request.getStep()){ + case StepExecutionRequest.Steps.ON_INIT_DOCUMENT:{ + break; + } + case StepExecutionRequest.Steps.ON_MATERIALIZE_DOCUMENT:{ + break; + } + case StepExecutionRequest.Steps.ON_DEMATERIALIZE_DOCUMENT:{ + break; + } + case StepExecutionRequest.Steps.ON_DEINDEX_DOCUMENT:{ + break; + } + case StepExecutionRequest.Steps.ON_INDEX_DOCUMENT:{ + break; + } + case StepExecutionRequest.Steps.ON_DELETE_DOCUMENT:{ + break; + } + default : throw new StepException("Invalid Step "+request.getStep()); + } + + + throw new StepException("Still to implement"); + } + + + + + @Override + public PluginDescriptor getDescriptor() { + return null; + } +} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/materialization/SDIManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/materialization/SDIManager.java index 0cdbed6..1691198 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/materialization/SDIManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/materialization/SDIManager.java @@ -67,7 +67,7 @@ public class SDIManager { geoserverHostName=new URL(currentGeoserver.getUrl()).getHost(); log.debug("Contacting Data Transfer from geoserver {} ",geoserverHostName); - dtGeoServer=DataTransferClient.getInstanceByEndpoint("http://"+geoserverHostName); + dtGeoServer=DataTransferClient.getInstanceByEndpoint("https://"+geoserverHostName); if(!currentGeoserver.getReader().existGeoserver()) throw new Exception("Geoserver not reachable"); }catch(Exception e) { @@ -222,7 +222,7 @@ public class SDIManager { RESTLayer l=gsReader.getLayer(workspace, toSetLayerName); RESTFeatureType f= gsReader.getFeatureType(l); - /*http://geoserver1.dev.d4science.org/geoserver/gna_conc_18/wms? + /*https://geoserver1.dev.d4science.org/geoserver/gna_conc_18/wms? service=WMS&version=1.1.0&request=GetMap&layers=gna_conc_18:pos& styles=&bbox=8.62091913167495,40.62975046683799,8.621178639172953,40.630257904721645& width=392&height=768&srs=EPSG:4326&format=application/openlayers */ diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java index 07e7c7e..fe9c811 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java @@ -24,6 +24,7 @@ import org.gcube.application.geoportal.service.engine.WorkspaceManager.FolderOpt import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex; import org.gcube.application.geoportal.service.model.internal.faults.*; import org.gcube.application.geoportal.service.utils.Serialization; +import org.gcube.application.geoportal.service.utils.UserUtils; import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.data.transfer.library.faults.RemoteServiceException; @@ -33,6 +34,7 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.sql.SQLException; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -48,7 +50,7 @@ public class ConcessioniMongoManager extends MongoManager{ super(); } private static final String collectionName="legacyConcessioni"; - private static final String DB_NAME="gna_dev"; + //private static final String DB_NAME="gna_dev"; private MongoDatabase db=null; @@ -78,34 +80,46 @@ public class ConcessioniMongoManager extends MongoManager{ } - // *** PUBLIC METHODS + + + + + /****************************** PUBLIC METHODS ***********************/ + + + public Concessione registerNew(Concessione toRegister) throws IOException { - log.trace("Registering {} ",toRegister); - toRegister.setDefaults(); + log.trace("Going to register {} ",toRegister); + toRegister=onUpdate(toRegister); + log.trace("Concessione with defaults is {}",toRegister); ObjectId id=insert(asDocument(toRegister), collectionName); + log.trace("Obtained id {}",id); Concessione toReturn=asConcessione(getById(id,collectionName)); toReturn.setMongo_id(asString(id)); - return asConcessione(replace(asDocument(toReturn),collectionName)); + + toReturn = asConcessione(replace(asDocument(toReturn),collectionName)); + log.debug("Registered {} ",toReturn); + return toReturn; } public Concessione replace(Concessione toRegister) throws IOException { log.trace("Replacing {} ",toRegister); - toRegister.setDefaults(); + toRegister=onUpdate(toRegister); return asConcessione(replace(asDocument(toRegister),collectionName)); } - public Concessione update(String id,String json) throws IOException { +/* public Concessione update(String id,String json) throws IOException { log.trace("Updating id {} with {} ",id,json); Concessione toReturn=asConcessione(update(asId(id),asDoc(json),collectionName)); log.debug("Refreshing defaults.."); toReturn.setDefaults(); return asConcessione(replace(asDocument(toReturn),collectionName)); } - +*/ public Iterable list(){ @@ -171,6 +185,7 @@ public class ConcessioniMongoManager extends MongoManager{ delete(asId(id), collectionName); }catch(DeletionException e) { //storing updated - partially deleted + concessione=onUpdate(concessione); replace(asDocument(concessione), collectionName); throw e; } @@ -188,15 +203,17 @@ public class ConcessioniMongoManager extends MongoManager{ log.debug("Removed from centroids "+toReturn.getMongo_id()); toReturn = unpublish(toReturn); log.debug("Concessione after unpublishing is "+toReturn); + toReturn = onUpdate(toReturn); + return asConcessione(replace(asDocument(toReturn),collectionName)); }catch(Throwable t){ throw new DeletionException("Unable to unpublish "+id,t); } } - public Concessione publish(String id) throws JsonProcessingException, IOException, InvalidStateException{ + public Concessione publish(String id) throws IOException{ Concessione toReturn=asConcessione(getById(asId(id),collectionName)); - toReturn.setDefaults(); + toReturn=onUpdate(toReturn); toReturn.validate(); // MATERIALIZE LAYERS @@ -211,35 +228,6 @@ public class ConcessioniMongoManager extends MongoManager{ } - - - private static Concessione removeContent(Concessione concessione) throws DeletionException { - if(concessione.getFolderId()==null) { - log.debug("No content for " + concessione.getMongo_id()); - return concessione; - } - try { - log.debug("Removing content for " + concessione.getMongo_id()); - WorkspaceManager manager = new WorkspaceManager(); - manager.removeFolderById(concessione.getFolderId()); - - //Removing references from Object - concessione.setFolderId(null); - ArrayList list = new ArrayList<>(); - list.add(concessione.getPosizionamentoScavo()); - list.addAll(concessione.getPianteFineScavo()); - list.addAll(concessione.getImmaginiRappresentative()); - list.addAll(concessione.getGenericContent()); - for (AssociatedContent c : list) { - c.getActualContent().clear(); - } - return concessione; - }catch(Throwable t){ - throw new DeletionException("Unable to delete from WS ",t); - } - - } - public Concessione unregisterFileset(String id, String toClearPath) throws Exception { log.info("Clearing Fileset at {} for {} ",toClearPath,id); try { @@ -258,8 +246,7 @@ public class ConcessioniMongoManager extends MongoManager{ } toClearContent.getActualContent().clear(); - log.debug("Updating dafults for {} ",c); - c.setDefaults(); + c=onUpdate(c); return asConcessione(replace(asDocument(c),collectionName)); }catch(Exception e) { @@ -288,14 +275,39 @@ public class ConcessioniMongoManager extends MongoManager{ AssociatedContent section=c.getContentByPath(destinationPath); log.debug("Found section {} for path {}",section,destinationPath); store(section,files,ws,storage,baseFolder); - log.debug("Updating dafults for {} ",c); - c.setDefaults(); + + c=onUpdate(c); return asConcessione(replace(asDocument(c),collectionName)); }catch(Exception e) { throw new Exception("Unable to save file.",e); } } + + /************************** STATIC ROUTINES *******************************/ + + + /** + Sets Accounting data and Defaults + */ + private static Concessione onUpdate(Concessione c){ + log.debug("Updating Account data for {} ",c); + + // SET ACCOUNTING + c.setLastUpdateTime(LocalDateTime.now()); + try{ + c.setLastUpdateUser(UserUtils.getCurrent().getUser().getId()); + }catch(Throwable t){ + log.warn("Unable to get User details ",t); + } + + log.debug("Updating defaults for {}",c); + // Set Defaults + c.setDefaults(); + return c; + } + + private static Concessione index(Concessione record) { log.info("Indexing {} ",record.getId()); ValidationReport report= new ValidationReport("Index Report "); @@ -400,6 +412,8 @@ public class ConcessioniMongoManager extends MongoManager{ ((LayerConcessione) c).setBbox(null); ((LayerConcessione) c).setWmsLink(null); ((LayerConcessione) c).setWorkspace(null); + ((LayerConcessione) c).setLayerName(null); + //Remove reference to removed content c.getActualContent().removeAll(toRemove); @@ -467,4 +481,31 @@ public class ConcessioniMongoManager extends MongoManager{ content.setMongo_id(asString(new ObjectId())); } + + private static Concessione removeContent(Concessione concessione) throws DeletionException { + if(concessione.getFolderId()==null) { + log.debug("No content for " + concessione.getMongo_id()); + return concessione; + } + try { + log.debug("Removing content for " + concessione.getMongo_id()); + WorkspaceManager manager = new WorkspaceManager(); + manager.removeFolderById(concessione.getFolderId()); + + //Removing references from Object + concessione.setFolderId(null); + ArrayList list = new ArrayList<>(); + list.add(concessione.getPosizionamentoScavo()); + list.addAll(concessione.getPianteFineScavo()); + list.addAll(concessione.getImmaginiRappresentative()); + list.addAll(concessione.getGenericContent()); + for (AssociatedContent c : list) { + c.getActualContent().clear(); + } + return concessione; + }catch(Throwable t){ + throw new DeletionException("Unable to delete from WS ",t); + } + + } } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java new file mode 100644 index 0000000..adb71f1 --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java @@ -0,0 +1,49 @@ +package org.gcube.application.geoportal.service.engine.mongo; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.bson.Document; +import org.gcube.application.cms.plugins.faults.StepException; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.service.model.internal.faults.DeletionException; + +import java.io.IOException; + +public interface MongoManagerI { + + + // create + + public T registerNew(Document toRegister) throws IOException, StepException; + + // update + public T update(String id,T toSet) throws IOException, StepException; + + // delete + + public void delete(String id,boolean force) throws DeletionException; + + // get By ID + + public T getByID(String id) throws IOException; + + // query + + public Iterable query(QueryRequest request); + public Iterable filter(QueryRequest request); + + // materialize + + public T materialize(String id); + + // dematerialize + + public T dematerialize(String id); + // index + + public T index(String id); + + // deIndex + public T deIndex(String id); + + public T performStep(String id, String step, Document options); +} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java index 55de3e1..df93e8b 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java @@ -1,5 +1,256 @@ package org.gcube.application.geoportal.service.engine.mongo; -public class ProfiledMongoManager { +import com.fasterxml.jackson.core.JsonProcessingException; +import com.mongodb.client.MongoDatabase; +import lombok.Synchronized; +import lombok.extern.slf4j.Slf4j; +import org.bson.Document; +import org.bson.types.ObjectId; +import org.gcube.application.cms.plugins.LifecycleManager; +import org.gcube.application.cms.plugins.faults.StepException; +import org.gcube.application.cms.plugins.model.PluginDescriptor; +import org.gcube.application.cms.plugins.reports.ExecutionReport; +import org.gcube.application.cms.plugins.requests.StepExecutionRequest; +import org.gcube.application.geoportal.common.model.document.*; +import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport; +import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration; +import org.gcube.application.geoportal.common.model.profile.Profile; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.service.engine.ImplementationProvider; +import org.gcube.application.geoportal.service.engine.providers.PluginManager; +import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; +import org.gcube.application.geoportal.service.model.internal.faults.DeletionException; +import org.gcube.application.geoportal.service.utils.Serialization; +import org.gcube.application.geoportal.service.utils.UserUtils; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.security.InvalidParameterException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.function.Consumer; + +import static org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager.asConcessione; + +@Slf4j +public class ProfiledMongoManager extends MongoManager implements MongoManagerI{ + + + Profile profile; + MongoDatabase db=null; + + LifecycleManager lfManager; + + + public ProfiledMongoManager(String profileId) throws ConfigurationException { + // Check Profile ID + log.info("Loading profile ID {} ",profileId); + if(profileId==null) throw new InvalidParameterException("Profile ID cannot be null"); + Map profiles=ImplementationProvider.get().getProfiles().getObject(); + if(!profiles.containsKey(profileId)) { + log.debug("Asked profile {} not found. Available ones are {} ",profileId,profiles.keySet()); + throw new WebApplicationException("Profile " + profileId + " not registered", Response.Status.NOT_FOUND); + } + profile=profiles.get(profileId); + log.debug("Loaded Profile {} ",profile); + + + + + //Getting Lifecycle Manager declaration from Profile + List handlerDeclarations= profile.getHandlersMap().get(PluginDescriptor.BaseTypes.LIFECYCLE_MANAGER); + if(handlerDeclarations==null || handlerDeclarations.isEmpty()) throw new ConfigurationException("No Lifecycle Handler defined for profile ID "+profileId); + if(handlerDeclarations.size()>1) throw new ConfigurationException("Too many Lifecycle Handlers defined ("+handlerDeclarations+") in profile ID "+profileId); + + HandlerDeclaration lcHandlerDeclaration=handlerDeclarations.get(0); + + // Loading Lifecycle Manager + log.debug("Looking for handler {} ",lcHandlerDeclaration); + try{ + lfManager=(LifecycleManager) ImplementationProvider.get().getPluginManager().getObject().get(lcHandlerDeclaration.getId()); + if(lfManager==null) throw new ConfigurationException("Unable to find Lifecycle Manager Plugin. ID "+lcHandlerDeclaration.getId()); + }catch(ClassCastException e){ + throw new ConfigurationException("Unable to use "+lcHandlerDeclaration.getId()+" as Lifecycle Manager"); + } + + + // Connect to DB + String toUseDB=super.client.getConnection().getDatabase(); + log.info("Connecting to DB {} ",toUseDB); + + // TODO MAP OF DATABASES? + db=client.getTheClient().getDatabase(toUseDB); + } + + + + + private ProfiledDocument onUpdate(ProfiledDocument updatedDocument) throws StepException { + + UserUtils.AuthenticatedUser u = UserUtils.getCurrent(); + updatedDocument.getInfo().setLastEditInfo(u.asInfo()); + + return step(updatedDocument,StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT).getResult(); + } + + private Document asDocument(ProfiledDocument d) throws JsonProcessingException { + return Document.parse(Serialization.write(d)); + } + + private ProfiledDocument asProfiledDocument(Document d) throws IOException { + return Serialization.read(d.toJson(),ProfiledDocument.class); + } + + private String getCollectionName(){ + // TODO Profile can directly specify, use ID only as default + + return profile.getId(); + } + + @Override + public MongoDatabase getDatabase(){ + return db; + } + + @Override + public ProfiledDocument registerNew(Document toRegisterDoc) throws IOException, StepException { + log.info("Registering new document in {} ",profile.getId()); + log.debug("Going to register {}",toRegisterDoc.toJson()); + + ProfiledDocument toRegister = new ProfiledDocument(); + toRegister.setTheDocument(toRegisterDoc); + + + PublicationInfo pubInfo=new PublicationInfo(); + pubInfo.setCreationInfo(UserUtils.getCurrent().asInfo()); + + // TODO Set Access From Profile + Access access=new Access(); + access.setLicense(""); + access.setPolicy(AccessPolicy.OPEN); + pubInfo.setAccess(access); + + toRegister.setInfo(pubInfo); + + toRegister.setProfileID(profile.getId()); + toRegister.setProfileVersion(profile.getVersion()); + toRegister.setVersion(new ComparableVersion("1.0.0")); + + // Apply Lifecycle + + toRegister=step(toRegister,StepExecutionRequest.Steps.ON_INIT_DOCUMENT).getResult(); + + log.debug("Going to register {} ",toRegister); + + // Insert object + ObjectId id =insert(asDocument(toRegister),getCollectionName()); + + log.info("Obtained id {} ",id); + return getByID(id.toHexString()); + } + + @Override + public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException, StepException { + log.trace("Replacing {} ",toSet); + toSet=onUpdate(toSet); + return asProfiledDocument(replace(asDocument(toSet),getCollectionName())); + } + + @Override + public void delete(String id,boolean force) throws DeletionException { + log.debug("Deleting by ID {}, force {}",id,force); + try{ + ProfiledDocument doc =getByID(id); + + // TODO INVOKE LIFECYCLE + + //if(!force&&isPublished(id)) throw new Exception("Cannot delete published documents. Unpublish it or use force = true"); + + try{ + // TODO CHECK PHASE AND STATUS + // DEINDEX + // DEMATERIALIZE + // DELETE CONTENT + // DELETE ENTRY + throw new DeletionException("IMPLEMENT THIS"); + // delete(asId(id), getCollectionName()); + }catch(DeletionException e) { + //storing updated - partially deleted + // concessione=onUpdate(concessione); + // replace(asDocument(concessione), collectionName); + throw e; + } + }catch(Throwable t){ + throw new DeletionException("Unable to delete "+id,t); + } + } + + @Override + public ProfiledDocument getByID(String id) throws IOException { + return asProfiledDocument(super.getById(asId(id),getCollectionName())); + } + + @Override + public Iterable query(QueryRequest queryRequest) { + log.info("Querying {} ",queryRequest); + LinkedBlockingQueue queue=new LinkedBlockingQueue(); + query(queryRequest,getCollectionName()).forEach( + (Consumer) (Document d)->{try{ + queue.put(d); + }catch(Throwable t){log.warn("Unable to translate "+d);}}); + log.info("Returned {} elements ",queue.size()); + return queue; + } + + @Override + public Iterable filter(QueryRequest queryRequest) { + log.info("Searching concessione for filter {} ",queryRequest); + LinkedBlockingQueue queue=new LinkedBlockingQueue(); + query(queryRequest,getCollectionName()).forEach( + (Consumer) (Document d)->{try{ + queue.put(d); + }catch(Throwable t){log.warn("Unable to translate "+d);}}); + log.info("Returned {} elements ",queue.size()); + return queue; + } + + @Override + public ProfiledDocument materialize(String id) { + throw new RuntimeException("TO IMPLEMENT"); + } + + @Override + public ProfiledDocument dematerialize(String id) { + throw new RuntimeException("TO IMPLEMENT"); + } + + @Override + public ProfiledDocument index(String id) { + throw new RuntimeException("TO IMPLEMENT"); + } + + @Override + public ProfiledDocument deIndex(String id) { + throw new RuntimeException("TO IMPLEMENT"); + } + + @Override + public ProfiledDocument performStep(String id, String step, Document options) { + throw new RuntimeException("TO IMPLEMENT"); + } + + + + private ExecutionReport step(ProfiledDocument theDocument,String step) throws StepException { + log.info("[Profile {} ] Invoking Step {} on " ,profile.getId(),step,lfManager.getDescriptor()); + StepExecutionRequest request=new StepExecutionRequest(); + request.setDocument(theDocument); + request.setProfile(profile); + request.setStep(StepExecutionRequest.Steps.ON_INIT_DOCUMENT); + log.debug("Requesting Step Execution {} ",request); + return lfManager.performStep(request); + } } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/AbstractScopedMap.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/AbstractScopedMap.java index d675162..f154040 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/AbstractScopedMap.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/AbstractScopedMap.java @@ -5,8 +5,9 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.Synchronized; import lombok.extern.slf4j.Slf4j; +import org.gcube.application.geoportal.common.utils.ContextUtils; import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; -import org.gcube.application.geoportal.service.utils.ContextUtils; + import java.time.LocalDateTime; import java.time.temporal.TemporalAmount; @@ -26,7 +27,7 @@ public abstract class AbstractScopedMap implements Engine{ private String name; @Synchronized public T getObject() throws ConfigurationException { - String currentScope=ContextUtils.getCurrentScope(); + String currentScope= ContextUtils.getCurrentScope(); log.debug(name+" : obtaining object for context "+currentScope); TTLObject found=scopeMap.get(currentScope); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/PluginManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/PluginManager.java new file mode 100644 index 0000000..bf2f9ad --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/PluginManager.java @@ -0,0 +1,110 @@ +package org.gcube.application.geoportal.service.engine.providers; + +import lombok.extern.slf4j.Slf4j; +import org.gcube.application.cms.plugins.InitializablePlugin; +import org.gcube.application.cms.plugins.Plugin; +import org.gcube.application.cms.plugins.faults.InitializationException; +import org.gcube.application.cms.plugins.faults.ShutDownException; +import org.gcube.application.cms.plugins.reports.InitializationReport; +import org.gcube.application.geoportal.common.utils.ContextUtils; +import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; + +import org.reflections.Reflections; +import org.reflections.util.ConfigurationBuilder; +import org.reflections.util.FilterBuilder; + +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceLoader; + +@Slf4j +public class PluginManager extends AbstractScopedMap>{ + + Map implementations=new HashMap<>(); + + + public PluginManager(){ + super("Plugin Cache"); + // reflections + + 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(); + log.debug("Loading {} descriptiorn : ", plugin, plugin.getDescriptor()); + implementations.put(plugin.getDescriptor().getId(), plugin); + }catch (Throwable t){ + log.warn("Unable to instantiate Plugin "+pluginClass,t); + } + } + + }); + + log.info("Loaded {} plugins",implementations.keySet().size()); + + // Init plugins + implementations.forEach((id,p)->{ + if(p instanceof InitializablePlugin){ + log.info("INIT Plugin {}",id); + try { + InitializablePlugin ip=(InitializablePlugin) p; + InitializationReport rep=ip.init(); + log.info("INIT REPORT : {}",rep); + }catch (InitializationException e){ + log.error("Failed to initialize "+id,e); + }catch(Throwable t){ + log.error("Unable to initialize "+id,t); + } + } + }); + } + + + @Override + protected Map retrieveObject() throws ConfigurationException { + // Init plugins + implementations.forEach((id,p)->{ + if(p instanceof InitializablePlugin){ + log.info("INIT Plugin {} in context {} ",id, ContextUtils.getCurrentScope()); + try { + InitializablePlugin ip=(InitializablePlugin) p; + InitializationReport rep=ip.initInContext(); + log.info("INIT REPORT : {}",rep); + }catch (InitializationException e){ + log.error("Failed to initialize "+id,e); + }catch(Throwable t){ + log.error("Unable to initialize "+id,t); + } + } + }); + return implementations; + } + + @Override + protected void dispose(Map toDispose) { + // ShutDown plugins + implementations.forEach((id,p)->{ + if(p instanceof InitializablePlugin){ + log.info("Shutting down Plugin {}",id); + try { + InitializablePlugin ip=(InitializablePlugin) p; + ip.shutdown(); + }catch (ShutDownException e){ + log.error("Failed to shutdown "+id,e); + }catch(Throwable t){ + log.error("Unable to shutdown "+id,t); + } + } + }); + } + + @Override + public void init() { + + } +} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ProfileMapCache.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ProfileMapCache.java index d9a8eb4..4545e6d 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ProfileMapCache.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ProfileMapCache.java @@ -1,34 +1,56 @@ package org.gcube.application.geoportal.service.engine.providers; +import com.fasterxml.jackson.core.JsonProcessingException; +import lombok.extern.slf4j.Slf4j; import org.gcube.application.geoportal.common.model.profile.Profile; +import org.gcube.application.geoportal.common.utils.Files; import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; +import org.gcube.application.geoportal.service.utils.Serialization; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.HashMap; import java.util.Map; - +@Slf4j public class ProfileMapCache extends AbstractScopedMap> { - public ProfileMapCache(String name) { - super(name); - // TODO Auto-generated constructor stub + public ProfileMapCache() { + super("Profiles CACHE"); + } @Override public void init() { - // TODO Auto-generated method stub } @Override protected void dispose(Map toDispose) { - // TODO Auto-generated method stub - + } @Override protected Map retrieveObject() throws ConfigurationException { - // TODO Auto-generated method stub - return null; + + + // Load from resources + HashMap toReturn=new HashMap<>(); + + try { + Profile p=Serialization.read(Files. + readFileAsString(Files.getFileFromResources("profiles/profiledConcessioni.json").getAbsolutePath(), Charset.defaultCharset()), Profile.class); + log.debug("Loaded "+p.getName()+" ID "+p.getId()); + toReturn.put(p.getId(),p); + + + }catch (JsonProcessingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return toReturn; + } } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java index 17cd57a..58d243a 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java @@ -65,6 +65,9 @@ public class DBConstants { public static final String PAROLE_CHIAVE="parole_chiave"; + // + + public static final ArrayList COLUMNS=new ArrayList(); public static final PostgisTable CENTROIDS=new PostgisTable("centroids_concessioni", diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java index 3d85e9c..426f46e 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java @@ -225,7 +225,8 @@ public class ConcessioniOverMongo { StringBuilder builder=new StringBuilder("["); manager.query(Serialization.parseQuery(queryString)) .forEach(d->{builder.append(d.toJson()+",");}); - builder.deleteCharAt(builder.length()-1); + if(builder.length()>1) + builder.deleteCharAt(builder.length()-1); builder.append("]"); return builder.toString(); } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java new file mode 100644 index 0000000..0422a28 --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java @@ -0,0 +1,118 @@ +package org.gcube.application.geoportal.service.rest; + +import lombok.extern.slf4j.Slf4j; +import org.bson.Document; +import org.gcube.application.geoportal.common.model.document.ProfiledDocument; +import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.rest.Configuration; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.rest.InterfaceConstants; +import org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager; +import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager; +import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex; +import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; +import org.gcube.application.geoportal.service.utils.Serialization; +import org.json.JSONArray; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + +@Path(InterfaceConstants.Methods.PROJECTS+"/{"+InterfaceConstants.Parameters.PROFILE_ID+"}") +@Slf4j +public class ProfiledDocuments { + + private ProfiledMongoManager manager; + + public ProfiledDocuments(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profileID) throws ConfigurationException { + log.debug("Accessing profiles "+profileID); + manager=new GuardedMethod(){ + @Override + protected ProfiledMongoManager run() throws Exception { + return new ProfiledMongoManager(profileID); + } + }.execute().getResult(); + } + + @GET + @Path(InterfaceConstants.Methods.CONFIGURATION_PATH) + @Produces(MediaType.APPLICATION_JSON) + public Configuration getConfiguration(){ + return new GuardedMethod(){ + + @Override + protected Configuration run() throws Exception, WebApplicationException { + //manager.getConfiguration(); + throw new Exception("Implement This Method"); + } + }.execute().getResult(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public ProfiledDocument createNew(Document d) { + return new GuardedMethod() { + @Override + protected ProfiledDocument run() throws Exception, WebApplicationException { + return manager.registerNew(d); + } + }.execute().getResult(); + } + + //********************************** READ + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Iterable list() { + return new GuardedMethod>() { + protected Iterable run() throws Exception ,WebApplicationException { + return manager.query(new QueryRequest()); + }; + }.execute().getResult(); + } + + // BY ID + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + public ProfiledDocument getById(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) { + return new GuardedMethod() { + @Override + protected ProfiledDocument run() throws Exception, WebApplicationException { + return manager.getByID(id); + } + }.execute().getResult(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/"+InterfaceConstants.Methods.SEARCH_PATH) + public String search(String filter){ + return new GuardedMethod() { + @Override + protected String run() throws Exception, WebApplicationException { + QueryRequest req=new QueryRequest(); + req.setFilter(Document.parse(filter)); + return Serialization.write(manager.query(req)); + } + }.execute().getResult(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/"+InterfaceConstants.Methods.QUERY_PATH) + public Iterable query(String queryString){ + return new GuardedMethod>() { + @Override + protected Iterable run() throws Exception, WebApplicationException { + return manager.query(Serialization.parseQuery(queryString)); + } + }.execute().getResult(); + } + + +} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/Profiles.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/Profiles.java deleted file mode 100644 index 5559c02..0000000 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/Profiles.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.gcube.application.geoportal.service.rest; - -public class Profiles { - -} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/Projects.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/Projects.java deleted file mode 100644 index d6f2acb..0000000 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/Projects.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.gcube.application.geoportal.service.rest; - -import lombok.extern.slf4j.Slf4j; -import org.bson.Document; -import org.gcube.application.geoportal.common.model.project.Project; -import org.gcube.application.geoportal.common.rest.InterfaceConstants; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import java.util.Collections; -import java.util.List; - -@Path(InterfaceConstants.Methods.PROJECTS) -@Slf4j -public class Projects { - - //***************** GENERIC PROJECTS - // GET ALL - @GET - @Produces(MediaType.APPLICATION_JSON) - public List getAll() { - return new GuardedMethod>() { - protected List run() throws Exception ,WebApplicationException { - return Collections.singletonList(new Project()); - }; - }.execute().getResult(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/search") - public List getFilteredAll(Document filter){ - return new GuardedMethod>() { - protected List run() throws Exception ,WebApplicationException { - return Collections.singletonList(new Project()); - }; - }.execute().getResult(); - } - - - //***************** BY PROFILE ID - - // Create new Project - @PUT - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}") - public Project registerNew(@PathParam(InterfaceConstants.Parameters.PROFILE_ID)String profileId, - Document toRegister) { - return new GuardedMethod() { - @Override - protected Project run() throws Exception, WebApplicationException { - return new Project(); - } - }.execute().getResult(); - } - - - // GET ALL (Filters apply) - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/search/{"+InterfaceConstants.Parameters.PROFILE_ID+"}") - public List getFilteredAllInProfiles(@PathParam(InterfaceConstants.Parameters.PROFILE_ID)String profileId, - Document filters) { - return new GuardedMethod>() { - protected List run() throws Exception ,WebApplicationException { - return Collections.singletonList(new Project()); - }; - }.execute().getResult(); - } - - // GET ALL - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}") - public List getAllinProfile(@PathParam(InterfaceConstants.Parameters.PROFILE_ID)String profileId) { - return new GuardedMethod>() { - protected List run() throws Exception ,WebApplicationException { - return Collections.singletonList(new Project()); - }; - }.execute().getResult(); - } - - - //***************** BY PROFILE ID + PROJECT ID - // GET BY ID - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") - public Project getByID(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profile, - @PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) { - Project toReturn=new GuardedMethod() { - @Override - protected Project run() throws Exception ,WebApplicationException{ - return new Project(); - } - }.execute().getResult(); - return toReturn; - } - - - // DELETE BY ID - @DELETE - @Produces(MediaType.APPLICATION_JSON) - @Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") - public void delete(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profile, - @PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) { - new GuardedMethod() { - @Override - protected Project run() throws Exception ,WebApplicationException{ - // TODO DELETE - return null; - } - }.execute().getResult(); - } - - @PUT - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") - public Project updateDocument(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profile, - @PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,Document toSetDocument) { - Project toReturn=new GuardedMethod() { - @Override - protected Project run() throws Exception ,WebApplicationException{ - return new Project(); - } - }.execute().getResult(); - return toReturn; - } -} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/ContextUtils.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/ContextUtils.java deleted file mode 100644 index c940b71..0000000 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/ContextUtils.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.gcube.application.geoportal.service.utils; - -import lombok.extern.slf4j.Slf4j; -import org.gcube.common.authorization.library.AuthorizationEntry; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.scope.api.ScopeProvider; - -import static org.gcube.common.authorization.client.Constants.authorizationService; - -@Slf4j -public class ContextUtils { - - public static String getCurrentScope(){ - try{ - String token=SecurityTokenProvider.instance.get(); - log.debug("Token is : "+token); - if(token==null) throw new Exception("Security Token is null"); - AuthorizationEntry entry = authorizationService().get(token); - return entry.getContext(); - }catch(Exception e ){ - log.debug("Unable to resolve token, checking scope provider..",e); - return ScopeProvider.instance.get(); - } - } - - public static String getCurrentCaller(){ - try{ - String token=SecurityTokenProvider.instance.get(); - log.debug("Token is : "+token); - if(token==null) throw new Exception("Security Token is null"); - AuthorizationEntry entry = authorizationService().get(token); - return entry.getClientInfo().getId(); - }catch(Exception e ){ - log.debug("Unable to resolve token, checking scope provider..",e); - return "Unidentified data-transfer user"; - } - } -} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/Serialization.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/Serialization.java index dbe892c..ef9812f 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/Serialization.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/Serialization.java @@ -5,6 +5,7 @@ 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 lombok.extern.slf4j.Slf4j; import org.bson.Document; import org.gcube.application.geoportal.common.model.rest.QueryRequest; @@ -12,6 +13,7 @@ import java.io.IOException; import java.time.format.DateTimeFormatter; import java.util.Iterator; +@Slf4j public class Serialization { @@ -43,11 +45,13 @@ public class Serialization { public static QueryRequest parseQuery(String queryString) throws IOException { + log.debug("Parsing query Request {} ",queryString); Document queryDocument = Document.parse(queryString); + log.debug("Document is ",queryDocument.toJson()); QueryRequest req = new QueryRequest(); - if (queryDocument.containsKey("ordering")) + if (queryDocument.getOrDefault("ordering",null)!=null) req.setOrdering(Serialization.read(((Document) queryDocument.get("ordering")).toJson(), QueryRequest.OrderedRequest.class)); - if (queryDocument.containsKey("paging")) + 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)); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java new file mode 100644 index 0000000..f7f7d7f --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java @@ -0,0 +1,86 @@ +package org.gcube.application.geoportal.service.utils; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.gcube.application.geoportal.common.model.document.AccountingInfo; +import org.gcube.application.geoportal.common.model.document.Context; +import org.gcube.application.geoportal.common.model.document.User; +import org.gcube.common.authorization.library.provider.AccessTokenProvider; +import org.gcube.common.authorization.library.provider.AuthorizationProvider; +import org.gcube.common.authorization.library.provider.ClientInfo; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; + +import java.time.LocalDateTime; + +@Slf4j +public class UserUtils { + + public static AuthenticatedUser getCurrent() throws SecurityException { + String context=ScopeProvider.instance.get(); + if(context==null) throw new SecurityException("Cannot determine context"); + + log.debug("Context is {}, checking tokens..",context); + + ClientInfo client = null; + try{ + AuthorizationProvider.instance.get().getClient(); + }catch(Throwable e) { + log.warn("Unable to get client info ",e); + } + AuthenticatedUser toReturn = new AuthenticatedUser(client, AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context); + + log.info("Current User is {} ",toReturn); + return toReturn; + } + + + @AllArgsConstructor + @Getter + public static class AuthenticatedUser { + private ClientInfo user; + private String uma_token; + + private String gcube_token; + + private String context; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("User [user="); + builder.append(user); + builder.append(", uma_token="); + builder.append(uma_token==null?uma_token:"***"); + + builder.append(", gcube_token="); + builder.append(gcube_token==null?gcube_token:"***"); + + builder.append(", context="); + builder.append(context); + builder.append("]"); + return builder.toString(); + } + + public AccountingInfo asInfo(){ + AccountingInfo info=new AccountingInfo(); + User user = new User(); + try{ + user.setUsername(this.getUser().getId()); + }catch(Exception e){ + log.warn("Unable to determine user id, using FAKE"); + user.setUsername("FAKE"); + } + + info.setUser(user); + info.setInstant(LocalDateTime.now()); + Context c=new Context(); + c.setId(this.context); + c.setName(context.contains("/")?context.substring(context.lastIndexOf("/")):context); + info.setContext(c); + return info; + } + + } +} diff --git a/geoportal-service/src/main/resources/profiles/profiledConcessioni.json b/geoportal-service/src/main/resources/profiles/profiledConcessioni.json new file mode 100644 index 0000000..b75605f --- /dev/null +++ b/geoportal-service/src/main/resources/profiles/profiledConcessioni.json @@ -0,0 +1,16 @@ +{ + "id" : "profiledConcessioni", + "version" : "1.0.0", + "name" : "Concessione", + "description" : "Embedded profile for concessioni [mibac] management", + "creationInfo": { + "user" : { + "username": "fabio.sinibaldi" + } + }, + "handlers" : [ + { + "id" : "GNA-CONCESSIONI-LC", + "type" : "LifecycleManagement"} + ] +} \ No newline at end of file diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java index ed06918..02990ae 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java @@ -20,7 +20,8 @@ public class BasicServiceTestUnit extends JerseyTest { } protected static String scope="/gcube/devsec/devVRE"; - +// protected static String scope="/pred4s/preprod/preVRE"; +// protected static String scope="/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype"; @BeforeClass public static void init() { @@ -32,40 +33,6 @@ public class BasicServiceTestUnit extends JerseyTest { } }); - -/* - ImplementationProvider.get().setStorageProvider(new StorageClientProvider() { - @Override - public IClient getObject() throws ConfigurationException { - TokenSetter.set(scope); - return super.getObject(); - } - }); - - - ImplementationProvider.get().setMongoConnectionProvider(new MongoConnectionProvider() { - @Override - public org.gcube.application.geoportal.service.model.internal.db.MongoConnection getObject() throws ConfigurationException { - TokenSetter.set(scope); - return super.getObject(); - } - }); - - ImplementationProvider.get().setMongoClientProvider(new MongoClientProvider() { - @Override - public MongoClient getObject() throws ConfigurationException { - TokenSetter.set(scope); - return super.getObject(); - } - }); - - ImplementationProvider.get().setDbProvider(new PostgisConnectionProvider() { - @Override - public PostgisDBManager getObject() throws ConfigurationException { - TokenSetter.set(scope); - return super.getObject(); - } - });*/ } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java index 15cdc48..f084f6d 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java @@ -1,18 +1,22 @@ package org.gcube.application.geoportal.service; import org.gcube.application.cms.tests.TokenSetter; -import org.gcube.application.cms.tests.model.TestFilters; -import org.gcube.application.cms.tests.model.TestQueries; -import org.gcube.application.cms.tests.model.TestModel; + +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniFilters; +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniQueries; +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.legacy.Concessione.Paths; import org.gcube.application.geoportal.common.model.legacy.LayerConcessione; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.common.utils.FileSets; import org.gcube.application.geoportal.common.utils.Files; import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.service.utils.Serialization; +import org.gcube.common.storagehub.model.query.Queries; import org.json.JSONObject; import org.junit.Assert; import org.junit.Before; @@ -48,7 +52,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ FileSets.RequestBuilder builder = FileSets.build(path); for(String file:files) - builder.add(storage.putOntoStorage(new File(TestModel.getBaseFolder(),file),file)); + builder.add(storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),file),file)); return check(target.path(FILES_PATH).path(id).request(MediaType.APPLICATION_JSON). post(Entity.entity(Serialization.write(builder.getTheRequest()), @@ -87,13 +91,14 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ return check(resp,Concessione.class); } + private static Concessione register(WebTarget target, Concessione c) throws Exception { Response resp=target.request(MediaType.APPLICATION_JSON).post(Entity.entity(Serialization.write(c), MediaType.APPLICATION_JSON)); return check(resp,Concessione.class); } private static Concessione get(WebTarget target) throws Exception { - return register(target, TestModel.prepareConcessione()); + return register(target, TestConcessioniModel.prepareConcessione()); } private static Concessione getById(WebTarget target ,String id) throws Exception { @@ -110,10 +115,10 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ private static Iterator queryFile(String filename, WebTarget target, Class clazz) throws Exception { - String queryString= TestQueries.queries.get(filename); + QueryRequest req= Serialization.parseQuery(TestConcessioniQueries.queries.get(filename)); String result = check(target.path(InterfaceConstants.Methods.QUERY_PATH).request(MediaType.APPLICATION_JSON_TYPE).post( - Entity.entity(queryString,MediaType.APPLICATION_JSON)),String.class); + Entity.entity(Serialization.write(req),MediaType.APPLICATION_JSON)),String.class); return Serialization.readCollection(result,clazz); } @@ -133,7 +138,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ public void search() throws Exception { WebTarget target=target(PATH); AtomicLong validatedCount= new AtomicLong(0); - Iterator it=search(TestFilters.filters.get("validated.json"),target); + Iterator it=search(TestConcessioniFilters.filters.get("validated.json"),target); it.forEachRemaining(concessione -> {validatedCount.incrementAndGet();}); System.out.println("Validated : "+ validatedCount.get()); } @@ -142,13 +147,14 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ public void query() throws Exception { WebTarget target=target(PATH); - Iterator it=null; - it=queryFile("lastRegistered.json", target); - assertTrue(count(it)==1); + Iterator it; + + assertEquals(1, count( queryFile("lastRegistered.json", target))); + assertEquals(0, count( queryFile("emptyresult.json",target))); it=queryFile("firstRegistered.json", target); - assertTrue(count(it)==1); + assertEquals(1, count(it)); System.out.println("Last Names by Fabio : "); queryFile("lastNameRegisteredByFabio.json", target, JSONObject.class).forEachRemaining(c -> {System.out.println(c);}); @@ -167,7 +173,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ @Test public void createNew() throws Exception { WebTarget target=target(PATH); - Concessione c=register(target,TestModel.prepareConcessione()); + Concessione c=register(target,TestConcessioniModel.prepareConcessione()); Assert.assertTrue(c.getMongo_id()!=null&&!c.getMongo_id().isEmpty()); } @@ -190,8 +196,8 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ @Test public void republish() throws Exception{ WebTarget target=target(PATH); -// Concessione published=getFullPublished(target); - Concessione published=getById(target,"6155ba6002ad3d2c23b72b5a"); + Concessione published=getFullPublished(target); + //Concessione published=getById(target,"6155ba6002ad3d2c23b72b5a"); published = unpublish(target,published.getMongo_id()); System.out.println("Republishing.."); published=publish(target,published.getMongo_id()); @@ -234,14 +240,14 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ @Test public void uploadFile() throws Exception { WebTarget target=target(PATH); - Response resp=target.request(MediaType.APPLICATION_JSON).post(Entity.entity(Serialization.write(TestModel.prepareEmptyConcessione()), MediaType.APPLICATION_JSON)); + Response resp=target.request(MediaType.APPLICATION_JSON).post(Entity.entity(Serialization.write(TestConcessioniModel.prepareEmptyConcessione()), MediaType.APPLICATION_JSON)); Concessione c=check(resp,Concessione.class); Assert.assertTrue(c.getMongo_id()!=null&&!c.getMongo_id().isEmpty()); System.out.println("ID IS "+c.getMongo_id()); // Insert section - c.setRelazioneScavo(TestModel.prepareConcessione().getRelazioneScavo()); - // c.getRelazioneScavo().setMongo_id(TestModel.rnd()); + c.setRelazioneScavo(TestConcessioniModel.prepareConcessione().getRelazioneScavo()); + // c.getRelazioneScavo().setMongo_id(TestConcessioniModel.rnd()); resp=target.request(MediaType.APPLICATION_JSON).put(Entity.entity(Serialization.write(c), MediaType.APPLICATION_JSON)); @@ -270,10 +276,8 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ System.out.println("Error for deletion is "+resp.readEntity(String.class)); //unpublish - resp= - target.path(InterfaceConstants.Methods.PUBLISH_PATH).path(published.getMongo_id()). - request(MediaType.APPLICATION_JSON).delete(); - check(resp,null); + + unpublish(target,published.getMongo_id()); //Actually cleaning posizionamento published=check( @@ -300,8 +304,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ assertNotNull(published.getReport()); assertEquals(ValidationStatus.PASSED,published.getReport().getStatus()); - assertEquals(published.getImmaginiRappresentative().size(),2); - assertEquals(published.getPianteFineScavo().size(),1); + assertNotNull(published.getPosizionamentoScavo().getWmsLink()); for(LayerConcessione l : published.getPianteFineScavo()) { assertNotNull(l.getWmsLink()); @@ -312,10 +315,13 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ private Concessione getFullPublished(WebTarget target) throws Exception { - File layerFolder=TestModel.getBaseFolder(); + File layerFolder=TestConcessioniModel.getBaseFolder(); Map> layers = Files.getAllShapeSet(layerFolder,true); - Concessione c=TestModel.prepareConcessione(layers.size(),1); + Concessione c=TestConcessioniModel.prepareConcessione(layers.size(),1); + + c.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED); + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); c.setNome("Concessione : publish test "); StorageUtils storage=new StorageUtils(); @@ -324,16 +330,20 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ // Register new c=register(target,c); + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); + //Upload files c=upload(storage,target,c.getMongo_id(),Paths.RELAZIONE,"relazione.pdf"); + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); + c=upload(storage,target,c.getMongo_id(),Paths.ABSTRACT_RELAZIONE,"relazione.pdf"); String[] keys=layers.keySet().toArray(new String [0]); c=upload(storage,target,c.getMongo_id(),Paths.POSIZIONAMENTO, -// TestModel.getBaseFolder().list((file,name)->{return name.startsWith("pianta.shp");})); +// TestConcessioniModel.getBaseFolder().list((file,name)->{return name.startsWith("pianta.shp");})); layers.get(keys[0]).toArray(new File[0])); - + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); // Clash on workspaces for(int i=0;i{return name.startsWith("pianta.shp");})); +// TestConcessioniModel.getBaseFolder().list((file,name)->{return name.startsWith("pianta.shp");})); layers.get(key).toArray(new File[0])); } + assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); // Immagini for (int i = 0; i iterator){ diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ProjectTests.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ProjectTests.java index cbbdb20..8b7e51b 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ProjectTests.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ProjectTests.java @@ -1,75 +1,94 @@ package org.gcube.application.geoportal.service; import org.bson.Document; +import org.gcube.application.cms.tests.TokenSetter; import org.gcube.application.geoportal.common.rest.InterfaceConstants; +import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import java.util.Collections; import java.util.List; +import static org.junit.Assert.assertEquals; + public class ProjectTests extends BasicServiceTestUnit{ - String testProfileId="profiled_concessione"; - String projectId="asdlkjgdasfjklgadjhkl"; - - @Test - public void getAll() { - WebTarget target=target(InterfaceConstants.Methods.PROJECTS); - System.out.println(target.request(MediaType.APPLICATION_JSON).get(List.class)); + String testProfileId="profiledConcessioni"; + + @Before + public void setContext(){ + TokenSetter.set(scope); } - + @Test - public void getFilteredAll() { - WebTarget target=target(InterfaceConstants.Methods.PROJECTS); - Document document =new Document(Collections.singletonMap("key", "value")); - - System.out.println(target.path("search").request(MediaType.APPLICATION_JSON). - post(Entity.entity(document, MediaType.APPLICATION_JSON))); - - } - - @Test - public void getAllByProfile() { - WebTarget target=target(InterfaceConstants.Methods.PROJECTS); - System.out.println(target.path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class)); + public void testMissingProfile(){ + Response resp = target(InterfaceConstants.Methods.PROJECTS) + .path("non-existent-profile").request().get(); + assertEquals(resp.getStatus(),404); } - + + @Test - public void getFilteredByProfile() { - WebTarget target=target(InterfaceConstants.Methods.PROJECTS); - Document document =new Document(Collections.singletonMap("key", "value")); - - System.out.println(target.path("search").path(testProfileId).request(MediaType.APPLICATION_JSON). - post(Entity.entity(document, MediaType.APPLICATION_JSON))); - + public void getAll() { + System.out.println(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class)); } - - + @Test - public void getById() { - WebTarget target=target(InterfaceConstants.Methods.PROJECTS); - System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON).get().readEntity(String.class)); - } - - - @Test public void registerNew() { WebTarget target=target(InterfaceConstants.Methods.PROJECTS); - Document document =new Document(Collections.singletonMap("key", "value")); - + + Document document =new Document(Collections.singletonMap("dumbKey","dumbValue")); System.out.println(target.path(testProfileId).request(MediaType.APPLICATION_JSON). - put(Entity.entity(document, MediaType.APPLICATION_JSON))); - } - - @Test - public void updateDocument() { - WebTarget target=target(InterfaceConstants.Methods.PROJECTS); - Document document =new Document(Collections.singletonMap("key", "value")); - - System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON). - put(Entity.entity(document, MediaType.APPLICATION_JSON))); + post(Entity.entity(document, MediaType.APPLICATION_JSON))); } + + + +// @Test +// public void getFilteredAll() { +// WebTarget target=target(InterfaceConstants.Methods.PROJECTS); +// Document document =new Document(Collections.singletonMap("key", "value")); +// +// System.out.println(target.path("search").request(MediaType.APPLICATION_JSON). +// post(Entity.entity(document, MediaType.APPLICATION_JSON))); +// +// } +// +// @Test +// public void getAllByProfile() { +// WebTarget target=target(InterfaceConstants.Methods.PROJECTS); +// System.out.println(target.path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class)); +// } +// +// @Test +// public void getFilteredByProfile() { +// WebTarget target=target(InterfaceConstants.Methods.PROJECTS); +// Document document =new Document(Collections.singletonMap("key", "value")); +// +// System.out.println(target.path("search").path(testProfileId).request(MediaType.APPLICATION_JSON). +// post(Entity.entity(document, MediaType.APPLICATION_JSON))); +// +// } +// +// +// @Test +// public void getById() { +// WebTarget target=target(InterfaceConstants.Methods.PROJECTS); +// System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON).get().readEntity(String.class)); +// } +// +// +// +// @Test +// public void updateDocument() { +// WebTarget target=target(InterfaceConstants.Methods.PROJECTS); +// Document document =new Document(Collections.singletonMap("key", "value")); +// +// System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON). +// put(Entity.entity(document, MediaType.APPLICATION_JSON))); +// } } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/caches/Caches.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/caches/Caches.java index 00c5081..bb75222 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/caches/Caches.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/caches/Caches.java @@ -4,7 +4,8 @@ import ch.qos.logback.core.net.SyslogOutputStream; import com.mongodb.MongoWaitQueueFullException; import lombok.extern.slf4j.Slf4j; import org.gcube.application.cms.tests.TokenSetter; -import org.gcube.application.cms.tests.model.TestModel; + +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.service.BasicServiceTestUnit; import org.gcube.application.geoportal.service.engine.ImplementationProvider; @@ -114,7 +115,7 @@ public class Caches extends BasicServiceTestUnit { final StorageUtils storage=ImplementationProvider.get().getStorageProvider().getObject(); - String id =storage.putOntoStorage(new File(TestModel.getBaseFolder(),"relazione.pdf"))[0].getId(); + String id =storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"))[0].getId(); //for 100 secs while(Duration.between(start,LocalDateTime.now()). diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/materialization/SDITests.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/materialization/SDITests.java index c6558f3..7896692 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/materialization/SDITests.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/materialization/SDITests.java @@ -3,7 +3,8 @@ package org.gcube.application.geoportal.service.engine.materialization; import lombok.extern.slf4j.Slf4j; import org.gcube.application.cms.tests.TokenSetter; -import org.gcube.application.cms.tests.model.TestModel; + +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.GeoServerContent; import org.gcube.application.geoportal.common.model.legacy.LayerConcessione; @@ -60,7 +61,7 @@ public class SDITests { //Disabled because dependant on state public void registerLayer() throws IOException, SDIInteractionException { Concessione toTest= Serialization.read(Files.readFileAsString( - new File(TestModel.getBaseFolder(),"transferTest.json").getAbsolutePath(), Charset.defaultCharset()), Concessione.class); + new File(TestConcessioniModel.getBaseFolder(),"transferTest.json").getAbsolutePath(), Charset.defaultCharset()), Concessione.class); SDIManager manager = new SDIManager(); diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ws/DescribeWSFolder.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ws/DescribeWSFolder.java index d4e6bbd..d23b88e 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ws/DescribeWSFolder.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ws/DescribeWSFolder.java @@ -7,13 +7,18 @@ import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.items.*; +import java.text.CharacterIterator; +import java.text.StringCharacterIterator; +import java.util.List; + public class DescribeWSFolder { static StorageHubClient shc =null; public static void main(String[] args) throws StorageHubException { - String context="/gcube/devsec/devVRE"; +// String context="/gcube/devsec/devVRE"; + String context="/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype"; String folderID="46b376db-32d7-4411-ad04-ca3dadab5f5b"; Boolean recursive = true; @@ -21,21 +26,46 @@ public class DescribeWSFolder { shc= new StorageHubClient(); shc.openVREFolder().get().getDescription(); - FolderContainer folder=shc.open(folderID).asFolder(); +// FolderContainer folder=shc.open(folderID).asFolder(); + FolderContainer folder = WorkspaceManager.getApplicationBaseFolder(shc); FolderItem item=folder.get(); System.out.print("PATH : "+item.getPath()+"\tHIDDEN : "+item.isHidden()+"\tDescription : "+item.getDescription()); System.out.println("Listing... "); - print(folder,""); + Long size=print(folder,"",recursive); + System.out.println("Size : "+humanReadableByteCountBin(size)); } - private static final void print(FolderContainer folder,String pad) throws StorageHubException { - for (Item i : folder.list().includeHidden().getItems()) { + private static final Long print(FolderContainer folder,String pad,Boolean recursive) throws StorageHubException { + Long toReturn=new Long(0); + List items =folder.list().includeHidden().withContent().getItems(); + System.out.println(pad+"Elements : "+items.size()); + for (Item i : items) { System.out.println(pad+ i.getName() + " [" + i.getPrimaryType()+"]"); if(i instanceof FolderItem){ - print(shc.open(i.getId()).asFolder(),pad+"\t"); + if(recursive) + toReturn+= print(shc.open(i.getId()).asFolder(),pad+"\t",recursive); + }else if (i instanceof AbstractFileItem){ +// toReturn+=shc.open(i.getId()).asFile().get().getContent().getSize(); + toReturn+=((AbstractFileItem) i).getContent().getSize(); } } + return toReturn; + } + + public static String humanReadableByteCountBin(long bytes) { + long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes); + if (absB < 1024) { + return bytes + " B"; + } + long value = absB; + CharacterIterator ci = new StringCharacterIterator("KMGTPE"); + for (int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) { + value >>= 10; + ci.next(); + } + value *= Long.signum(bytes); + return String.format("%.1f %ciB", value / 1024.0, ci.current()); } } diff --git a/geoportal-service/src/test/resources/logback.xml b/geoportal-service/src/test/resources/logback.xml index ef54588..8ec1f7c 100644 --- a/geoportal-service/src/test/resources/logback.xml +++ b/geoportal-service/src/test/resources/logback.xml @@ -10,7 +10,7 @@ - + diff --git a/pom.xml b/pom.xml index bec41f5..e26f4de 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.application.cms gcube-cms-suite pom - 1.0.0 + 1.0.1 Gcube CMS Suite gCube CMS Suite is a set of components designed to manage complex space-temporal Documents defined by metadata Profiles. @@ -32,10 +32,24 @@ - + geoportal-service - geoportal-client + + geoportal-common + cms-plugin-framework + + + geoportal-client + + + + concessioni-lifecycle + concessioni-model + + + + cms-test-commons use-cases @@ -69,13 +83,20 @@ geoportal-service [1.0.6-SNAPSHOT,2.0.0) + + + org.gcube.application.cms + cms-plugin-framework + [1.0.0-SNAPSHOT,2.0.0) + + org.gcube.application geoportal-client [1.0.5-SNAPSHOT,2.0.0) - org.gcube.application + org.gcube.application.cms geoportal-common [1.0.7-SNAPSHOT,2.0.0) @@ -90,6 +111,25 @@ [1.0.0-SNAPSHOT,2.0.0) + + org.gcube.application.cms + concessioni-model + [1.0.0-SNAPSHOT,2.0.0) + + + + org.gcube.application.cms + concessioni-lifecycle + [1.0.0-SNAPSHOT,2.0.0) + + + + org.reflections + reflections + 0.10.2 + + + org.projectlombok lombok diff --git a/test-data/concessioni/packages/concessioni04-03.csv b/test-data/concessioni/packages/concessioni04-03.csv index 2294fbc..00e4fda 100644 --- a/test-data/concessioni/packages/concessioni04-03.csv +++ b/test-data/concessioni/packages/concessioni04-03.csv @@ -9,7 +9,6 @@ "GNA_AQUILEIAcomellimoro_2019_rev","GNA_AQUILEIAcomellimoro_2019_rev/GNA_topografia_AQUILEIAcomellimoro_2019/D.Posizionamento_AQU19COM/Tav01_line_posizionamento_EPSG4326.shp" "GNA_Poggio Pimperiale_Poggibonsi","GNA_Poggio Pimperiale_Poggibonsi/5591449/GNA_topografia_PoggioImperiale/POSIZIONAMENTO/POSIZIONAMENTO A22.shp" "Jesolo (Ve) - Loc. San Mauro e Torre del Caligo","Jesolo (Ve) - Loc. San Mauro e Torre del Caligo/GNA_topografia_Jesolo/GIS_shp/Area di Scavo 2019.shp" -"Monterotondo (RM)_loc. Tor Mancina_documentazione fine scavo 2019 (paragr. IVa)","Monterotondo (RM)_loc. Tor Mancina_documentazione fine scavo 2019 (paragr. IVa)/IVa_D_E_F_GNA_topografia_Via Nomentum-Eretum/pianta fine scavo fasi.dxf" "Quarto d'Altino -Loc. Fornace","Quarto d'Altino -Loc. Fornace/Cupitò/GNA_Altino_posizionamento_shp/ALT19_area survey_EPSG4326.shp" "Tolfa (RM)_Bufalareccia_documentazione IVa 2019","Tolfa (RM)_Bufalareccia_documentazione IVa 2019/IVa_D_GNA_posizionamento dei limiti in formato vectoriale_Bufalareccia 2019/BUFFA_POLYGON_.shp" "UNIME_ LAINO_REV","UNIME_ LAINO_REV/D. Limiti saggi/laino 2019 limiti saggi/SAGGI.shp" diff --git a/test-data/concessioni/packages/concessioni04-03_filtered.csv b/test-data/concessioni/packages/concessioni04-03_filtered.csv index d8ae97d..20330bf 100644 --- a/test-data/concessioni/packages/concessioni04-03_filtered.csv +++ b/test-data/concessioni/packages/concessioni04-03_filtered.csv @@ -1 +1,5 @@ +"GNA_AQUILEIAcomellimoro_2019_rev","GNA_AQUILEIAcomellimoro_2019_rev/GNA_topografia_AQUILEIAcomellimoro_2019/D.Posizionamento_AQU19COM/Tav01_line_posizionamento_EPSG4326.shp" +"UsiniTomestighes","UsiniTomestighes/GNA_TOMESTIGHES_2019/GNA_Topografia_Tomestighes/D_GNA_Posizionamento_limiti_aree_indagate/Limiti.shp" +"GNA_Poggio Pimperiale_Poggibonsi","GNA_Poggio Pimperiale_Poggibonsi/5591449/GNA_topografia_PoggioImperiale/POSIZIONAMENTO/POSIZIONAMENTO A22.shp" +"UNIME_ LAINO_REV","UNIME_ LAINO_REV/D. Limiti saggi/laino 2019 limiti saggi/SAGGI.shp" "UsiniTomestighes","UsiniTomestighes/GNA_TOMESTIGHES_2019/GNA_Topografia_Tomestighes/D_GNA_Posizionamento_limiti_aree_indagate/Limiti.shp" \ No newline at end of file diff --git a/test-data/concessioni/packages/reinvii.csv b/test-data/concessioni/packages/reinvii.csv new file mode 100644 index 0000000..8f5c259 --- /dev/null +++ b/test-data/concessioni/packages/reinvii.csv @@ -0,0 +1,2 @@ +"GNA_ELAIUSSA_FAC-SIMILE_2021","GNA_ELAIUSSA_FAC-SIMILE_2021/GNA_topografia_Elaiussa/POSIZIONAMENTO/Elaiussa_EPSG4326.shp" +"GNA_Ferrandina_2020_inserimento","GNA_Ferrandina_2020_inserimento/New Folder With Items/topografia/Posizionamento_Ferrandina_2020.shp" \ No newline at end of file diff --git a/test-data/concessioni/queries/emptyresult.json b/test-data/concessioni/queries/emptyresult.json new file mode 100644 index 0000000..2592e30 --- /dev/null +++ b/test-data/concessioni/queries/emptyresult.json @@ -0,0 +1,4 @@ +{ + "filter" : { "nome" : { "$eq" : "stupid_mock_impossible_to_find_one" } } + +} \ No newline at end of file diff --git a/use-cases/CHANGELOG.md b/use-cases/CHANGELOG.md index ab99ae3..47165ed 100644 --- a/use-cases/CHANGELOG.md +++ b/use-cases/CHANGELOG.md @@ -2,5 +2,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for org.gcube.application.geoportal-client +## [v1.0.1] - 2021-09-20 +- Updated parent + ## [v1.0.0] - 2021-09-20 -First release, extracted from client \ No newline at end of file +- First release, extracted from client \ No newline at end of file diff --git a/use-cases/pom.xml b/use-cases/pom.xml index 646bac3..f8f52f2 100644 --- a/use-cases/pom.xml +++ b/use-cases/pom.xml @@ -4,12 +4,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 use-cases - 1.0.0 + 1.0.1 CMS Use cases gcube-cms-suite org.gcube.application.cms - 1.0.0 + 1.0.1-SNAPSHOT diff --git a/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearConcessioni.java b/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearConcessioni.java index b065cf3..af14952 100644 --- a/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearConcessioni.java +++ b/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearConcessioni.java @@ -19,7 +19,11 @@ import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.sta public class ClearConcessioni { public static void main(String[] args) throws Exception { - TokenSetter.set("/gcube/devsec/devVRE"); +// String context="/gcube/devsec/devVRE"; + + String context="/pred4s/preprod/preVRE"; + + TokenSetter.set(context); ConcessioniManagerI manager=statefulMongoConcessioni().build(); @@ -35,9 +39,9 @@ public class ClearConcessioni { Iterator it=null; // it=manager.getList(); - it=manager.search("{\"creationUser\" : {\"$exists\" : \"false\"}}"); + it=manager.search("{\"nome\" : {$regex : \"Mock .*\"}, \"creationTime\" :{$gt : \"2021-10-18T13:58:53.326\"}}"); - ExecutorService service = Executors.newFixedThreadPool(10); + ExecutorService service = Executors.newFixedThreadPool(3); it.forEachRemaining((Concessione c)->{ @@ -46,7 +50,7 @@ public class ClearConcessioni { @Override public void run() { try{ - TokenSetter.set("/gcube/devsec/devVRE"); + TokenSetter.set(context); String currentId=c.getMongo_id(); if(currentId==null) { System.out.println("ID IS NULL " + c); @@ -70,7 +74,7 @@ public class ClearConcessioni { }); }); - while (!service.awaitTermination(2, TimeUnit.MINUTES)) { + while (!service.awaitTermination(1, TimeUnit.MINUTES)) { log.info("Waiting .. completed {}, out of {} ",count.get(),found.get()); if(found.get()==count.get()) service.shutdown(); } diff --git a/use-cases/src/test/java/org/gcube/application/cms/usecases/Export.java b/use-cases/src/test/java/org/gcube/application/cms/usecases/Export.java index 22c596b..608b0fc 100644 --- a/use-cases/src/test/java/org/gcube/application/cms/usecases/Export.java +++ b/use-cases/src/test/java/org/gcube/application/cms/usecases/Export.java @@ -33,9 +33,9 @@ public class Export { public static void main(String[] args) { - File dir= new File("/Users/fabioisti/git/geoportal-client/import1628178107083"); -// String targetContext="/pred4s/preprod/preVRE"; - String targetContext= "/org/gcube/devsec/devVRE"; + File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1632326294149"); + String targetContext="/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype"; +// String targetContext= "/gcube/devsec/devVRE"; @@ -101,6 +101,7 @@ public class Export { c.setFolderId(null); c.setMongo_id(null); + // PUSH PROJECT manager.createNew(c); diff --git a/use-cases/src/test/java/org/gcube/application/cms/usecases/StressTest.java b/use-cases/src/test/java/org/gcube/application/cms/usecases/StressTest.java index 2412cdc..cbf3b2e 100644 --- a/use-cases/src/test/java/org/gcube/application/cms/usecases/StressTest.java +++ b/use-cases/src/test/java/org/gcube/application/cms/usecases/StressTest.java @@ -2,7 +2,8 @@ package org.gcube.application.cms.usecases; import lombok.extern.slf4j.Slf4j; import org.gcube.application.cms.tests.TokenSetter; -import org.gcube.application.cms.tests.model.TestModel; + +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.rest.AddSectionToConcessioneRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; @@ -25,11 +26,11 @@ public class StressTest { private static ExecutorService service = Executors.newFixedThreadPool(5); public static void main(String[] args) throws FileNotFoundException { - TokenSetter.set("/gcube/devsec/devVRE"); + TokenSetter.set("/pred4s/preprod/preVRE"); AtomicLong executed=new AtomicLong(0); AddSectionToConcessioneRequest request= FileSets.prepareRequest( - new StorageUtils(), Concessione.Paths.RELAZIONE,new File(TestModel.getBaseFolder(),"relazione.pdf")); + new StorageUtils(), Concessione.Paths.RELAZIONE,new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf")); int numRequests=100000; for(int i=0;i> piante, List pos, MongoConcessioni client, StorageUtils storage) throws Exception { - Concessione c= TestModel.prepareConcessione(piante.size(), 1); + Concessione c= TestConcessioniModel.prepareConcessione(piante.size(), 1); c.setNome("Mock for "+baseName+" ("+packageName+")"); c= client.createNew(c); String mongoId=c.getMongo_id(); // TEST DATA, DO NOT CARE client.registerFileSet(mongoId, FileSets.prepareRequest(storage, - Concessione.Paths.RELAZIONE,new File (TestModel.getBaseFolder(),"relazione.pdf"))); + Concessione.Paths.RELAZIONE,new File (TestConcessioniModel.getBaseFolder(),"relazione.pdf"))); client.registerFileSet(mongoId, FileSets.prepareRequest(storage, - Concessione.Paths.imgByIndex(0),Files.getSiblings(TestModel.getBaseFolder(),"immagine").get(0))); + Concessione.Paths.imgByIndex(0),Files.getSiblings(TestConcessioniModel.getBaseFolder(),"immagine").get(0))); // POSIZIONAMENTO diff --git a/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/MockFromFolder.java b/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/MockFromFolder.java index fbfe307..802f845 100644 --- a/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/MockFromFolder.java +++ b/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/MockFromFolder.java @@ -2,8 +2,8 @@ package org.gcube.application.cms.usecases.mocks; import com.opencsv.CSVReader; import lombok.extern.slf4j.Slf4j; -import org.gcube.application.cms.tests.model.TestModel; import org.gcube.application.cms.tests.TokenSetter; +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.utils.FileSets; @@ -26,9 +26,11 @@ public class MockFromFolder { public static void main(String[] args) throws Exception { //PARAMS - String context= "/gcube/devsec/devVRE"; +// String context= "/gcube/devsec/devVRE"; + String context = "/pred4s/preprod/preVRE"; - File descriptorsBaseFolder=new File(TestModel.getBaseFolder(),"packages"); + + File descriptorsBaseFolder=new File(TestConcessioniModel.getBaseFolder(),"packages"); // config csv -> base folder Map configurations=new HashMap<>(); @@ -36,16 +38,20 @@ public class MockFromFolder { //Concessioni 04-03 configurations.put("concessioni04-03.csv","/Users/fabioisti/Documents/Concessioni 04-03/"); +// configurations.put("concessioni04-03_filtered.csv","/Users/fabioisti/Documents/Concessioni 04-03/"); //DATASET_GNA_01 configurations.put("DATASET_GNA_01.csv","/Users/fabioisti/Documents/DATASET_GNA_01"); //DATASET_GNA_02 configurations.put("DATASET_GNA_02.csv","/Users/fabioisti/Documents/DATASET_GNA_02"); // invio_08_02 configurations.put("invio_08_05.csv","/Users/fabioisti/Documents/invio_08_05"); - // concessioni 23_04 +// // concessioni 23_04 configurations.put("concessioni_23_04.csv","/Users/fabioisti/Documents/Concessioni_23_04"); - TokenSetter.set(context); + //reinvii + configurations.put("reinvii.csv","/Users/fabioisti/Documents/reinvii"); + + TokenSetter.set(context); long start= System.currentTimeMillis();