created the common component

This commit is contained in:
Francesco Mangiacrapa 2020-12-01 15:53:44 +01:00
commit 04dc075827
24 changed files with 1529 additions and 0 deletions

38
.classpath Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/bin/
/target/

29
.project Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>geoportal-data-common</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.8"/>
</faceted-project>

9
CHANGELOG.md Normal file
View File

@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.0-SNAPSHOT] - 2020-12-01
First release

311
LICENSE.md Normal file
View File

@ -0,0 +1,311 @@
#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 Licensees 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

55
README.md Normal file
View File

@ -0,0 +1,55 @@
# GeoPortal Data Common
GeoPortal Data Common is common library used by GUI components developed for GeoNA
## Built With
* [OpenJDK](https://openjdk.java.net/) - The JDK used
* [Maven](https://maven.apache.org/) - Dependency Management
## Documentation
N/A
## Change log
See the [Releases](https://code-repo.d4science.org/gCubeSystem/geoportal-data-common/releases)
## Authors
* **Francesco Mangiacrapa** ([ORCID](https://orcid.org/0000-0002-6528-664X)) Computer Scientist at [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
## 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);
- EUBrazilOpenBio (grant no. 288754);
- iMarine(grant no. 283644).
- the H2020 research and innovation programme
- BlueBRIDGE (grant no. 675680);
- EGIEngage (grant no. 654142);
- ENVRIplus (grant no. 654182);
- PARTHENOS (grant no. 654119);
- SoBigData (grant no. 654024);
- DESIRA (grant no. 818194);
- ARIADNEplus (grant no. 823914);
- RISIS2 (grant no. 824091);
- PerformFish (grant no. 727610);
- AGINFRAplus (grant no. 731001).

30
descriptor.xml Normal file
View File

@ -0,0 +1,30 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README.md</include>
<include>LICENSE.md</include>
<include>profile.xml</include>
<include>CHANGELOG.md</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

134
pom.xml Normal file
View File

@ -0,0 +1,134 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
</parent>
<groupId>org.gcube.application</groupId>
<artifactId>geoportal-data-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<developers>
<developer>
<name>Francesco Mangiacrapa</name>
<email>francesco.mangiacrapa@isti.cnr.it</email>
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>1.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- FWS -->
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<scope>provided</scope>
</dependency>
<!-- END FWS -->
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-url-shortener</artifactId>
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<!-- JUNIT -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<!-- <finalName>${artifactId}</finalName> -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

25
profile.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Portlet</Type>
<Profile>
<Description>${project.description}</Description>
<Class>Application</Class>
<Name>${project.artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${project.artifactId}</Name>
<Description>${project.description}</Description>
<MavenCoordinates>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</MavenCoordinates>
<Files>
<File>${project.build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

View File

@ -0,0 +1,203 @@
package org.gcube.application;
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.StringReader;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.gcube.application.shared.GeoNaDataViewerProfile;
import org.gcube.application.shared.LayerItem;
import org.gcube.application.shared.exception.ApplicationProfileNotFoundException;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/**
* The Class GeoNaViewerProfileReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 12, 2020
*/
public class GeoNaDataViewerProfileReader {
private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body";
/**
*
*/
public static final String SECONDARY_TYPE = "ApplicationProfile";
public static final String WORKSPACE_EXPLORER_APP_NAME = "GeoNa-Viewer-Profile";
private Logger logger = LoggerFactory.getLogger(GeoNaDataViewerProfileReader.class);
private String secondaryType;
private String scope;
private String appID;
/**
* Instantiates a new application profile reader.
*
* @param appID the app id
*/
public GeoNaDataViewerProfileReader(String appID) {
this.appID = appID;
this.secondaryType = SECONDARY_TYPE;
this.scope = ScopeProvider.instance.get();
}
/**
* Read profile from infrastrucure.
*
* @return the map
*/
public GeoNaDataViewerProfile readProfileFromInfrastrucure() throws Exception {
String queryString = getGcubeGenericQueryString(secondaryType, appID);
logger.info("Scope "+scope+", trying to perform query: "+queryString);
try {
if (scope == null)
throw new Exception("Scope is null, set scope into ScopeProvider");
GeoNaDataViewerProfile profile = new GeoNaDataViewerProfile();
logger.info("Trying to fetch ApplicationProfile in the scope: " + scope + ", SecondaryType: "
+ secondaryType + ", AppId: " + appID);
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType
+ ", AppId: " + appID + " is not registered in the scope: " + scope);
else {
String elem = appProfile.get(0);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(elem)));
XPathHelper helper = new XPathHelper(doc.getDocumentElement());
List<String> currValue = null;
String xPathExp = RESOURCE_PROFILE_BODY+"/RestrictedPortletURL/text()";
currValue = helper.evaluate(xPathExp);
if (currValue != null && currValue.size() > 0) {
profile.setRestrictedPortletURL(currValue.get(0));
}else
throw new Exception("I'm not able to read the path: "+xPathExp);
xPathExp = RESOURCE_PROFILE_BODY+"/OpenPortletURL/text()";
currValue = helper.evaluate(xPathExp);
if (currValue != null && currValue.size() > 0) {
profile.setOpenPortletURL(currValue.get(0));
}else
throw new Exception("I'm not able to read the path: "+xPathExp);
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.compile("/Resource/Profile/Body/AvailableLayers/Layer")
.evaluate(doc, XPathConstants.NODESET);
Map<String, LayerItem> mapLayers = new HashMap<String, LayerItem>(nodeList.getLength());
for (int i = 0; i < nodeList.getLength(); i++) {
Node layerNode = nodeList.item(i);
if (layerNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) layerNode;
String layerType = eElement.getElementsByTagName("Type").item(0).getTextContent();
String wmsLink = eElement.getElementsByTagName("WMSLink").item(0).getTextContent();
String decodedURL = URLDecoder.decode(wmsLink, "UTF-8");
LayerItem layer = new LayerItem();
layer.setWmsLink(decodedURL);
mapLayers.put(layerType.toLowerCase(), layer);
}
}
profile.setMapLayers(mapLayers);
logger.info("returning: "+profile);
return profile;
}
} catch (Exception e) {
logger.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType "
+ WORKSPACE_EXPLORER_APP_NAME + " from scope " + scope, e);
return null;
} finally {
}
}
/**
* Gets the gcube generic query string.
*
* @param secondaryType the secondary type
* @param appId the app id
* @return the gcube generic query string
*/
public static String getGcubeGenericQueryString(String secondaryType, String appId) {
return "for $profile in collection('/db/Profiles/GenericResource')//Resource "
+ "where $profile/Profile/SecondaryType/string() eq '" + secondaryType
+ "' and $profile/Profile/Body/AppId/string() " + " eq '" + appId + "'" + "return $profile";
}
/**
* Gets the secondary type.
*
* @return the secondary type
*/
public String getSecondaryType() {
return secondaryType;
}
/**
* Gets the scope.
*
* @return the scope
*/
public String getScope() {
return scope;
}
@Override
public String toString() {
return "GeoNaViewerProfileReader [secondaryType=" + secondaryType + ", scope=" + scope + ", appID=" + appID
+ "]";
}
/*
public static void main(String[] args) throws Exception {
ScopeProvider.instance.set("/gcube/devNext/NextNext");
GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader("geoportal-data-viewer-app");
GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure();
System.out.println(profile.getRestrictedPortletURL());
System.out.println(profile.getOpenPortletURL());
if(profile.getMapLayers()!=null) {
for (String type : profile.getMapLayers().keySet()) {
System.out.println("key: "+type+", value: "+profile.getMapLayers().get(type));
}
}
}*/
}

View File

@ -0,0 +1,140 @@
package org.gcube.application;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import org.gcube.application.shared.GeoNaDataViewerProfile;
import org.gcube.application.shared.GeoNaItemRef;
import org.gcube.application.shared.PublicLink;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class GeoportalCommon.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 1, 2020
*/
public class GeoportalCommon {
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(GeoportalCommon.class);
/**
* Gets the public links for.
*
* @param item the item
* @return the public links for
* @throws Exception the exception
*/
public GeoNaItemRef getPublicLinksFor(GeoNaItemRef item) throws Exception {
LOG.info("getPublicLinksFor called for: " + item);
try {
if (item == null)
throw new Exception("Bad request, the item is null");
if (item.getItemId() == null)
throw new Exception("Bad request, the item id is null");
if (item.getItemType() == null)
throw new Exception("Bad request, the item type is null");
GeoNaDataViewerProfile geonaDataProfile = getGeoNaDataViewProfile(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
// Restricted Link
String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
GeoportalCommonConstants.GET_GEONA_ITEM_ID, item.getItemId(),
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, item.getItemType());
String shortUrl = getShortUrl(link);
item.setRestrictedLink(new PublicLink(link, shortUrl));
// Open Link
link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(),
GeoportalCommonConstants.GET_GEONA_ITEM_ID, item.getItemId(),
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, item.getItemType());
shortUrl = getShortUrl(link);
item.setOpenLink(new PublicLink(link, shortUrl));
LOG.info("returning: " + item);
return item;
} catch (Exception e) {
LOG.error("Error on getPublicLinksFor for: " + item, e);
throw new Exception("Share link not available for this item. Try later or contact the support. Error: "
+ e.getMessage());
}
}
/**
* Gets the GeoNaData Viewer Profile
*
* @param appID if null or empty uses the default appID that is {@link GeoportalCommonConstants#GEOPORTAL_DATA_VIEWER_APP}
* @return the GeoNaData Viewer Profile
* @throws Exception the exception
*/
public GeoNaDataViewerProfile getGeoNaDataViewProfile(String appID) throws Exception {
LOG.info("getGeoNaDataViewProfile called");
if(appID==null || appID.isEmpty())
appID = GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP;
GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader(appID);
GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure();
LOG.info("Returning profile: " + profile);
return profile;
}
/**
* Gets the short url.
*
* @param longUrl the long url
* @return the short url
* @throws Exception the exception
*/
public String getShortUrl(String longUrl) throws Exception {
LOG.info("getShortUrl called for " + longUrl);
if (longUrl == null)
return longUrl;
UrlShortener shortener = new UrlShortener();
try {
if (shortener != null && shortener.isAvailable()) {
String toShort = longUrl;
String[] splitted = toShort.split("\\?");
LOG.debug("Splitted long URL is: " + Arrays.asList(splitted));
String link = toShort;
if (splitted.length > 1) {
LOG.debug("Query string detected, encoding it...");
String encodedQuery = splitted[1];
try {
encodedQuery = URLEncoder.encode(splitted[1], "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
LOG.debug("encodedQuery is: " + encodedQuery);
link = String.format("%s?%s", splitted[0], encodedQuery);
}
return shortener.shorten(link);
}
return longUrl;
} catch (Exception e) {
LOG.error("Error on shortening the longURL " + longUrl, e);
return null;
}
}
}

View File

@ -0,0 +1,18 @@
package org.gcube.application;
/**
* The Class GeoportalCommonConstants.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 1, 2020
*/
public class GeoportalCommonConstants {
public static final String GET_GEONA_ITEM_TYPE = "git";
public static final String GET_GEONA_ITEM_ID = "gid";
public static final String GEOPORTAL_DATA_VIEWER_APP = "geoportal-data-viewer-app";
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='geoportaldatacommon'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
</module>

View File

@ -0,0 +1,105 @@
package org.gcube.application.shared;
import java.io.Serializable;
import java.util.Map;
/**
* The Class GeoNaDataViewerProfile.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 13, 2020
*/
public class GeoNaDataViewerProfile implements Serializable{
/**
*
*/
private static final long serialVersionUID = 2968334957258327191L;
private String restrictedPortletURL;
private String openPortletURL;
//the key is the layer type
private Map<String, LayerItem> mapLayers;
/**
* Instantiates a new geo na data viewer profile.
*/
public GeoNaDataViewerProfile() {
}
/**
* Gets the restricted portlet URL.
*
* @return the restricted portlet URL
*/
public String getRestrictedPortletURL() {
return restrictedPortletURL;
}
/**
* Sets the restricted portlet URL.
*
* @param restrictedPortletURL the new restricted portlet URL
*/
public void setRestrictedPortletURL(String restrictedPortletURL) {
this.restrictedPortletURL = restrictedPortletURL;
}
/**
* Gets the open portlet URL.
*
* @return the open portlet URL
*/
public String getOpenPortletURL() {
return openPortletURL;
}
/**
* Sets the open portlet URL.
*
* @param openPortletURL the new open portlet URL
*/
public void setOpenPortletURL(String openPortletURL) {
this.openPortletURL = openPortletURL;
}
/**
* Gets the map layers.
*
* @return the map layers
*/
public Map<String, LayerItem> getMapLayers() {
return mapLayers;
}
/**
* Sets the map layers.
*
* @param mapLayers the map layers
*/
public void setMapLayers(Map<String, LayerItem> mapLayers) {
this.mapLayers = mapLayers;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoNaDataViewerProfile [restrictedPortletURL=");
builder.append(restrictedPortletURL);
builder.append(", openPortletURL=");
builder.append(openPortletURL);
builder.append(", mapLayers=");
builder.append(mapLayers);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,162 @@
package org.gcube.application.shared;
import java.io.Serializable;
/**
* The Class GeoNaItemRef.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 1, 2020
*/
public class GeoNaItemRef implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7021431511279022193L;
private Long itemId;
private String itemType;
private String itemName;
private PublicLink restrictedLink;
private PublicLink openLink;
/**
* Instantiates a new geo na object.
*/
public GeoNaItemRef() {
}
/**
* Instantiates a new geo na object.
*
* @param itemId the item id
* @param itemType the item type
*/
public GeoNaItemRef(Long itemId, String itemType) {
super();
this.itemId = itemId;
this.itemType = itemType;
}
/**
* Gets the item id.
*
* @return the item id
*/
public Long getItemId() {
return itemId;
}
/**
* Sets the item id.
*
* @param itemId the new item id
*/
public void setItemId(Long itemId) {
this.itemId = itemId;
}
/**
* Gets the item type.
*
* @return the item type
*/
public String getItemType() {
return itemType;
}
/**
* Sets the item type.
*
* @param itemType the new item type
*/
public void setItemType(String itemType) {
this.itemType = itemType;
}
/**
* Gets the item name.
*
* @return the item name
*/
public String getItemName() {
return itemName;
}
/**
* Sets the item name.
*
* @param itemName the new item name
*/
public void setItemName(String itemName) {
this.itemName = itemName;
}
/**
* Gets the restricted link.
*
* @return the restricted link
*/
public PublicLink getRestrictedLink() {
return restrictedLink;
}
/**
* Sets the restricted link.
*
* @param restrictedLink the new restricted link
*/
public void setRestrictedLink(PublicLink restrictedLink) {
this.restrictedLink = restrictedLink;
}
/**
* Gets the open link.
*
* @return the open link
*/
public PublicLink getOpenLink() {
return openLink;
}
/**
* Sets the open link.
*
* @param openLink the new open link
*/
public void setOpenLink(PublicLink openLink) {
this.openLink = openLink;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoNaItemRef [itemId=");
builder.append(itemId);
builder.append(", itemType=");
builder.append(itemType);
builder.append(", itemName=");
builder.append(itemName);
builder.append(", restrictedLink=");
builder.append(restrictedLink);
builder.append(", openLink=");
builder.append(openLink);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,78 @@
package org.gcube.application.shared;
import java.io.Serializable;
/**
* The Class LayerItem.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 1, 2020
*/
public class LayerItem implements Serializable {
/**
*
*/
private static final long serialVersionUID = 3261972168416698955L;
/** The name. */
private String name;
/** The url. */
private String wmsLink;
private String geonaType;
public LayerItem() {
}
public LayerItem(String name, String wmsLink, String geonaType) {
super();
this.name = name;
this.wmsLink = wmsLink;
this.geonaType = geonaType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWmsLink() {
return wmsLink;
}
public void setWmsLink(String wmsLink) {
this.wmsLink = wmsLink;
}
public String getGeonaType() {
return geonaType;
}
public void setGeonaType(String geonaType) {
this.geonaType = geonaType;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("LayerItem [name=");
builder.append(name);
builder.append(", wmsLink=");
builder.append(wmsLink);
builder.append(", geonaType=");
builder.append(geonaType);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,95 @@
/**
*
*/
package org.gcube.application.shared;
import java.io.Serializable;
/**
* The Class PublicLink.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
* Sep 13, 2016
*/
public class PublicLink implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8157172818802297440L;
private String completeURL;
private String shortURL;
/**
* Instantiates a new public link.
*/
public PublicLink() {
}
/**
* Instantiates a new public link.
*
* @param completeURL the complete url
* @param shortURL the short url
*/
public PublicLink(String completeURL, String shortURL) {
super();
this.completeURL = completeURL;
this.shortURL = shortURL;
}
/**
* Gets the complete url.
*
* @return the completeURL
*/
public String getCompleteURL() {
return completeURL;
}
/**
* Gets the short url.
*
* @return the shortURL
*/
public String getShortURL() {
return shortURL;
}
/**
* Sets the complete url.
*
* @param completeURL the completeURL to set
*/
public void setCompleteURL(String completeURL) {
this.completeURL = completeURL;
}
/**
* Sets the short url.
*
* @param shortURL the shortURL to set
*/
public void setShortURL(String shortURL) {
this.shortURL = shortURL;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PublicLink [completeURL=");
builder.append(completeURL);
builder.append(", shortURL=");
builder.append(shortURL);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,20 @@
package org.gcube.application.shared.exception;
/**
* The Class ApplicationProfileException.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
* Sep 6, 2016
*/
@SuppressWarnings("serial")
public class ApplicationProfileNotFoundException extends Exception {
/**
* Instantiates a new application profile exception.
*
* @param message the message
*/
public ApplicationProfileNotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='geoportaldatacommon'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
</module>

View File

@ -0,0 +1,28 @@
package org.gcube.application;
import org.gcube.application.shared.GeoNaDataViewerProfile;
import org.gcube.common.scope.api.ScopeProvider;
public class TestGeonaReader {
private static String scope ="/gcube/devsec/devVRE";
public static void main(String[] args) throws Exception {
getGeoNaDataViewProfile();
}
public static GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception{
System.out.println("getGeoNaDataViewProfile called");
ScopeProvider.instance.set(scope);
GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader("geoportal-data-viewer-app");
GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure();
System.out.println("Returning profile: "+profile);
return profile;
}
}

6
src/test/resources/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/devNext.gcubekey
/devsec.gcubekey
/gcube.gcubekey
/log4j.properties
/pred4s.gcubekey
/preprod.gcubekey