diff --git a/pom.xml b/pom.xml index 2b38320..94f0ec8 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ UTF-8 8.0-M4 + 3.0.1 distro https://code-repo.d4science.org/gCubeSystem @@ -34,9 +35,9 @@ - + - + sdi-interface diff --git a/sdi-interface/.DS_Store b/sdi-interface/.DS_Store new file mode 100644 index 0000000..9a874b5 Binary files /dev/null and b/sdi-interface/.DS_Store differ diff --git a/sdi-interface/CHANGELOG.md b/sdi-interface/CHANGELOG.md new file mode 100644 index 0000000..1e8ce9c --- /dev/null +++ b/sdi-interface/CHANGELOG.md @@ -0,0 +1,13 @@ +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +# Changelog for sdi-interface + +## [v1.3.0-SNAPSHOT] - 2020-09-03 +Added support for generic client plugin + + +## [v1.2.0] - 2020-09-03 + +### Fixes + +- Integration with gcube distribution (https://support.d4science.org/issues/19612) \ No newline at end of file diff --git a/sdi-interface/FUNDING.md b/sdi-interface/FUNDING.md new file mode 100644 index 0000000..9e48b94 --- /dev/null +++ b/sdi-interface/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/sdi-interface/LICENSE.md b/sdi-interface/LICENSE.md new file mode 100644 index 0000000..3af0507 --- /dev/null +++ b/sdi-interface/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/sdi-interface/README.md b/sdi-interface/README.md new file mode 100644 index 0000000..655f20e --- /dev/null +++ b/sdi-interface/README.md @@ -0,0 +1,51 @@ +Spatial Data Infrastucture - Interface +-------------------------------------------------- + +SDI-Interface is one of the subsystems forming the gCube Spatial Data Infrastructure Facilities. It aims to provide gCube Applications simplified feature in order to manage GeoSpatial Data and Metadata. + +## Built with +* [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/SDI-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/sdi-interface/pom.xml b/sdi-interface/pom.xml new file mode 100644 index 0000000..7b697f6 --- /dev/null +++ b/sdi-interface/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + org.gcube.tools + maven-parent + 1.1.0 + + org.gcube.spatial.data + sdi-interface + 1.3.0-SNAPSHOT + SDI Interface + SDI Service interface and model + + + ${project.basedir}/distro + https://code-repo.d4science.org/gCubeSystem/ + 3.0.1 + + + + + scm:git:${gitBaseUrl}/${project.artifactId}.git + scm:git:${gitBaseUrl}/${project.artifactId}.git + ${gitBaseUrl}/${project.artifactId}.git + + + + + + + + org.gcube.distribution + gcube-bom + 2.0.0 + pom + import + + + + + + + + + + org.gcube.common + authorization-client + + + + junit + junit + 4.10 + test + + + + org.glassfish.jersey.media + jersey-media-json-jackson + test + + + + commons-collections + commons-collections + 3.0 + test + + + + + org.opengis + geoapi + ${geoAPI-version} + + + + + + org.projectlombok + lombok + 1.14.8 + + + org.slf4j + slf4j-api + + + + + \ No newline at end of file diff --git a/sdi-interface/src/main/java/org/gcube/spatia/data/model/profiles/ApplicationProfile.java b/sdi-interface/src/main/java/org/gcube/spatia/data/model/profiles/ApplicationProfile.java new file mode 100644 index 0000000..bc8dd19 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatia/data/model/profiles/ApplicationProfile.java @@ -0,0 +1,114 @@ +package org.gcube.spatia.data.model.profiles; + +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@RequiredArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ApplicationProfile { + + public static interface Properties{ + public static final String GEOSERVER_STORAGE="geoserver.storage"; + public static final String GEOSERVER_WORKSPACE="geoserver.workspace"; + + public static final String GEONETWORK_CATEGORY="geonetwork.category"; + public static final String GEONETWORK_STYLE="geonetwork.style"; + + public static final String THREDDS_CATALOG="thredds.catalog"; + } + + + @NonNull + private String serviceClass; + @NonNull + private String serviceName; + @NonNull + private Map properties; + + + public String getProperty(String propertyName) { + return properties==null?null:properties.get(propertyName); + } + + + @Override + public String toString() { + return "ApplicationProfile [serviceClass=" + serviceClass + ", serviceName=" + serviceName + ", properties=" + + properties + "]"; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + + if(properties!=null && !properties.isEmpty()) + for(Entry prop:properties.entrySet()) { + result = prime * result + ((prop.getKey() == null) ? 0 : prop.getKey().hashCode()); + result = prime * result + ((prop.getValue() == null) ? 0 : prop.getValue().hashCode()); + } + + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); + result = prime * result + ((serviceClass == null) ? 0 : serviceClass.hashCode()); + result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ApplicationProfile other = (ApplicationProfile) obj; + + + + if (properties == null) { + if (other.properties != null) + return false; + } else { + if(properties.size()!= other.properties.size()) return false; + for(Entry prop:properties.entrySet()) { + if(!other.properties.containsKey(prop.getKey())) return false; + if(!prop.getValue().equals(other.properties.get(prop.getKey()))) return false; + } + } + + + if (serviceClass == null) { + if (other.serviceClass != null) + return false; + } else if (!serviceClass.equals(other.serviceClass)) + return false; + if (serviceName == null) { + if (other.serviceName != null) + return false; + } else if (!serviceName.equals(other.serviceName)) + return false; + return true; + } + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/plugins/GISServicePlugin.java b/sdi-interface/src/main/java/org/gcube/spatial/data/plugins/GISServicePlugin.java new file mode 100644 index 0000000..8a5c693 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/plugins/GISServicePlugin.java @@ -0,0 +1,5 @@ +package org.gcube.spatial.data.plugins; + +public interface GISServicePlugin { + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/interfaces/GeoNetwork.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/interfaces/GeoNetwork.java new file mode 100644 index 0000000..a67a6ea --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/interfaces/GeoNetwork.java @@ -0,0 +1,43 @@ +package org.gcube.spatial.data.sdi.interfaces; + +import org.gcube.spatial.data.sdi.model.faults.ConfigurationException; +import org.gcube.spatial.data.sdi.model.faults.InternalException; +import org.gcube.spatial.data.sdi.model.faults.RemoteException; +import org.gcube.spatial.data.sdi.model.gn.LoginLevel; +import org.gcube.spatial.data.sdi.model.gn.query.GNSearchRequest; +import org.gcube.spatial.data.sdi.model.gn.query.GNSearchResponse; +import org.gcube.spatial.data.sdi.model.metadata.MetadataInfo; + + + +public interface GeoNetwork { + + // MANAGEMENT + +// public Credentials getCredentials(String host); + + + + public GNSearchResponse query(GNSearchRequest request) + throws InternalException,RemoteException,ConfigurationException; + + + public Metadata getById(long id) throws InternalException,RemoteException,ConfigurationException; + + public Metadata getById(String UUID) throws InternalException,RemoteException,ConfigurationException; + + public String getByIdAsRawString(String UUID) throws InternalException,RemoteException,ConfigurationException; + + + public void login()throws InternalException,RemoteException,ConfigurationException; + + public void login(LoginLevel level)throws InternalException,RemoteException,ConfigurationException; + + public void logout() throws InternalException,RemoteException,ConfigurationException; + + public MetadataInfo getInfo(Long id) throws InternalException,RemoteException,ConfigurationException; + + public MetadataInfo getInfo(String uuid) throws InternalException,RemoteException,ConfigurationException; + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/interfaces/Metadata.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/interfaces/Metadata.java new file mode 100644 index 0000000..45f976b --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/interfaces/Metadata.java @@ -0,0 +1,14 @@ +package org.gcube.spatial.data.sdi.interfaces; + +import java.io.File; + +import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions; +import org.gcube.spatial.data.sdi.model.metadata.MetadataReport; +import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection; + +public interface Metadata { + + public TemplateCollection getAvailableTemplates(); + public MetadataReport pushMetadata(File toPublish); + public MetadataReport pushMetadata(File toPublish,MetadataPublishOptions options); +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/MapAdapter.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/MapAdapter.java new file mode 100644 index 0000000..068e148 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/MapAdapter.java @@ -0,0 +1,50 @@ +package org.gcube.spatial.data.sdi.model; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class MapAdapter extends XmlAdapter> { + + private DocumentBuilder documentBuilder; + + public MapAdapter() throws Exception { + documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } + + @Override + public Element marshal(Map map) throws Exception { + Document document = documentBuilder.newDocument(); + Element rootElement = document.createElement("data"); + document.appendChild(rootElement); + for(Entry entry : map.entrySet()) { + Element childElement = document.createElement(entry.getKey()); + childElement.setTextContent(entry.getValue()); + rootElement.appendChild(childElement); + } + return rootElement; + } + + @Override + public Map unmarshal(Element rootElement) throws Exception { + NodeList nodeList = rootElement.getChildNodes(); + Map map = new HashMap(nodeList.getLength()); + for(int x=0; x geonetworkConfiguration; + @NonNull + private List geoserverClusterConfiguration; + @NonNull + private List threddsConfiguration; + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/ServiceConstants.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/ServiceConstants.java new file mode 100644 index 0000000..c05f3e8 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/ServiceConstants.java @@ -0,0 +1,45 @@ +package org.gcube.spatial.data.sdi.model; + +public class ServiceConstants { + + public static final String APPLICATION="SDI-Service"; + public static final String INTERFACE="SDI"; + + public static final String SERVICE_CLASS="SDI"; + public static final String SERVICE_NAME="sdi-service"; + public static final String NAMESPACE="http://gcube-system.org/namespaces/data/sdi-service"; + + + public static final class Metadata{ + public static final String INTERFACE="Metadata"; + public static final String LIST_METHOD="list"; + public static final String PUBLISH_METHOD="publish"; + public static final String VALIDATE_PARAMETER="validate"; + public static final String PUBLIC_PARAMETER="public"; + public static final String STYLESHEET_PARAMETER="stylesheet"; + public static final String UPLOADED_FILE_PARAMETER="theMeta"; + public static final String METADATA_ENRICHMENTS_PARAMETER="metadataEnrichments"; + // Defaults + + public static final Boolean DEFAULT_VALIDATE=true; + public static final Boolean DEFAULT_PUBLIC=false; + public static final String DEFAULT_CATEGORY="Dataset"; + public static final String DEFAULT_STYLESHEET="_none_"; + + } + + + public static final class GeoNetwork{ + public static final String INTERFACE="GeoNetwork"; + public static final String CONFIGURATION_PATH="configuration"; + public static final String GROUPS_PATH="groups"; + + } + + public static final class GeoServer{ + public static final String INTERFACE="GeoServer"; + public static final String HOST_PARAM="host"; + } + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/StringEntry.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/StringEntry.java new file mode 100644 index 0000000..9871972 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/StringEntry.java @@ -0,0 +1,20 @@ +package org.gcube.spatial.data.sdi.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.Data; + +@XmlRootElement +@Data +@XmlAccessorType(XmlAccessType.NONE) +public class StringEntry { + + @XmlElement(name = "name") + private String name; + @XmlElement(name = "value") + private String value; + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/credentials/AccessType.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/credentials/AccessType.java new file mode 100644 index 0000000..68a8088 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/credentials/AccessType.java @@ -0,0 +1,10 @@ +package org.gcube.spatial.data.sdi.model.credentials; + +public enum AccessType { + + ADMIN, + CONTEXT_MANAGER, + CONTEXT_USER, + CKAN; + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/credentials/Credentials.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/credentials/Credentials.java new file mode 100644 index 0000000..f3ee67a --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/credentials/Credentials.java @@ -0,0 +1,34 @@ +package org.gcube.spatial.data.sdi.model.credentials; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@RequiredArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class Credentials { + + @NonNull + private String username; + @NonNull + private String password; + @NonNull + private AccessType accessType; + @Override + public String toString() { + return "Credentials [username=" + username + ", password=****, accessType=" + accessType + "]"; + } + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/ConfigurationException.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/ConfigurationException.java new file mode 100644 index 0000000..6d17701 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/ConfigurationException.java @@ -0,0 +1,35 @@ +package org.gcube.spatial.data.sdi.model.faults; + +public class ConfigurationException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -8621547149713561540L; + + public ConfigurationException() { + // TODO Auto-generated constructor stub + } + + public ConfigurationException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public ConfigurationException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + public ConfigurationException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public ConfigurationException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + // TODO Auto-generated constructor stub + } + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/ErrorMessage.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/ErrorMessage.java new file mode 100644 index 0000000..a39533d --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/ErrorMessage.java @@ -0,0 +1,36 @@ +package org.gcube.spatial.data.sdi.model.faults; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.Data; + +@XmlRootElement +@Data +@XmlAccessorType(XmlAccessType.NONE) +public class ErrorMessage { + + /** contains the same HTTP Status code returned by the server */ + @XmlElement(name = "status") + int status; + + /** application specific error code */ + @XmlElement(name = "code") + int code; + + /** message describing the error*/ + @XmlElement(name = "message") + String message; + + /** link point to page where the error message is documented */ + @XmlElement(name = "link") + String link; + + /** extra information that might useful for developers */ + @XmlElement(name = "developerMessage") + String developerMessage; + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/InternalException.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/InternalException.java new file mode 100644 index 0000000..7a609f7 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/InternalException.java @@ -0,0 +1,39 @@ +package org.gcube.spatial.data.sdi.model.faults; + +public class InternalException extends Exception { + + + + /** + * + */ + private static final long serialVersionUID = 7957607092593029526L; + + public InternalException() { + super(); + // TODO Auto-generated constructor stub + } + + public InternalException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + // TODO Auto-generated constructor stub + } + + public InternalException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public InternalException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public InternalException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/RemoteException.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/RemoteException.java new file mode 100644 index 0000000..412210e --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/RemoteException.java @@ -0,0 +1,34 @@ +package org.gcube.spatial.data.sdi.model.faults; + +public class RemoteException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 3758504937629040958L; + + public RemoteException() { + // TODO Auto-generated constructor stub + } + + public RemoteException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public RemoteException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + public RemoteException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public RemoteException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + // TODO Auto-generated constructor stub + } + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/Account.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/Account.java new file mode 100644 index 0000000..9c7392e --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/Account.java @@ -0,0 +1,28 @@ +package org.gcube.spatial.data.sdi.model.gn; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor +public class Account { + + public static enum Type{ + CKAN,SCOPE + } + + private String user; + private String password; + private Type type; + @Override + public String toString() { + return "Account [user=" + user + ", password=" + "***" + ", type=" + + type + "]"; + } + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/Group.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/Group.java new file mode 100644 index 0000000..eeafd4e --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/Group.java @@ -0,0 +1,50 @@ +package org.gcube.spatial.data.sdi.model.gn; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@AllArgsConstructor +@ToString +public class Group { + + private String name; + private String description; + private String mail; + private Integer id; + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Group other = (Group) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/LoginLevel.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/LoginLevel.java new file mode 100644 index 0000000..2b500c0 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/LoginLevel.java @@ -0,0 +1,9 @@ +package org.gcube.spatial.data.sdi.model.gn; + +public class LoginLevel { + + public LoginLevel() { + // TODO Auto-generated constructor stub + } + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/User.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/User.java new file mode 100644 index 0000000..fa38551 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/User.java @@ -0,0 +1,74 @@ +package org.gcube.spatial.data.sdi.model.gn; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class User { + + public static enum Profile{ + Editor, // R+W rights + RegisteredUser, // R rights + Administrator, + UserAdmin, + Reviewer, + Guest, + Monitor + } + + + private Integer id; + private String username; + private String password; + private Profile profile; + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((username == null) ? 0 : username.hashCode()); + return result; + } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + User other = (User) obj; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("User [id="); + builder.append(id); + builder.append(", username="); + builder.append(username); + builder.append(", password="); + builder.append("*******"); + builder.append(", profile="); + builder.append(profile); + builder.append("]"); + return builder.toString(); + } +} \ No newline at end of file diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/query/GNSearchRequest.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/query/GNSearchRequest.java new file mode 100644 index 0000000..ee47ed5 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/query/GNSearchRequest.java @@ -0,0 +1,5 @@ +package org.gcube.spatial.data.sdi.model.gn.query; + +public class GNSearchRequest { + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/query/GNSearchResponse.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/query/GNSearchResponse.java new file mode 100644 index 0000000..908d683 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/gn/query/GNSearchResponse.java @@ -0,0 +1,9 @@ +package org.gcube.spatial.data.sdi.model.gn.query; + +public class GNSearchResponse { + + public GNSearchResponse() { + // TODO Auto-generated constructor stub + } + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataInfo.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataInfo.java new file mode 100644 index 0000000..38cbb86 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataInfo.java @@ -0,0 +1,9 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +public class MetadataInfo { + + public MetadataInfo() { + // TODO Auto-generated constructor stub + } + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataPublishOptions.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataPublishOptions.java new file mode 100644 index 0000000..56e5bfd --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataPublishOptions.java @@ -0,0 +1,35 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +import java.util.HashSet; +import java.util.Set; + +import org.gcube.spatial.data.sdi.model.ServiceConstants; +import org.gcube.spatial.data.sdi.model.ServiceConstants.Metadata; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class MetadataPublishOptions { + + private boolean validate=ServiceConstants.Metadata.DEFAULT_VALIDATE; + private boolean makePublic=ServiceConstants.Metadata.DEFAULT_PUBLIC; + + private String geonetworkCategory=ServiceConstants.Metadata.DEFAULT_CATEGORY; + private String geonetworkStyleSheet=ServiceConstants.Metadata.DEFAULT_STYLESHEET; + private Set templateInvocations=new HashSet<>(); + + public MetadataPublishOptions(Set invocations){ + setTemplateInvocations(invocations); + + + } + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataReport.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataReport.java new file mode 100644 index 0000000..9ef9aa8 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataReport.java @@ -0,0 +1,36 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +@EqualsAndHashCode +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class MetadataReport { + + @XmlElement(name="publishedUUID") + private String publishedUUID; + + @XmlElement(name="publishedID") + private Long publishedID; + + @XmlElement(name="appliedTemplates") + private Set appliedTemplates; + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateApplicationRequest.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateApplicationRequest.java new file mode 100644 index 0000000..4006b8c --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateApplicationRequest.java @@ -0,0 +1,71 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +import java.util.HashSet; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class TemplateApplicationRequest { + + @XmlElement(name="invocationSet") + private HashSet invocationSet; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + if(invocationSet!=null && !invocationSet.isEmpty()) + for(TemplateInvocation inv:invocationSet) + result=prime*result+inv.hashCode(); + + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TemplateApplicationRequest other = (TemplateApplicationRequest) obj; + + + if (invocationSet == null ) { + if (other.invocationSet != null) + return false; + } else if (invocationSet.size()!=other.invocationSet.size()) + return false; + else for(TemplateInvocation inv:invocationSet) { + boolean ok=false; + for(TemplateInvocation inv2:other.invocationSet) + if(inv.equals(inv2)) { + ok=true; + break; + } + if(!ok)return false; + } + + + return true; + } + + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateCollection.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateCollection.java new file mode 100644 index 0000000..954327f --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateCollection.java @@ -0,0 +1,65 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +import java.util.HashSet; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class TemplateCollection { + + @XmlElement(name="availableTemplates") + private Set availableTemplates=new HashSet(); + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + if(availableTemplates!=null && !availableTemplates.isEmpty()) + for(TemplateDescriptor inv:availableTemplates) + result=prime*result+inv.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TemplateCollection other = (TemplateCollection) obj; + + + if (availableTemplates == null ) { + if (other.availableTemplates != null) + return false; + } else if (availableTemplates.size()!=other.availableTemplates.size()) + return false; + else for(TemplateDescriptor inv:availableTemplates) + if(!other.availableTemplates.contains(inv))return false; + + + + return true; + } + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateDescriptor.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateDescriptor.java new file mode 100644 index 0000000..c2fef40 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateDescriptor.java @@ -0,0 +1,113 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +import java.util.ArrayList; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.spatial.data.sdi.model.ParameterType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class TemplateDescriptor { + + @XmlElement(name="templateID") + private String id; + @XmlElement(name="name") + private String name; + @XmlElement(name="description") + private String description; + @XmlElement(name="sourceURL") + private String sourceURL; + +// @XmlAnyElement +// @XmlJavaTypeAdapter(MapAdapter.class) + + @XmlElement(name="parameters") + private ArrayList expectedParameters; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + if(!(expectedParameters == null || expectedParameters.isEmpty())) + for(ParameterType param:expectedParameters) + result=prime*result+param.hashCode(); + + + + + result = prime * result + ((description == null) ? 0 : description.hashCode()); + + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((sourceURL == null) ? 0 : sourceURL.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TemplateDescriptor other = (TemplateDescriptor) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + + + + if (expectedParameters == null || expectedParameters.isEmpty()) { + if (!(other.expectedParameters == null || other.expectedParameters.isEmpty())) + return false; + } else if (expectedParameters.size()!=other.expectedParameters.size()) + return false; + else + if(!other.expectedParameters.containsAll(this.expectedParameters)) return false; + + + + + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (sourceURL == null) { + if (other.sourceURL != null) + return false; + } else if (!sourceURL.equals(other.sourceURL)) + return false; + return true; + } + + public void addParameter(String name,String value) { + if(expectedParameters==null) expectedParameters=new ArrayList<>(); + expectedParameters.add(new ParameterType(name,value)); + } + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocation.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocation.java new file mode 100644 index 0000000..673c119 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocation.java @@ -0,0 +1,81 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +import java.util.ArrayList; +import java.util.Map.Entry; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.spatial.data.sdi.model.ParameterType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class TemplateInvocation { + + @XmlElement(name="templateID") + private String toInvokeTemplateID; + +// @XmlAnyElement +// @XmlJavaTypeAdapter(MapAdapter.class) + @XmlElement(name="parameters") + private ArrayList templateParameters; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + if(!(templateParameters == null || templateParameters.isEmpty())) + for(ParameterType param:templateParameters) + result=prime*result+param.hashCode(); + + + result = prime * result + ((toInvokeTemplateID == null) ? 0 : toInvokeTemplateID.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TemplateInvocation other = (TemplateInvocation) obj; + + if (templateParameters == null || templateParameters.isEmpty()) { + if (!(other.templateParameters == null || other.templateParameters.isEmpty())) + return false; + } else if (templateParameters.size()!=other.templateParameters.size()) + return false; + else + if(!other.templateParameters.containsAll(this.templateParameters)) return false; + + + + if (toInvokeTemplateID == null) { + if (other.toInvokeTemplateID != null) + return false; + } else if (!toInvokeTemplateID.equals(other.toInvokeTemplateID)) + return false; + return true; + } + + public void addParameter(String name,String value) { + if(templateParameters==null) templateParameters=new ArrayList<>(); + templateParameters.add(new ParameterType(name,value)); + } +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocationBuilder.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocationBuilder.java new file mode 100644 index 0000000..248b3f1 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocationBuilder.java @@ -0,0 +1,36 @@ +package org.gcube.spatial.data.sdi.model.metadata; + +import java.util.HashSet; + +public class TemplateInvocationBuilder { + + // Constants + public static final class THREDDS_ONLINE{ + public static final String ID="THREDDS_ONLINE_RESOURCES"; + public static final String HOSTNAME="hostname"; + public static final String FILENAME="filename"; + public static final String CATALOG="catalog"; + } + + + + + private HashSet invocations=new HashSet(); + + + public TemplateInvocationBuilder threddsOnlineResources(String hostname, String filename, String catalog){ + TemplateInvocation toAdd=new TemplateInvocation(); + toAdd.setToInvokeTemplateID(THREDDS_ONLINE.ID); + + toAdd.addParameter(THREDDS_ONLINE.HOSTNAME, hostname); + toAdd.addParameter(THREDDS_ONLINE.FILENAME, filename); + toAdd.addParameter(THREDDS_ONLINE.CATALOG, catalog); + invocations.add(toAdd); + return this; + } + + public HashSet get(){ + return invocations; + } +} + diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ACCESS_TYPE.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ACCESS_TYPE.java new file mode 100644 index 0000000..b82394a --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ACCESS_TYPE.java @@ -0,0 +1,5 @@ +package org.gcube.spatial.data.sdi.model.services; + +public enum ACCESS_TYPE{ + CONFIDENTIAL,SHARED,PUBLIC +} \ No newline at end of file diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/CatalogDefinition.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/CatalogDefinition.java new file mode 100644 index 0000000..e4ebb4a --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/CatalogDefinition.java @@ -0,0 +1,30 @@ +package org.gcube.spatial.data.sdi.model.services; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class CatalogDefinition { + + @XmlElement + private String name; + + @XmlElement + private ACCESS_TYPE access; +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoNetworkServiceDefinition.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoNetworkServiceDefinition.java new file mode 100644 index 0000000..2671b9a --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoNetworkServiceDefinition.java @@ -0,0 +1,35 @@ +package org.gcube.spatial.data.sdi.model.services; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class GeoNetworkServiceDefinition extends ServiceDefinition { + + @XmlElement(name = "priority") + private int priority; + + @Override + public Type getType() { + return Type.GEONETWORK; + } + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoServerDefinition.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoServerDefinition.java new file mode 100644 index 0000000..aa31b07 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoServerDefinition.java @@ -0,0 +1,79 @@ +package org.gcube.spatial.data.sdi.model.services; + +import java.util.ArrayList; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class GeoServerDefinition extends ServiceDefinition { + + @Override + public Type getType() { + return Type.GEOSERVER; + } + + @XmlElement + private ArrayList workspaces; + + + public void addWorkspace(WorkspaceDefinition def) { + if(workspaces==null) workspaces=new ArrayList<>(); + workspaces.add(def); + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + + if(!(workspaces == null || workspaces.isEmpty())) + for(WorkspaceDefinition workspace:workspaces) + result=prime*result+workspace.hashCode(); + + + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + GeoServerDefinition other = (GeoServerDefinition) obj; + + if (workspaces == null || workspaces.isEmpty()) { + if (!(other.workspaces == null || other.workspaces.isEmpty())) + return false; + } else if (workspaces.size()!=other.workspaces.size()) + return false; + else + if(!other.workspaces.containsAll(this.workspaces)) return false; + + + return true; + } + + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/SdiStatusReport.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/SdiStatusReport.java new file mode 100644 index 0000000..2e251ac --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/SdiStatusReport.java @@ -0,0 +1,10 @@ +package org.gcube.spatial.data.sdi.model.services; + +public class SdiStatusReport { + + + + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ServiceDefinition.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ServiceDefinition.java new file mode 100644 index 0000000..3721e64 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ServiceDefinition.java @@ -0,0 +1,168 @@ +package org.gcube.spatial.data.sdi.model.services; + +import java.util.ArrayList; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.spatial.data.sdi.model.ParameterType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@RequiredArgsConstructor +public abstract class ServiceDefinition { + + public static enum Type{ + THREDDS,GEOSERVER,GEONETWORK + } + + + @XmlElement(name ="hostname") + @NonNull + private String hostname; + + @XmlElement(name ="majorVersion") + @NonNull + private Short majorVersion; + + @XmlElement(name ="minorVersion") + @NonNull + private Short minorVersion; + + @XmlElement(name ="releaseVersion") + private Short releaseVersion; + + @XmlElement(name ="type") + @NonNull + private Type type; + + @XmlElement(name ="adminPassword") + @NonNull + private String adminPassword; + + @XmlElement(name ="properties") + private ArrayList properties; + + @XmlElement(name ="description") + private String description; + + @XmlElement(name ="name") + @NonNull + private String name; + + @Override + public String toString() { + return "ServiceDefinition [hostname=" + hostname + ", majorVersion=" + majorVersion + ", minorVersion=" + + minorVersion + ", releaseVersion=" + releaseVersion + ", type=" + type + ", properties=" + properties + + ", description=" + description + ", name=" + name + "]"; + } + + + + public void addProperty(String name,String value) { + if(properties==null) properties=new ArrayList<>(); + properties.add(new ParameterType(name,value)); + } + + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((adminPassword == null) ? 0 : adminPassword.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); + result = prime * result + ((majorVersion == null) ? 0 : majorVersion.hashCode()); + result = prime * result + ((minorVersion == null) ? 0 : minorVersion.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + + if(!(properties == null || properties.isEmpty())) + for(ParameterType param:properties) + result=prime*result+param.hashCode(); + + + result = prime * result + ((releaseVersion == null) ? 0 : releaseVersion.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServiceDefinition other = (ServiceDefinition) obj; + if (adminPassword == null) { + if (other.adminPassword != null) + return false; + } else if (!adminPassword.equals(other.adminPassword)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (hostname == null) { + if (other.hostname != null) + return false; + } else if (!hostname.equals(other.hostname)) + return false; + if (majorVersion == null) { + if (other.majorVersion != null) + return false; + } else if (!majorVersion.equals(other.majorVersion)) + return false; + if (minorVersion == null) { + if (other.minorVersion != null) + return false; + } else if (!minorVersion.equals(other.minorVersion)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + + + if (properties == null || properties.isEmpty()) { + if (!(other.properties == null || other.properties.isEmpty())) + return false; + } else if (properties.size()!=other.properties.size()) + return false; + else + if(!other.properties.containsAll(this.properties)) return false; + + + + if (releaseVersion == null) { + if (other.releaseVersion != null) + return false; + } else if (!releaseVersion.equals(other.releaseVersion)) + return false; + if (type != other.type) + return false; + return true; + } + + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ThreddsDefinition.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ThreddsDefinition.java new file mode 100644 index 0000000..a2b741e --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/ThreddsDefinition.java @@ -0,0 +1,74 @@ +package org.gcube.spatial.data.sdi.model.services; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class ThreddsDefinition extends ServiceDefinition { + + @Override + public Type getType() { + return Type.THREDDS; + } + + @XmlElement + private List catalogs; + + + public void addCatalog(CatalogDefinition catalog) { + if(catalogs==null) catalogs=new ArrayList<>(); + catalogs.add(catalog); + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + if(!(catalogs == null || catalogs.isEmpty())) + for(CatalogDefinition catalog:catalogs) + result=prime*result+catalog.hashCode(); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + ThreddsDefinition other = (ThreddsDefinition) obj; + + if (catalogs == null || catalogs.isEmpty()) { + if (!(other.catalogs == null || other.catalogs.isEmpty())) + return false; + } else if (catalogs.size()!=other.catalogs.size()) + return false; + else + if(!other.catalogs.containsAll(this.catalogs)) return false; + + return true; + } + + +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/WorkspaceDefinition.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/WorkspaceDefinition.java new file mode 100644 index 0000000..3023586 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/services/WorkspaceDefinition.java @@ -0,0 +1,30 @@ +package org.gcube.spatial.data.sdi.model.services; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class WorkspaceDefinition { + + @XmlElement + private String name; + + @XmlElement + private ACCESS_TYPE access; +} diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/utils/ScopeUtils.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/utils/ScopeUtils.java new file mode 100644 index 0000000..9802fb6 --- /dev/null +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/utils/ScopeUtils.java @@ -0,0 +1,113 @@ +package org.gcube.spatial.data.sdi.utils; + +import static org.gcube.common.authorization.client.Constants.authorizationService; + +import java.util.ArrayList; + +import org.gcube.common.authorization.library.AuthorizationEntry; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; + +import lombok.extern.slf4j.Slf4j; + + + +@Slf4j +public class ScopeUtils { + + 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"; + } + } + + + 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(); + // } + + String scope=ScopeProvider.instance.get(); + if(scope!=null) { + log.debug("Found scope provider {}, skipping token",scope); + return scope; + }else{ + try{ + log.debug("Scope provider not set, reverting to token"); + 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){ + throw new RuntimeException("Unable to evaluate scope ",e); + } + } + } + + + + // Commented version doesn't check ScopeProvider + // 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 getCurrentScopeName(){ + return getScopeName(getCurrentScope()); + } + + public static String getScopeName(String scope) { + return scope.substring(scope.lastIndexOf('/')+1); + } + + + public static ArrayList getParentScopes(){ + String currentScope=getCurrentScope(); + String[] splitted=currentScope.substring(1).split("/"); + ArrayList toReturn=new ArrayList(); + for(int i=0;i getParentScopes(String scope){ + String[] splitted=scope.substring(1).split("/"); + ArrayList toReturn=new ArrayList(); + for(int i=0;i existing,int length){ + String toReturn=generateRandomString(length); + while(existing.contains(toReturn)) + toReturn=generateRandomString(length); + return toReturn; + } +} diff --git a/sdi-interface/src/test/java/org/gcube/spatial/data/sdi/MarshallUnmarshallTest.java b/sdi-interface/src/test/java/org/gcube/spatial/data/sdi/MarshallUnmarshallTest.java new file mode 100644 index 0000000..0b560ed --- /dev/null +++ b/sdi-interface/src/test/java/org/gcube/spatial/data/sdi/MarshallUnmarshallTest.java @@ -0,0 +1,209 @@ +package org.gcube.spatial.data.sdi; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; + +import javax.xml.bind.JAXBException; + +import org.apache.commons.collections.CollectionUtils; +import org.gcube.spatia.data.model.profiles.ApplicationProfile; +import org.gcube.spatial.data.sdi.model.ParameterType; +import org.gcube.spatial.data.sdi.model.faults.ErrorMessage; +import org.gcube.spatial.data.sdi.model.metadata.MetadataReport; +import org.gcube.spatial.data.sdi.model.metadata.TemplateApplicationRequest; +import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection; +import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor; +import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocationBuilder; +import org.gcube.spatial.data.sdi.model.services.ACCESS_TYPE; +import org.gcube.spatial.data.sdi.model.services.GeoNetworkServiceDefinition; +import org.gcube.spatial.data.sdi.model.services.GeoServerDefinition; +import org.gcube.spatial.data.sdi.model.services.WorkspaceDefinition; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; + +public class MarshallUnmarshallTest { + + + + static ObjectMapper mapper=null; + + static ArrayList modelInstance=new ArrayList<>(); + + + @BeforeClass + public static void init() throws JAXBException{ + + mapper=new ObjectMapper(); + AnnotationIntrospector introspector=new JaxbAnnotationIntrospector(mapper.getTypeFactory()); + mapper.setAnnotationIntrospector(introspector); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + + modelInstance.add(getTemplateInvocations()); + modelInstance.add(getDescriptors()); + modelInstance.add(getError()); + modelInstance.add(getReport()); + modelInstance.add(getGSDefinition()); + modelInstance.add(getGNDefinition()); + modelInstance.add(getBasicProfile()); + } + + public static boolean roundTrip(Object obj) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException{ + Object roundTripResult=mapper.readValue(marshal(obj), obj.getClass()); + + if(obj instanceof Collection) { + return CollectionUtils.isEqualCollection((Collection)obj, (Collection)roundTripResult); + } + return obj.equals(roundTripResult); + + } + + @Test + public void testHashAndEquals() throws IOException { + for(Object obj:modelInstance) { + assertTrue(obj.equals(copy(obj))); + assertTrue(obj.hashCode()==copy(obj).hashCode()); + } + } + + + @Test + public void Marshall() throws IOException{ + for(Object obj:modelInstance) + print(obj); + } + @Test + public void unMarshall() throws JsonParseException, JsonMappingException, JsonProcessingException, IOException{ + for(Object obj:modelInstance) + assertTrue(roundTrip(obj)); + } + + @Test + public void toStringTest() throws IOException{ + for(Object obj:modelInstance) + System.out.println(obj); + } + + + public static String marshal(Object toSerialize) throws JsonProcessingException { + return mapper.writeValueAsString(toSerialize); + } + + public static void print(Object obj) throws JsonProcessingException { + System.out.println(marshal(obj)); + } + +// public static T unmarshal(Class resourceClass, String toRead) throws JsonParseException, JsonMappingException, IOException { +// return mapper.readValue(toRead, resourceClass); +// } + + + + private static TemplateApplicationRequest getTemplateInvocations(){ + return new TemplateApplicationRequest(new TemplateInvocationBuilder().threddsOnlineResources("localhost", "myDataset.nc", "my Catalog").get()); + } + + private static TemplateCollection getDescriptors(){ + HashSet descriptors=new HashSet<>(); + descriptors.add(new TemplateDescriptor(TemplateInvocationBuilder.THREDDS_ONLINE.ID,"Thredds Online Resources","Online reousrce template for thredds resources","http://some.place.org/theTemplate", new ArrayList())); + descriptors.add(new TemplateDescriptor(TemplateInvocationBuilder.THREDDS_ONLINE.ID,"Thredds Online Resources","Online reousrce template for thredds resources","http://some.place.org/theTemplate", new ArrayList())); + return new TemplateCollection(descriptors); + } + + private static MetadataReport getReport(){ + return new MetadataReport("theUUID", 12335l, Collections.singleton(TemplateInvocationBuilder.THREDDS_ONLINE.ID)); + } + + private static GeoServerDefinition getGSDefinition() { + GeoServerDefinition toReturn=new GeoServerDefinition(); + toReturn.setAdminPassword("*****"); + toReturn.setDescription("Dummy geoserver"); + toReturn.setHostname("some.place.org"); + toReturn.setMajorVersion((short)2); + toReturn.setMinorVersion((short)10); + toReturn.setReleaseVersion((short)3); + toReturn.setName("My GeoServer"); + toReturn.addWorkspace(new WorkspaceDefinition("myWS", ACCESS_TYPE.PUBLIC)); + toReturn.addProperty("my own application property", "some value"); + return toReturn; + + } + + private static ApplicationProfile getBasicProfile() { + HashMap props=new HashMap(); + props.put(ApplicationProfile.Properties.GEONETWORK_CATEGORY,"blah"); + props.put(ApplicationProfile.Properties.GEOSERVER_STORAGE,"blahBlah"); + + return new ApplicationProfile("Fake Class", "Fake Name", props); + } + + + private static GeoNetworkServiceDefinition getGNDefinition() { + GeoNetworkServiceDefinition def=new GeoNetworkServiceDefinition(); + def.setAdminPassword("admin"); + def.setDescription("Connector for GN 3.0.4 development instance"); + def.setHostname("geonetwork-sdi.dev.d4science.org"); + def.setMajorVersion((short)3); + def.setMinorVersion((short)0); + def.setReleaseVersion((short)4); + def.setName("GN 3.0.4 connector"); + def.setPriority(100); + ParameterType[] params=new ParameterType[] { + new ParameterType("suffixes","1,2"), + //devNext Manually configured + new ParameterType("scope1","devNext"), + new ParameterType("scopeUser1","devNext_context"), + new ParameterType("scopePwd1","123456"), + new ParameterType("ckanUser1","devNext_ckan"), + new ParameterType("scopePwd1","987456"), + new ParameterType("mngUser1","devNext_manager"), + new ParameterType("mngPwd1","741852"), + new ParameterType("default1","1"), + new ParameterType("public1","1"), + new ParameterType("confidential1","1"), + new ParameterType("private1","1"), + //NextNext + new ParameterType("scope2","NextNext"), + new ParameterType("scopeUser2","nextNext_context"), + new ParameterType("scopePwd2","456789"), + new ParameterType("ckanUser2","nextNext_ckan"), + new ParameterType("scopePwd2","123789"), + new ParameterType("mngUser2","nextNext_manager"), + new ParameterType("mngPwd2","963852"), + new ParameterType("default2","1"), + new ParameterType("public2","1"), + new ParameterType("confidential2","1"), + new ParameterType("private2","1"), + }; + def.setProperties(new ArrayList(Arrays.asList(params))); + return def; + } + private static ErrorMessage getError(){ + ErrorMessage error=new ErrorMessage(); + error.setCode(500); + error.setDeveloperMessage("Develop it better!"); + error.setMessage("You didn't see anything"); + error.setLink("www.sto.ca.z.z.o.org"); + return error; + } + + + private T copy(T obj) throws IOException { + return (T) mapper.readValue(marshal(obj), obj.getClass()); + } + +}