Compare commits

..

No commits in common. "master" and "feature/18038" have entirely different histories.

105 changed files with 1523 additions and 8916 deletions

View File

@ -8,20 +8,15 @@
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> <classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes> <attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
<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> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
@ -32,7 +27,6 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>

View File

@ -30,11 +30,6 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>

View File

@ -1,3 +1,4 @@
#Tue Mar 12 14:16:46 CET 2013
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8 encoding//src/main/resources=UTF-8

View File

@ -1,11 +1,9 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 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.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 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.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,529 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="uri-resolver">
<wb-module deploy-name="uri-resolver-2.10.0">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="geoportal-client-1.2.2.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-client/geoportal-client"> <dependent-module archiveName="ckan-util-library-2.12.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="geoportal-common-1.1.1.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-common/geoportal-common">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="uri-resolver"/> <property name="context-root" value="uri-resolver"/>
<property name="java-output-path" value="/uri-resolver/target/classes"/> <property name="java-output-path" value="/uri-resolver/target/classes"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

View File

@ -2,7 +2,7 @@
<faceted-project> <faceted-project>
<fixed facet="wst.jsdt.web"/> <fixed facet="wst.jsdt.web"/>
<installed facet="wst.jsdt.web" version="1.0"/> <installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.jaxrs" version="2.0"/> <installed facet="jst.jaxrs" version="2.0"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="java" version="1.8"/>
</faceted-project> </faceted-project>

View File

@ -1,2 +0,0 @@
boot.validation.initialized=true
eclipse.preferences.version=1

View File

@ -1,259 +0,0 @@
# Changelog for uri-resolver
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).
## [v2.10.0]
- GeoPortal-Resolver enhancement: implemented share link towards Geoportal Data-Entry facility [#27135]
- Added Geoportal Exporter as PDF [#27274]
- Migrated to `catalogue-util-library` [#27423]
- Included new SHUB client library [#27944]
- Moved to `gcube-smartgears-bom 2.5.1{-SNAPSHOT}` [#28026]
- Bug fixing StorageID resolver [#28276]
- Added HealthCheckResponse via `microprofile-health-api` (see https://microprofile.io/specifications/microprofile-health/)
## [v2.9.0]
- GeoPortal-Resolver implemented [#24792]
## [v2.8.1] - 2022-06-13
**New**
- [#23156] CatalogueResolver enhanced to manage (create/resolve) an input query string
**Bug Fixing**
- [#23495] Removed the check on the gcube token stored in thread local. The working context of VRE will be checked from ScopeProvider
## [v2.7.3-SNAPSHOT] - 2022-04-27
**Bug Fixing**
- [#23213] Fixed NoClassDefFoundError: org/geotoolkit/xml/XML
## [v2.7.2] - 2022-04-06
**New**
- [#23113] Implemented a new legacy-token resolver interface
- [#23049] Integrated Enunciate engine for Java Web service API (https://github.com/stoicflame/enunciate/)
- [#20743] Integrated JavaMelody
- [#23105] Added D4Science brand in the APIs Documentation pages
- [#22757] Moved to storagehub-client-library 2.0.0[-SNAPSHOT]
**Bug Fixing**
- [#20743] Integration with javamelody
## [v2.6.1] - 2022-01-17
**New features**
- [#21411] add forceClose method from storage-manager, used for closing mongodb connections related to the old https urls (managed by storage-manager)
- migrated to storage-manager3
**Bug fixes**
- [#21560] Checking the bug fix done
- Moved to gcube-smartgears-bom.2.1.0
## [v2.5.0] - 2021-04-08
**New features**
[#20993] Supported new resource "Wekeo Interface" - gettoken.
**Bug fixes**
[#21093] StorageHubResolver HEAD request does not support Content-Length
## [v2.4.1] - 2021-01-13
**Bug Fixes**
[#19942] Fixing master build fails
## [v2-4-0] [r4-24-0]- 2020-06-18
**New Features**
[#18967] Extend the URIResolver behaviour to deal with Catalogue items belonging to Dismissed VREs
## [v2-3-2] [r4-23-0]- 2020-05-18
[#19288] Release the URI-Resolver to integrate the patched Uri-Resolver-Manager
## [2-3-1] - [2020-04-06]
[Bug #18951] URI-Resolver: redirect to catalogue public item must manage the case 'catalogue-'
## [2-2-0] - [2019-11-12]
[Feature #18038] Catalogue Resolver: resolve a public ITEM URL to the public VRE Catalogue (if available)
## [2-2-0] - [2019-10-04]
[Feature #17630] Support parametric Content-Disposition
[Bug #17650] Bug #17650: URI-Resolver: HEAD request to StorageID link does not return the "content-disposition
## [2-1-1] - [2019-07-16]
[Incident #17180] Bug fixes
## [2-1-0] - [2019-03-14]
[Feature #16263] Added new dataminer-invocation-model
[Task #16296] Bug fixes
[Task #16471] Tested Catalogue Resolver backward compatibility
[Incident #16671] Fixing Catalogue Resolver in case of working with INFRASTRUCTURE and VO scope
[Incident #16713] GN harvesting from CKAN does not work properly
## [2-0-0] - [2018-10-23]
[Task #12740] Developed as web-service by using jersey framework
[Task #12294] Created the resolver 'parthenosregistry'
[Task #13006] Fixing issue on resolving public Catalogues
[Task #12969] Create the new resolvers: "Analitycs" and "Knime"
[Feature #13072] Provide Metadata of a public link
## [1-15-0] - [2018-07-20]
[Task #10070] Catalogue Resolver enhancement: resolve public/private items to public/private catalogue
## [1-14-0] - [2017-09-06]
[Task #9538] Geonetwork-Uri Resolver enhancement: provide new filters and improve current ones
## [1-13-0] - [2017-07-03]
[Feature #9108] Edit the GenericResource (ApplicationProfile-Gis Viewer Application)
## [1-12-0] - [2017-05-15]
[Feature #8494] Remove GeoServices query from URI-Resolver
## [1-11-0] - [2017-03-22]
[Feature #7350] GeoExplorer Resolver: resolve a GeoExplorer Link
[Task #7626] Fix issue on set/reset scope
[Task #7807] Provide a check for HAProxy
## [1-10-0] - [2017-02-28]
[Task #6492] Catalogue Resolver: "improve"/"build better" public URLs to products
[Task #6952] Catalogue Resolver: update on the fly the Application Profile for VRE's used to resolve Product URL
## [1-9-0] - [2016-12-20]
[Task #6119] Provide CatalogueResolver: get/resolve a link to a CKAN Entity
[Task #6262] Catalogue Resolver: get/resolve a direct link
## [1-8-0] - [2016-10-26]
Removed scope provider from several resolver
## [1-7-0] - [2016-06-09]
[Feature #4207] Uri Resolver upgrade: it must support new Geonetwork Manager
[Task #4250] Geonetwork Resolver upgrade: it must return only "private" Metadata Ids for CKAN harversting
## [1-6-0] - [2016-05-16]
[Task #3135] Uri Resolver enhancements: create a Geonetwork Resolver
[Feature #4000] URI Resolver - must support HEAD request
## [1-5-0] - [2016-03-17]
[Feature #2008] Updated the method to resolve gCube Storage ID
[Feature #1925] Added class UriResolverRewriteFilter to filter the different public link types, see: #1959
[gCube - Support #2695] Uri Resolver: patch to fix old bug in HL renaming files
## [1-4-0] - [2015-09-21]
[Feature #416] Added code to read fileName and content-type (mime type) from Storage
## [1-3-0] - [2015-04-28]
Fixed bug on encoding
Added new resolver: Storage ID Resolver
## [1-2-0] - [2014-10-20]
Integrated Gis-Resolver
## [1-1-0] - [2013-07-09]
Added fileName and contentType parameters to SMP URI resolver
## [1-0-0] - [2013-04-19]
first release

View File

@ -1,8 +1,6 @@
# gCube URI Resolver # gCube URI Resolver
The URI Resolver is a RESTful service which gives access via HTTP(s) to different gCube Resolver services and gCube Applications. The URI Resolver is a RESTful service which gives access via HTTP(s) to different gCube Resolver services and gCube Applications
The URI Resolver production service is available at [D4Science URI Resolver](https://data.d4science.org/)
## Built With ## Built With
@ -13,8 +11,6 @@ The URI Resolver production service is available at [D4Science URI Resolver](htt
You can find the URI Resolver documentation at [URI Resolver Wiki Page](https://wiki.gcube-system.org/gcube/URI_Resolver) You can find the URI Resolver documentation at [URI Resolver Wiki Page](https://wiki.gcube-system.org/gcube/URI_Resolver)
The API documentation accessible by this [link](https://wiki.gcube-system.org/gcube/URI_Resolver#Instances) is provided by [Enunciate](https://github.com/stoicflame/enunciate/)
## Change log ## Change log
See the [URI Resolver Releases](https://code-repo.d4science.org/gCubeSystem/uri-resolver/releases) See the [URI Resolver Releases](https://code-repo.d4science.org/gCubeSystem/uri-resolver/releases)

135
changelog.xml Normal file
View File

@ -0,0 +1,135 @@
<ReleaseNotes>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-2-0" date="2019-11-12">
<Change>[Feature #18038] Catalogue Resolver: resolve a public ITEM URL to the public VRE Catalogue (if available)
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-2-0" date="2019-10-04">
<Change>[Feature #17630] Support parametric Content-Disposition
</Change>
<Change>[Bug #17650] Bug #17650: URI-Resolver: HEAD request to
StorageID link does not return the "content-disposition
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-1-1" date="2019-07-16">
<Change>[Incident #17180] Bug fixes
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-1-0" date="2019-03-14">
<Change>[Feature #16263] Added new dataminer-invocation-model
</Change>
<Change>[Task #16296] Bug fixes
</Change>
<Change>[Task #16471] Tested Catalogue Resolver backward compatibility
</Change>
<Change>[Incident #16671] Fixing Catalogue Resolver in case of working
with INFRASTRUCTURE and VO scope
</Change>
<Change>[Incident #16713] GN harvesting from CKAN does not work
properly
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-0-0" date="2018-10-23">
<Change>[Task #12740] Developed as web-service by using jersey
framework
</Change>
<Change>[Task #12294] Created the resolver 'parthenosregistry'
</Change>
<Change>[Task #13006] Fixing issue on resolving public Catalogues
</Change>
<Change>[Task #12969] Create the new resolvers: "Analitycs" and
"Knime"
</Change>
<Change>
[Feature #13072] Provide Metadata of a public link
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-15-0" date="2018-07-20">
<Change>[Task #10070] Catalogue Resolver enhancement: resolve
public/private items to public/private catalogue
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-14-0" date="2017-09-06">
<Change>[Task #9538] Geonetwork-Uri Resolver enhancement: provide new
filters and improve current ones
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-13-0" date="2017-07-03">
<Change>[Feature #9108] Edit the GenericResource
(ApplicationProfile-Gis Viewer Application)
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-12-0" date="2017-05-15">
<Change>[Feature #8494] Remove GeoServices query from URI-Resolver
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-11-0" date="2017-03-22">
<Change>[Feature #7350] GeoExplorer Resolver: resolve a GeoExplorer
Link
</Change>
<Change>[Task #7626] Fix issue on set/reset scope
</Change>
<Change>[Task #7807] Provide a check for HAProxy</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-10-0" date="2017-02-28">
<Change>[Task #6492] Catalogue Resolver: "improve"/"build better"
public URLs to products
</Change>
<Change>[Task #6952] Catalogue Resolver: update on the fly the
Application Profile for VRE's used to resolve Product URL
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-9-0" date="2016-12-20">
<Change>[Task #6119] Provide CatalogueResolver: get/resolve a link to
a CKAN Entity
</Change>
<Change>[Task #6262] Catalogue Resolver: get/resolve a direct link
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-8-0" date="2016-10-26">
<Change>Removed scope provider from several resolver</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-7-0" date="2016-06-09">
<Change>[Feature #4207] Uri Resolver upgrade: it must support new
Geonetwork Manager
</Change>
<Change>[Task #4250] Geonetwork Resolver upgrade: it must return only
"private" Metadata Ids for CKAN harversting
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-6-0" date="2016-05-16">
<Change>[Task #3135] Uri Resolver enhancements: create a Geonetwork
Resolver
</Change>
<Change>[Feature #4000] URI Resolver - must support HEAD request
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-5-0" date="2016-03-17">
<Change>[Feature #2008] Updated the method to resolve gCube Storage ID
</Change>
<Change>[Feature #1925] Added class UriResolverRewriteFilter to filter
the different public link types, see: #1959
</Change>
<Change>[gCube - Support #2695] Uri Resolver: patch to fix old bug in
HL renaming files
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-4-0" date="2015-09-21">
<Change>[Feature #416] Added code to read fileName and content-type
(mime type) from Storage
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-3-0" date="2015-04-28">
<Change>Fixed bug on encoding</Change>
<Change>Added new resolver: Storage ID Resolver</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-2-0" date="2014-10-20">
<Change>Integrated Gis-Resolver</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-1-0" date="2013-07-09">
<Change>Added fileName and contentType parameters to SMP URI resolver
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-0-0" date="2013-04-19">
<Change>first release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -15,7 +15,7 @@
<include>README.md</include> <include>README.md</include>
<include>LICENSE.md</include> <include>LICENSE.md</include>
<include>profile.xml</include> <include>profile.xml</include>
<include>CHANGELOG.md</include> <include>changelog.xml</include>
</includes> </includes>
<fileMode>755</fileMode> <fileMode>755</fileMode>
<filtered>true</filtered> <filtered>true</filtered>

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<enunciate
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.14.0.xsd">
<api-classes>
<exclude
pattern="org.gcube.datatransfer.resolver.services.DocsGenerator" />
<exclude
pattern="org.gcube.datatransfer.resolver.services.UriResolverIndex" />
<exclude
pattern="org.gcube.datatransfer.resolver.services.UriResolverInfo" />
<exclude
pattern="org.gcube.datatransfer.resolver.services.OatResolver" />
<exclude
pattern="org.gcube.datatransfer.resolver.services.tobackward.BackCatalogueResolver" />
<exclude
pattern="org.gcube.datatransfer.resolver.services.tobackward.BackUriResolverCatalogueResolver" />
<exclude pattern="org.geotoolkit.internal.jaxb.referencing.*" />
<exclude pattern="org.opengis.metadata.*" />
</api-classes>
<modules>
<gwt-json-overlay disabled="true" />
<php-json-client disabled="true" />
<ruby-json-client disabled="true" />
<java-json-client disabled="true" />
<javascript-client disabled="true" />
<docs docsDir="${project.build.directory}" docsSubdir="docs" />
<!-- REPLACE THE ${project.artifactId} WITH YOUR APPLICATION NAME. E.g.
/gcat, /uri-resolver /> if the ${project.artifactId} is not equal to YOUR
APPLICATION NAME -->
<!-- <swagger basePath="${project.artifactId}" /> -->
<docs
freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt">
<additional-css
file="css/d4science_enunciate_custom.css" />
</docs>
</modules>
</enunciate>

245
pom.xml
View File

@ -5,13 +5,13 @@
<parent> <parent>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<version>1.2.0</version> <version>1.1.0</version>
</parent> </parent>
<groupId>org.gcube.data.transfer</groupId> <groupId>org.gcube.data.transfer</groupId>
<artifactId>uri-resolver</artifactId> <artifactId>uri-resolver</artifactId>
<version>2.10.0</version> <version>2.3.0-SNAPSHOT</version>
<packaging>war</packaging> <packaging>war</packaging>
<description>The URI Resolver is an HTTP URI resolver implemented as a REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description> <description>The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description>
<scm> <scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection> <connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
@ -19,62 +19,25 @@
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url> <url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm> </scm>
<profiles>
<!-- PROD profile -->
<profile>
<id>uri-resolver-release-profile</id>
<activation>
<property>
<name>Release</name>
</property>
</activation>
<properties> <properties>
<!-- <gcube-bom>2.4.0</gcube-bom> --> <jersey.version>2.24.1</jersey.version>
<gcube-smartgears-bom-version>2.5.1</gcube-smartgears-bom-version> <maven.compiler.source>1.7</maven.compiler.source>
<authorization-utils-range>[2.0.0, 3.0.0-SNAPSHOT)</authorization-utils-range>
</properties>
</profile>
<!-- DEV profile -->
<profile>
<id>uri-resolver-snapshot-profile</id>
<activation>
<property>
<name>!Release</name>
</property>
</activation>
<properties>
<!-- <gcube-bom>2.4.1-SNAPSHOT</gcube-bom> -->
<gcube-smartgears-bom-version>2.5.1-SNAPSHOT</gcube-smartgears-bom-version>
<authorization-utils-range>[2.0.0, 3.0.0-SNAPSHOT)</authorization-utils-range>
</properties>
</profile>
</profiles>
<properties>
<jersey.version>2.25.1</jersey.version>
<!-- Using 2.8.4 because storagehub-model.1.1.1 uses indirectly this version
via jsersey-media-json -->
<jackson.version>2.8.4</jackson.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<enunciate.version>2.14.0</enunciate.version> <!-- <additionalparam>-Xdoclint:none</additionalparam> -->
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId> <artifactId>maven-smartgears-bom</artifactId>
<version>${gcube-smartgears-bom-version}</version> <version>LATEST</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
@ -82,13 +45,6 @@
<artifactId>common-smartgears</artifactId> <artifactId>common-smartgears</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.microprofile.health</groupId>
<artifactId>microprofile-health-api</artifactId>
<version>4.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId> <artifactId>common-smartgears-app</artifactId>
@ -102,13 +58,13 @@
<dependency> <dependency>
<groupId>org.gcube.contentmanagement</groupId> <groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId> <artifactId>storage-manager-wrapper</artifactId>
<version>[3.0.0, 4.0.0-SNAPSHOT)</version> <version>[2.0.0, 3.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.contentmanagement</groupId> <groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId> <artifactId>storage-manager-core</artifactId>
<version>[3.0.0,4.0.0-SNAPSHOT)</version> <version>[2.0.0,3.0.0-SNAPSHOT)</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>slf4j-nop</artifactId> <artifactId>slf4j-nop</artifactId>
@ -120,39 +76,24 @@
<dependency> <dependency>
<groupId>org.gcube.data-publishing</groupId> <groupId>org.gcube.data-publishing</groupId>
<artifactId>storagehub-application-persistence</artifactId> <artifactId>storagehub-application-persistence</artifactId>
<version>[1.0.0, 3.0.0-SNAPSHOT)</version> <version>[1.0.0, 2.0.0-SNAPSHOT)</version>
<exclusions>
<exclusion>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.data.analysis</groupId> <groupId>org.gcube.data.analysis</groupId>
<artifactId>dataminer-invocation-model</artifactId> <artifactId>dataminer-invocation-model</artifactId>
<version>[1.0.0,2.0.0-SNAPSHOT)</version> <version>[0.0.1,1.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.infrastructure.detachedres</groupId>
<artifactId>detachedres-library</artifactId>
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<!-- TODO REMOVE THIS IMPORT -->
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId> <artifactId>gxHTTP</artifactId>
<version>${authorization-utils-range}</version> <scope>compile</scope>
</dependency> </dependency>
<dependency> <!-- //TO BE ADDED THE VERSION 18.0 <dependency> <groupId>com.google.guava</groupId>
<groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> -->
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
@ -173,6 +114,7 @@
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId> <artifactId>storagehub-client-library</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<dependency> <dependency>
@ -181,6 +123,7 @@
<version>${jersey.version}</version> <version>${jersey.version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.glassfish.jersey.core</groupId> <groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId> <artifactId>jersey-server</artifactId>
@ -188,58 +131,25 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- java melody -->
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-core</artifactId>
<version>1.82.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.interceptor/javax.interceptor-api -->
<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>1.2.2</version>
</dependency>
<!-- weld --> <!-- weld -->
<dependency> <dependency>
<groupId>javax.enterprise</groupId> <groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId> <artifactId>cdi-api</artifactId>
<version>2.0</version> <version>1.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss.weld.servlet</groupId> <groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId> <artifactId>weld-servlet</artifactId>
<version>3.1.0.Final</version> <version>2.2.10.Final</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss</groupId> <groupId>org.jboss</groupId>
<artifactId>jandex</artifactId> <artifactId>jandex</artifactId>
<version>2.2.2.Final</version> <version>1.2.2.Final</version>
</dependency> </dependency>
<!-- end weld -->
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
@ -254,46 +164,23 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- FOR BUILDING towards JDK_11 -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<!-- <version>2.3.0</version> -->
<scope>provided</scope>
</dependency>
<!-- FOR BUILDING towards JDK_11 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- <version>1.18.4</version> -->
<scope>provided</scope>
</dependency>
<!-- GIS RESOLVER DEPENDENCIES --> <!-- GIS RESOLVER DEPENDENCIES -->
<dependency> <dependency>
<groupId>org.gcube.spatial.data</groupId> <groupId>org.gcube.spatial.data</groupId>
<artifactId>geonetwork</artifactId> <artifactId>geonetwork</artifactId>
<version>[3.4.5, 4.0.0-SNAPSHOT)</version> <version>[3.0.0, 4.0.0-SNAPSHOT)</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- THIS ONE IS NOT A DIRECT DEPENDENCY OF URI-RESOLVER IT IS REQUIRED
TO BUILD -->
<dependency>
<groupId>org.opengis</groupId>
<artifactId>geoapi</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
<version>2.6</version> <version>2.6</version>
</dependency> </dependency>
<!-- DOM --> <!-- DOM -->
<dependency> <dependency>
<groupId>org.w3c</groupId> <groupId>org.w3c</groupId>
@ -303,45 +190,19 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.datacatalogue</groupId> <groupId>org.gcube.data-catalogue</groupId>
<artifactId>catalogue-util-library</artifactId> <artifactId>ckan-util-library</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version> <version>[2.0.0, 3.0.0-SNAPSHOT)</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- END GIS RESOLVER DEPENDENCIES --> <!-- END GIS RESOLVER DEPENDENCIES -->
<dependency>
<groupId>org.gcube.application</groupId>
<artifactId>geoportal-data-mapper</artifactId>
<version>[1.1.0, 2.0.0-SNAPSHOT)</version>
<!-- Excluding these beacuse geoportal uses [2-3] ranges conflicting with
[3-4] used by URI-Resolver -->
<exclusions>
<exclusion>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
</exclusion>
<exclusion>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version> <version>1.6.4</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
@ -375,6 +236,8 @@
</resource> </resource>
</resources> </resources>
<!-- <finalName>${artifactId}</finalName> -->
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
@ -383,51 +246,25 @@
<target>${maven.compiler.target}</target> <target>${maven.compiler.target}</target>
</configuration> </configuration>
</plugin> </plugin>
<!-- Enunciate Maven plugin -->
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>${enunciate.version}</version>
<configuration>
<!-- <docsDir>${project.build.directory}/docs</docsDir> -->
</configuration>
<executions>
<execution>
<id>assemble</id>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Copy Enunciate Docs -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<version>2.5</version> <configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions> <executions>
<execution> <execution>
<id>copy-enunciate-docs</id> <id>servicearchive</id>
<phase>process-resources</phase> <phase>install</phase>
<goals> <goals>
<goal>copy-resources</goal> <goal>single</goal>
</goals> </goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<targetPath>${project.build.directory}/${project.artifactId}-${project.version}/docs</targetPath>
<directory>${project.build.directory}/docs</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -18,8 +18,6 @@ public class UriResolver extends ResourceConfig {
// Register all resources present under the package. // Register all resources present under the package.
packages(CatalogueResolver.class.getPackage().getName(), RequestHandler.class.getPackage().getName(), BackCatalogueResolver.class.getPackage().getName()); packages(CatalogueResolver.class.getPackage().getName(), RequestHandler.class.getPackage().getName(), BackCatalogueResolver.class.getPackage().getName());
packages(DataMinerInvocation.class.getPackage().getName()); packages(DataMinerInvocation.class.getPackage().getName());
//
// register(JspMvcFeature.class);
// property(JspMvcFeature.TEMPLATE_BASE_PATH, "/WEB-INF/img");
} }
} }

View File

@ -11,15 +11,14 @@ import java.util.Set;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.glassfish.jersey.server.model.Resource; import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.server.model.ResourceMethod; import org.glassfish.jersey.server.model.ResourceMethod;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
/** /**
@ -193,9 +192,8 @@ public class UriResolverServices {
if(listResourcePath.isEmpty()){ if(listResourcePath.isEmpty()){
log.info("Reference to the List of Resources/Services is empty, creating it..."); log.info("Reference to the List of Resources/Services is empty, creating it...");
readResources(applicationClasses); readResources(applicationClasses);
List<String> listHardCodedResources = Arrays.asList(ConstantsResolver.resourcesHardCoded); log.info("Hard-Coding the resource/s: "+ConstantsResolver.resourcesHardCoded);
log.info("Hard-Coding the resource/s: "+listHardCodedResources); listResourcePath.addAll(Arrays.asList(ConstantsResolver.resourcesHardCoded));
listResourcePath.addAll(listHardCodedResources);
} }
return listResourcePath; return listResourcePath;

View File

@ -53,7 +53,7 @@ public class LoadingGNPublicLayerIDsInstanceCache {
RemovalListener<String, List<String>> removalListener = new RemovalListener<String, List<String>>() { RemovalListener<String, List<String>> removalListener = new RemovalListener<String, List<String>>() {
public void onRemoval(RemovalNotification<String, List<String>> removal) { public void onRemoval(RemovalNotification<String, List<String>> removal) {
logger.debug("cache expired"); logger.info("cache expired");
} }
}; };

View File

@ -46,7 +46,7 @@ public class LoadingGeoExplorerApplicationURLCache {
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() { RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
public void onRemoval(RemovalNotification<String, String> removal) { public void onRemoval(RemovalNotification<String, String> removal) {
logger.debug("cache expired"); logger.info("cache expired");
} }
}; };

View File

@ -48,7 +48,7 @@ public class LoadingGeonetworkInstanceCache {
RemovalListener<String, GeonetworkInstance> removalListener = new RemovalListener<String, GeonetworkInstance>() { RemovalListener<String, GeonetworkInstance> removalListener = new RemovalListener<String, GeonetworkInstance>() {
public void onRemoval(RemovalNotification<String, GeonetworkInstance> removal) { public void onRemoval(RemovalNotification<String, GeonetworkInstance> removal) {
logger.debug("cache expired"); logger.info("cache expired");
} }
}; };

View File

@ -46,7 +46,7 @@ public class LoadingGisViewerApplicationURLCache {
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() { RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
public void onRemoval(RemovalNotification<String, String> removal) { public void onRemoval(RemovalNotification<String, String> removal) {
logger.debug("cache expired"); logger.info("cache expired");
} }
}; };

View File

@ -1,208 +0,0 @@
/**
*
*/
package org.gcube.datatransfer.resolver.caches;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
/**
* The Class LoadingMapOfDetachedVRE.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Jun 10, 2020
*/
public class LoadingMapOfDetachedVRE {
private static Logger LOG = LoggerFactory.getLogger(LoadingMapOfDetachedVRE.class);
private static LoadingCache<String, VRE> vreNameToVRE;
static{
CacheLoader<String, VRE> loader = new CacheLoader<String, VRE>(){
@Override
public VRE load(String vreName)
throws Exception {
LOG.info("Loading the cache for VRE name: {}",vreName);
VRE theVRE = loadVREObjForVREName(vreName);
if(theVRE!=null)
LOG.info("Returning {} with scope {} for the VRE name: {}", VRE.class.getSimpleName(), theVRE.getScope(), vreName);
else {
LOG.info("No VRE obj for VRE name {}",vreName);
}
return theVRE;
}
};
RemovalListener<String, VRE> removalListener = new RemovalListener<String, VRE>() {
@Override
public void onRemoval(RemovalNotification<String, VRE> arg0) {
LOG.debug("cache expired");
}
};
vreNameToVRE = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite(
12, TimeUnit.HOURS).removalListener(removalListener).
build(loader);
//Populating the cache at init stage
populateTheCache();
LOG.info("Pre-Loaded detached VRE Name to VRE Obj cache with: "+vreNameToVRE.asMap().size()+" item/s");
}
/**
* Populate the cache.
*/
private static void populateTheCache(){
String authorizationToken = null;
try{
//Populating the cache by using the detachedres-library
LOG.info("Trying to pre-populate the detached VREs cache with mapping (VRE Name, VRE Obj)");
ScopeProvider.instance.set(UriResolverSmartGearManagerInit.getRootContextScope());
authorizationToken = SecurityTokenProvider.instance.get();
if(authorizationToken==null) {
LOG.info("No token found into {} to instance the {}, so reading it from SG configurations",
SecurityTokenProvider.class.getSimpleName(), DetachedREsClient.class.getSimpleName());
authorizationToken = UriResolverSmartGearManagerInit.getRootTokenFromSGConfiguration();
if(authorizationToken!=null)
SecurityTokenProvider.instance.set(authorizationToken);
}
DetachedREsClient detachedREsClient = new DetachedREsClient();
DetachedREs detachedREs = detachedREsClient.getDetachedREs();
int totalVREDimissed = 0;
for (Gateway gateway : detachedREs.getGateways().values()) {
LOG.trace("Gateway: " + gateway.getName());
int vreDismissedPerGatew = 0;
for (VO vo : gateway.getVos().values()) {
LOG.trace("VO: " + vo.getName());
for (VRE vre : vo.getVres().values()) {
if(LOG.isTraceEnabled()) {
LOG.trace("VRE name: " + vre.getName() +
" scope: "+vre.getScope() +
" VRE catalogue url: " + vre.getCatalogUrl() +
" VRE catalog Portlet URL: "+vre.getCatalogPortletURL());
}
try {
if(vre.getScope()!=null && !vre.getScope().isEmpty()) {
String vreName = vre.getScope().split("/")[3];
vreNameToVRE.asMap().put(vreName, vre);
vreDismissedPerGatew++;
}
}catch (Exception e) {
LOG.warn("Error on parsing the scope: "+vre.getScope()+ " skipping it");
}
}
}
LOG.debug("VREs dismissed loaded and cached per " + gateway.getName() + " are: "+vreDismissedPerGatew);
totalVREDimissed+=vreDismissedPerGatew;
}
LOG.debug("Total detached VREs are: "+totalVREDimissed);
LOG.info("Cache populated with: ");
Map<String, VRE> mapOfVreNames = vreNameToVRE.asMap();
for (String key : mapOfVreNames.keySet()) {
VRE theDetachedVRE = mapOfVreNames.get(key);
LOG.info("VRE name {}, VRE obj with scope {}, catalogueURL {}, cataloguePortletURL {}",
key,
theDetachedVRE.getScope(),
theDetachedVRE.getCatalogUrl(),
theDetachedVRE.getCatalogPortletURL());
}
}catch(Exception e){
//SILENT
}finally{
if(authorizationToken!=null) {
LOG.info("resetting security token provider");
SecurityTokenProvider.instance.reset();
}
}
}
/**
* Gets the VRE obj for input VRE name.
*
* @param vreName the vre name
* @return the vre
* @throws ExecutionException the execution exception
*/
public static VRE get(String vreName) throws ExecutionException{
try {
return vreNameToVRE.get(vreName);
}catch (Exception e) {
LOG.info("Error on getting VRE obj for vreName {}. Is the key {} not found in the cache?", vreName, vreName);
throw e;
}
}
/**
* Load VRE obj for VRE name.
*
* @param vreName the vre name
* @return the vre
*/
protected static VRE loadVREObjForVREName(String vreName){
VRE theVRE = vreNameToVRE.getIfPresent(vreName);
//THIS CHECK SHOULD NOT BE NEEDED
if(theVRE==null){
populateTheCache();
theVRE = vreNameToVRE.getIfPresent(vreName);
}
return theVRE;
}
/**
* Gets the cache.
*
* @return the cache
*/
public LoadingCache<String, VRE> getCache(){
return vreNameToVRE;
}
}

View File

@ -54,7 +54,7 @@ public class LoadingMapOfScopeCache {
@Override @Override
public void onRemoval(RemovalNotification<String, ScopeBean> arg0) { public void onRemoval(RemovalNotification<String, ScopeBean> arg0) {
logger.debug("cache expired"); logger.info("cache expired");
//prePopulateCache(); //prePopulateCache();
} }
@ -86,6 +86,13 @@ public class LoadingMapOfScopeCache {
} }
logger.info("Cache populated with: "+scopeNamesToFullScopes.asMap().toString()); logger.info("Cache populated with: "+scopeNamesToFullScopes.asMap().toString());
//logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
// if(UriResolverSmartGearManagerInit.getRootContextScope().compareTo("/gcube")==0){
// logger.warn("HARD-CABLING PARTHENOS_Registry scope to resolve PARTHENOS_REGISTRY Links in dev environment");
// scopeNamesToFullScopes.asMap().put("PARTHENOS_Registry", "/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry");
// }
}catch(Exception e){ }catch(Exception e){
//SILENT //SILENT
@ -116,9 +123,9 @@ public class LoadingMapOfScopeCache {
*/ */
protected static ScopeBean loadFullScopeforScopeName(String scopeName){ protected static ScopeBean loadFullScopeforScopeName(String scopeName){
//THIS CHECK SHOULD BE NOT NEEDED
ScopeBean fullScope = scopeNamesToFullScopes.getIfPresent(scopeName); ScopeBean fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);
//THIS CHECK SHOULD NOT BE NEEDED
if(fullScope==null){ if(fullScope==null){
populateTheCache(); populateTheCache();
fullScope = scopeNamesToFullScopes.getIfPresent(scopeName); fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);

View File

@ -1,18 +1,19 @@
package org.gcube.datatransfer.resolver.catalogue; package org.gcube.datatransfer.resolver.catalogue;
/** /**
* The Class CatalogueRequest. * The Class CatalogueRequest.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 6, 2018
* *
* Apr 20, 2022 * Binding Catalogue Request as a JSON
*/ */
public class CatalogueRequest { public class CatalogueRequest {
private String gcube_scope; private String gcube_scope;
private String entity_context; private String entity_context;
private String entity_name; private String entity_name;
private String query_string;
/** /**
* Gets the gcube_scope. * Gets the gcube_scope.
@ -41,22 +42,12 @@ public class CatalogueRequest {
return entity_name; return entity_name;
} }
/** /* (non-Javadoc)
* Gets the query string. * @see java.lang.Object#toString()
*
* @return the query string
*/
public String getQuery_string() {
return query_string;
}
/**
* To string.
*
* @return the string
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("CatalogueRequest [gcube_scope="); builder.append("CatalogueRequest [gcube_scope=");
builder.append(gcube_scope); builder.append(gcube_scope);
@ -64,8 +55,6 @@ public class CatalogueRequest {
builder.append(entity_context); builder.append(entity_context);
builder.append(", entity_name="); builder.append(", entity_name=");
builder.append(entity_name); builder.append(entity_name);
builder.append(", query_string=");
builder.append(query_string);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }

View File

@ -23,7 +23,6 @@ public class ItemCatalogueURLs {
private String itemName; private String itemName;
private boolean isPublicItem; private boolean isPublicItem;
private String privateVRECataloguePortletURL; private String privateVRECataloguePortletURL;
private String publicVRECataloguePortletURL; private String publicVRECataloguePortletURL;
private String publicGatewayCataloguePortletURL; private String publicGatewayCataloguePortletURL;

View File

@ -3,27 +3,28 @@
*/ */
package org.gcube.datatransfer.resolver.catalogue; package org.gcube.datatransfer.resolver.catalogue;
import java.util.Arrays; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* The Enum ResourceCatalogueCodes. * The Enum ResourceCatalogueCodes.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 31, 2017 * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 31, 2017
* *
* see wiki page: * see wiki page: https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
* https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
*/ */
public enum ResourceCatalogueCodes { public enum ResourceCatalogueCodes {
CTLG("ctlg", "dataset", "Catalogue Product/Dataset"), CTLG("ctlg","dataset", "Catalogue Product/Dataset"),
// CTLGP("ctlg-p","product", "Catalogue Product"), //CTLGP("ctlg-p","product", "Catalogue Product"),
CTLGD("ctlg-d", "dataset", "Catalogue Dataset"), CTLGO("ctlg-o", "organization", "Catalogue Organization"), CTLGD("ctlg-d","dataset", "Catalogue Dataset"),
CTLGG("ctlg-g", "group", "Catalogue Group"); CTLGO("ctlg-o","organization", "Catalogue Organization"),
CTLGG("ctlg-g","group", "Catalogue Group");
private String id; // the code id private String id; //the code id
private String value; // the code value private String value; //the code value
private String description; private String description;
/** /**
@ -49,6 +50,7 @@ public enum ResourceCatalogueCodes {
return id; return id;
} }
/** /**
* Gets the value. * Gets the value.
* *
@ -59,6 +61,7 @@ public enum ResourceCatalogueCodes {
return value; return value;
} }
/** /**
* Gets the description. * Gets the description.
* *
@ -69,37 +72,40 @@ public enum ResourceCatalogueCodes {
return description; return description;
} }
/** /**
* Codes. * Codes.
* *
* @return the list * @return the list
*/ */
public static List<String> codes() { public static List<String> codes(){
return Arrays.asList(ResourceCatalogueCodes.values()).stream().map(ResourceCatalogueCodes::getId) List<String> codes = new ArrayList<String>(ResourceCatalogueCodes.values().length);
.collect(Collectors.toList()); for (ResourceCatalogueCodes value : ResourceCatalogueCodes.values()) {
codes.add(value.getId());
} }
return codes;
}
/** /**
* Value of code id. * Value of code id.
* *
* @param id the id * @param id the id
* @return the resource catalogue codes * @return the resource catalogue codes
*/ */
public static ResourceCatalogueCodes valueOfCodeId(String id) { public static ResourceCatalogueCodes valueOfCodeId(String id){
if (id == null || id.isEmpty()) if(id==null || id.isEmpty())
return null; return null;
List<ResourceCatalogueCodes> codes = Arrays.asList(ResourceCatalogueCodes.values()).stream() for (ResourceCatalogueCodes value : ResourceCatalogueCodes.values()) {
.filter(r -> r.getId().compareTo(id) == 0) if(value.id.compareTo(id)==0)
.collect(Collectors.toList()); return value;
if (codes == null || codes.isEmpty())
return null;
return codes.get(0);
} }
return null;
}
/** /**
* Value of code value. * Value of code value.
@ -107,17 +113,14 @@ public enum ResourceCatalogueCodes {
* @param codeValue the code value * @param codeValue the code value
* @return the resource catalogue codes * @return the resource catalogue codes
*/ */
public static ResourceCatalogueCodes valueOfCodeValue(String codeValue) { public static ResourceCatalogueCodes valueOfCodeValue(String codeValue){
if (codeValue == null || codeValue.isEmpty()) if(codeValue==null || codeValue.isEmpty())
return null; return null;
List<ResourceCatalogueCodes> codes = Arrays.asList(ResourceCatalogueCodes.values()).stream() for (ResourceCatalogueCodes rcc : ResourceCatalogueCodes.values()) {
.filter(r -> r.getValue().compareTo(codeValue) == 0) if(rcc.value.compareTo(codeValue)==0)
.collect(Collectors.toList()); return rcc;
}
if (codes == null || codes.isEmpty())
return null; return null;
return codes.get(0);
} }
} }

View File

@ -12,7 +12,7 @@ import java.util.Map;
import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl; import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger; import org.slf4j.Logger;

View File

@ -1,142 +0,0 @@
package org.gcube.datatransfer.resolver.catalogue.resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class CatalogueStaticConfigurations.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Apr 6, 2020
*/
public class CatalogueStaticConfigurations{
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(CatalogueStaticConfigurations.class);
/** The Constant PREFIX_FOR_PORTAL_RELATIVE_URL_TO_CATALOGUE. */
static final String PREFIX_FOR_PORTAL_RELATIVE_URL_TO_CATALOGUE = "PREFIX_FOR_PORTAL_RELATIVE_URL_TO_CATALOGUE";
/** The Constant BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME. */
static final String BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME = "BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME";
/** The Constant DATACATALOGUE_URLs_CONFIGURATIONS_PROPERTIES. */
static final String DATACATALOGUE_URLs_CONFIGURATIONS_PROPERTIES = "datacatalogue_urls_configurations.properties";
/** The prefix to be used for catalogue URL. */
private String prefixToBeUsedForCatalogueURL;
/** The prefixes used for ckan hostname. */
private List<String> prefixesUsedForCkanHostname;
/**
* Instantiates a new static configurations.
*/
public CatalogueStaticConfigurations() {
loadCataloguePortalURLsConfigurations();
}
/**
* Load catalogue portal URLs configurations.
*/
private void loadCataloguePortalURLsConfigurations(){
Properties prop = new Properties();
try {
InputStream in = CkanCatalogueConfigurationsReader.class.getResourceAsStream(DATACATALOGUE_URLs_CONFIGURATIONS_PROPERTIES);
// load a properties file
prop.load(in);
// get the property value
String property = prop.getProperty(PREFIX_FOR_PORTAL_RELATIVE_URL_TO_CATALOGUE);
prefixToBeUsedForCatalogueURL = property;
// get the property value
property = prop.getProperty(BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME);
if(property.contains(",")) {
String[] values = property.split(",");
prefixesUsedForCkanHostname = Arrays.asList(values);
}else {
prefixesUsedForCkanHostname = Arrays.asList(property);
}
} catch (IOException e) {
LOG.error("An error occurred on read property file: "+DATACATALOGUE_URLs_CONFIGURATIONS_PROPERTIES, e);
}
}
/**
* Extract catalogue name from a ckan or balancer hostname.
*
* @param privateCKANCatalogueURL the private CKAN catalogue URL
* @return the catalogue name
*
* e.g. Returns "-bb" for "ckan-bb"
*/
private String extractCatalogueName(String privateCKANCatalogueURL) {
String toPrivateCKANCatalogueURL = privateCKANCatalogueURL;
LOG.debug("Private Catalogue URL is: "+toPrivateCKANCatalogueURL);
//removing protocol HTTPs or HTTP
toPrivateCKANCatalogueURL = toPrivateCKANCatalogueURL.replaceFirst("https://", "");
toPrivateCKANCatalogueURL = toPrivateCKANCatalogueURL.replaceFirst("http://", "");
LOG.debug("Removed HTTP[s] protocol, now I have: "+toPrivateCKANCatalogueURL);
for (String prefix :prefixesUsedForCkanHostname) {
LOG.trace(prefix+ " found as prefix of: "+privateCKANCatalogueURL);
if(toPrivateCKANCatalogueURL.startsWith(prefix)) {
toPrivateCKANCatalogueURL = toPrivateCKANCatalogueURL.replaceFirst(prefix, ""); //removing prefix
String catalogueName = toPrivateCKANCatalogueURL.substring(0,toPrivateCKANCatalogueURL.indexOf(".d4science"));
LOG.info("Catalogue Name extraction returning value: "+catalogueName);
return catalogueName;
}
}
LOG.info("Catalogue Name extraction returning null");
return null;
}
/**
* Builds the relative URL to public catalogue gateway.
*
* @param privateCKANCatalogueURL the private CKAN catalogue URL
*
* @return the relative URL that must be used for Public Catalogue Gateway
*/
public String buildRelativeURLToPublicCatalogueGateway(String privateCKANCatalogueURL) {
LOG.info("Trying to build the Catalogue Gateway URL using the prefix: "+prefixToBeUsedForCatalogueURL);
LOG.debug("The prefixes to build the URL for Public Catalogue published at Gateway level are: "+prefixesUsedForCkanHostname);
String catalogueName = extractCatalogueName(privateCKANCatalogueURL);
catalogueName = catalogueName == null? "":catalogueName;
String toNormalizedNameForURL = catalogueName.replaceAll("\\.", "-");
String publicCatalogueGatewayURL = String.format("%s%s", prefixToBeUsedForCatalogueURL,toNormalizedNameForURL);
LOG.info("The Catalogue Gateway URL built is: "+publicCatalogueGatewayURL);
return publicCatalogueGatewayURL;
}
/**
* Gets the prefixes used for ckan hostname.
*
* @return the prefixes used for ckan hostname
*/
public List<String> getPrefixesUsedForCkanHostname() {
return prefixesUsedForCkanHostname;
}
/**
* Gets the prefix to be used for catalogue URL.
*
* @return the prefix to be used for catalogue URL
*/
public String getPrefixToBeUsedForCatalogueURL() {
return prefixToBeUsedForCatalogueURL;
}
}

View File

@ -8,21 +8,21 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.gcube.resources.discovery.icclient.ICFactory.client; import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader; import java.io.StringReader;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.utillibrary.jackan.CkanClient; import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl; import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.exceptions.CkanException;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
import org.gcube.datatransfer.resolver.catalogue.endpoint.CatalogueServiceEndpointReader; import org.gcube.datatransfer.resolver.catalogue.endpoint.CatalogueServiceEndpointReader;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -33,6 +33,10 @@ import org.slf4j.LoggerFactory;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import eu.trentorise.opendata.jackan.CkanClient;
import eu.trentorise.opendata.jackan.exceptions.CkanException;
import eu.trentorise.opendata.jackan.model.CkanDataset;
/** /**
* The Class CkanCatalogueConfigurationsReader. * The Class CkanCatalogueConfigurationsReader.
@ -42,17 +46,13 @@ import org.xml.sax.InputSource;
*/ */
public class CkanCatalogueConfigurationsReader { public class CkanCatalogueConfigurationsReader {
//private static final String PREFIX_FOR_PORTAL_RELATIVE_URL_TO_CATALOGUE = "PREFIX_FOR_PORTAL_RELATIVE_URL_TO_CATALOGUE";
/** The Constant logger. */
//private static final String BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME = "BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME";
private static final Logger logger = LoggerFactory.getLogger(CkanCatalogueConfigurationsReader.class); private static final Logger logger = LoggerFactory.getLogger(CkanCatalogueConfigurationsReader.class);
/** The Constant APPLICATION_PROFILE_NAME. */
public final static String APPLICATION_PROFILE_NAME = "CkanPortlet"; public final static String APPLICATION_PROFILE_NAME = "CkanPortlet";
private static final String DATACATALOGUECONFIGURATION_PROPERTIES = "datacatalogueconfiguration.properties";
/** /**
* Load catalogue end points through the ckan-util-library. * Load catalogue end points.
* *
* @return the gateway ckan catalogue reference * @return the gateway ckan catalogue reference
* @throws Exception the exception * @throws Exception the exception
@ -64,29 +64,28 @@ public class CkanCatalogueConfigurationsReader {
DataCatalogueImpl catalogueImpl = CatalogueServiceEndpointReader.getDataCatalogueImpl(); DataCatalogueImpl catalogueImpl = CatalogueServiceEndpointReader.getDataCatalogueImpl();
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> accessLevelMap = catalogueImpl.getMapAccessURLToCatalogue(); Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> accessLevelMap = catalogueImpl.getMapAccessURLToCatalogue();
for (ACCESS_LEVEL_TO_CATALOGUE_PORTLET accessLevel : accessLevelMap.keySet()) { links.setMapAccessURLToCatalogue(accessLevelMap);
links.setCatalogueURL(accessLevelMap.get(accessLevel), accessLevel);
}
//String publicVREPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
String privatePortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE); String privatePortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE);
links.setPrivateVREPortletURL(privatePortletURL);
String publicVREPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
links.setPublicVREPortletURL(publicVREPortletURL);
String publicGatewayPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY); String publicGatewayPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY);
links.setPublicGatewayPortletURL(publicGatewayPortletURL);
try{ try{
//If a catalogue gateway portlet URL is not provided/read from GR, building it
if(publicGatewayPortletURL==null || publicGatewayPortletURL.isEmpty()) { if(publicGatewayPortletURL==null || publicGatewayPortletURL.isEmpty()) {
//Building the gateway catalogue public URL from private VRE Portlet URL //Building the gateway catalogue public URL from private VRE Portlet URL
URI toURL = new URI(privatePortletURL); URI toURL = new URI(privatePortletURL);
String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost(); String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost();
//It returns the string "catalogue" //It returns the string "catalogue"
CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations(); String prefixToPublicCtlg = getRelativeURLToCatalogue();
//Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g catalogue-bb) //Replacing for example "ckan-bb" with "catalogue-bb"
String relativeURLWithCatalogueName = staticConf.buildRelativeURLToPublicCatalogueGateway(catalogueImpl.getCatalogueUrl()); String publicCatalogueName = extractCatalogueName(catalogueImpl.getCatalogueUrl(), prefixToPublicCtlg);
String toGatewayPortletURL = String.format("%s/%s", publicURL, relativeURLWithCatalogueName); links.setPublicGatewayPortletURL(publicURL+"/"+publicCatalogueName);
links.setCatalogueURL(toGatewayPortletURL, ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY);
} }
}catch(Exception e){ }catch(Exception e){
logger.warn("Erron on creating public catalogue URL from private URL: "+privatePortletURL, e); logger.warn("Erron on generating public catalogue URL from private URL: "+privatePortletURL, e);
} }
//Getting the CKAN Portlet URL for current scope //Getting the CKAN Portlet URL for current scope
@ -100,6 +99,21 @@ public class CkanCatalogueConfigurationsReader {
return links; return links;
} }
/**
* Extract catalogue name.
*
* @param privateCKANCatalogueURL the private ckan catalogue url
* @param replaceCKANWith the replace ckan with
* @return the string
*/
public static String extractCatalogueName(String privateCKANCatalogueURL, String replaceCKANWith){
privateCKANCatalogueURL = privateCKANCatalogueURL.replaceFirst("https://ckan", replaceCKANWith);
privateCKANCatalogueURL = privateCKANCatalogueURL.replaceFirst("http://ckan", replaceCKANWith);
return privateCKANCatalogueURL.substring(0,privateCKANCatalogueURL.indexOf("."));
}
/** /**
* Retrieve a ckan dataset given its id. The CkanClient is used, without api key. The result is null also when the dataset is private. * Retrieve a ckan dataset given its id. The CkanClient is used, without api key. The result is null also when the dataset is private.
@ -119,7 +133,7 @@ public class CkanCatalogueConfigurationsReader {
CkanClient client = new CkanClient(catalogueURL); CkanClient client = new CkanClient(catalogueURL);
return client.getDataset(datasetIdorName); return client.getDataset(datasetIdorName);
}catch(CkanException e){ }catch(CkanException e){
logger.info("Getting dataset "+datasetIdorName+" thrown a CkanException, returning null", e); logger.info("Getting dataset "+datasetIdorName+" thrown a CkanException, returning null");
return null; return null;
} }
@ -173,20 +187,44 @@ public class CkanCatalogueConfigurationsReader {
} }
/** /**
* The main method. * Gets the relative url to catalogue.
* *
* @param args the arguments * @return the relative url to catalogue
*/ */
public static void main(String[] args) { private static String getRelativeURLToCatalogue(){
Properties prop = new Properties();
ScopeProvider.instance.set("/gcube/devsec/devVRE"); String relativeURLToCatalogue = null;
try { try {
GatewayCKANCatalogueReference links = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints(); InputStream in = CkanCatalogueConfigurationsReader.class.getResourceAsStream(DATACATALOGUECONFIGURATION_PROPERTIES);
System.out.println(links); // load a properties file
} prop.load(in);
catch (Exception e) { // get the property value
// TODO Auto-generated catch block relativeURLToCatalogue = prop.getProperty("PORTAL_RELATIVE_URL_TO_CATALOGUE");
e.printStackTrace();
if(relativeURLToCatalogue==null || relativeURLToCatalogue.isEmpty())
return "catalogue";
} catch (IOException e) {
logger.error("An error occurred on read property file: "+DATACATALOGUECONFIGURATION_PROPERTIES, e);
} }
return relativeURLToCatalogue;
} }
// /**
// * The main method.
// *
// * @param args the arguments
// */
// public static void main(String[] args) {
//
// ScopeProvider.instance.set("/gcube/devsec/devVRE");
// try {
// GatewayCKANCatalogueReference links = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
// System.out.println(links);
// }
// catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
} }

View File

@ -4,17 +4,17 @@
package org.gcube.datatransfer.resolver.catalogue.resource; package org.gcube.datatransfer.resolver.catalogue.resource;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET; import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString; import lombok.ToString;
// TODO: Auto-generated Javadoc
/** /**
* The Class GatewayCKANCatalogueReference. * The Class GatewayCKANCatalogueReference.
* *
@ -23,65 +23,27 @@ import lombok.ToString;
* Nov 12, 2019 * Nov 12, 2019
*/ */
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Getter
@Setter
@ToString @ToString
public class GatewayCKANCatalogueReference implements Serializable{ public class GatewayCKANCatalogueReference implements Serializable{
/** The Constant serialVersionUID. */ /**
*
*/
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** The scope. */
private String scope; private String scope;
/** The ckan URL. */ private String privateVREPortletURL;
private String publicVREPortletURL;
private String publicGatewayPortletURL;
private String ckanURL; private String ckanURL;
/** The map access URL to catalogue. */ public Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue;
private Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue;
/**
* Gets the catalogue URL.
*
* @param accessLevel the access level
* @return the catalogue URL
*/
public String getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET accessLevel) {
return mapAccessURLToCatalogue.get(accessLevel);
}
/**
* Sets the catalogue URL.
*
* @param catalogueURL the catalogue URL
* @param accessLevel the access level
*/
protected void setCatalogueURL(String catalogueURL, ACCESS_LEVEL_TO_CATALOGUE_PORTLET accessLevel) {
if(mapAccessURLToCatalogue==null)
mapAccessURLToCatalogue = new HashMap<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String>();
mapAccessURLToCatalogue.put(accessLevel, catalogueURL);
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getCkanURL() {
return ckanURL;
}
public void setCkanURL(String ckanURL) {
this.ckanURL = ckanURL;
}
} }

View File

@ -1,14 +0,0 @@
# Property file
#
# author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
# created 11/2017
# updated 03/2020
#
# BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME
# eg. for https://ckan-territoriaperti.d4science.org is ckan
# eg. for https://ckan-imarine.d4science.org is ckan
# eg. for https://catalogue.d4science.org is catalogue
#
PREFIX_FOR_PORTAL_RELATIVE_URL_TO_CATALOGUE = catalogue
BALANCER_AND_CKAN_PREFIXES_USED_FOR_HOSTNAME = ckan,catalogue

View File

@ -0,0 +1,7 @@
# Property files
#
# author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
# created 11/2017
#
PORTAL_RELATIVE_URL_TO_CATALOGUE = catalogue

View File

@ -1,19 +0,0 @@
package org.gcube.datatransfer.resolver.geoportal;
/**
* 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_ID = "geoportal-data-viewer-app";
public static final String GEOPORTAL_DATA_ENTRY_APP_ID = "geoportal-data-entry-app";
}

View File

@ -1,80 +0,0 @@
package org.gcube.datatransfer.resolver.geoportal;
import java.io.Serializable;
/**
* The Class GeoportalConfigApplicationProfile.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 3, 2024
*/
public class GeoportalConfigApplicationProfile implements Serializable {
/**
*
*/
private static final long serialVersionUID = 8340275391003882511L;
private String restrictedPortletURL;
private String openPortletURL;
/**
* Instantiates a new geo na data viewer profile.
*/
public GeoportalConfigApplicationProfile() {
}
/**
* 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;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoportalConfigApplicationProfile [restrictedPortletURL=");
builder.append(restrictedPortletURL);
builder.append(", openPortletURL=");
builder.append(openPortletURL);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,179 +0,0 @@
package org.gcube.datatransfer.resolver.geoportal;
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.StringReader;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
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.xml.sax.InputSource;
/**
* The Class GeoportalConfigApplicationProfileReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 3, 2024
*/
public class GeoportalConfigApplicationProfileReader {
private static Logger LOG = LoggerFactory.getLogger(GeoportalConfigApplicationProfileReader.class);
private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body";
public static final String SECONDARY_TYPE = "ApplicationProfile";
private String secondaryType;
private String scope;
private String appID;
private GeoportalConfigApplicationProfile geoportalConfigAppProfile;
/**
* Instantiates a new geoportal config application profile reader.
*
* @param appID the app ID
* @throws Exception the exception
*/
public GeoportalConfigApplicationProfileReader(String appID) throws Exception {
this.appID = appID;
this.secondaryType = SECONDARY_TYPE;
this.scope = ScopeProvider.instance.get();
this.geoportalConfigAppProfile = readProfileFromInfrastructure();
}
/**
* Read profile from infrastrucure.
*
* @return the map
* @throws Exception the exception
*/
private GeoportalConfigApplicationProfile readProfileFromInfrastructure() throws Exception {
String queryString = getGcubeGenericQueryString(secondaryType, appID);
LOG.info("Scope " + scope + ", trying to perform query: " + queryString);
try {
if (scope == null)
throw new Exception("Scope is null, set scope into ScopeProvider");
GeoportalConfigApplicationProfile profile = new GeoportalConfigApplicationProfile();
LOG.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);
// String item_fields = "";
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);
LOG.info("returning: " + profile);
return profile;
}
} catch (Exception e) {
LOG.error("Error while trying to read the SecondaryType " + SECONDARY_TYPE + " with appID " + appID
+ " from scope " + scope, e);
return null;
} finally {
}
}
/**
* Gets the geoportal config app profile.
*
* @return the geoportal config app profile
*/
public GeoportalConfigApplicationProfile getGeoportalConfigAppProfile() {
return geoportalConfigAppProfile;
}
/**
* 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;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoportalConfigApplicationProfileReader [secondaryType=");
builder.append(secondaryType);
builder.append(", scope=");
builder.append(scope);
builder.append(", appID=");
builder.append(appID);
builder.append(", geoportalConfigAppProfile=");
builder.append(geoportalConfigAppProfile);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,47 +0,0 @@
package org.gcube.datatransfer.resolver.geoportal;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
/**
* The Class GeoportalRequest.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 23, 2023
*/
@Slf4j
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class GeoportalRequest {
public static final String P_GCUBE_SCOPE = "gcube_scope";
public static final String P_ITEM_TYPE = "item_type";
public static final String P_ITEM_ID = "item_id";
public static final String P_RESOLVES_AS = "res";
public static final String P_QUERY_STRING = "query_string";
@JsonProperty(P_GCUBE_SCOPE)
private String gcubeScope;
/**
* It is the UCD ID {usecase_id}
*/
@JsonProperty(P_ITEM_TYPE)
private String itemType;
/**
* It is the Project ID {project_id}
*/
@JsonProperty(P_ITEM_ID)
private String itemID;
@JsonProperty(P_QUERY_STRING)
private String queryString;
@JsonProperty(P_RESOLVES_AS)
private String res;
}

View File

@ -1,121 +0,0 @@
/**
*
*/
package org.gcube.datatransfer.resolver.geoportal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.gcube.datatransfer.resolver.services.GeoportalResolver;
/**
* The Enum TargetAppGeoportalCodes.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2023
*/
public enum TargetAppGeoportalCodes {
GEO_DV(GeoportalResolver.GEO_DV, "data-viewer", "Geoportal Viewer"),
GEO_DE(GeoportalResolver.GEO_DE, "data-entry", "Geoportal Entry");
private String id; // the code id
private String name; // the code value
private String description;
/**
* Instantiates a new resource catalogue codes.
*
* @param id the id
* @param name the target app
* @param description the description
*/
private TargetAppGeoportalCodes(String id, String name, String description) {
this.id = id;
this.name = name;
this.description = description;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Gets the target app.
*
* @return the target app
*/
public String getTarget_app() {
return name;
}
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Codes.
*
* @return the list
*/
public static List<String> codes() {
return Arrays.asList(TargetAppGeoportalCodes.values()).stream().map(TargetAppGeoportalCodes::getId)
.collect(Collectors.toList());
}
/**
* Value of id.
*
* @param id the id
* @return the target app geoportal codes
*/
public static TargetAppGeoportalCodes valueOfId(String id) {
if (id == null || id.isEmpty())
return null;
List<TargetAppGeoportalCodes> codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
.filter(value -> value.getId().compareTo(id) == 0).collect(Collectors.toList());
if (codes == null || codes.isEmpty())
return null;
return codes.get(0);
}
/**
* Value of name.
*
* @param name the name
* @return the target app geoportal codes
*/
public static TargetAppGeoportalCodes valueOfName(String name) {
if (name == null || name.isEmpty())
return null;
List<TargetAppGeoportalCodes> codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
.filter(value -> value.getTarget_app().compareTo(name) == 0).collect(Collectors.toList());
if (codes == null || codes.isEmpty())
return null;
return codes.get(0);
}
}

View File

@ -1,66 +0,0 @@
package org.gcube.datatransfer.resolver.geoportal.exporter;
import org.gcube.application.geoportaldatamapper.shared.FileReference;
public class FetchPDF {
private final int MAX_RETRY = 60;
private FileReference fileRef;
private String code;
private int attempt = 0;
public FetchPDF() {
}
public FetchPDF(FileReference fileRef, String code, int attempt) {
super();
this.fileRef = fileRef;
this.code = code;
this.attempt = attempt;
}
public int getMAX_RETRY() {
return MAX_RETRY;
}
public FileReference getFileRef() {
return fileRef;
}
public String getCode() {
return code;
}
public int getAttempt() {
return attempt;
}
public void setFileRef(FileReference fileRef) {
this.fileRef = fileRef;
}
public synchronized int incrementAttempt() {
attempt++;
return attempt;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FetchPDF [MAX_RETRY=");
builder.append(MAX_RETRY);
builder.append(", fileRef=");
builder.append(fileRef);
builder.append(", code=");
builder.append(code);
builder.append(", attempt=");
builder.append(attempt);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,12 +0,0 @@
package org.gcube.datatransfer.resolver.geoportal.exporter;
import lombok.Data;
@Data
public class GeoportalJsonResponse {
//State can be "OK" or "ERROR"
String state;
String url;
String message;
}

View File

@ -1,171 +0,0 @@
package org.gcube.datatransfer.resolver.geoportal.exporter;
public class Geoportal_HTML_Page {
/**
* Sets the HTML message.
*
* @param action the action
* @param message the message
* @param waiting the waiting
* @return the string
*/
public static String entityHTMLMessage(String action, String message, boolean waiting, String viewPdfURL) {
//NB the images are located at https://data.d4science.net/qLix
String newHTML = "<html>\n"
+ "\n"
+ " <head>\n"
+ " <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n"
+ " <style>\n"
+ " html,\n"
+ " body {\n"
+ " margin: 10px;\n"
+ " width: 100%;\n"
+ " height: 100%;\n"
+ " display: table\n"
+ " }\n"
+ "\n"
+ " #content {\n"
+ " position: absolute;\n"
+ " left: 50%;\n"
+ " top: 50%;\n"
+ " -webkit-transform: translate(-50%, -50%);\n"
+ " transform: translate(-50%, -50%);\n"
+ " text-align: center;\n"
+ " }\n"
+ "\n"
+ " #title-geo {\n"
+ " font-weight: bold;\n"
+ " color: black;\n"
+ " font-size: 26px;\n"
+ " }\n"
+ "\n"
+ " #message {\n"
+ " color: gray;\n"
+ " font-size: 24px;\n"
+ " }\n"
+ "\n"
+ " </style>\n"
+ " <script type=\"text/javascript\">\n"
+ " async function fetchPDF_URL() {\n"
+ " try {\n"
+ "\n"
+ " const response = await fetch('"+viewPdfURL+"');\n"
+ " console.log(\"polling response\");\n"
+ " return response.json();\n"
+ " } catch (error) {\n"
+ " console.error(\"polling error: \" + error);\n"
+ " showError(\"Error when exporting PDF :-(\");\n"
+ " }\n"
+ " }\n"
+ " async function playPDFPoll() {\n"
+ " const response_object = await fetchPDF_URL();\n"
+ " try {\n"
+ " console.log(\"json response \" + response_object);\n"
+ " if (response_object.state === \"OK\") {\n"
+ " if (!(response_object.url === null) && !(response_object.url === undefined)) {\n"
+ " window.location.replace(response_object.url);\n"
+ " } else {\n"
+ " setTimeout(() => {\n"
+ " playPDFPoll();\n"
+ " }, 1000);\n"
+ " }\n"
+ " } else {\n"
+ " showError(response_object.message);\n"
+ " }\n"
+ " } catch (error) {\n"
+ " console.log(\"no json response \" + response_object);\n"
+ " //console.log(\"error \" + error);\n"
+ " showError(\"Error when exporting PDF :-(\");\n"
+ " }\n"
+ "\n"
+ " }\n"
+ "\n"
+ " function showError(error_msg) {\n"
+ " let inner_div = document.getElementById(\"inner-content\");\n"
+ " inner_div.innerHTML = error_msg;\n"
+ " }\n"
+ "\n"
+ " </script>\n"
+ " <title>D4Science Geoportal - Action</title>\n"
+ " </head>\n"
+ "\n"
+ " <body onload=\"playPDFPoll()\">";
newHTML += "<img alt=\"D4Science Logo\" src=\"https://services.d4science.org/image/layout_set_logo?img_id=32727\"><br />";
newHTML += "<div id=\"content\">";
newHTML += "<p id=\"title-geo\">Geoportal</p><br />";
newHTML += "<div id=\"inner-content\">";
newHTML += "<p style=\"font-size: 18px;\">" + action + "</p>";
if (waiting) {
newHTML += "<img alt=\"D4Science Geoportal Loading Icon\" src=\"https://data.d4science.org/shub/E_a2Y1N2ZIaUhCVlE5R0JXNjJhVXVsTlNyNVJta2ZKZVFMaG52N2gxZm05VWJOb2RFTVBpa0pyV1hsUlg2WXJSTw==\"><br />";
}
newHTML += "<br/><p id=\"message\">" + message + "</p>";
newHTML += "</div></div></body></html>";
return newHTML;
}
/**
* Sets the HTML message.
*
* @param action the action
* @param message the message
* @param waiting the waiting
* @return the string
*/
public static String getErrorPage(String action, String message) {
String newHTML = "<html>\n"
+ "\n"
+ " <head>\n"
+ " <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n"
+ " <style>\n"
+ " html,\n"
+ " body {\n"
+ " margin: 10px;\n"
+ " width: 100%;\n"
+ " height: 100%;\n"
+ " display: table\n"
+ " }\n"
+ "\n"
+ " #content {\n"
+ " position: absolute;\n"
+ " left: 50%;\n"
+ " top: 50%;\n"
+ " -webkit-transform: translate(-50%, -50%);\n"
+ " transform: translate(-50%, -50%);\n"
+ " text-align: center;\n"
+ " }\n"
+ "\n"
+ " #title-geo {\n"
+ " font-weight: bold;\n"
+ " color: black;\n"
+ " font-size: 26px;\n"
+ " }\n"
+ "\n"
+ " #message {\n"
+ " color: gray;\n"
+ " font-size: 24px;\n"
+ " }\n"
+ "\n"
+ " </style>\n"
+ "</head>";
newHTML += "<img alt=\"D4Science Logo\" src=\"https://services.d4science.org/image/layout_set_logo?img_id=32727\"><br />";
newHTML += "<div id=\"content\">";
newHTML += "<p id=\"title-geo\">Geoportal Exporter</p><br />";
newHTML += "<p style=\"font-size: 18px;\">" + action + "</p>";
newHTML += "<br/><p id=\"message\">" + message + "</p>";
newHTML += "</div></body></html>";
return newHTML;
}
}

View File

@ -189,4 +189,23 @@ public class MetadataConverter {
return gisLI; return gisLI;
} }
/*
public static void main(String[] args) throws Exception {
// String geoserver = "http://www.fao.org/figis/a/wms/?service=WMS&version=1.1.0&request=GetMap&layers=area:FAO_AREAS&styles=Species_prob, puppa&bbox=-180.0,-88.0,180.0,90.0000000694&width=667&height=330&srs=EPSG:4326&format=image%2Fpng";
// System.out.println(MetadataConverter.getGeoserverBaseUri(geoserver));
String user ="admin";
String pwd = "admin";
boolean authenticate = true;
// String uuid ="177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
String uuid ="fao-species-map-bep";
// String uuid ="fao-species-map-bon"; //FAO
String geoNetworkUrl ="http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork";
GeonetworkInstance geonetowrkInstance = new GeonetworkInstance(geoNetworkUrl, user, pwd, authenticate);
String onLineResource = getWMSOnLineResource(geonetowrkInstance, uuid);
System.out.println(onLineResource);
}*/
} }

View File

@ -8,7 +8,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -18,13 +17,10 @@ import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache; import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache;
import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache; import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache;
import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE;
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache; import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfilePropertyReader; import org.gcube.datatransfer.resolver.gis.property.ApplicationProfilePropertyReader;
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException; import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.ApplicationManager;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -98,7 +94,6 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
new LoadingGeonetworkInstanceCache(); new LoadingGeonetworkInstanceCache();
new LoadingGisViewerApplicationURLCache(); new LoadingGisViewerApplicationURLCache();
new LoadingMapOfScopeCache(); new LoadingMapOfScopeCache();
new LoadingMapOfDetachedVRE();
} }
} }
catch (Exception e) { catch (Exception e) {
@ -234,30 +229,4 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
public static void setRootContextScope(String rootContextScope) { public static void setRootContextScope(String rootContextScope) {
UriResolverSmartGearManagerInit.rootContextScope = rootContextScope; UriResolverSmartGearManagerInit.rootContextScope = rootContextScope;
} }
/**
* Gets the root token from SG configurations.
*
* @return the root token from SG configurations
*/
public static String getRootTokenFromSGConfiguration() {
try {
ApplicationContext ctx = ContextProvider.get();
Set<String> tokens = ctx.configuration().startTokens();
for (String token : tokens) {
//I'm using the first token,
//it should be a token of root because of URI-Resolver works at root level
log.info("Token read from SG configuration is {}-MASKED-TOKEN",token.substring(0,10));
return token;
}
log.warn("Token not found by reading the SG configurations!!! Returning null");
return null;
} catch (Exception e) {
log.error("Error on reading the start tokens from SG configuration",e);
return null;
}
}
} }

View File

@ -11,41 +11,20 @@ import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
/** /**
* Instantiates a new parthenos request. *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 26, 2018
*/ */
@NoArgsConstructor @NoArgsConstructor
/**
* Instantiates a new parthenos request.
*
* @param entity_name the entity name
*/
@AllArgsConstructor @AllArgsConstructor
/**
* Gets the entity name.
*
* @return the entity name
*/
@Getter @Getter
/**
* Sets the entity name.
*
* @param entity_name the new entity name
*/
@Setter @Setter
/**
* To string.
*
* @return the java.lang. string
*/
@ToString @ToString
public class ParthenosRequest { public class ParthenosRequest {
@JsonProperty(value = "entity_name", required = true) @JsonProperty(value="entity_name", required=true)
private String entity_name; private String entity_name;
} }

View File

@ -19,19 +19,14 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.GCubeSecret;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.ConstantsResolver; import org.gcube.datatransfer.resolver.ConstantsResolver;
import org.gcube.datatransfer.resolver.UriResolverServices; import org.gcube.datatransfer.resolver.UriResolverServices;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class RequestHandler. * The Class RequestHandler.
* *
@ -49,8 +44,7 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
private static final Logger log = LoggerFactory.getLogger(RequestHandler.class); private static final Logger log = LoggerFactory.getLogger(RequestHandler.class);
@Context @Context ServletContext context;
ServletContext context;
@Context @Context
HttpServletRequest webRequest; HttpServletRequest webRequest;
@ -61,31 +55,20 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
@Context @Context
ResourceContext resourceContext; ResourceContext resourceContext;
/** /* (non-Javadoc)
* Filter. * @see javax.ws.rs.container.ContainerRequestFilter#filter(javax.ws.rs.container.ContainerRequestContext)
*
* @param reqContext the req context
* @throws IOException Signals that an I/O exception has occurred.
*/
/*
* (non-Javadoc)
*
* @see
* javax.ws.rs.container.ContainerRequestFilter#filter(javax.ws.rs.container.
* ContainerRequestContext)
*/ */
@Override @Override
public void filter(ContainerRequestContext reqContext) throws IOException { public void filter(ContainerRequestContext reqContext) throws IOException {
log.debug(RequestHandler.class.getSimpleName() + " Request called"); log.info(RequestHandler.class.getSimpleName() +" Request called");
setSecretManager(reqContext);
if (SecurityTokenProvider.instance.get() == null) if(SecurityTokenProvider.instance.get()==null)
SecurityTokenProvider.instance.set(context.getInitParameter(ROOT_APP_TOKEN)); SecurityTokenProvider.instance.set(context.getInitParameter(ROOT_APP_TOKEN));
if (ScopeProvider.instance.get() == null) if(ScopeProvider.instance.get()==null)
ScopeProvider.instance.set(context.getInitParameter(ROOT_SCOPE)); ScopeProvider.instance.set(context.getInitParameter(ROOT_SCOPE));
log.debug("Token and Scope Provider set called"); log.info("Token and Scope Provider set called");
List<String> listOfPath = UriResolverServices.getInstance().getListOfResourcePath(application.getClasses()); List<String> listOfPath = UriResolverServices.getInstance().getListOfResourcePath(application.getClasses());
log.debug("The resources are: {}", listOfPath); log.debug("The resources are: {}", listOfPath);
@ -93,17 +76,19 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
String path = reqContext.getUriInfo().getPath(); String path = reqContext.getUriInfo().getPath();
log.debug("The path is: {}", path); log.debug("The path is: {}", path);
// HOW TO READ THE QUERY STRING //HOW TO READ THE QUERY STRING
/* /*MultivaluedMap<String, String> queryParameters = reqContext.getUriInfo().getQueryParameters();
* MultivaluedMap<String, String> queryParameters = String queryString = "";
* reqContext.getUriInfo().getQueryParameters(); String queryString = ""; try { try {
* queryString = Util.toQueryString(queryParameters); }catch (Exception e) { queryString = Util.toQueryString(queryParameters);
* //silent }catch (Exception e) {
* log.warn("Error on reading the query string, trying to continue..."); } //silent
* log.debug("The query string is: {}", queryString); log.warn("Error on reading the query string, trying to continue...");
}
log.debug("The query string is: {}", queryString);
*/ */
if (path == null || path.isEmpty()) { if(path==null || path.isEmpty()) {
log.debug("The path is null or empty, redirecting to /index"); log.debug("The path is null or empty, redirecting to /index");
URI newRequestURI = reqContext.getUriInfo().getBaseUriBuilder().path("/index").build(); URI newRequestURI = reqContext.getUriInfo().getBaseUriBuilder().path("/index").build();
reqContext.setRequestUri(newRequestURI); reqContext.setRequestUri(newRequestURI);
@ -115,36 +100,33 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
String candidateResource = ""; String candidateResource = "";
try { try {
splittePath = path.split("/"); splittePath = path.split("/");
if (splittePath != null && splittePath.length > 0) { if(splittePath!=null && splittePath.length>0) {
String requestedResourceName = splittePath[0]; String requestedResourceName = splittePath[0];
log.debug("The resource requested is: {}", requestedResourceName); log.debug("The resource requested is: {}",requestedResourceName);
if (requestedResourceName != null && !requestedResourceName.isEmpty()) { if(requestedResourceName!=null && !requestedResourceName.isEmpty()) {
for (String resource : listOfPath) { for (String resource : listOfPath) {
log.trace("Is resource '{}' starting with '{}' ?", resource, requestedResourceName); log.trace("Is resource '{}' starting with '{}' ?",resource,requestedResourceName);
if (resource.startsWith(requestedResourceName)) { if(resource.startsWith(requestedResourceName)) {
log.trace("Yes it starts!"); log.trace("Yes it starts!");
candidateResource = requestedResourceName; candidateResource = requestedResourceName;
log.info("The candidate resource to manage the request is: {}", candidateResource); log.info("The candidate resource to manage the request is: {}",candidateResource);
resourceToRedirectFound = true; resourceToRedirectFound = true;
break; break;
} }
} }
// Try to manage as Catalogue Request ctlg, ctlg-p, etc. //Try to manage as Catalogue Request ctlg, ctlg-p, etc.
if (!resourceToRedirectFound) { if(!resourceToRedirectFound) {
log.info("Trying to manage as hard-coded case among cases: {}", log.info("Trying to manage as hard-coded case among cases: {}", Arrays.asList(ConstantsResolver.resourcesHardCoded).toString());
Arrays.asList(ConstantsResolver.resourcesHardCoded).toString());
String[] hardCode = ConstantsResolver.resourcesHardCoded; String[] hardCode = ConstantsResolver.resourcesHardCoded;
for (String resource : hardCode) { for (String resource : hardCode) {
log.trace("Is requested resource '{}' starting with hard-coded resource '{}'?", log.trace("Is requested resource '{}' starting with hard-coded resource '{}'?",requestedResourceName,resource);
requestedResourceName, resource); if(requestedResourceName.startsWith(resource)) {
if (requestedResourceName.startsWith(resource)) {
log.trace("Yes it starts!"); log.trace("Yes it starts!");
candidateResource = resource; candidateResource = resource;
log.info("The candidate resource to manage the request is the hard-coded resource: {}", log.info("The candidate resource to manage the request is the hard-coded resource: {}",candidateResource);
candidateResource);
resourceToRedirectFound = true; resourceToRedirectFound = true;
break; break;
} }
@ -152,33 +134,29 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
} }
} else }else
log.warn( log.warn("It was not possible to get the resource name from the splitted path {}. No action performed", path);
"It was not possible to get the resource name from the splitted path {}. No action performed", }else {
path);
} else {
log.warn("It was not possible to split the path {}. No action performed", path); log.warn("It was not possible to split the path {}. No action performed", path);
} }
} catch (Exception e) { }catch (Exception e) {
log.error("Error trying to retrieve the service able to manage the request. No action performed", e); log.error("Error trying to retrieve the service able to manage the request. No action performed", e);
} }
if (resourceToRedirectFound) { if(resourceToRedirectFound) {
log.debug("The input request '{}' can be managed by the service '{}'. No redirect performed", path, log.debug("The input request '{}' can be managed by the service '{}'. No redirect performed", path, candidateResource);
candidateResource); }else {
} else {
log.info("No resource/service found to manage the input request '{}'", path); log.info("No resource/service found to manage the input request '{}'", path);
String newPath = String.format("/%s/%s", ConstantsResolver.defaultServiceToRedirect, path); String newPath = String.format("/%s/%s", ConstantsResolver.defaultServiceToRedirect,path);
// log.debug("The path to redirect is '{}'", newPath); //log.debug("The path to redirect is '{}'", newPath);
// URI newRequestURI = //URI newRequestURI = reqContext.getUriInfo().getBaseUriBuilder().path(newPath).build();
// reqContext.getUriInfo().getBaseUriBuilder().path(newPath).build();
UriBuilder uriBuilder = reqContext.getUriInfo().getBaseUriBuilder(); UriBuilder uriBuilder = reqContext.getUriInfo().getBaseUriBuilder();
// ADDING THE INPUT QUERY STRING //ADDING THE INPUT QUERY STRING
MultivaluedMap<String, String> queryParameters = reqContext.getUriInfo().getQueryParameters(); MultivaluedMap<String, String> queryParameters = reqContext.getUriInfo().getQueryParameters();
for (String param : queryParameters.keySet()) { for (String param : queryParameters.keySet()) {
List<String> values = queryParameters.get(param); List<String> values = queryParameters.get(param);
if (values != null && !values.isEmpty()) if(values!=null && !values.isEmpty())
uriBuilder.queryParam(param, values.toArray()); uriBuilder.queryParam(param,values.toArray());
} }
URI newRequestURI = uriBuilder.path(newPath).build(); URI newRequestURI = uriBuilder.path(newPath).build();
@ -187,69 +165,17 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
} }
} }
/** /* (non-Javadoc)
* Filter. * @see javax.ws.rs.container.ContainerResponseFilter#filter(javax.ws.rs.container.ContainerRequestContext, javax.ws.rs.container.ContainerResponseContext)
*
* @param requestContext the request context
* @param responseContext the response context
* @throws IOException Signals that an I/O exception has occurred.
*/
/*
* (non-Javadoc)
*
* @see
* javax.ws.rs.container.ContainerResponseFilter#filter(javax.ws.rs.container.
* ContainerRequestContext, javax.ws.rs.container.ContainerResponseContext)
*/ */
@Override @Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException { throws IOException {
log.debug(RequestHandler.class.getSimpleName() + " Response called"); log.info(RequestHandler.class.getSimpleName() +" Response called");
SecurityTokenProvider.instance.reset(); SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset(); ScopeProvider.instance.reset();
log.debug("Token and Scope Provider reset called"); log.info("Token and Scope Provider reset called");
resetScretManager(requestContext, responseContext);
} }
/**
* Reset scret manager.
*
* @param requestContext the request context
* @param responseContext the response context
* @throws IOException Signals that an I/O exception has occurred.
*/
private void resetScretManager(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
log.debug("SecreteManager instance remove");
SecretManagerProvider.instance.remove();
}
/**
* Sets the secret manager.
*
* @param requestContext the new secret manager
* @throws IOException Signals that an I/O exception has occurred.
*/
private void setSecretManager(ContainerRequestContext requestContext) throws IOException {
log.debug("setSecretManager called");
SecretManagerProvider.instance.remove();
SecretManager secretManager = new SecretManager();
String token = AccessTokenProvider.instance.get();
if (token != null) {
Secret secret = new JWTSecret(token);
secretManager.addSecret(secret);
}
token = SecurityTokenProvider.instance.get();
if (token != null) {
Secret secret = new GCubeSecret(token);
secretManager.addSecret(secret);
}
SecretManagerProvider.instance.set(secretManager);
}
} }

View File

@ -43,6 +43,7 @@ import org.gcube.common.storagehub.model.Metadata;
import org.gcube.data.analysis.dminvocation.ActionType; import org.gcube.data.analysis.dminvocation.ActionType;
import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager; import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager;
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation; import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
import org.gcube.datatransfer.resolver.requesthandler.RequestHandler;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.services.exceptions.InternalServerException; import org.gcube.datatransfer.resolver.services.exceptions.InternalServerException;
import org.gcube.datatransfer.resolver.util.ScopeUtil; import org.gcube.datatransfer.resolver.util.ScopeUtil;
@ -56,12 +57,7 @@ import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
* The AnalyticsCreateResolver provides a method to get the Analytics URLs by * The Class AnalyticsCreateResolver.
* which is possible to invoke through the DataMiner Executor the run of an
* algorithm stored in a certain VRE.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 12, 2018 * Dec 12, 2018
@ -81,14 +77,10 @@ public class AnalyticsCreateResolver {
private static Logger logger = LoggerFactory.getLogger(AnalyticsCreateResolver.class); private static Logger logger = LoggerFactory.getLogger(AnalyticsCreateResolver.class);
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver"; private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver";
/** /**
* Creates the analytics url. * Creates the analytics url.
* *
* Request format: [URI_RESOLVER_SERVICE_ENDPOINT]/analytics/create
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_POST:_Create_an_Analytics_URL
*
* @param req the req * @param req the req
* @param body the body * @param body the body
* @return the response * @return the response
@ -98,246 +90,220 @@ public class AnalyticsCreateResolver {
@Path("/create") @Path("/create")
@Consumes(MediaType.TEXT_PLAIN) @Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response createAnalyticsURL(@Context HttpServletRequest req, String body) throws WebApplicationException { public Response createAnalyticsURL(@Context HttpServletRequest req, String body) throws WebApplicationException{
logger.info(this.getClass().getSimpleName() + " POST starts..."); logger.info(this.getClass().getSimpleName()+" POST starts...");
try { try{
logger.info("body is: " + body); logger.info("body is: "+body);
DataMinerInvocation jsonRequest = null; DataMinerInvocation jsonRequest = null;
try { try {
jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body), jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body), true);
true); }
} catch (IOException | JAXBException | SAXException e1) { catch (IOException | JAXBException | SAXException e1) {
logger.error("The body is not a valid DataMinerInvocation JSON request", e1); logger.error("The body is not a valid DataMinerInvocation JSON request",e1);
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Bad 'dataminer-invocation' JSON request: \n"+e1.getCause().getMessage(), this.getClass(), helpURI);
"Bad 'dataminer-invocation' JSON request: \n" + e1.getCause().getMessage(), this.getClass(),
helpURI);
} }
logger.debug("The body contains the request: " + jsonRequest.toString()); logger.debug("The body contains the request: "+jsonRequest.toString());
String contextToken = SecurityTokenProvider.instance.get();
String scope = ScopeProvider.instance.get(); String scope = ScopeProvider.instance.get();
// logger.info("SecurityTokenProvider contextToken: "+contextToken); // logger.info("SecurityTokenProvider contextToken: "+contextToken);
logger.info("ScopeProvider has scope: " + scope); logger.info("ScopeProvider has scope: "+scope);
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
if(contextToken.compareTo(appToken)==0){
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
}
String operatorID = jsonRequest.getOperatorId(); String operatorID = jsonRequest.getOperatorId();
if (scope == null || scope.isEmpty()) { if(scope==null || scope.isEmpty()){
logger.error("The parameter 'scope' not found or empty in the JSON object"); logger.error("The parameter 'scope' not found or empty in the JSON object");
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'scope' not found or empty in the JSON object", this.getClass(), helpURI);
"Mandatory body parameter 'scope' not found or empty in the JSON object", this.getClass(),
helpURI);
} }
if (operatorID == null || operatorID.isEmpty()) {
if(operatorID==null || operatorID.isEmpty()){
logger.error("The parameter 'operatorId' not found or empty in the JSON object"); logger.error("The parameter 'operatorId' not found or empty in the JSON object");
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(), helpURI);
"Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(),
helpURI);
} }
ScopeBean scopeBean = new ScopeBean(scope); ScopeBean scopeBean = new ScopeBean(scope);
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE");
throw ExceptionManager.unauthorizedException(req,
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
}
String publicLinkToDMInvFile = ""; String publicLinkToDMInvFile = "";
if (scopeBean.is(Type.VRE)) { if(scopeBean.is(Type.VRE)){
String vreName = scopeBean.name(); String vreName = scopeBean.name();
String analyticsGetResolverURL = String.format("%s/%s", Util.getServerURL(req), "analytics/get"); String analyticsGetResolverURL = String.format("%s/%s", Util.getServerURL(req), "analytics/get");
// Creating DM invocation file //Creating DM invocation file
if (jsonRequest.getActionType() == null) if(jsonRequest.getActionType()==null)
jsonRequest.setActionType(ActionType.RUN); jsonRequest.setActionType(ActionType.RUN);
File tempInvocationFile = null; File tempInvocationFile = null;
try { try {
String contextToken = SecurityTokenProvider.instance.get();
String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true); String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true);
String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId()); String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId());
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlRequest.getBytes()); tempInvocationFile = createTempFile(uniqueName, ".xml", xmlRequest.getBytes());
logger.info("Created StorageHubClient Instance, uploading file: " + tempInvocationFile.getName()); logger.info("Created StorageHubClient Instance, uploading file: "+tempInvocationFile.getName());
AuthorizationEntry entry = authorizationService().get(contextToken); AuthorizationEntry entry = authorizationService().get(contextToken);
// retrieve the info of the token owner //retrieve the info of the token owner
ClientInfo clientInfo = entry.getClientInfo(); ClientInfo clientInfo = entry.getClientInfo();
String owner = clientInfo.getId(); // IS THIS THE USERNAME? String owner = clientInfo.getId(); //IS THIS THE USERNAME?
String infra = ScopeUtil.getInfrastructureNameFromScope(ScopeProvider.instance.get()); String infra = ScopeUtil.getInfrastructureNameFromScope(ScopeProvider.instance.get());
String theAppToken = readApplicationTokenFromSE(req, infra); String theAppToken = readApplicationTokenFromSE(req, infra);
logger.info("By using infra scope: " + infra + " and the Application Token: " logger.info("By using infra scope: "+infra +" and the Application Token: "+theAppToken.substring(0,theAppToken.length()/2)+"... of "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" to instance the "+StorageHubManagement.class.getSimpleName());
+ theAppToken.substring(0, theAppToken.length() / 2) + "... of "
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " to instance the "
+ StorageHubManagement.class.getSimpleName());
ScopeProvider.instance.set(infra); ScopeProvider.instance.set(infra);
ApplicationMode applicationMode = new ApplicationMode(theAppToken); ApplicationMode applicationMode = new ApplicationMode(theAppToken);
applicationMode.start(); applicationMode.start();
StorageHubManagement storageHubManagement = new StorageHubManagement(); StorageHubManagement storageHubManagement = new StorageHubManagement();
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
Map<String, Object> theMap = new HashMap<String, Object>(); Map<String, String> theMap = new HashMap<String, String>();
theMap.put("owner", owner); theMap.put("owner", owner);
metadata.setMap(theMap);
URL thePublicLink = null; URL thePublicLink = null;
try { try{
logger.info("Saving dataminer-invocation file for the user: " + owner); logger.info("Saving dataminer-invocation file for the user: "+owner);
thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "application/xml", metadata);
tempInvocationFile.getName(), "application/xml", metadata); logger.info("Saved dataminer-invocation file at: "+thePublicLink);
logger.info("Saved dataminer-invocation file at: " + thePublicLink); }catch(Exception e){
} catch (Exception e) {
logger.error("Error when storing your 'dataminer-invocation':", e); logger.error("Error when storing your 'dataminer-invocation':", e);
throw ExceptionManager throw ExceptionManager.internalErrorException(req, "Error when storing your 'dataminer-invocation' request with "+jsonRequest+". \nPlease contact the support", this.getClass(), helpURI);
.internalErrorException(
req, "Error when storing your 'dataminer-invocation' request with "
+ jsonRequest + ". \nPlease contact the support",
this.getClass(), helpURI);
} }
publicLinkToDMInvFile = thePublicLink != null ? thePublicLink.toString() : null; // FileContainer fileContainer = shc.getWSRoot().uploadFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "DataMinerInvocation Request created by "+this.getClass().getSimpleName());
} catch (Exception e) { // logger.info("UPLOADED FILE at: "+fileContainer.getPublicLink());
// URL thePublicLink = fileContainer.getPublicLink();
publicLinkToDMInvFile = thePublicLink!=null?thePublicLink.toString():null;
}
catch (Exception e) {
if (e instanceof InternalServerException) { if(e instanceof InternalServerException){
// error during storing the file via StorageHubManagent //error during storing the file via StorageHubManagent
throw e; throw e;
} }
logger.error("Error on creating 'dataminer-invocation:", e); logger.error("Error on creating 'dataminer-invocation:", e);
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Error on creating your 'dataminer-invocation' request with "+jsonRequest+". \nPlease contact the support", this.getClass(), helpURI);
"Error on creating your 'dataminer-invocation' request with " + jsonRequest }finally{
+ ". \nPlease contact the support", //No needed to reset the scope, it is provided by TokenSetter
this.getClass(), helpURI); try{
} finally { //DELETING THE TEMP FILE
// No needed to reset the scope, it is provided by TokenSetter if(tempInvocationFile!=null && tempInvocationFile.exists())
try {
// DELETING THE TEMP FILE
if (tempInvocationFile != null && tempInvocationFile.exists())
tempInvocationFile.delete(); tempInvocationFile.delete();
} catch (Exception e) { }catch(Exception e){
// silent //silent
} }
} }
if (publicLinkToDMInvFile == null) { if(publicLinkToDMInvFile==null){
logger.error("Error on creating the public link to file"); logger.error("Error on creating the public link to file");
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Error on getting link to your 'dataminer-invocation' request. Plese contact the support "+jsonRequest, this.getClass(), helpURI);
"Error on getting link to your 'dataminer-invocation' request. Plese contact the support "
+ jsonRequest,
this.getClass(), helpURI);
} }
String dataMinerURL = String.format("%s/%s?%s=%s", analyticsGetResolverURL, vreName, String dataMinerURL = String.format("%s/%s?%s=%s", analyticsGetResolverURL, vreName, DATAMINER_INVOCATION_MODEL, publicLinkToDMInvFile);
DATAMINER_INVOCATION_MODEL, publicLinkToDMInvFile); logger.info("Returning Analytics URL: "+dataMinerURL);
logger.info("Returning Analytics URL: " + dataMinerURL);
return Response.ok(dataMinerURL).header("Location", dataMinerURL).build(); return Response.ok(dataMinerURL).header("Location", dataMinerURL).build();
} else { }else{
logger.error("The input scope " + scope + " is not a VRE"); logger.error("The input scope "+scope+" is not a VRE");
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Working in the "+scope+" scope that is not a VRE. Use a token of VRE", this.getClass(), helpURI);
"Working in the " + scope + " scope that is not a VRE. Use a token of VRE", this.getClass(),
helpURI);
} }
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on creating the Analytics for the request " + body String error = "Error occurred on creating the Analytics for the request "+body+". Please, contact the support!";
+ ". Please, contact the support!"; if(e.getCause()!=null)
if (e.getCause() != null) error+="\n\nCaused: "+e.getCause().getMessage();
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Reads the Application Token from Service Endpoint * Reads the Application Token from Service Endpoint {@link AnalyticsCreateResolver#ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME}
* {@link AnalyticsCreateResolver#ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME}
* *
* @param req the req * @param req the req
* @param scope the scope * @param scope the scope
* @return the string * @return the string
*/ */
private static String readApplicationTokenFromSE(HttpServletRequest req, String scope) { private static String readApplicationTokenFromSE(HttpServletRequest req, String scope){
String callerScope = null; String callerScope = null;
String gCubeAppToken = null; String gCubeAppToken = null;
try { try{
callerScope = ScopeProvider.instance.get(); callerScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
logger.info("Searching SE " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " configurations in the scope: " logger.info("Searching SE "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" configurations in the scope: "+ScopeProvider.instance.get());
+ ScopeProvider.instance.get());
SimpleQuery query = queryFor(ServiceEndpoint.class); SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '" + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + "'"); query.addCondition("$resource/Profile/Name/text() eq '"+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME +"'");
query.addCondition("$resource/Profile/Category/text() eq 'Service'"); query.addCondition("$resource/Profile/Category/text() eq 'Service'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class); DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> toReturn = client.submit(query); List<ServiceEndpoint> toReturn = client.submit(query);
logger.info("The query returned " + toReturn.size() + " ServiceEndpoint/s"); logger.info("The query returned "+toReturn.size()+ " ServiceEndpoint/s");
if (toReturn.size() == 0) { if(toReturn.size()==0){
String errorMessage = "No " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " registered in the scope: " String errorMessage = "No "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" registered in the scope: "+ScopeProvider.instance.get();
+ ScopeProvider.instance.get();
logger.error(errorMessage); logger.error(errorMessage);
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
helpURI);
} }
ServiceEndpoint se = toReturn.get(0); ServiceEndpoint se = toReturn.get(0);
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection(); Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
for (AccessPoint accessPoint : theAccessPoints) { for (AccessPoint accessPoint : theAccessPoints) {
Collection<Property> properties = accessPoint.properties().asCollection(); Collection<Property> properties = accessPoint.properties().asCollection();
for (Property property : properties) { for (Property property : properties) {
if (property.name().equalsIgnoreCase(GCUBE_TOKEN)) { if(property.name().equalsIgnoreCase(GCUBE_TOKEN)){
logger.info("gcube-token as property was found, returning it"); logger.info("gcube-token as property was found, returning it");
gCubeAppToken = property.value(); gCubeAppToken = property.value();
break; break;
} }
} }
if (gCubeAppToken != null) if(gCubeAppToken!=null)
break; break;
} }
if (gCubeAppToken != null) { if(gCubeAppToken!=null){
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(gCubeAppToken); String decryptedPassword = StringEncrypter.getEncrypter().decrypt(gCubeAppToken);
logger.info("Returning decrypted Application Token registered into " logger.info("Returning decrypted Application Token registered into "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME +" SE: "+decryptedPassword.substring(0,decryptedPassword.length()/2)+"....");
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE: "
+ decryptedPassword.substring(0, decryptedPassword.length() / 2) + "....");
return decryptedPassword; return decryptedPassword;
} }
String errorMessage = "No " + GCUBE_TOKEN + " as Property saved in the "
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE registered in the scope: " String errorMessage = "No "+GCUBE_TOKEN+" as Property saved in the "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
+ ScopeProvider.instance.get();
logger.error(errorMessage); logger.error(errorMessage);
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI); throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
} catch (Exception e) {
String errorMessage = "Error occurred on reading the " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME }catch(Exception e){
+ " SE registered in the scope: " + ScopeProvider.instance.get(); String errorMessage = "Error occurred on reading the "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
logger.error(errorMessage, e); logger.error(errorMessage, e);
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI); throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
} finally { }finally{
if (callerScope != null) { if(callerScope!=null){
logger.info("Setting to the callerScope scope: " + callerScope); logger.info("Setting to the callerScope scope: "+callerScope);
ScopeProvider.instance.set(callerScope); ScopeProvider.instance.set(callerScope);
} else { }else{
logger.info("Reset scope"); logger.info("Reset scope");
ScopeProvider.instance.reset(); ScopeProvider.instance.reset();
} }
@ -345,6 +311,7 @@ public class AnalyticsCreateResolver {
} }
/** /**
* Creates the temp file. * Creates the temp file.
* *
@ -360,23 +327,32 @@ public class AnalyticsCreateResolver {
File file = path.toFile(); File file = path.toFile();
// writing sample data // writing sample data
Files.write(path, data); Files.write(path, data);
logger.info("Created the Temp File: " + file.getAbsolutePath()); logger.info("Created the Temp File: "+file.getAbsolutePath());
return file; return file;
} }
/** /**
* Creates the dm invocation file name. * Creates the dm invocation file name.
* *
* @param operatorId the operator id * @param operatorId the operator id
* @return the string * @return the string
*/ */
private static String createDMInvocationFileName(String operatorId) { private static String createDMInvocationFileName(String operatorId){
String fileName = "dim"; String fileName = "dim";
int index = operatorId.lastIndexOf("."); int index = operatorId.lastIndexOf(".");
if (index > 0 && index < operatorId.length()) { if(index>0 && index<operatorId.length()){
fileName += "-" + operatorId.substring(index + 1, operatorId.length()); fileName+="-"+operatorId.substring(index+1,operatorId.length());
} }
fileName += "-" + System.currentTimeMillis(); fileName+="-"+System.currentTimeMillis();
return fileName; return fileName;
} }
// public static void main(String[] args) {
//
// System.out.println(readApplicationTokenFromSE(null, "/gcube"));
//
// }
} }

View File

@ -23,22 +23,20 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/** /**
* The AnalyticsGetResolver to resolve an Analytics URL * The Class AnalyticsGetResolver.
* *
* See more at * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver * Dec 13, 2018
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2022
*/ */
@Path("analytics") @Path("analytics")
public class AnalyticsGetResolver { public class AnalyticsGetResolver {
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class); private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);
private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL = "org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl"; private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL =
"org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl";
private static final String APPLICATION_PROFILE = "ApplicationProfile"; private static final String APPLICATION_PROFILE = "ApplicationProfile";
@ -46,73 +44,60 @@ public class AnalyticsGetResolver {
private static final String ANALYTICS_EXECUTOR_PORTLET_NAME = "Analytics Executor"; private static final String ANALYTICS_EXECUTOR_PORTLET_NAME = "Analytics Executor";
/** /**
* Resolve analytics url. * Resolve analytics url.
* *
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_GET:_Resolve_an_Analytics_URL
*
* @param req the req * @param req the req
* @param vreName the vre name * @param vreName the vre name
* @return the response * @return the response
* @throws WebApplicationException the web application exception
*/ */
@GET @GET
@Path("/get/{vreName}") @Path("/get/{vreName}")
public Response resolveAnalyticsURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) public Response resolveAnalyticsURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) throws WebApplicationException{
throws WebApplicationException { logger.info(this.getClass().getSimpleName()+" GET starts...");
logger.info(this.getClass().getSimpleName() + " GET starts...");
try { try {
if (vreName == null || vreName.isEmpty()) { if(vreName==null || vreName.isEmpty()){
logger.error("The path parameter 'vreName' not found or empty in the path"); logger.error("The path parameter 'vreName' not found or empty in the path");
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
this.getClass(), helpURI);
} }
ScopeBean fullScopeBean = null; ScopeBean fullScopeBean = null;
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE... //CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
try { try{
fullScopeBean = LoadingMapOfScopeCache.get(vreName); fullScopeBean = LoadingMapOfScopeCache.get(vreName);
} catch (ExecutionException | InvalidCacheLoadException e) { }catch(ExecutionException | InvalidCacheLoadException e){
logger.error("Error on getting the fullscope from cache for vreName " + vreName, e); logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
throw ExceptionManager.wrongParameterException(req, throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
"Error on getting full scope for the VRE name " + vreName
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
this.getClass(), helpURI);
} }
ApplicationProfileReader reader = null; ApplicationProfileReader reader = null;
try { try{
reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE, reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false); }catch(Exception e){
} catch (Exception e) { logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, e);
logger.error("Error on reading the " + APPLICATION_PROFILE + " with APPID: " throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+ANALYTICS_EXECUTOR_PORTLET_NAME+". Please contact the support", this.getClass(), helpURI);
+ ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, e);
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "
+ ANALYTICS_EXECUTOR_PORTLET_NAME + ". Please contact the support", this.getClass(), helpURI);
} }
// READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE //READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
// fullScope
String analyticsExecutorEndPoint = reader.getApplicationProfile().getUrl(); String analyticsExecutorEndPoint = reader.getApplicationProfile().getUrl();
// CHECKING THE QUERY STRING //CHECKING THE QUERY STRING
String queryString = req.getQueryString() != null ? req.getQueryString() : ""; String queryString = req.getQueryString()!=null?req.getQueryString():"";
String analitycsExecutorURL = String.format("%s?%s", analyticsExecutorEndPoint, queryString); String analitycsExecutorURL = String.format("%s?%s", analyticsExecutorEndPoint, queryString);
logger.info("Resolving the request with the " + ANALYTICS_EXECUTOR_PORTLET_NAME + " URL: " logger.info("Resolving the request with the "+ANALYTICS_EXECUTOR_PORTLET_NAME+" URL: "+analitycsExecutorURL);
+ analitycsExecutorURL);
return Response.seeOther(new URI(analitycsExecutorURL)).build(); return Response.seeOther(new URI(analitycsExecutorURL)).build();
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!"; String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
if (e.getCause() != null) if(e.getCause()!=null)
error += "\n\nCaused: " + e.getCause().getMessage(); error+="\n\nCaused: "+e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -1,9 +1,6 @@
package org.gcube.datatransfer.resolver.services; package org.gcube.datatransfer.resolver.services;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -18,39 +15,29 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.datatransfer.resolver.ConstantsResolver; import org.gcube.datatransfer.resolver.ConstantsResolver;
import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE;
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache; import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest; import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
import org.gcube.datatransfer.resolver.catalogue.ItemCatalogueURLs; import org.gcube.datatransfer.resolver.catalogue.ItemCatalogueURLs;
import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes; import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.catalogue.resource.CatalogueStaticConfigurations;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader; import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference; import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes; import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.util.Util; import org.gcube.datatransfer.resolver.util.Util;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
import org.gcube.smartgears.utils.InnerMethodName; import org.gcube.smartgears.utils.InnerMethodName;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import eu.trentorise.opendata.jackan.model.CkanDataset;
/** /**
* The CatalogueResolver is able to get/resolve a link to a "Catalogue Entity" * The Class CatalogueResolver.
* stored in one of the D4Science Catalogue's instances. A Catalogue Entity is
* either a "group" or an "organization" or a "product" of D4Science Data
* Catalogue.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 16, 2018 * Nov 16, 2018
@ -58,37 +45,27 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
@Path("{entityContext:ctlg(-(o|g|p|d))?}") @Path("{entityContext:ctlg(-(o|g|p|d))?}")
public class CatalogueResolver { public class CatalogueResolver {
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class); private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver"; private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver";
/** /**
* The Enum SCOPE_STATUS. * Resolve catalogue.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2022
*/
private static enum SCOPE_STATUS {
ACTIVE, DETACHED
}
/**
* Resolve an entity of the Catalogue
* *
* @param req the req * @param req the req
* @param entityName the entity name * @param entityName the entity name
* @param vreName the vre name * @param vreName the vre name
* @param entityContext the entity context * @param entityContext the entity context
* @return the response * @return the response
* @throws WebApplicationException the web application exception
*/ */
@GET @GET
@Path("/{vreName}/{entityName}") @Path("/{vreName}/{entityName}")
public Response resolveCatalogue(@Context HttpServletRequest req, @PathParam("entityName") String entityName, public Response resolveCatalogue(@Context HttpServletRequest req,
@PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) @PathParam("entityName") String entityName,
throws WebApplicationException { @PathParam("vreName") String vreName,
@PathParam("entityContext") String entityContext) throws WebApplicationException{
logger.info(this.getClass().getSimpleName() + " GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
try { try {
InnerMethodName.instance.set("resolveCataloguePublicLink"); InnerMethodName.instance.set("resolveCataloguePublicLink");
@ -96,129 +73,96 @@ public class CatalogueResolver {
String itemCatalogueURL; String itemCatalogueURL;
if (itemCatalogueURLs.isPublicItem()) { if(itemCatalogueURLs.isPublicItem()){
logger.info("The dataset " + itemCatalogueURLs.getItemName() logger.info("The dataset "+itemCatalogueURLs.getItemName()+" should be a public item (not private to VRE).");
+ " was detected as public item (not private to VRE)"); if(itemCatalogueURLs.getPublicVRECataloguePortletURL()!=null && !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
if (itemCatalogueURLs.getPublicVRECataloguePortletURL() != null
&& !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL(); itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL();
logger.info( logger.info("I found the public VRE catalogue URL, so using public access to it: "+itemCatalogueURL);
"I found the public VRE catalogue URL, so using public access to it: " + itemCatalogueURL); }else {
} else {
itemCatalogueURL = itemCatalogueURLs.getPublicGatewayCataloguePortletURL(); itemCatalogueURL = itemCatalogueURLs.getPublicGatewayCataloguePortletURL();
logger.info("No public VRE catalogue URL found, so using public access to gateway CKAN portlet: " logger.info("No public VRE catalogue URL found, so using public access to gateway CKAN portlet: "+itemCatalogueURL);
+ itemCatalogueURL);
} }
} else { }else{
itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL(); itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL();
logger.info("Either the " + itemCatalogueURLs.getItemName() logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a private item (to VRE) so using protected access to CKAN portlet: "+itemCatalogueURL);
+ " is not an item (alias dataset) or it is a private item (to VRE) so using protected access to CKAN portlet: "
+ itemCatalogueURL);
}
String queryString = req.getQueryString();
if (queryString != null) {
logger.info("Query string found: " + queryString);
byte[] stringEncBytes = Base64.encodeBase64(queryString.getBytes());
String queryStringEnc = "query_string=" + new String(stringEncBytes);
logger.info("Adding Base64 encoded: " + queryString);
itemCatalogueURL += itemCatalogueURL.contains("?") ? "&" : "?";
itemCatalogueURL += queryStringEnc;
} }
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build(); return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the " + CatalogueResolver.class.getSimpleName() String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!";
+ " URL. Please, contact the support!"; if(e.getCause()!=null)
if (e.getCause() != null) error+="\n\nCaused: "+e.getCause().getMessage();
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Create a Catalogue Link * Post catalogue.
*
* *
* @param req the req * @param req the req
* @param jsonRequest the json request * @param jsonRequest the json request
* @return the response * @return the response
* @throws WebApplicationException the web application exception
*/ */
@POST @POST
@Path("") @Path("")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) throws WebApplicationException{
throws WebApplicationException { logger.info(this.getClass().getSimpleName()+" POST starts...");
logger.info(this.getClass().getSimpleName() + " POST starts...");
try { try{
InnerMethodName.instance.set("postCataloguePublicLink"); InnerMethodName.instance.set("postCataloguePublicLink");
logger.info("The body contains the request: " + jsonRequest.toString()); logger.info("The body contains the request: "+jsonRequest.toString());
// CHECK IF INPUT SCOPE IS VALID //CHECK IF INPUT SCOPE IS VALID
String scope = jsonRequest.getGcube_scope(); String scope = jsonRequest.getGcube_scope();
if (!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)) { if(!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)){
logger.info("Scope not start with char '{}' adding it", ConstantsResolver.SCOPE_SEPARATOR); logger.info("Scope not start with char '{}' adding it",ConstantsResolver.SCOPE_SEPARATOR);
scope += ConstantsResolver.SCOPE_SEPARATOR + scope; scope+=ConstantsResolver.SCOPE_SEPARATOR+scope;
} }
String serverUrl = Util.getServerURL(req); String serverUrl = Util.getServerURL(req);
final String vreName = scope.substring(scope.lastIndexOf(ConstantsResolver.SCOPE_SEPARATOR) + 1, final String vreName = scope.substring(scope.lastIndexOf(ConstantsResolver.SCOPE_SEPARATOR)+1, scope.length());
scope.length());
ScopeBean fullScope = null; ScopeBean fullScope = null;
// CHECK IF THE vreName has a valid scope, so it is a valid VRE //CHECK IF THE vreName has a valid scope, so it is a valid VRE
try { try {
fullScope = LoadingMapOfScopeCache.get(vreName); fullScope = LoadingMapOfScopeCache.get(vreName);
} catch (ExecutionException e) { }catch(ExecutionException e){
logger.error("Error on getting the fullscope from cache for vreName " + vreName, e); logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
throw ExceptionManager.wrongParameterException(req, throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
"Error on getting full scope for the VRE name " + vreName
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
this.getClass(), helpURI);
} }
if (fullScope == null) if(fullScope==null)
throw ExceptionManager.notFoundException(req, throw ExceptionManager.notFoundException(req, "The scope '"+scope+"' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI);
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
this.getClass(), helpURI);
ResourceCatalogueCodes rc = ResourceCatalogueCodes.valueOfCodeValue(jsonRequest.getEntity_context()); ResourceCatalogueCodes rc = ResourceCatalogueCodes.valueOfCodeValue(jsonRequest.getEntity_context());
if (rc == null) { if(rc==null){
logger.error("Entity context is null/malformed"); logger.error("Entity context is null/malformed");
throw ExceptionManager.badRequestException(req, "Entity context is null/malformed", this.getClass(), throw ExceptionManager.badRequestException(req, "Entity context is null/malformed", this.getClass(), helpURI);
helpURI);
} }
String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name()); String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name());
logger.info("Returining Catalogue URL: "+linkURL);
if (jsonRequest.getQuery_string() != null) {
linkURL += "?" + jsonRequest.getQuery_string();
}
logger.info("Returning " + CatalogueResolver.class.getSimpleName() + " URL: " + linkURL);
return Response.ok(linkURL).header("Location", linkURL).build(); return Response.ok(linkURL).header("Location", linkURL).build();
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on creating the " + CatalogueResolver.class.getSimpleName() String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
+ " URL. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs //ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
@ -234,137 +178,61 @@ public class CatalogueResolver {
* @return the item catalogue UR ls * @return the item catalogue UR ls
* @throws Exception the exception * @throws Exception the exception
*/ */
protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String scopeName, protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String scopeName, String entityContext, String entityName) throws Exception{
String entityContext, String entityName) throws Exception {
try { try {
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue(); String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
ScopeBean scopeBean = null; ScopeBean scopeBean = null;
SCOPE_STATUS scopeStatus = SCOPE_STATUS.ACTIVE; try{
VRE vreDetached = null;
try {
scopeBean = LoadingMapOfScopeCache.get(scopeName); scopeBean = LoadingMapOfScopeCache.get(scopeName);
} catch (ExecutionException | InvalidCacheLoadException e) { }catch(ExecutionException | InvalidCacheLoadException e){
logger.error( logger.error("Error on getting the fullscope from cache for scopeName "+scopeName, e);
"Error on getting the fullscope from cache for scopeName {}. Trying to load it from DetachedRE", throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the scope name '"+scopeName+"'. Is it registered as a valid Scope in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI);
scopeName);
boolean isScopeDetached = false;
try {
vreDetached = LoadingMapOfDetachedVRE.get(scopeName);
scopeBean = new ScopeBean(vreDetached.getScope());
scopeStatus = SCOPE_STATUS.DETACHED;
logger.info("I loaded a valid VRE obj for scope name {}", scopeName);
isScopeDetached = true;
} catch (Exception e1) {
logger.warn("I was not able to load a detached VRE for vreName {}. Going to error for wrong scope",
scopeName);
}
// If is not a cas of scope detached, going to error for wrong scope
if (!isScopeDetached) {
logger.error("Error on getting the fullscope from cache for scopeName " + scopeName, e);
throw ExceptionManager.wrongParameterException(req,
"Error on getting full scope for the scope name '" + scopeName
+ "'. Is it registered as a valid Scope in the D4Science Infrastructure System?",
CatalogueResolver.class, helpURI);
}
} }
String fullScope = scopeBean.toString(); String fullScope = scopeBean.toString();
logger.info("Read fullScope: " + fullScope + " for SCOPE name: " + scopeName + " from cache created by: " logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());
+ GetAllInfrastructureScopes.class.getSimpleName());
if (scopeBean.is(Type.VO)) { if(scopeBean.is(Type.VO)) {
logger.info("It is a {} scope", Type.VO); logger.info("It is a {} scope", Type.VO);
logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO, logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO, Type.INFRASTRUCTURE);
Type.INFRASTRUCTURE);
String[] splitScope = fullScope.split(ConstantsResolver.SCOPE_SEPARATOR); String[] splitScope = fullScope.split(ConstantsResolver.SCOPE_SEPARATOR);
fullScope = ConstantsResolver.SCOPE_SEPARATOR + splitScope[1]; // THIS IS THE INFRASTRUCTURE SCOPE fullScope = ConstantsResolver.SCOPE_SEPARATOR+splitScope[1]; //THIS IS THE INFRASTRUCTURE SCOPE
logger.info("Overriden the input scope {} with {} as type: {}", scopeBean.toString(), logger.info("Overriden the input scope {} with {} as type: {}", scopeBean.toString(), Type.INFRASTRUCTURE, fullScope);
Type.INFRASTRUCTURE, fullScope);
} }
ScopeProvider.instance.set(fullScope); ScopeProvider.instance.set(fullScope);
GatewayCKANCatalogueReference ckanCatalogueReference = null; GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
logger.info("Managing scope status: {}", scopeStatus);
switch (scopeStatus) { logger.info("For scope "+fullScope+" loaded end points: "+ckanCatalogueReference);
case DETACHED:
String privatePortletURL = vreDetached.getCatalogPortletURL(); //IS THE PRODUCT PLUBLIC OR PRIVATE?
// The private portlet URL
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue = new HashMap<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String>(
3);
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE, privatePortletURL);
// Building the gateway catalogue public URL from private VRE Portlet URL
URI toURL = new URI(privatePortletURL);
String publicURL = privatePortletURL.startsWith("https://") ? "https://" + toURL.getHost()
: "http://" + toURL.getHost();
// It returns the string "catalogue"
CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations();
// Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g
// catalogue-bb)
String relativeURLWithCatalogueName = staticConf
.buildRelativeURLToPublicCatalogueGateway(vreDetached.getCatalogUrl());
String toGatewayPortletURL = String.format("%s/%s", publicURL, relativeURLWithCatalogueName);
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY, toGatewayPortletURL);
ckanCatalogueReference = new GatewayCKANCatalogueReference(fullScope, vreDetached.getCatalogUrl(),
mapAccessURLToCatalogue);
break;
case ACTIVE:
default:
ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
break;
}
logger.info("For scope " + fullScope + " loaded end points: " + ckanCatalogueReference);
// IS THE PRODUCT PLUBLIC OR PRIVATE?
String datasetName = entityName; String datasetName = entityName;
boolean isPublicItem = false; boolean isPublicItem = false;
if (ckanCatalogueReference.getCkanURL() != null) { if(ckanCatalogueReference.getCkanURL()!=null){
try { try{
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName, CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName, ckanCatalogueReference.getCkanURL());
ckanCatalogueReference.getCkanURL()); if(dataset!=null){
if (dataset != null) {
isPublicItem = true; isPublicItem = true;
// ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL(); //ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
logger.info("The dataset " + datasetName + " is a public item"); logger.info("The dataset "+datasetName+" is a public item");
} }
} catch (Exception e) { }catch(Exception e){
logger.warn("Error on checking if dataset: " + datasetName + " is private or not", e); logger.warn("Error on checking if dataset: "+datasetName+" is private or not", e);
isPublicItem = true; isPublicItem = true;
} }
} }
String publicGatewayPorltetURL = String.format("%s?path=/%s/%s", String publicGatewayPorltetURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicGatewayPortletURL(),entityContextValue, entityName);
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY), String privateVREPortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPrivateVREPortletURL(),entityContextValue, entityName);
entityContextValue, entityName); String publicVREPortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicVREPortletURL(),entityContextValue, entityName);
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL, publicGatewayPorltetURL);
String privateVREPortletURL = String.format("%s?path=/%s/%s", }catch (Exception e) {
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE),
entityContextValue, entityName);
// Checking if the public VRE portlet URL is available (so it was read from GR)
String publicVREPortletURL = null;
String toCheckPublicVREPortletURL = ckanCatalogueReference
.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
if (toCheckPublicVREPortletURL != null && !toCheckPublicVREPortletURL.isEmpty()) {
// here the catalogue is available/deployed as public at VRE level
publicVREPortletURL = String.format("%s?path=/%s/%s", toCheckPublicVREPortletURL, entityContextValue,
entityName);
}
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL,
publicGatewayPorltetURL);
} catch (Exception e) {
logger.error("Error when resolving CatalogueURL:", e); logger.error("Error when resolving CatalogueURL:", e);
throw e; throw e;
} }
} }
} }

View File

@ -1,69 +0,0 @@
/**
*
*/
package org.gcube.datatransfer.resolver.services;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class DocsGenerator.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 1, 2022
*/
@Path("docs")
public class DocsGenerator {
private static Logger logger = LoggerFactory.getLogger(DocsGenerator.class);
/**
* To doc.
*
* @param req the req
* @return the input stream
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/{any: .*}")
public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException {
logger.info(DocsGenerator.class.getSimpleName() + " toDoc called");
String pathInfo = req.getPathInfo();
logger.debug("pathInfo {}", pathInfo);
try {
if (pathInfo.endsWith("/docs/")) {
pathInfo += "index.html";
}
logger.info("going to {}", pathInfo);
String realPath = req.getServletContext().getRealPath(pathInfo);
return new FileInputStream(new File(realPath));
} catch (Exception e) {
if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = pathInfo + " not found. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
}
// ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e);
throw (WebApplicationException) e;
}
}
}

View File

@ -48,11 +48,7 @@ import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
/** /**
* The GeonetworkResolver is a "middle tier" to perform queries * The Class GeonetworkResolver.
* to D4Science's Geonetwork services.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geonetwork_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Oct 23, 2018 * Oct 23, 2018
@ -64,8 +60,7 @@ public class GeonetworkResolver {
* *
*/ */
public static final String REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE = "Replaced a public UUID, please ignore"; public static final String REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE = "Replaced a public UUID, please ignore";
public static final String REPLACED_UUID_BY_FILTER_PLEASE_IGNORE = "Replaced UUID by " public static final String REPLACED_UUID_BY_FILTER_PLEASE_IGNORE = "Replaced UUID by "+GeonetworkResolver.class.getSimpleName()+" filters, please ignore";
+ GeonetworkResolver.class.getSimpleName() + " filters, please ignore";
private static Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class); private static Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
@ -83,21 +78,21 @@ public class GeonetworkResolver {
public static final String QUERY_PARAM_RESET_CACHE_PARAM = "resetcache"; public static final String QUERY_PARAM_RESET_CACHE_PARAM = "resetcache";
public static final String QUERY_PARAM_RESET_CACHED_SCOPE_PARAM = "resetcachedscope"; public static final String QUERY_PARAM_RESET_CACHED_SCOPE_PARAM = "resetcachedscope";
public static final String SRV_EN_MEF_EXPORT = "/srv/en/mef.export"; // MEF Geonetwork service public static final String SRV_EN_MEF_EXPORT = "/srv/en/mef.export"; //MEF Geonetwork service
public static final String UUID = "uuid"; public static final String UUID = "uuid";
public static final String SCOPE_SEPARATOR = "|"; public static final String SCOPE_SEPARATOR = "|";
// protected Map<String, GeonetworkInstance> cacheGNInstances; //protected Map<String, GeonetworkInstance> cacheGNInstances;
private String helpURI = "https://wiki.gcube-system.org/gcube/GCube_Resource_Catalogue#Geonetwork_Resolver"; private String helpURI = "https://wiki.gcube-system.org/gcube/GCube_Resource_Catalogue#Geonetwork_Resolver";
/** /**
* Gets the geonetwork request criteria. Creates a request criteria from input * Gets the geonetwork request criteria.
* parameter pathWithoutGN. The parameter pathWithoutGN should be an ordered * Creates a request criteria from input parameter pathWithoutGN
* string (like REST request): SCOPE/MODE/VISIBILITY/OWNER/$$ * The parameter pathWithoutGN should be an ordered string (like REST request):
* * SCOPE/MODE/VISIBILITY/OWNER/$$
* SCOPE must be: ROOT|VO|VRE * SCOPE must be: ROOT|VO|VRE
* MODE must be: {@link MODE} * MODE must be: {@link MODE}
* VISIBILITY must be: {@link VISIBILITY} * VISIBILITY must be: {@link VISIBILITY}
@ -117,84 +112,73 @@ public class GeonetworkResolver {
*/ */
@GET @GET
@Path("/{" + PATH_PARAM_SCOPE + "}/{" + PATH_PARAM_MODE + "}/{" + PATH_PARAM_VISIBILITY @Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
+ "}/{filterKey}/{filterValue}/$${" + PATH_PARAM_REMAINPATH + ":(/[^?$]+)?}") public Response submitGet(@Context HttpServletRequest req,
public Response submitGet(@Context HttpServletRequest req, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode, @PathParam(PATH_PARAM_MODE) @Nullable String mode,
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility, @PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
@PathParam("filterKey") @Nullable String filterKey, @PathParam("filterValue") @Nullable String filterValue, @PathParam("filterKey") @Nullable String filterKey,
@PathParam("filterValue") @Nullable String filterValue,
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath, @PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache, @QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) @QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) throws WebApplicationException{
throws WebApplicationException {
logger.info(this.getClass().getSimpleName() + " GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
String gnGetlURL = null; String gnGetlURL = null;
try { try {
logger.info( logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", filterKey: "+filterKey+", filterValue: "+filterValue+", remainPath: "+remainPath+"]");
"Params are [mode: " + mode + ", scope: " + scope + ", visibility: " + visibility + ", filterKey: "
+ filterKey + ", filterValue: " + filterValue + ", remainPath: " + remainPath + "]");
if (scope == null || scope.isEmpty()) { if(scope==null || scope.isEmpty()){
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), helpURI);
this.getClass(), helpURI);
} }
if (mode == null || mode.isEmpty()) { if(mode==null || mode.isEmpty()){
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), helpURI);
this.getClass(), helpURI);
} }
scope = ScopeUtil.normalizeScope(scope, "|"); scope = ScopeUtil.normalizeScope(scope, "|");
mode = mode.toUpperCase(); mode = mode.toUpperCase();
try { try{
MODE.valueOf(mode); MODE.valueOf(mode);
} catch (Exception e) { }catch(Exception e){
List<MODE> toPrint = Arrays.asList(MODE.values()); List<MODE> toPrint = Arrays.asList(MODE.values());
logger.error( logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?");
"The 'mode' parameter is wrong, Have you pass a valid parameter MODE like " + toPrint + "?"); throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), helpURI);
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of " + toPrint,
this.getClass(), helpURI);
} }
if (visibility == null) { if(visibility==null){
logger.error("Path Parameter 'visibility' not found"); logger.error("Path Parameter 'visibility' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), helpURI);
this.getClass(), helpURI);
} }
visibility = visibility.toUpperCase(); visibility = visibility.toUpperCase();
try { try{
VISIBILITY.valueOf(visibility); VISIBILITY.valueOf(visibility);
} catch (Exception e) { }catch (Exception e) {
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values()); List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like " logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?");
+ toPrint + "?"); throw ExceptionManager.wrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), helpURI);
throw ExceptionManager.wrongParameterException(req,
"The 'visibility' parameter must be value of " + toPrint, this.getClass(), helpURI);
} }
logger.info("Remaining path is: " + remainPath); logger.info("Remaining path is: "+remainPath);
try { try {
// I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED //I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN,
// SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION //AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED
// ON GN,
// AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF
// NEEDED
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope); GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
logger.info("set scope provider " + scope); logger.info("set scope provider "+scope);
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
Account account = gnInstance.getAccount(); Account account = gnInstance.getAccount();
Version version = gnInstance.getVersion(); Version version = gnInstance.getVersion();
String geonetworkUrl = gnInstance.getEndPoint(); String geonetworkUrl = gnInstance.getEndPoint();
Configuration config = gnInstance.getConfig() != null ? gnInstance.getConfig() : null; Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
if (account == null || account.getUser() == null || account.getPassword() == null || config == null) { if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
logger.info("Loading GN instance and configurations via Geonetwork Library..."); logger.info("Loading GN instance and configurations via Geonetwork Library...");
config = gnInstance.getGeonetworkPublisher().getConfiguration(); config = gnInstance.getGeonetworkPublisher().getConfiguration();
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN); account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
@ -202,18 +186,16 @@ public class GeonetworkResolver {
geonetworkUrl = config.getGeoNetworkEndpoint(); geonetworkUrl = config.getGeoNetworkEndpoint();
} }
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}", scope, account.getUser(), logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl);
geonetworkUrl);
HTTPCallsUtils httpUtils = new HTTPCallsUtils(); HTTPCallsUtils httpUtils = new HTTPCallsUtils();
if (visibility.equals(VISIBILITY.PRV.name())) { if(visibility.equals(VISIBILITY.PRV.name())){
if (account.getUser() != null) { if(account.getUser()!=null){
switch (version) { switch (version) {
case DUE: case DUE:
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword());
account.getPassword()); logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized);
logger.info("Authorized on GN2 " + geonetworkUrl + " ? " + authorized);
break; break;
default: default:
@ -222,60 +204,54 @@ public class GeonetworkResolver {
break; break;
} }
} else { }else {
logger.warn("I'm not able to perform authentication, the user read from config with " logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null");
+ Type.CKAN + " is null");
} }
} }
String baseURL = remainPath == null || remainPath.isEmpty() ? geonetworkUrl + "/" + CSW_SERVER String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
: geonetworkUrl + "/" + CSW_SERVER + remainPath; logger.info("The base URL is: "+baseURL);
logger.info("The base URL is: " + baseURL); String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString();
String queryString = req.getQueryString() == null || req.getQueryString().isEmpty() ? "" gnGetlURL = baseURL+queryString;
: "?" + req.getQueryString(); logger.info("Sending get request to URL: "+gnGetlURL);
gnGetlURL = baseURL + queryString;
logger.info("Sending get request to URL: " + gnGetlURL);
HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL); HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL);
switch (proxedGNResponse.getStatus()) { switch(proxedGNResponse.getStatus()){
case HttpServletResponse.SC_OK: case HttpServletResponse.SC_OK:
// Building the response //Building the response
InputStream streamToWrite = IOUtils.toInputStream(proxedGNResponse.getResponse()); InputStream streamToWrite = IOUtils.toInputStream(proxedGNResponse.getResponse());
StreamingOutput so = new SingleFileStreamingOutput(streamToWrite); StreamingOutput so = new SingleFileStreamingOutput(streamToWrite);
logger.info("Response return Content-Type: " + httpUtils.getLastContentType()); logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
ResponseBuilder responseBuilder = Response.ok(so).header(ConstantsResolver.CONTENT_TYPE, ResponseBuilder responseBuilder = Response
httpUtils.getLastContentType()); .ok(so)
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType());
return responseBuilder.build(); return responseBuilder.build();
case HttpServletResponse.SC_FORBIDDEN: case HttpServletResponse.SC_FORBIDDEN:
throw ExceptionManager.forbiddenException(req, throw ExceptionManager.forbiddenException(req, "You are not authorized to perform the request "+gnGetlURL, this.getClass(), helpURI);
"You are not authorized to perform the request " + gnGetlURL, this.getClass(), helpURI);
default: default:
throw ExceptionManager.internalErrorException(req, throw ExceptionManager.internalErrorException(req, "Sorry, an error occurred performing the geonetwork request "+gnGetlURL+" with scope "+scope, this.getClass(), helpURI);
"Sorry, an error occurred performing the geonetwork request " + gnGetlURL + " with scope "
+ scope,
this.getClass(), helpURI);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
String error = "Sorry, an error occurred on resolving geonetwork request with scope " + scope String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!";
+ ". Please, contact support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
} catch (Exception e) {
if (!(e instanceof WebApplicationException)) { }catch (Exception e) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error during perform GET operation to: " + gnGetlURL + ". Please, contact the support!"; if(!(e instanceof WebApplicationException)){
//UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error during perform GET operation to: "+gnGetlURL+". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
@ -283,7 +259,7 @@ public class GeonetworkResolver {
} }
/** /**
* The post request * Submit post.
* *
* @param req the req * @param req the req
* @param scope the scope * @param scope the scope
@ -298,159 +274,144 @@ public class GeonetworkResolver {
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application exception
*/ */
@POST @POST
@Path("/{" + PATH_PARAM_SCOPE + "}/{" + PATH_PARAM_MODE + "}/{" + PATH_PARAM_VISIBILITY @Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
+ "}/{filterKey}/{filterValue}/$${" + PATH_PARAM_REMAINPATH + ":(/[^?$]+)?}") public Response submitPost(@Context HttpServletRequest req,
public Response submitPost(@Context HttpServletRequest req, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode, @PathParam(PATH_PARAM_MODE) @Nullable String mode,
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility, @PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
@PathParam("filterKey") @Nullable String filterKey, @PathParam("filterValue") @Nullable String filterValue, @PathParam("filterKey") @Nullable String filterKey,
@PathParam("filterValue") @Nullable String filterValue,
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath, @PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache, @QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) @QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) throws WebApplicationException{
throws WebApplicationException {
logger.info(this.getClass().getSimpleName() + " POST starts..."); logger.info(this.getClass().getSimpleName()+" POST starts...");
String gnCSWlURL = null; String gnCSWlURL = null;
try { try{
logger.info( logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", filterKey: "+filterKey+", filterValue: "+filterValue+", remainPath: "+remainPath+"]");
"Params are [mode: " + mode + ", scope: " + scope + ", visibility: " + visibility + ", filterKey: "
+ filterKey + ", filterValue: " + filterValue + ", remainPath: " + remainPath + "]");
if (scope == null || scope.isEmpty()) { if(scope==null || scope.isEmpty()){
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), helpURI);
this.getClass(), helpURI);
} }
if (mode == null || mode.isEmpty()) { if(mode==null || mode.isEmpty()){
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), helpURI);
helpURI);
} }
scope = ScopeUtil.normalizeScope(scope, "|"); scope = ScopeUtil.normalizeScope(scope, "|");
mode = mode.toUpperCase(); mode = mode.toUpperCase();
try { try{
MODE.valueOf(mode); MODE.valueOf(mode);
} catch (Exception e) { }catch(Exception e){
List<MODE> toPrint = Arrays.asList(MODE.values()); List<MODE> toPrint = Arrays.asList(MODE.values());
logger.error( logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?");
"The 'mode' parameter is wrong, Have you pass a valid parameter MODE like " + toPrint + "?"); throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), helpURI);
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of " + toPrint,
this.getClass(), helpURI);
} }
if (visibility == null) { if(visibility==null){
logger.error("Path Parameter 'visibility' not found"); logger.error("Path Parameter 'visibility' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), helpURI);
this.getClass(), helpURI);
} }
visibility = visibility.toUpperCase(); visibility = visibility.toUpperCase();
try { try{
VISIBILITY.valueOf(visibility); VISIBILITY.valueOf(visibility);
} catch (Exception e) { }catch (Exception e) {
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values()); List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like " logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?");
+ toPrint + "?"); throw ExceptionManager.wrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), helpURI);
throw ExceptionManager.wrongParameterException(req,
"The 'visibility' parameter must be value of " + toPrint, this.getClass(), helpURI);
} }
// HOW TO PASS ANY FILTER? //HOW TO PASS ANY FILTER?
// TODO INVESTIGATE ON HOW TO PASS MORE THAN ONE FILTER... //TODO INVESTIGATE ON HOW TO PASS MORE THAN ONE FILTER...
Map<String, String> filters = new HashMap<String, String>(); Map<String,String> filters = new HashMap<String, String>();
if (filterKey != null && filterValue != null) { if(filterKey!=null && filterValue!=null){
// IGNORING THE EMPTY FILTER 'null|null' //IGNORING THE EMPTY FILTER 'null|null'
if (filterKey.compareToIgnoreCase("null") != 0) { if(filterKey.compareToIgnoreCase("null")!=0){
filters.put(filterKey, filterValue); filters.put(filterKey, filterValue);
logger.debug("Added filter parmas to map filters: " + filters); logger.debug("Added filter parmas to map filters: "+filters);
} }
} }
try { try {
// I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED //I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN,
// SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION //AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED
// ON GN,
// AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF
// NEEDED
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope); GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
logger.info("set scope provider " + scope); logger.info("set scope provider "+scope);
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
Account account = gnInstance.getAccount(); Account account = gnInstance.getAccount();
Version version = gnInstance.getVersion(); Version version = gnInstance.getVersion();
String geonetworkUrl = gnInstance.getEndPoint(); String geonetworkUrl = gnInstance.getEndPoint();
Configuration config = gnInstance.getConfig() != null ? gnInstance.getConfig() : null; Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
if (account == null || account.getUser() == null || account.getPassword() == null || config == null) { if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
logger.info("Loading GN instance and configurations via Geonetwork Library..."); logger.info("Loading GN instance and configurations via Geonetwork Library...");
config = gnInstance.getGeonetworkPublisher().getConfiguration(); config = gnInstance.getGeonetworkPublisher().getConfiguration();
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN); account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
version = config.getGeoNetworkVersion(); version = config.getGeoNetworkVersion();
geonetworkUrl = config.getGeoNetworkEndpoint(); geonetworkUrl = config.getGeoNetworkEndpoint();
} }
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}", scope, account.getUser(), logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl);
geonetworkUrl);
// logger.info("Parameters.."); // logger.info("Parameters..");
// for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){ // for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){
// String p = e.nextElement(); // String p = e.nextElement();
// logger.debug("param "+p + " value // logger.debug("param "+p + " value "+Arrays.toString(req.getParameterValues(p)));
// "+Arrays.toString(req.getParameterValues(p)));
// } // }
// DEBUG BODY //DEBUG BODY
// String readBody = IOUtils.toString(req.getReader()); // String readBody = IOUtils.toString(req.getReader());
// logger.debug("doPost read body request: "+readBody); // logger.debug("doPost read body request: "+readBody);
ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
// SPECIFIC HANDLER FOR GEONETWORK REQUEST: /srv/en/mef.export // SPECIFIC HANDLER FOR GEONETWORK REQUEST: /srv/en/mef.export
if (remainPath != null && remainPath.compareTo(SRV_EN_MEF_EXPORT) == 0) { if(remainPath!=null && remainPath.compareTo(SRV_EN_MEF_EXPORT)==0){
logger.info("In case of mef.export, performing a custom handler"); logger.info("In case of mef.export, perfoming a custom handler");
gnCSWlURL = geonetworkUrl + SRV_EN_MEF_EXPORT; gnCSWlURL = geonetworkUrl + SRV_EN_MEF_EXPORT;
String[] uuidValues = req.getParameterValues(UUID); String[] uuidValues = req.getParameterValues(UUID);
if (uuidValues != null) { if(uuidValues!=null){
String data = null; String data = null;
for (String uuid : uuidValues) { for (String uuid : uuidValues) {
data = UUID + "=" + uuid; data = UUID+"="+uuid;
} }
if (data != null) { if(data!=null){
logger.debug("Writing " + data + " into byte array"); logger.debug("Writing "+data +" into byte array");
byteArray.write(data.getBytes()); byteArray.write(data.getBytes());
} else }else
IOUtils.copy(req.getInputStream(), byteArray); IOUtils.copy(req.getInputStream(), byteArray);
} else }else
IOUtils.copy(req.getInputStream(), byteArray); IOUtils.copy(req.getInputStream(), byteArray);
} else { }else{
logger.debug("IS NOT A REQUEST TO " + SRV_EN_MEF_EXPORT); logger.debug("IS NOT A REQUEST TO "+SRV_EN_MEF_EXPORT);
gnCSWlURL = remainPath == null || remainPath.isEmpty() ? geonetworkUrl + "/" + CSW_SERVER gnCSWlURL = remainPath==null || remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
: geonetworkUrl + "/" + CSW_SERVER + remainPath;
IOUtils.copy(req.getInputStream(), byteArray); IOUtils.copy(req.getInputStream(), byteArray);
} }
HTTPCallsUtils httpUtils = new HTTPCallsUtils(); HTTPCallsUtils httpUtils = new HTTPCallsUtils();
// PRIVATE LAYERS //PRIVATE LAYERS
if (visibility.equals(VISIBILITY.PRV.name())) { if(visibility.equals(VISIBILITY.PRV.name())){
logger.info("Visibility: " + VISIBILITY.PRV + " getting private layers.."); logger.info("Visibility: "+VISIBILITY.PRV+" getting private layers..");
// VRE LAYERS //VRE LAYERS
if (mode.equals(MODE.VRE.name())) { if(mode.equals(MODE.VRE.name())){
logger.info("Getting " + MODE.VRE + " layers.."); logger.info("Getting "+MODE.VRE+" layers..");
// HARVESTED LAYERS //HARVESTED LAYERS
} else { }else{
filters.put("isHarvested", "y"); filters.put("isHarvested", "y");
logger.info("Getting " + MODE.HARVEST + " layers, I added 'isHarvested = y' to the filters [" logger.info("Getting "+MODE.HARVEST+" layers, I added 'isHarvested = y' to the filters ["+filters+"]");
+ filters + "]");
} }
if (account.getUser() != null) { if(account.getUser()!=null){
switch (version) { switch (version) {
case DUE: case DUE:
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword());
account.getPassword()); logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized);
logger.info("Authorized on GN2 " + geonetworkUrl + " ? " + authorized);
break; break;
default: default:
@ -459,100 +420,80 @@ public class GeonetworkResolver {
break; break;
} }
} else { }else {
logger.warn("I'm not able to perform authentication, the user read from config with " logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null");
+ Type.CKAN + " is null");
} }
// PUBLIC LAYERS //PUBLIC LAYERS
} else { }else{
logger.info("Visibility: " + VISIBILITY.PUB + " getting public layers.."); logger.info("Visibility: "+VISIBILITY.PUB+" getting public layers..");
// VRE LAYERS //VRE LAYERS
if (mode.equals(MODE.VRE.name())) { if(mode.equals(MODE.VRE.name())){
logger.info("Getting " + MODE.VRE + " layers, the VRE account: " + account.getUser() logger.info("Getting "+MODE.VRE+" layers, the VRE account: "+account.getUser() +" will be used as owner user for filtering... Is it right?");
+ " will be used as owner user for filtering... Is it right?");
filters.put("ownername", account.getUser()); filters.put("ownername", account.getUser());
// HARVESTED LAYERS //HARVESTED LAYERS
} else { }else{
// filters.put("isHarvested", "y"); //filters.put("isHarvested", "y");
logger.info("Getting " + MODE.HARVEST + " layers, I'm applying the filters [" + filters + "]"); logger.info("Getting "+MODE.HARVEST+" layers, I'm applying the filters ["+filters+"]");
} }
} }
logger.info("Sending CSW POST request to URL: " + gnCSWlURL); logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
logger.debug("Content-Type: " + req.getContentType()); logger.debug("Content-Type: "+req.getContentType());
// DEBUG //DEBUG
// logger.debug("POST - BODY : "+byteArray.toString()); //logger.debug("POST - BODY : "+byteArray.toString());
InputStream in = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray.toByteArray()), InputStream in = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray.toByteArray()), req.getContentType(), req.getParameterMap());
req.getContentType(), req.getParameterMap());
if (in == null) { if(in==null){
logger.warn("Input stream returned is null, sending " + HttpServletResponse.SC_NOT_FOUND); logger.warn("Input stream returned is null, sending "+HttpServletResponse.SC_NOT_FOUND);
throw ExceptionManager.notFoundException(req, throw ExceptionManager.notFoundException(req, "Input stream is null to the request "+gnCSWlURL+ " with body: "+byteArray.toString(), this.getClass(), helpURI);
"Input stream is null to the request " + gnCSWlURL + " with body: " + byteArray.toString(),
this.getClass(), helpURI);
} }
try { try{
ReusableInputStream reus = new ReusableInputStream(in); ReusableInputStream reus = new ReusableInputStream(in);
if (visibility.equals(VISIBILITY.PRV.name())) { if(visibility.equals(VISIBILITY.PRV.name())){
logger.info( logger.info("Private VISIBILITY requested, retrieving public file identifiers to apply filtering..");
"Private VISIBILITY requested, retrieving public file identifiers to apply filtering..");
FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString(), geonetworkUrl); FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString(), geonetworkUrl);
if (filterGetRecords.getFoundPublicIds() != null if(filterGetRecords.getFoundPublicIds()!=null && filterGetRecords.getFoundPublicIds().size()>0){
&& filterGetRecords.getFoundPublicIds().size() > 0) { logger.info("I'm removing list of public IDs with "+filterGetRecords.getFoundPublicIds().size() +" item/s. Is it right?");
logger.info("I'm removing list of public IDs with " in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, filterGetRecords.getFoundPublicIds(), REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE);
+ filterGetRecords.getFoundPublicIds().size() + " item/s. Is it right?");
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus,
filterGetRecords.getFoundPublicIds(), REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE);
} }
} }
if (filters.size() > 0) { if(filters.size()>0){
logger.info("Applying filtering on geonet:info... filter/s used: " + filters); logger.info("Applying filtering on geonet:info... filter/s used: "+filters);
Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus); Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier");
"gmd:fileIdentifier");
List<String> noMatchingFilter = new ArrayList<String>(); List<String> noMatchingFilter = new ArrayList<String>();
for (String fileId : fileIdentifiers) { for (String fileId : fileIdentifiers) {
// CKECKING THE FILTERS //CKECKING THE FILTERS
for (String fkey : filters.keySet()) { for (String fkey : filters.keySet()) {
String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId, String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword(), fkey);
config.getGeoNetworkEndpoint(), config.getAdminAccount().getUser(), //String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
config.getAdminAccount().getPassword(), fkey);
// String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId,
// config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(),
// config.getAdminAccount().getPassword());
String fValue = filters.get(fkey); String fValue = filters.get(fkey);
// Either the filter KEY doesn't matching any geonet:info (value==null) //Either the filter KEY doesn't matching any geonet:info (value==null)
// or the value of filterKey in geonet:info doesn't matching the passed //or the value of filterKey in geonet:info doesn't matching the passed filterValue (value.compareTo(fValue)!=0)
// filterValue (value.compareTo(fValue)!=0) if(value==null || value.compareTo(fValue)!=0){
if (value == null || value.compareTo(fValue) != 0) { logger.trace(fkey +" of File Identifier "+fileId+" not matching the filter: "+fkey+" with value: "+fValue+", adding it to list to remove file identifier and exit from loop..");
logger.trace(fkey + " of File Identifier " + fileId + " not matching the filter: "
+ fkey + " with value: " + fValue
+ ", adding it to list to remove file identifier and exit from loop..");
noMatchingFilter.add(fileId); noMatchingFilter.add(fileId);
// WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING //WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING FILTERS LOOP
// FILTERS LOOP
break; break;
} }
} }
} }
if (noMatchingFilter.size() > 0) { if(noMatchingFilter.size()>0){
logger.info("Removing " + noMatchingFilter.size() logger.info("Removing "+noMatchingFilter.size()+" layer/s that not macthing the filters: "+filters);
+ " layer/s that not macthing the filters: " + filters); //Document doc2 = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
// Document doc2 = GetResponseRecordFilter.inputStreamToW3CDocument(reus); in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingFilter, REPLACED_UUID_BY_FILTER_PLEASE_IGNORE);
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingFilter, //in = GetResponseRecordFilter.w3CDocumentToInputStream(doc);
REPLACED_UUID_BY_FILTER_PLEASE_IGNORE);
// in = GetResponseRecordFilter.w3CDocumentToInputStream(doc);
} else { }else{
logger.info("No replace on UUIDs was applied from filters: " + filters); logger.info("No replace on UUIDs was applied from filters: "+filters);
in = reus; in = reus;
} }
@ -560,50 +501,47 @@ public class GeonetworkResolver {
ReusableInputStream reusIs = new ReusableInputStream(in); ReusableInputStream reusIs = new ReusableInputStream(in);
// END DEBUG //END DEBUG
logger.info("Response return Content-Type: " + httpUtils.getLastContentType()); logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
return Response.ok(reusIs) return Response
// .header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = .ok(reusIs)
// \""+fileName+"\"") //.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = \""+fileName+"\"")
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build(); .header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build();
} catch (Exception e) { }catch(Exception e){
logger.error("Error on copy the response to send to client: ", e); logger.error("Error on copy the response to send to client: ", e);
throw ExceptionManager.internalErrorException(req, "Error on copy the response!", this.getClass(), throw ExceptionManager.internalErrorException(req, "Error on copy the response!", this.getClass(), helpURI);
helpURI); }finally{
} finally {
IOUtils.closeQuietly(in); IOUtils.closeQuietly(in);
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e){
logger.error("IllegalArgumentException:", e); logger.error("IllegalArgumentException:", e);
throw ExceptionManager.badRequestException(req, "Illegal argument to carry out the request!", throw ExceptionManager.badRequestException(req, "Illegal argument to carry out the request!", this.getClass(), helpURI);
this.getClass(), helpURI);
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
String error = "Sorry, an error occurred on resolving geonetwork request with scope " + scope String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!";
+ ". Please, contact support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error during perform POST operation to: " + gnCSWlURL String error = "Error during perform POST operation to: "+gnCSWlURL+". Please, contact the support!";
+ ". Please, contact the support!"; if(e.getCause()!=null)
if (e.getCause() != null) error+="\n\nCaused: "+e.getCause().getMessage();
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Gets the geonetwork instance for scope. * Gets the geonetwork instance for scope.
* *
@ -611,15 +549,15 @@ public class GeonetworkResolver {
* @return the geonetwork instance for scope * @return the geonetwork instance for scope
* @throws Exception the exception * @throws Exception the exception
*/ */
protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception { protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception{
logger.info("Trying to read the {} from cache for scope: {}", GeonetworkInstance.class.getSimpleName(), scope); logger.info("Trying to read the {} from cache for scope: {}",GeonetworkInstance.class.getSimpleName(), scope);
GeonetworkInstance geoInstance; GeonetworkInstance geoInstance;
try { try {
geoInstance = LoadingGeonetworkInstanceCache.get(scope); geoInstance = LoadingGeonetworkInstanceCache.get(scope);
} catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred on reading GeonetworkInstance for scope " + scope, e); logger.error("An error occurred on reading GeonetworkInstance for scope "+scope, e);
throw new Exception("Sorry, An error occurred on reading GeonetworkInstance for scope " + scope); throw new Exception("Sorry, An error occurred on reading GeonetworkInstance for scope "+scope);
} }
return geoInstance; return geoInstance;

View File

@ -1,502 +0,0 @@
package org.gcube.datatransfer.resolver.services;
import java.io.InputStream;
import java.util.LinkedHashMap;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences;
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences.SHARE_LINK_TO;
import org.gcube.application.geoportaldatamapper.exporter.Geoportal_PDF_Exporter;
import org.gcube.application.geoportaldatamapper.shared.ExporterProjectSource;
import org.gcube.application.geoportaldatamapper.shared.FileReference;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.user.User;
import org.gcube.datatransfer.resolver.ConstantsResolver;
import org.gcube.datatransfer.resolver.geoportal.exporter.FetchPDF;
import org.gcube.datatransfer.resolver.geoportal.exporter.GeoportalJsonResponse;
import org.gcube.datatransfer.resolver.geoportal.exporter.Geoportal_HTML_Page;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException;
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
import org.gcube.datatransfer.resolver.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class GeoportalExporter.
*
* The Geoportal Exporter provides the facilities to export GIS projects stored in
* the Geoportal system provided via D4Science VREs.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 16, 2024
*/
@Path("geoportal")
public class GeoportalExporter {
private static final String JOB_CODE = "jobCode";
public static final String EXPORT_TYPE = "type";
public static final String PATH_PROJECT_ID = GeoportalResolver.PATH_PROJECT_ID;
public static final String PATH_USECASE_ID = GeoportalResolver.PATH_USECASE_ID;
public static final String PATH_VRE_NAME = GeoportalResolver.PATH_VRE_NAME;
public static final String QUERY_PARAMETER_AS_URL = "as-url";
private static final Logger LOG = LoggerFactory.getLogger(GeoportalExporter.class);
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver";
private static LinkedHashMap<String, FetchPDF> map = new LinkedHashMap<String, FetchPDF>();
/**
* The Enum ACCEPTED_EXPORT_TYPE.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 22, 2024
*/
public enum ACCEPTED_EXPORT_TYPE {
pdf
}
/**
* Export.
*
* @param req the req
* @param export_type the export type. Must be a value of the enum
* {#ACCEPTED_EXPORT_TYPE}
* @param ucdID the ucd ID
* @param projectID the project ID
* @param asURL the as URL. If true returns the project exported as an URL
* in the response
* @return the response. Can be an URL or a Stream of the project exported.
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/export/{type}/{usecase_id}/{project_id}")
@Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_OCTET_STREAM })
public Response export(@Context HttpServletRequest req, @PathParam(EXPORT_TYPE) String export_type,
@PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID,
@QueryParam(QUERY_PARAMETER_AS_URL) @Nullable String asURL) throws WebApplicationException {
String userAgentName = req.getHeader("User-Agent");
LOG.info(this.getClass().getSimpleName() + " export - GET starts...");
LOG.info("Params: [" + EXPORT_TYPE + ": {}, " + PATH_USECASE_ID + ": {}, " + PATH_PROJECT_ID + ": {}, "
+ QUERY_PARAMETER_AS_URL + ": {}]", export_type, ucdID, projectID, asURL);
checkPathParameterNotNull(req, EXPORT_TYPE, export_type);
checkPathParameterNotNull(req, PATH_USECASE_ID, ucdID);
checkPathParameterNotNull(req, PATH_PROJECT_ID, projectID);
boolean getAsURL = false;
try {
getAsURL = Boolean.parseBoolean(asURL);
} catch (Exception e) {
}
LOG.info("getAsURL is: {}", getAsURL);
checkExportType(req, export_type);
boolean checked = false;
SecretManager secreteManager = SecretManagerProvider.instance.get();
final String context = secreteManager.getContext();
if (context == null) {
throw ExceptionManager.forbiddenException(req, "Cannot determine context (the scope)", this.getClass(),
helpURI);
}
final org.gcube.common.authorization.utils.user.User user = secreteManager.getUser();
if (user == null) {
throw ExceptionManager.forbiddenException(req, "Cannot determine user", this.getClass(), helpURI);
}
LOG.info("Identified caller {} in context {}", user.getUsername(), context);
try {
Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter();
checked = pdfExporter.checkConfig();
} catch (Exception e) {
LOG.error("Error on performing export", e);
throw ExceptionManager
.internalErrorException(req,
"Error the " + Geoportal_PDF_Exporter.class.getSimpleName()
+ " seems to be not configured in the context: " + context,
this.getClass(), helpURI);
}
// if the configuration exists in the context
if (checked) {
if (getAsURL) {
try {
LOG.info("Serving request as getAsURL...");
FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user);
String theURL = pdfRef.getStorageVolatileURL().toString();
LOG.info("returning URL {}", theURL);
return Response.ok(theURL).build();
} catch (Exception e) {
LOG.error("Error on performing export by url", e);
throw ExceptionManager.internalErrorException(req,
"Sorry, error occurred when generating the project URL. Error is: " + e.getMessage(),
this.getClass(), helpURI);
}
}
try {
if (userAgentName != null) {
LOG.info("Serving request as User-Agent {}", userAgentName);
final String jobCode = ucdID + "_" + projectID + "_" + System.currentTimeMillis();
final FetchPDF fetchPDF = new FetchPDF(null, jobCode, 0);
map.put(jobCode, fetchPDF);
try {
Thread t = new Thread() {
@Override
public void run() {
LOG.info("exportAsPDF called in thread...");
FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user);
LOG.info("exportAsPDF setFileRef in thread for code: " + jobCode);
fetchPDF.setFileRef(pdfRef);
map.put(jobCode, fetchPDF);
}
};
t.start();
} catch (Exception e) {
LOG.error("Error on performing export in thread", e);
throw e;
}
String serviceViewPDF_URL = String.format("%s/%s/view/%s", Util.getServerURL(req), "geoportal",
jobCode);
String entity = Geoportal_HTML_Page.entityHTMLMessage("Exporting as PDF...",
"The project with id: " + projectID, true, serviceViewPDF_URL);
LOG.info("returning waiting HTML page");
return Response.ok(entity).encoding("UTF-8").header(ConstantsResolver.CONTENT_TYPE, "text/html")
.build();
} else {
LOG.info("Serving request as client...");
FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user);
// returning as stream
InputStream input = pdfRef.getStorageVolatileURL().openStream();
StreamingOutput so = new SingleFileStreamingOutput(input);
LOG.info("returning project streaming...");
return Response.ok(so)
.header(ConstantsResolver.CONTENT_DISPOSITION,
"inline; filename=\"" + pdfRef.getFileName() + "\"")
.header("Content-Type", pdfRef.getContentType()).build();
}
} catch (Exception e) {
LOG.error("Error on performing export", e);
throw ExceptionManager.internalErrorException(req, "Sorry, error occurred when exporting the project",
this.getClass(), helpURI);
}
} else {
return Response
.status(Status.NOT_FOUND).entity(GeoportalExporter.class.getSimpleName()
+ "seems to be not configured in the context: " + context)
.type(MediaType.TEXT_PLAIN).build();
}
}
/**
* Healthcheck. Checks if the export facility is configured in the context (i.e.
* the scope read from input token).
*
* @param req the req
* @param export_type the export type
* @return an object of type {#GeoportalJsonResponse) that contains the response
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/export/{type}/healthcheck")
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.TEXT_HTML })
public Response healthcheck(@Context HttpServletRequest req, @PathParam(EXPORT_TYPE) String export_type)
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " healthcheck - GET starts...");
LOG.debug("param is: exportType: {}", export_type);
checkPathParameterNotNull(req, EXPORT_TYPE, export_type);
checkExportType(req, export_type);
try {
SecretManager cm = SecretManagerProvider.instance.get();
String context = cm.getContext();
if (context == null) {
throw ExceptionManager.forbiddenException(req, "Cannot determine context (the scope)", this.getClass(),
helpURI);
}
org.gcube.common.authorization.utils.user.User user = cm.getUser();
LOG.info("Identified caller {} in context {}", user.getUsername(), context);
Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter();
boolean checked = pdfExporter.checkConfig();
GeoportalJsonResponse theJson = new GeoportalJsonResponse();
if (checked) {
theJson.setState("OK");
theJson.setMessage(GeoportalExporter.class.getSimpleName() + " Config OK in the context: " + context);
String jsonResponse = responseToString(theJson);
return Response.ok(jsonResponse).build();
} else {
theJson.setState("KO");
theJson.setMessage(GeoportalExporter.class.getSimpleName() + " Config "
+ Status.NOT_FOUND.getReasonPhrase() + " in the context: " + context);
String jsonResponse = responseToString(theJson);
return Response.status(Status.NOT_FOUND).entity(jsonResponse).build();
}
} catch (Exception e) {
LOG.error("Error on performing healthcheck", e);
throw ExceptionManager.internalErrorException(req,
"Error when performing " + GeoportalExporter.class.getSimpleName() + " healthcheck",
this.getClass(), helpURI);
}
}
/**
* View job. Check the job export status.
*
* @param req the req
* @param jobCode the job code. The job ID assigned by export facility that
* returns a waiting HTML page
* @return the response. It is a {#GeoportalJsonResponse} with the status of the
* job. An export job completed contains the URL of the project
* exported.
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/view/{jobCode}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
public Response viewJob(@Context HttpServletRequest req, @PathParam(JOB_CODE) String jobCode)
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " viewPDF - GET starts...");
LOG.info("viewJob param " + JOB_CODE + ": {}", jobCode);
FetchPDF fetchedPDF = map.get(jobCode);
LOG.info("viewJob FileReference at code {} is {}", jobCode, fetchedPDF);
String theURL = null;
String messagge = null;
String state = null;
GeoportalJsonResponse theJson = new GeoportalJsonResponse();
theJson.setState(state);
theJson.setUrl(theURL);
theJson.setMessage(messagge);
String jsonReponse = null;
if (fetchedPDF == null) {
theJson.setState(Status.NOT_FOUND.getReasonPhrase());
theJson.setMessage("No job found with id: " + jobCode);
try {
jsonReponse = responseToString(theJson);
LOG.info("viewJob returning not found: " + jsonReponse);
return Response.status(Status.NOT_FOUND).entity(jsonReponse).build();
} catch (JsonProcessingException e) {
throw ExceptionManager.internalErrorException(req, "Error when returning "
+ GeoportalExporter.class.getSimpleName() + " not found job for " + jobCode, this.getClass(),
helpURI);
}
}
try {
// File PDF is not available
if (fetchedPDF.getFileRef() == null) {
int attempt = fetchedPDF.incrementAttempt();
if (fetchedPDF.getAttempt() < fetchedPDF.getMAX_RETRY()) {
state = "OK";
messagge = "Attempt #" + attempt;
} else {
state = "ERROR";
messagge = "Sorry, an error occurred trying to create the PDF. Max retries reached";
theJson.setState(state);
}
// updating map status
map.put(jobCode, fetchedPDF);
} else {
// File PDF is available
state = "OK";
theURL = fetchedPDF.getFileRef().getStorageVolatileURL().toString();
messagge = "PDF created correclty";
// removing from map
map.put(jobCode, null);
}
theJson.setState(state);
theJson.setUrl(theURL);
theJson.setMessage(messagge);
try {
jsonReponse = responseToString(theJson);
LOG.info("viewJob returning OK: " + jsonReponse);
return Response.ok(jsonReponse).build();
} catch (JsonProcessingException e) {
throw ExceptionManager.internalErrorException(req,
"Error when returning " + GeoportalExporter.class.getSimpleName() + " response for " + jobCode,
this.getClass(), helpURI);
}
} catch (Exception e) {
LOG.error("Error on checking job", e);
throw ExceptionManager.internalErrorException(req,
"Error when checking " + GeoportalExporter.class.getSimpleName() + " job view for " + jobCode,
this.getClass(), helpURI);
}
}
public String responseToString(GeoportalJsonResponse jsonResponse) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(jsonResponse);
}
/**
* Check path parameter not null.
*
* @param req the req
* @param parameter the parameter
* @param value the value
* @throws BadRequestException the bad request exception
*/
public void checkPathParameterNotNull(HttpServletRequest req, String parameter, String value)
throws BadRequestException {
if (value == null || value.isEmpty()) {
LOG.error("The path parameter {} not found or empty in the path", parameter);
throw ExceptionManager.badRequestException(req,
"Mandatory path parameter " + parameter + " not found or empty", this.getClass(), helpURI);
}
}
/**
* Check export type.
*
* @param req the req
* @param export_type the export type
* @return the accepted export type
* @throws BadRequestException the bad request exception
*/
public ACCEPTED_EXPORT_TYPE checkExportType(HttpServletRequest req, String export_type) throws BadRequestException {
ACCEPTED_EXPORT_TYPE exportType;
try {
exportType = ACCEPTED_EXPORT_TYPE.valueOf(export_type);
} catch (Exception e) {
throw ExceptionManager
.wrongParameterException(req,
"The path parameter " + EXPORT_TYPE + " has a bad value: " + export_type
+ ". It must be value of " + ACCEPTED_EXPORT_TYPE.values(),
this.getClass(), helpURI);
}
return exportType;
}
/**
* Export as PDF.
*
* @param req the req
* @param profileID the profile ID
* @param projectID the project ID
* @param profileTitle the profile title
* @param context the context
* @param user the user
* @return the file reference
* @throws WebApplicationException the web application exception
*/
public FileReference exportAsPDF(HttpServletRequest req, String profileID, String projectID, String profileTitle,
String context, User user) throws WebApplicationException {
LOG.info("exportAsPDF for profileID: " + profileID + ", projectID: " + projectID + "called");
LOG.info("exportAsPDF context is {}, user is {}", context, user);
FileReference pdfRef = null;
try {
Geoportal_PDF_Exporter gpdfe = new Geoportal_PDF_Exporter();
ExporterProjectSource exportSource = new ExporterProjectSource();
exportSource.setProfileID(profileID);
exportSource.setProfileTitle(profileTitle);
exportSource.setProjectID(projectID);
exportSource.setScope(context);
GeoportalItemReferences geoportalItemReferences = new GeoportalItemReferences(projectID, profileID,
SHARE_LINK_TO.DATA_VIEWER);
GeoportalItemReferences gir = getPublicLinksFor(geoportalItemReferences, context);
if (user.isApplication()) {
exportSource.setGisLink(gir.getOpenLink().getShortURL());
exportSource.setAccountname(null);
} else {
exportSource.setGisLink(gir.getRestrictedLink().getShortURL());
exportSource.setAccountname(user.getUsername());
}
pdfRef = gpdfe.createPDFFile(exportSource);
} catch (Exception e1) {
LOG.error("Error occurred when exporting the project", e1);
throw ExceptionManager.internalErrorException(req, "Sorry, an error occurred when exporting the project",
this.getClass(), helpURI);
}
return pdfRef;
}
/**
* Gets the public links for.
*
* @param item the item
* @param context the context
* @return the public links for
* @throws Exception the exception
*/
public GeoportalItemReferences getPublicLinksFor(GeoportalItemReferences item, String context) throws Exception {
LOG.info("getPublicLinksFor called for: " + item);
try {
if (item == null)
throw new Exception("Bad request, the item is null");
if (item.getProjectID() == null)
throw new Exception("Bad request, the projectID is null");
if (item.getProfileID() == null)
throw new Exception("Bad request, the profileID is null");
GeoportalCommon gc = new GeoportalCommon();
return gc.getPublicLinksFor(context, item, true);
} 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());
}
}
}

View File

@ -1,494 +0,0 @@
package org.gcube.datatransfer.resolver.services;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.datatransfer.resolver.ConstantsResolver;
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
import org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants;
import org.gcube.datatransfer.resolver.geoportal.GeoportalConfigApplicationProfile;
import org.gcube.datatransfer.resolver.geoportal.GeoportalConfigApplicationProfileReader;
import org.gcube.datatransfer.resolver.geoportal.GeoportalRequest;
import org.gcube.datatransfer.resolver.geoportal.TargetAppGeoportalCodes;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.util.Util;
import org.gcube.smartgears.utils.InnerMethodName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/**
* The GeoportalResolver is able to get/resolve a link to "Geoportal Viewer" or
* "Geoportal Entry" Application.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 03, 2024
*/
@Path("geo")
public class GeoportalResolver {
public static final String GEO_DE = "de"; // data-entry
public static final String GEO = "geo"; // geoportal
public static final String GEO_DV = "dv"; // data-viewer
public static final String QP_RESOLVE_AS = "res";
public static final String PATH_PROJECT_ID = "project_id";
public static final String PATH_USECASE_ID = "usecase_id";
public static final String PATH_VRE_NAME = "vre_name";
public static final String PATH_TARGET_APP = "targetAppId";
private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class);
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver";
/**
* The Enum RESOLVE_AS_PARAMETER.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2023
*/
public static enum RESOLVE_AS {
PUBLIC, PRIVATE
}
/**
* Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" App
*
* @param req the req
* @param vreName the vre name
* @param ucdID the ucd ID
* @param projectID the project ID
* @param resolveAs the resolve as
* @return the response
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/{vre_name}/{usecase_id}/{project_id}")
public Response resolveGeoportalNoAppDef(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName,
@PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID,
@QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " resolveGeoportalNoAppDef - GET starts...");
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null);
LOG.info("The target app is: " + targetAppGeoportalCodes);
return genericResolveLink(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs);
}
/**
* Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" or "Data-Entry"
* App
*
* @param req the req
* @param targetAppId the target app id
* @param vreName the vre name
* @param ucdID the ucd ID
* @param projectID the project ID
* @param resolveAs the resolve as
* @return the response
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/{targetAppId}/{vre_name}/{usecase_id}/{project_id}")
public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
@PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID,
@PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " resolveGeoportal - GET starts...");
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId);
LOG.info("The target app is: " + targetAppGeoportalCodes);
return genericResolveLink(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs);
}
/**
* Resolve data viewer link.
*
* @param req the req
* @param gcubeScope the gcube scope
* @param itemId the item id
* @param itemType the item type
* @param resolveAs the resolve as
* @return the response
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/")
public Response resolveDataViewerLink(@Context HttpServletRequest req,
@QueryParam(GeoportalRequest.P_GCUBE_SCOPE) String gcubeScope,
@QueryParam(GeoportalRequest.P_ITEM_ID) String itemId,
@QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType, @QueryParam(QP_RESOLVE_AS) String resolveAs)
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " resolveDataViewerLink - GET starts...");
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null);
LOG.info("The target app is: " + targetAppGeoportalCodes);
if (gcubeScope == null || gcubeScope.isEmpty()) {
LOG.error("The query parameter '" + GeoportalRequest.P_GCUBE_SCOPE + "' not found or empty");
throw ExceptionManager.badRequestException(req,
"Mandatory query parameter '" + GeoportalRequest.P_GCUBE_SCOPE + "' not found or empty",
this.getClass(), helpURI);
}
String scope = gcubeScope.substring(gcubeScope.lastIndexOf("/") + 1, gcubeScope.length());
return genericResolveLink(req, targetAppGeoportalCodes, scope, itemType, itemId, resolveAs);
}
/**
* Post geoportal. Create a Geoportal Link to "Data-Viewer" App
*
* @param req the req
* @param jsonRequest the json request
* @return the response
* @throws WebApplicationException the web application exception
*/
@POST
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postGeoportalNoAppDef(@Context HttpServletRequest req, GeoportalRequest jsonRequest)
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " postGeoportalNoAppDef - POST starts...");
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null);
LOG.info("The target app is: " + targetAppGeoportalCodes);
String linkURL = genericCreateLink(req, jsonRequest, targetAppGeoportalCodes);
return Response.ok(linkURL).header("Location", linkURL).build();
}
/**
* Post geoportal. Create a Geoportal Link to "Data-Viewer" or "Data-Entry" App
*
* @param req the req
* @param targetAppId the target app id
* @param jsonRequest the json request
* @return the response
* @throws WebApplicationException the web application exception
*/
@POST
@Path("/{targetAppId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
GeoportalRequest jsonRequest) throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " postGeoportal - POST starts...");
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId);
LOG.info("The target app is: " + targetAppGeoportalCodes);
String linkURL = genericCreateLink(req, jsonRequest, targetAppGeoportalCodes);
return Response.ok(linkURL).header("Location", linkURL).build();
}
/**
* Check target appliction ID.
*
* @param req the req
* @param targetAppId the target app id
* @return the target app geoportal codes
*/
private TargetAppGeoportalCodes checkTargetApplictionID(@Context HttpServletRequest req, String targetAppId) {
TargetAppGeoportalCodes targetAppGeoportalCodes = null;
if (targetAppId == null) {
targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV;
LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes);
} else {
// IF the target application passed in the request. It must be proper.
targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
if (targetAppGeoportalCodes == null) {
LOG.error("Target application parameter is malformed");
List<String> targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
.map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList());
List<String> targetPaths = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
.map(TargetAppGeoportalCodes::getId).collect(Collectors.toList());
throw ExceptionManager.badRequestException(req,
"Target application is wrong. Add a target path as /"+targetPaths+" to resolve towards the applications: " + targetApps, this.getClass(),
helpURI);
}
}
return targetAppGeoportalCodes;
}
/**
* Generic resolve link.
*
* @param req the req
* @param resoruceGeoportalCodes the resoruce geoportal codes
* @param vreName the vre name
* @param ucdID the ucd ID
* @param projectID the project ID
* @param resolveAs the resolve as
* @return the response
* @throws WebApplicationException the web application exception
*/
public Response genericResolveLink(@Context HttpServletRequest req, TargetAppGeoportalCodes resoruceGeoportalCodes,
@PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID,
@PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " genericResolveLink starts...");
try {
InnerMethodName.instance.set("resolveGeoportalPublicLink");
LOG.info("Found target app: " + resoruceGeoportalCodes);
if (resoruceGeoportalCodes == null) {
LOG.error("The path parameter '" + PATH_TARGET_APP + "' not found or empty in the path");
throw ExceptionManager.badRequestException(req,
"Mandatory path parameter '" + PATH_TARGET_APP + "' not found or empty", this.getClass(),
helpURI);
}
if (vreName == null || vreName.isEmpty()) {
LOG.error("The path parameter '" + PATH_VRE_NAME + "' not found or empty in the path");
throw ExceptionManager.badRequestException(req,
"Mandatory path parameter '" + PATH_VRE_NAME + "' not found or empty", this.getClass(),
helpURI);
}
if (ucdID == null) {
LOG.error("The path parameter '" + PATH_USECASE_ID + "' not found or empty in the path");
throw ExceptionManager.badRequestException(req,
"Mandatory path parameter '" + PATH_USECASE_ID + "' not found or empty", this.getClass(),
helpURI);
}
if (projectID == null) {
LOG.error("The path parameter '" + PATH_PROJECT_ID + "' not found or empty in the path");
throw ExceptionManager.badRequestException(req,
"Mandatory path parameter '" + PATH_PROJECT_ID + "' not found or empty", this.getClass(),
helpURI);
}
ScopeBean fullScopeBean = null;
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
try {
fullScopeBean = LoadingMapOfScopeCache.get(vreName);
} catch (ExecutionException | InvalidCacheLoadException e) {
LOG.error("Error on getting the fullscope from cache for vreName " + vreName, e);
throw ExceptionManager.wrongParameterException(req,
"Error on getting full scope for the VRE name " + vreName
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
this.getClass(), helpURI);
}
RESOLVE_AS resolveTO = RESOLVE_AS.PUBLIC;
if (resolveAs != null) {
switch (resolveAs.toLowerCase()) {
case "public":
resolveTO = RESOLVE_AS.PUBLIC;
break;
case "private":
resolveTO = RESOLVE_AS.PRIVATE;
break;
}
}
LOG.info("Found RESOLVE_AS_PARAMETER: " + resolveAs);
String originalScope = ScopeProvider.instance.get();
GeoportalConfigApplicationProfileReader reader;
String itemLink = null;
String appID = null;
// Resolving towards Data-Viewer or Data-Entry Application
switch (resoruceGeoportalCodes) {
case GEO_DE: {
appID = org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_ENTRY_APP_ID;
break;
}
case GEO_DV:
default: {
appID = org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP_ID;
break;
}
}
try {
String theScope = fullScopeBean.toString();
LOG.info("Full scope is: " + theScope);
ScopeProvider.instance.set(theScope);
reader = new GeoportalConfigApplicationProfileReader(appID);
} catch (Exception e) {
String error = "Error on reading the generic resource with SecondaryType: "
+ GeoportalConfigApplicationProfileReader.SECONDARY_TYPE + " and APP ID: " + appID
+ " in the scope: " + appID;
LOG.error(error, e);
throw ExceptionManager.internalErrorException(req, error + ". Please contact the support",
this.getClass(), helpURI);
} finally {
if (originalScope != null && !originalScope.isEmpty()) {
ScopeProvider.instance.set(originalScope);
LOG.info("scope provider set to orginal scope: " + originalScope);
} else {
ScopeProvider.instance.reset();
LOG.info("scope provider reset");
}
}
GeoportalConfigApplicationProfile geonaDataProfile = reader.getGeoportalConfigAppProfile();
switch (resolveTO) {
case PUBLIC: {
// Open Link
itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(),
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
break;
}
case PRIVATE: {
// Restricted Link
itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
break;
}
default:
break;
}
LOG.info("Returning link: " + itemLink);
return Response.seeOther(new URL(itemLink).toURI()).build();
} catch (Exception e) {
if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the " + GeoportalResolver.class.getSimpleName()
+ " URL. Please, contact the support!";
if (e.getCause() != null)
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
}
// ALREADY MANAGED AS WebApplicationException
LOG.error("Exception:", e);
throw (WebApplicationException) e;
}
}
/**
* Generic create link.
*
* @param req the req
* @param jsonRequest the json request
* @param targetAppGeoportalCodes the target app geoportal codes
* @return the URL
*/
protected String genericCreateLink(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
TargetAppGeoportalCodes targetAppGeoportalCodes) {
LOG.info(this.getClass().getSimpleName() + " genericCreateLink starts...");
try {
InnerMethodName.instance.set("postGeoportalPublicLink");
LOG.info("The body contains the request: " + jsonRequest.toString());
if (jsonRequest.getGcubeScope() == null) {
throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_GCUBE_SCOPE,
this.getClass(), helpURI);
}
if (jsonRequest.getItemID() == null) {
throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_ITEM_ID,
this.getClass(), helpURI);
}
if (jsonRequest.getItemType() == null) {
throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_ITEM_TYPE,
this.getClass(), helpURI);
}
// CHECK IF INPUT SCOPE IS VALID
String scope = jsonRequest.getGcubeScope();
if (!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)) {
LOG.info("Scope not start with char '{}' adding it", ConstantsResolver.SCOPE_SEPARATOR);
scope += ConstantsResolver.SCOPE_SEPARATOR + scope;
}
String serverUrl = Util.getServerURL(req);
final String vreName = scope.substring(scope.lastIndexOf(ConstantsResolver.SCOPE_SEPARATOR) + 1,
scope.length());
ScopeBean fullScope = null;
// CHECK IF THE vreName has a valid scope, so it is a valid VRE
try {
fullScope = LoadingMapOfScopeCache.get(vreName);
} catch (ExecutionException e) {
LOG.error("Error on getting the fullscope from cache for vreName " + vreName, e);
throw ExceptionManager.wrongParameterException(req,
"Error on getting full scope for the VRE name " + vreName
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
this.getClass(), helpURI);
}
if (fullScope == null)
throw ExceptionManager.notFoundException(req,
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
this.getClass(), helpURI);
String linkURL = String.format("%s/%s/%s/%s/%s/%s", serverUrl, GEO, targetAppGeoportalCodes.getId(),
vreName, jsonRequest.getItemType(), jsonRequest.getItemID());
if (jsonRequest.getQueryString() != null) {
linkURL += "?" + jsonRequest.getQueryString();
}
LOG.info("Returning " + GeoportalResolver.class.getSimpleName() + " URL: " + linkURL);
return linkURL;
} catch (Exception e) {
if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on creating the " + GeoportalResolver.class.getSimpleName()
+ " URL. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
}
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
LOG.error("Exception:", e);
throw (WebApplicationException) e;
}
}
}

View File

@ -32,13 +32,10 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/** /**
* The GisResolver is able to resolve GIS Links (as a redirect to Gis Viewer * The Class GisResolver.
* Application) in order to display and navigate on web-map the gis layers
* stored in D4Science's Geonetwork
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#GIS_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018 * Dec 14, 2018
@ -56,6 +53,7 @@ public class GisResolver {
public static final String SCOPE = "scope"; public static final String SCOPE = "scope";
public static final String GEO_EXPLORER_LAYER_UUID = "geo-exp"; public static final String GEO_EXPLORER_LAYER_UUID = "geo-exp";
/** /**
* Submit get. * Submit get.
* *
@ -68,48 +66,49 @@ public class GisResolver {
*/ */
@GET @GET
@Path("") @Path("")
public Response submitGet(@Context HttpServletRequest req, @QueryParam(SCOPE) String scope, public Response submitGet(@Context HttpServletRequest req, @
@QueryParam(GIS_UUID) String gisUUID, @QueryParam(GEO_EXPLORER_LAYER_UUID) String geoExplorerUUID) QueryParam(SCOPE) String scope,
throws WebApplicationException { @QueryParam(GIS_UUID) String gisUUID,
@QueryParam(GEO_EXPLORER_LAYER_UUID) String geoExplorerUUID) throws WebApplicationException{
logger.info(this.getClass().getSimpleName() + " GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
try { try{
boolean isGisLink = false; boolean isGisLink = false;
boolean isGeoExplorerLink = false; boolean isGeoExplorerLink = false;
if (scope == null || scope.isEmpty()) { if(scope==null || scope.isEmpty()){
logger.error("Query Parameter 'scope' not found"); logger.error("Query Parameter 'scope' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'scope'", throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'scope'", this.getClass(), help);
this.getClass(), help);
} }
if (gisUUID == null || gisUUID.isEmpty()) { if(gisUUID==null || gisUUID.isEmpty()){
logger.error("Path Parameter 'gis-UUID' not found"); logger.error("Path Parameter 'gis-UUID' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'gis-UUID'", throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'gis-UUID'", this.getClass(), help);
this.getClass(), help); }else
} else
isGisLink = true; isGisLink = true;
logger.info(SCOPE + " is: " + scope); logger.info(SCOPE +" is: " + scope);
logger.info(GIS_UUID + " is: " + gisUUID); logger.info(GIS_UUID +" is: " + gisUUID);
if (geoExplorerUUID == null || geoExplorerUUID.isEmpty()) { if (geoExplorerUUID == null || geoExplorerUUID.isEmpty()) {
logger.debug(GEO_EXPLORER_LAYER_UUID + " not found"); logger.debug(GEO_EXPLORER_LAYER_UUID+ " not found");
} else }else
isGeoExplorerLink = true; isGeoExplorerLink = true;
logger.info(GEO_EXPLORER_LAYER_UUID + " is: " + geoExplorerUUID); logger.info(GEO_EXPLORER_LAYER_UUID +" is: " + geoExplorerUUID);
if (!isGisLink && !isGeoExplorerLink) { if(!isGisLink && !isGeoExplorerLink){
String err = GIS_UUID + " or " + GEO_EXPLORER_LAYER_UUID + " not found or empty in the query string"; String err = GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string";
logger.error(err); logger.error(err);
throw ExceptionManager.badRequestException(req, err, this.getClass(), help); throw ExceptionManager.badRequestException(req, err, this.getClass(), help);
} }
if (isGisLink) {
if(isGisLink){
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
// ServerParameters geonetworkParams = getCachedServerParameters(scope); //ServerParameters geonetworkParams = getCachedServerParameters(scope);
GisLayerItem gisLayerItem = getGisLayerForLayerUUID(req, scope, gisUUID); GisLayerItem gisLayerItem = getGisLayerForLayerUUID(req, scope, gisUUID);
logger.info("wms url is: " + gisLayerItem.getFullWmsUrlRequest()); logger.info("wms url is: " + gisLayerItem.getFullWmsUrlRequest());
@ -117,89 +116,74 @@ public class GisResolver {
logger.info("encoded WMS url is: " + wmsRequest); logger.info("encoded WMS url is: " + wmsRequest);
String layerTitle = null; String layerTitle = null;
if (gisLayerItem.getCitationTitle() != null && !gisLayerItem.getCitationTitle().isEmpty()) if(gisLayerItem.getCitationTitle()!=null && !gisLayerItem.getCitationTitle().isEmpty())
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8); layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
logger.info("layer Title encoded is: " + layerTitle); logger.info("layer Title encoded is: " + layerTitle);
String gisViewerPortletUrl = null; String gisViewerPortletUrl = null;
try { try{
gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.get(scope); gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.get(scope);
} catch (ExecutionException | InvalidCacheLoadException e) { }catch(ExecutionException | InvalidCacheLoadException e){
logger.error("Error on getting the GisViewer Applicaton URL from cache for scope " + scope, e); logger.error("Error on getting the GisViewer Applicaton URL from cache for scope "+scope, e);
throw ExceptionManager.wrongParameterException(req, throw ExceptionManager.wrongParameterException(req, "Error on getting the GisViewer Applicaton URL from cache for scope "+scope+".\nIs the Application Profile with APPID "+UriResolverSmartGearManagerInit.getGisViewerProfile().getAppId()+" registered for this scope: "+scope+"?", this.getClass(), help);
"Error on getting the GisViewer Applicaton URL from cache for scope " + scope
+ ".\nIs the Application Profile with APPID "
+ UriResolverSmartGearManagerInit.getGisViewerProfile().getAppId()
+ " registered for this scope: " + scope + "?",
this.getClass(), help);
} }
// CHECKING IF THE GisViewer Portlet URL is valid //CHECKING IF THE GisViewer Portlet URL is valid
if (gisViewerPortletUrl == null || gisViewerPortletUrl.isEmpty()) if(gisViewerPortletUrl==null || gisViewerPortletUrl.isEmpty())
throw ExceptionManager.notFoundException(req, throw ExceptionManager.notFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help);
"GisViewer Portlet URL not found in the scope: " + scope + ". Please contact the support",
this.getClass(), help);
logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl); logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl);
gisViewerPortletUrl += "?rid=" + new Random().nextLong() + "&wmsrequest=" + wmsRequest + "&uuid=" gisViewerPortletUrl+="?rid="+new Random().nextLong()
+ URLEncoder.encode(gisUUID, UTF_8); +"&wmsrequest="+wmsRequest
+"&uuid="+URLEncoder.encode(gisUUID, UTF_8);
if (layerTitle != null) if(layerTitle!=null)
gisViewerPortletUrl += "&layertitle=" + layerTitle; gisViewerPortletUrl+="&layertitle="+layerTitle;
logger.info("Redirecting to: " + gisViewerPortletUrl); logger.info("Redirecting to: "+gisViewerPortletUrl);
return Response.seeOther(new URI(gisViewerPortletUrl)).build(); return Response.seeOther(new URI(gisViewerPortletUrl)).build();
} }
if (isGeoExplorerLink) { if(isGeoExplorerLink){
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
String geoExplorerPortletUrl = null; String geoExplorerPortletUrl = null;
try { try{
geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.get(scope); geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.get(scope);
} catch (ExecutionException e) { }catch(ExecutionException e){
logger.error("Error on getting the GeoExplorer Applicaton URL from cache for scope " + scope, e); logger.error("Error on getting the GeoExplorer Applicaton URL from cache for scope "+scope, e);
throw ExceptionManager.wrongParameterException(req, throw ExceptionManager.wrongParameterException(req, "Error on getting the GeoExplorer Applicaton URL from cache for scope "+scope+".\nIs the Application Profile with APPID "+UriResolverSmartGearManagerInit.getGeoExplorerProfile().getAppId()+" registered for this scope: "+scope+"?", this.getClass(), help);
"Error on getting the GeoExplorer Applicaton URL from cache for scope " + scope
+ ".\nIs the Application Profile with APPID "
+ UriResolverSmartGearManagerInit.getGeoExplorerProfile().getAppId()
+ " registered for this scope: " + scope + "?",
this.getClass(), help);
} }
// CHECKING IF THE GeoExplorer Portlet URL is valid //CHECKING IF THE GeoExplorer Portlet URL is valid
if (geoExplorerPortletUrl == null || geoExplorerPortletUrl.isEmpty()) if(geoExplorerPortletUrl==null || geoExplorerPortletUrl.isEmpty())
throw ExceptionManager.notFoundException(req, throw ExceptionManager.notFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help);
"GeoExplorer Portlet URL not found in the scope: " + scope + ". Please contact the support",
this.getClass(), help);
logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl); logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl);
geoExplorerPortletUrl += "?rid=" + new Random().nextLong() + "&luuid=" geoExplorerPortletUrl+="?rid="+new Random().nextLong()
+ URLEncoder.encode(geoExplorerUUID, UTF_8); +"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8);
// urlRedirect(req, resp, geoExplorerPortletUrl); //urlRedirect(req, resp, geoExplorerPortletUrl);
return Response.seeOther(new URI(geoExplorerPortletUrl)).build(); return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
} }
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string", this.getClass(), help);
GIS_UUID + " or " + GEO_EXPLORER_LAYER_UUID + " not found or empty in the query string",
this.getClass(), help);
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Sorry, an error occurred on resolving request with UUID " + gisUUID + " and scope " String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!";
+ scope + ". Please, contact support!"; if(e.getCause()!=null)
if (e.getCause() != null) error+="\n\nCaused: "+e.getCause().getMessage();
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help); throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Gets the gis layer for layer uuid. * Gets the gis layer for layer uuid.
* *
@ -209,40 +193,35 @@ public class GisResolver {
* @return the gis layer for layer uuid * @return the gis layer for layer uuid
* @throws Exception the exception * @throws Exception the exception
*/ */
public GisLayerItem getGisLayerForLayerUUID(HttpServletRequest req, String scope, String gisUUID) throws Exception { public GisLayerItem getGisLayerForLayerUUID(HttpServletRequest req, String scope, String gisUUID) throws Exception{
try { try {
GeonetworkInstance gi = null; GeonetworkInstance gi = null;
try { try {
gi = LoadingGeonetworkInstanceCache.get(scope); gi = LoadingGeonetworkInstanceCache.get(scope);
} catch (ExecutionException | InvalidCacheLoadException e) { }catch(ExecutionException | InvalidCacheLoadException e){
logger.error("Error on getting the Geonetwork Instance from cache for scope " + scope, e); logger.error("Error on getting the Geonetwork Instance from cache for scope "+scope, e);
throw ExceptionManager.wrongParameterException(req, throw ExceptionManager.wrongParameterException(req, "Error on getting the Geonetwork Instance from cache for scope "+scope+". Is it registered for this scope: "+scope+"?", this.getClass(), help);
"Error on getting the Geonetwork Instance from cache for scope " + scope
+ ". Is it registered for this scope: " + scope + "?",
this.getClass(), help);
} }
if (gi == null) if(gi==null)
throw new Exception("GeonetworkInstance not instanciable in the scope: " + scope); throw new Exception("GeonetworkInstance not instanciable in the scope: "+scope);
LoginLevel toLoginLevel = LoginLevel.SCOPE; LoginLevel toLoginLevel = LoginLevel.SCOPE;
logger.info( logger.info("Performing authentication on GN with "+LoginLevel.class.getSimpleName()+" "+toLoginLevel);
"Performing authentication on GN with " + LoginLevel.class.getSimpleName() + " " + toLoginLevel);
gi.getGeonetworkPublisher().login(toLoginLevel); gi.getGeonetworkPublisher().login(toLoginLevel);
GisLayerItem gisLayerItem = MetadataConverter.getWMSOnLineResource(gi, gisUUID); GisLayerItem gisLayerItem = MetadataConverter.getWMSOnLineResource(gi, gisUUID);
return gisLayerItem; return gisLayerItem;
// TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter. //TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter.
} catch (GeonetworkInstanceException e) { }catch (GeonetworkInstanceException e){
logger.error("An error occurred when instancing geonetowrk gis layer with UUID " + gisUUID, e); logger.error("An error occurred when instancing geonetowrk gis layer with UUID "+gisUUID, e);
throw new IllegalArgumentException( throw new IllegalArgumentException("Sorry, An error occurred when instancing geonetwork with UUID: "+gisUUID);
"Sorry, An error occurred when instancing geonetwork with UUID: " + gisUUID);
} catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred when retrieving gis layer with UUID " + gisUUID, e); logger.error("An error occurred when retrieving gis layer with UUID "+gisUUID, e);
throw new IllegalArgumentException( throw new IllegalArgumentException("Sorry, An error occurred when retrieving gis layer with UUID "+gisUUID);
"Sorry, An error occurred when retrieving gis layer with UUID " + gisUUID);
} }
} }
} }

View File

@ -13,23 +13,21 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.datatransfer.resolver.requesthandler.RequestHandler;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.util.Util; import org.gcube.datatransfer.resolver.util.Util;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The KnimeCreateResolver is able to create a KNIME URL.
* *
* See more at * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver * Dec 13, 2018
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2022
*/ */
@Path("knime") @Path("knime")
public class KnimeCreateResolver { public class KnimeCreateResolver {
@ -38,12 +36,9 @@ public class KnimeCreateResolver {
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver"; private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
/** /**
* Creates the KNIME URL. Generate a Knime URL (then resolved by the /get path) * Creates the knime URL.
* for a KNIME Model Simulation passed by query string.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_POST:_Create_a_KNIME_URL
* *
* @param req the req * @param req the req
* @return the response * @return the response
@ -53,51 +48,51 @@ public class KnimeCreateResolver {
@Path("/create") @Path("/create")
@Consumes(MediaType.TEXT_PLAIN) @Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response createKnimeURL(@Context HttpServletRequest req) throws WebApplicationException { public Response createKnimeURL(@Context HttpServletRequest req) throws WebApplicationException{
logger.info(this.getClass().getSimpleName() + " POST starts..."); logger.info(this.getClass().getSimpleName()+" POST starts...");
try {
try{
String contextToken = SecurityTokenProvider.instance.get();
String scope = ScopeProvider.instance.get(); String scope = ScopeProvider.instance.get();
// logger.info("SecurityTokenProvider contextToken: "+contextToken); // logger.info("SecurityTokenProvider contextToken: "+contextToken);
logger.info("ScopeProvider has scope: " + scope); logger.info("ScopeProvider has scope: "+scope);
ScopeBean scopeBean = new ScopeBean(scope); String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE"); if(contextToken.compareTo(appToken)==0){
throw ExceptionManager.unauthorizedException(req, logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI); throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
} }
if (scopeBean.is(Type.VRE)) { ScopeBean scopeBean = new ScopeBean(scope);
if(scopeBean.is(Type.VRE)){
String vreName = scopeBean.name(); String vreName = scopeBean.name();
String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName); String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName);
String queryString = req.getQueryString() == null ? "" : req.getQueryString(); String queryString =req.getQueryString()==null?"":req.getQueryString();
if (req.getQueryString() != null) if(req.getQueryString()!=null)
knimeGetResolverURL += "?" + queryString; knimeGetResolverURL+="?"+queryString;
logger.info("Returning Knime Resolver URL: " + knimeGetResolverURL); logger.info("Returning Knime Resolver URL: "+knimeGetResolverURL);
return Response.ok(knimeGetResolverURL).header("Location", knimeGetResolverURL).build(); return Response.ok(knimeGetResolverURL).header("Location", knimeGetResolverURL).build();
} else { }else{
logger.error("The input scope " + scope + " is not a VRE"); logger.error("The input scope "+scope+" is not a VRE");
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Working in the "+scope+" scope that is not a VRE. Use a token of VRE", this.getClass(), helpURI);
"Working in the " + scope + " scope that is not a VRE. Use a token of VRE", this.getClass(),
helpURI);
} }
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Sorry, an error occurred on creating Knime URL. Please, contact the support!"; String error = "Sorry, an error occurred on creating Knime URL. Please, contact the support!";
if (e.getCause() != null) if(e.getCause()!=null)
error += "\n\nCaused: " + e.getCause().getMessage(); error+="\n\nCaused: "+e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -23,14 +23,12 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/** /**
* The KnimeGetResolver provides a method to get the Knime URLs (that are simply * The Class KnimeGetResolver.
* URLs) by which is possible to invoke the KNIME Model Simulation Application.
* *
* See more at * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver * Dec 13, 2018
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Dec 13, 2018
*/ */
@Path("knime") @Path("knime")
public class KnimeGetResolver { public class KnimeGetResolver {
@ -39,7 +37,8 @@ public class KnimeGetResolver {
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver"; private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
private static final String ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL = "org.gcube.portlets.user.model-simulation-configuration.server.KnimeModelSimulationManagerServiceImpl"; private static final String ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL =
"org.gcube.portlets.user.model-simulation-configuration.server.KnimeModelSimulationManagerServiceImpl";
private static final String APPLICATION_PROFILE = "ApplicationProfile"; private static final String APPLICATION_PROFILE = "ApplicationProfile";
@ -55,55 +54,48 @@ public class KnimeGetResolver {
@GET @GET
@Path("/get/{vreName}") @Path("/get/{vreName}")
public Response resolveKnimeURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) { public Response resolveKnimeURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) {
logger.info(this.getClass().getSimpleName() + " GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
try { try {
if (vreName == null || vreName.isEmpty()) { if(vreName==null || vreName.isEmpty()){
logger.error("The path parameter 'vreName' not found or empty in the path"); logger.error("The path parameter 'vreName' not found or empty in the path");
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
this.getClass(), helpURI);
} }
ScopeBean scopeBean = null; ScopeBean scopeBean = null;
try { try{
scopeBean = LoadingMapOfScopeCache.get(vreName); scopeBean = LoadingMapOfScopeCache.get(vreName);
} catch (ExecutionException | InvalidCacheLoadException e) { }catch(ExecutionException | InvalidCacheLoadException e){
logger.error("Error on getting the fullscope from cache for vreName " + vreName, e); logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
throw ExceptionManager.wrongParameterException(req, throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
"Error on getting full scope for the VRE name " + vreName
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
this.getClass(), helpURI);
} }
ApplicationProfileReader reader = null; ApplicationProfileReader reader = null;
String fullScope = scopeBean.toString(); String fullScope = scopeBean.toString();
try { try{
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false); }catch(Exception e){
} catch (Exception e) { logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e);
logger.error("Error on reading the " + APPLICATION_PROFILE + " with APPID: " throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+KNIME_EXECUTOR_APPLICATION+". Please contact the support", this.getClass(), helpURI);
+ ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e);
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "
+ KNIME_EXECUTOR_APPLICATION + ". Please contact the support", this.getClass(), helpURI);
} }
// READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope //READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
String knimeExecutorEndPoint = reader.getApplicationProfile().getUrl(); String knimeExecutorEndPoint = reader.getApplicationProfile().getUrl();
// CHECKING THE QUERY STRING //CHECKING THE QUERY STRING
String queryString = req.getQueryString() != null ? req.getQueryString() : ""; String queryString = req.getQueryString()!=null?req.getQueryString():"";
String knimeExecutorURL = String.format("%s?%s", knimeExecutorEndPoint, queryString); String knimeExecutorURL = String.format("%s?%s", knimeExecutorEndPoint, queryString);
logger.info("Resolving the Knime URL with: " + knimeExecutorURL); logger.info("Resolving the Knime URL with: "+knimeExecutorURL);
return Response.seeOther(new URI(knimeExecutorURL)).build(); return Response.seeOther(new URI(knimeExecutorURL)).build();
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Sorry, an error occurred on resolving the Knime URL. Please, contact the support!"; String error = "Sorry, an error occurred on resolving the Knime URL. Please, contact the support!";
if (e.getCause() != null) if(e.getCause()!=null)
error += "\n\nCaused: " + e.getCause().getMessage(); error+="\n\nCaused: "+e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -1,76 +0,0 @@
package org.gcube.datatransfer.resolver.services;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.UserInfo;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class OatResolver.
*
* generates an old authz token from an UMAToken
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 5, 2022
*/
@Path("oat")
public class OatResolver {
private static Logger LOG = LoggerFactory.getLogger(OatResolver.class);
/**
* Gets the legacy token.
*
* @param req the req
* @return the legacy token
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/get")
@Produces(MediaType.TEXT_PLAIN)
public Response getLegacyToken(@Context HttpServletRequest req) throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " GET starts...");
try {
String scope = ScopeProvider.instance.get();
LOG.info("ScopeProvider has scope: " + scope);
String username = AuthorizationProvider.instance.get().getClient().getId();
UserInfo userInfo = new UserInfo(username, new ArrayList<>());
String userToken = authorizationService().generateUserToken(userInfo, scope);
String msgToken = userToken.substring(0, 10) + "_MASKED_TOKEN";
LOG.info("returning legacy token {} for user {}", msgToken, username);
return Response.ok(userToken).build();
} catch (Exception e) {
LOG.error("Exception:", e);
if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on getting legacy token. Please, contact the support!";
if (e.getCause() != null)
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
}
// ALREADY MANAGED AS WebApplicationException
throw (WebApplicationException) e;
}
}
}

View File

@ -28,13 +28,12 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The PartheosRegistryResolver. * The Class PartheosRegistryResolver.
* *
* See more at * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Parthenos_URL_Resolver * Nov 16, 2018
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 16, 2018
*/ */
@Path("parthenos_registry") @Path("parthenos_registry")
public class PartheosRegistryResolver { public class PartheosRegistryResolver {
@ -45,9 +44,6 @@ public class PartheosRegistryResolver {
/** /**
* Resolve parthenos url. * Resolve parthenos url.
* *
* To resolve an "item" from a Parthenos URL stored in the Parthenos Catalogue
* at https://ckan-parthenos.d4science.org/
*
* @param req the req * @param req the req
* @param provider the provider * @param provider the provider
* @param path the path * @param path the path
@ -56,56 +52,54 @@ public class PartheosRegistryResolver {
*/ */
@GET @GET
@Path("/{provider}/{path}{remainPath:(/[^?$]+)?}") @Path("/{provider}/{path}{remainPath:(/[^?$]+)?}")
public Response resolveParthenosURL(@Context HttpServletRequest req, @PathParam("provider") String provider, public Response resolveParthenosURL(@Context HttpServletRequest req,
@PathParam("path") String path, @PathParam("remainPath") String remainPath) throws WebApplicationException { @PathParam("provider") String provider,
@PathParam("path") String path,
@PathParam("remainPath") String remainPath) throws WebApplicationException {
logger.info(this.getClass().getSimpleName() + " GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
String remainPathParthenosURL = null; String remainPathParthenosURL = null;
try { try {
logger.debug("provider is: " + provider); logger.debug("provider is: "+provider);
logger.debug("path is: " + path); logger.debug("path is: "+path);
logger.debug("remainPath is: " + remainPath); logger.debug("remainPath is: "+remainPath);
remainPathParthenosURL = String.format("%s/%s", provider, path); remainPathParthenosURL = String.format("%s/%s",provider,path);
if (remainPath != null && !remainPath.isEmpty()) { if(remainPath!=null && !remainPath.isEmpty()){
remainPathParthenosURL += remainPath.startsWith("/") ? remainPath : "/" + remainPath; remainPathParthenosURL+=remainPath.startsWith("/")?remainPath:"/"+remainPath;
} }
logger.info("Resolving parthenos URL: " + remainPathParthenosURL); logger.info("Resolving parthenos URL: "+remainPathParthenosURL);
// APPLYING URL DECODING //APPLYING URL DECODING
remainPathParthenosURL = URLDecoder.decode(remainPathParthenosURL, "UTF-8"); remainPathParthenosURL = URLDecoder.decode(remainPathParthenosURL, "UTF-8");
// APPLYING NAME TRANSFORMATION //APPLYING NAME TRANSFORMATION
String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL); String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL);
logger.info("Trying to resolve with Catalogue EntityName: " + normalizedEntityName); logger.info("Trying to resolve with Catalogue EntityName: "+normalizedEntityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(),
normalizedEntityName);
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateVRECataloguePortletURL()).toURI()).build(); return Response.seeOther(new URL(itemCatalogueURLs.getPrivateVRECataloguePortletURL()).toURI()).build();
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the path " + remainPathParthenosURL String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact the support!";
+ ". Please, contact the support!"; if(e.getCause()!=null)
if (e.getCause() != null) error+="\n\nCaused: "+e.getCause().getMessage();
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* To get a normalized item name from a Parthenos URL. It applies a * Post catalogue.
* normalization function to get from an input Parthenos URL an item name that
* is catalogue compliant.
* *
* @param req the req * @param req the req
* @param jsonRequest the json request * @param jsonRequest the json request
@ -116,66 +110,58 @@ public class PartheosRegistryResolver {
@Path("") @Path("")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest) public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest) throws WebApplicationException{
throws WebApplicationException { logger.info(this.getClass().getSimpleName()+" POST starts...");
logger.info(this.getClass().getSimpleName() + " POST starts...");
try { try{
String entityName = jsonRequest.getEntity_name(); String entityName = jsonRequest.getEntity_name();
if (entityName == null || entityName.isEmpty()) { if(entityName==null || entityName.isEmpty()){
logger.error("Entity Name Parameter like 'entity_name' not found or empty"); logger.error("Entity Name Parameter like 'entity_name' not found or empty");
throw ExceptionManager.badRequestException(req, throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
"Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
} }
// REMOVING FIRST '/' IF EXISTS //REMOVING FIRST '/' IF EXISTS
entityName = entityName.startsWith("/") ? entityName.substring(1, entityName.length()) : entityName; entityName = entityName.startsWith("/")?entityName.substring(1,entityName.length()):entityName;
// APPLYING NAME TRANSFORMATION //APPLYING NAME TRANSFORMATION
String normalizedEntityName = toNameForCatalogue(entityName); String normalizedEntityName = toNameForCatalogue(entityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), logger.info("Returining Catalogue URL: "+itemCatalogueURLs.getPrivateVRECataloguePortletURL());
normalizedEntityName); return Response.ok(normalizedEntityName).header("Location", itemCatalogueURLs.getPrivateVRECataloguePortletURL()).build();
logger.info("Returining Catalogue URL: " + itemCatalogueURLs.getPrivateVRECataloguePortletURL());
return Response.ok(normalizedEntityName)
.header("Location", itemCatalogueURLs.getPrivateVRECataloguePortletURL()).build();
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on transforming the " + jsonRequest + ". Please, contact the support!"; String error = "Error occurred on transforming the "+jsonRequest+". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* To name for catalogue. this method applyes a fuction to transform a parthenos * To name for catalogue.
* URL to acceptable catalogue name (that is URL) * this method applyes a fuction to transform a parthenos URL to acceptable catalogue name (that is URL)
*
* @param remainPathParthenosURL the remain path parthenos url * @param remainPathParthenosURL the remain path parthenos url
* @return the string * @return the string
* @throws UnsupportedEncodingException the unsupported encoding exception * @throws UnsupportedEncodingException the unsupported encoding exception
*/ */
protected String toNameForCatalogue(final String remainPathParthenosURL) throws UnsupportedEncodingException { protected String toNameForCatalogue(final String remainPathParthenosURL) throws UnsupportedEncodingException {
// need to double decode for URLs like: //need to double decode for URLs like: http://parthenos.d4science.org/handle/Parthenos/REG/Dataset/Appellation/Isidore%2520Dataset
// http://parthenos.d4science.org/handle/Parthenos/REG/Dataset/Appellation/Isidore%2520Dataset String name = StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL,"UTF-8"),"/ .:", "_").toLowerCase().replaceAll("[^A-Za-z0-9]", "_");
String name = StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL, "UTF-8"), "/ .:", "_") //TO LOWERCASE FOR CKAN SUPPORTING
.toLowerCase().replaceAll("[^A-Za-z0-9]", "_");
// TO LOWERCASE FOR CKAN SUPPORTING
return name.toLowerCase(); return name.toLowerCase();
} }
// TO TEST //TO TEST
// public static void main(String[] args) throws UnsupportedEncodingException { // public static void main(String[] args) throws UnsupportedEncodingException {
// //
// String remainPathParthenosURL = // String remainPathParthenosURL = "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
// "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8")); // System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8"));
// //
// } // }

View File

@ -19,15 +19,11 @@ import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The SMPIDResolver is able to give HTTP resolution to storage resource by ID.
* *
* See more at * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#SMP-ID_Resolver * Oct 22, 2018
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2022
*/ */
@Path("id") @Path("id")
public class SMPIDResolver { public class SMPIDResolver {
@ -41,6 +37,7 @@ public class SMPIDResolver {
private static Logger logger = LoggerFactory.getLogger(SMPIDResolver.class); private static Logger logger = LoggerFactory.getLogger(SMPIDResolver.class);
/** /**
* Gets the smpid. * Gets the smpid.
* *
@ -48,47 +45,46 @@ public class SMPIDResolver {
* @param smpId the smp id * @param smpId the smp id
* @param fileName the file name * @param fileName the file name
* @param contentType the content type * @param contentType the content type
* @param contentDisposition the content disposition
* @param validation the validation * @param validation the validation
* @return the smpid * @return the smpid
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application exception
*/ */
@GET @GET
@Path("") @Path("")
public Response getSMPID(@Context HttpServletRequest req, @QueryParam(SMP_ID) @Nullable String smpId, public Response getSMPID(@Context HttpServletRequest req,
@QueryParam(SMP_ID) @Nullable String smpId,
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName, @QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException { @QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
logger.info(this.getClass().getSimpleName() + " GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
try { try{
// Checking mandatory parameter smpId //Checking mandatory parameter smpId
if (smpId == null || smpId.isEmpty()) { if(smpId==null || smpId.isEmpty()){
logger.error(SMP_ID + " not found"); logger.error(SMP_ID+" not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter " + SMP_ID, throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class, helpURI);
SMPIDResolver.class, helpURI);
} }
// Checking the optional parameter "Content-Disposition"
//Checking the optional parameter "Content-Disposition"
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment; CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
// Validating the Content-Disposition value //Validating the Content-Disposition value
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition); dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
return StorageIDResolver.resolveStorageId(req, smpId, fileName, contentType, dispositionValue, validation); return StorageIDResolver.resolveStorageId(req, smpId, fileName, contentType, dispositionValue, validation);
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the " + SMP_ID + ": " + smpId String error = "Error occurred on resolving the "+SMP_ID+": "+smpId+". Please, contact the support!";
+ ". Please, contact the support!"; if(e.getCause()!=null)
if (e.getCause() != null) error+="\n\nCaused: "+e.getCause().getMessage();
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -19,15 +19,12 @@ import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The SMPResolver is able to give HTTP resolution to SMP protocol URIs * The Class SMPResolver.
* *
* See more at * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#SMP_Resolver * Dec 14, 2018
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2022
*/ */
@Path("smp") @Path("smp")
public class SMPResolver { public class SMPResolver {
@ -48,44 +45,44 @@ public class SMPResolver {
* @param smpURI the smp uri * @param smpURI the smp uri
* @param fileName the file name * @param fileName the file name
* @param contentType the content type * @param contentType the content type
* @param contentDisposition the content disposition
* @param validation the validation * @param validation the validation
* @return the smpuri * @return the smpuri
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application exception
*/ */
@GET @GET
@Path("") @Path("")
public Response getSMPURI(@Context HttpServletRequest req, @QueryParam(SMP_URI) @Nullable String smpURI, public Response getSMPURI(@Context HttpServletRequest req,
@QueryParam(SMP_URI) @Nullable
String smpURI,
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName, @QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException { @QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
logger.info(this.getClass().getSimpleName() + " GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
try { try{
// Checking mandatory parameter smpURI //Checking mandatory parameter smpURI
if (smpURI == null || smpURI.isEmpty()) { if(smpURI==null || smpURI.isEmpty()){
logger.error(SMP_URI + " not found"); logger.error(SMP_URI+" not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter " + SMP_URI, throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, helpURI);
SMPResolver.class, helpURI);
} }
// Checking the optional parameter "Content-Disposition" //Checking the optional parameter "Content-Disposition"
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment; CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
// Validating the Content-Disposition value //Validating the Content-Disposition value
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition); dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, dispositionValue, validation); return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, dispositionValue, validation);
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the smpURI " + smpURI + ". Please, contact the support!"; String error = "Error occurred on resolving the smpURI "+smpURI+". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -1,119 +0,0 @@
/**
*
*/
package org.gcube.datatransfer.resolver.services;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.StreamingOutput;
import org.apache.commons.io.IOUtils;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class StaticImageController.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* May 2, 2024
*/
@Path("img")
public class StaticImageController {
private static Logger logger = LoggerFactory.getLogger(StaticImageController.class);
// /**
// * To doc.
// *
// * @param req the req
// * @return the input stream
// * @throws WebApplicationException the web application exception
// */
// @GET
// @Path("/{any: .*}")
// @Produces({ "image/png", "image/jpg", "image/gif" })
// public InputStream toFile(@Context HttpServletRequest req) throws WebApplicationException {
// logger.info(StaticImageController.class.getSimpleName() + " toFile called");
//
// String pathInfo = req.getPathInfo();
// logger.debug("pathInfo {}", pathInfo);
// try {
//
// logger.info("going to {}", pathInfo);
//
// String realPath = req.getServletContext().getRealPath(pathInfo);
// return new FileInputStream(new File(realPath));
//
// } catch (Exception e) {
//
// if (!(e instanceof WebApplicationException)) {
// // UNEXPECTED EXCEPTION managing it as WebApplicationException
// String error = pathInfo + " not found. Please, contact the support!";
// throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
// }
// // ALREADY MANAGED AS WebApplicationException
// logger.error("Exception:", e);
// throw (WebApplicationException) e;
// }
// }
//
/**
* To file out.
*
* @param req the req
* @return the streaming output
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/{any: .*}")
@Produces({ "image/png", "image/jpg", "image/gif" })
public StreamingOutput toFileOut(@Context HttpServletRequest req) throws WebApplicationException {
logger.info(StaticImageController.class.getSimpleName() + " toFileOut called");
String pathInfo = req.getPathInfo();
logger.debug("pathInfo {}", pathInfo);
try {
final String realPath = req.getServletContext().getRealPath(pathInfo);
logger.info("going to {}", pathInfo);
return new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException, WebApplicationException {
FileInputStream fileIS = null;
try {
fileIS = new FileInputStream(new File(realPath));
IOUtils.copy(fileIS, os);
} catch (Exception e) {
try {
if(fileIS!=null)
fileIS.close();
} catch (Exception e2) {
}
}
}
};
} catch (Exception e) {
if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = pathInfo + " not found. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
}
// ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e);
throw (WebApplicationException) e;
}
}
}

View File

@ -25,11 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The StorageHubResolver provides the methods either to download a gCube * The Class StorageHubResolver.
* Workspace file or to get its metadata.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-HUB_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018 * Dec 14, 2018
@ -50,6 +46,7 @@ public class StorageHubResolver {
@PathParam(STORAGE_HUB_ID) @PathParam(STORAGE_HUB_ID)
String id; String id;
/** /**
* Gets the metadata. * Gets the metadata.
* *
@ -59,47 +56,45 @@ public class StorageHubResolver {
@HEAD @HEAD
@Path("/{id}") @Path("/{id}")
public Response getMetadata(@Context HttpServletRequest req) { public Response getMetadata(@Context HttpServletRequest req) {
logger.info(this.getClass().getSimpleName() + " HEAD getMetadata called"); logger.info(this.getClass().getSimpleName()+" HEAD getMetadata called");
try { try{
// TODO Do we need to check the token? //TODO Do we need to check the token?
// Checking mandatory parameter id //Checking mandatory parameter id
if (id == null || id.isEmpty()) { if(id==null || id.isEmpty()){
logger.error("Path Parameter " + STORAGE_HUB_ID + " not found"); logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter " + STORAGE_HUB_ID, throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, this.getClass(), help);
this.getClass(), help);
} }
try { try{
ItemManagerClient client = AbstractPlugin.item().build(); ItemManagerClient client = AbstractPlugin.item().build();
StreamDescriptor descriptor = client.resolvePublicLink(id); StreamDescriptor descriptor = client.resolvePublicLink(id);
ResponseBuilder response = Response.ok(); ResponseBuilder response = Response.noContent();
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, CONTENT_DISPOSITION_VALUE.attachment);
CONTENT_DISPOSITION_VALUE.attachment);
return response.build(); return response.build();
} catch (Exception e) { }catch(Exception e){
logger.error("Error on getting metadata for file with " + id, e); logger.error("Error on getting metadata for file with "+id, e);
String errorMsg = "Error on getting metadata for file with hub id '" + id + "'. " + e.getMessage(); String errorMsg = "Error on getting metadata for file with hub id '"+id+"'. "+e.getMessage();
throw ExceptionManager.internalErrorException(req, errorMsg, this.getClass(), help); throw ExceptionManager.internalErrorException(req, errorMsg, this.getClass(), help);
} }
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the StorageHub URL with id: " + id String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!";
+ ". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help); throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
} }
// ALREADY MANAGED as WebApplicationException //ALREADY MANAGED as WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Download. * Download.
* *
@ -108,50 +103,46 @@ public class StorageHubResolver {
*/ */
@GET @GET
@Path("/{id}") @Path("/{id}")
public Response download(@Context HttpServletRequest req, public Response download(@Context HttpServletRequest req, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition) {
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition) { logger.info(this.getClass().getSimpleName()+" GET download called");
logger.info(this.getClass().getSimpleName() + " GET download called");
try { try{
InnerMethodName.instance.set("resolveStorageHubPublicLink"); InnerMethodName.instance.set("resolveStorageHubPublicLink");
// Checking mandatory parameter "id" //Checking mandatory parameter "id"
if (id == null || id.isEmpty()) { if(id==null || id.isEmpty()){
logger.error("Path Parameter " + STORAGE_HUB_ID + " not found"); logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter " + STORAGE_HUB_ID, throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolver.class, help);
StorageHubResolver.class, help);
} }
// Checking the optional parameter "Content-Disposition" //Checking the optional parameter "Content-Disposition"
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment; CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
// Validating the Content-Disposition value //Validating the Content-Disposition value
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), help, contentDisposition); dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), help, contentDisposition);
try { try{
ItemManagerClient client = AbstractPlugin.item().build(); ItemManagerClient client = AbstractPlugin.item().build();
StreamDescriptor descriptor = client.resolvePublicLink(id); StreamDescriptor descriptor = client.resolvePublicLink(id);
ResponseBuilder response = Response.ok(descriptor.getStream()); ResponseBuilder response = Response.ok(descriptor.getStream());
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, dispositionValue);
dispositionValue);
return response.build(); return response.build();
} catch (Exception e) { }catch(Exception e){
logger.error("Error on getting file with " + id, e); logger.error("Error on getting file with "+id, e);
String errorMsg = "Error on getting file with hub id '" + id + "'. " + e.getMessage(); String errorMsg = "Error on getting file with hub id '"+id+"'. "+e.getMessage();
throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolver.class, help); throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolver.class, help);
} }
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the StorageHub URL with id: " + id String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!";
+ ". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help); throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -2,7 +2,6 @@ package org.gcube.datatransfer.resolver.services;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -14,19 +13,19 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.StreamingOutput;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.gcube.contentmanagement.blobstorage.resource.MyFile; import org.gcube.contentmanagement.blobstorage.resource.MyFile;
import org.gcube.contentmanagement.blobstorage.service.IClient; import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanager.storageclient.wrapper.AccessType; import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType; import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient; import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.gcube.datatransfer.resolver.ConstantsResolver; import org.gcube.datatransfer.resolver.ConstantsResolver;
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE; import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.storage.StorageClientInstance;
import org.gcube.datatransfer.resolver.storage.StorageMetadataFile; import org.gcube.datatransfer.resolver.storage.StorageMetadataFile;
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput; import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition; import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
@ -36,10 +35,7 @@ import org.slf4j.LoggerFactory;
/** /**
* The StorageIDResolver is able to give HTTP resolution to storage resource by ID * The Class StorageIDResolver.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018 * Dec 14, 2018
@ -52,14 +48,11 @@ public class StorageIDResolver {
*/ */
protected static final String STORAGEID_RESOLVER = "storageid-resolver"; protected static final String STORAGEID_RESOLVER = "storageid-resolver";
private static final String STORAGE_ID = "storage-id"; private static final String STORAGE_ID = "storage-id";
private static final AccessType STORAGE_ACCESS_TYPE=AccessType.PUBLIC;
private static final BackendType STORAGE_BACKEND_TYPE=BackendType.MongoDB;
private static final Logger LOG = LoggerFactory.getLogger(StorageIDResolver.class); private static final Logger LOG = LoggerFactory.getLogger(StorageIDResolver.class);
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver"; private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
protected static IClient storageManagerClient;
private static MemoryType memory;
/** /**
* Gets the storage id. * Gets the storage id.
@ -130,17 +123,21 @@ public class StorageIDResolver {
LOG.error("storageId not found"); LOG.error("storageId not found");
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help); throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
} }
storageId = identifyIdAndMemory(storageId);
IClient iClient = getStorageClientInstance(memory); StorageClientInstance scInstance = buildStorageClientInstance(storageId);
String toSEID = null; String toSEID = null;
IClient iClient = null;
storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
LOG.info("I'm using the storageId {}",storageId); LOG.info("I'm using the storageId {}",storageId);
try{ try{
iClient = scInstance.getStorageClient().getClient();
toSEID = iClient.getId(storageId); //to Storage Encrypted ID toSEID = iClient.getId(storageId); //to Storage Encrypted ID
LOG.info("Decoded ID"+" = "+ toSEID); LOG.info("Decoded ID"+" = "+ toSEID);
}catch(Exception e){ }catch(Exception e){
LOG.error("Storage Client Exception when getting file from storage: ", e); LOG.error("Storage Client Exception when getting file from storage: ", e);
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
} }
if(toSEID==null || toSEID.isEmpty()){ if(toSEID==null || toSEID.isEmpty()){
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!"); LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help); throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
@ -169,9 +166,6 @@ public class StorageIDResolver {
//Reading the content size //Reading the content size
size = metaFile.getSize(); size = metaFile.getSize();
LOG.debug("Read size {} from {}", size, StorageMetadataFile.class.getSimpleName()); LOG.debug("Read size {} from {}", size, StorageMetadataFile.class.getSimpleName());
}else {
//Bug fixing #28276
throw ExceptionManager.notFoundException(httpRequest, "Error on accessing the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
} }
//CHECKING TO DEFAULT METADATA //CHECKING TO DEFAULT METADATA
@ -199,9 +193,6 @@ public class StorageIDResolver {
} }
/** /**
* Http do head. * Http do head.
* *
@ -225,7 +216,7 @@ public class StorageIDResolver {
//THIS IS FOR HPROXY CHECK //THIS IS FOR HPROXY CHECK
if(hproxycheck){ if(hproxycheck){
LOG.trace("returning status 200 for Hproxy check"); LOG.trace("returning status 200 for Hproxy check");
ResponseBuilder response = Response.status(Status.OK); ResponseBuilder response = Response.status(HttpStatus.SC_OK);
return response.build(); return response.build();
} }
@ -263,21 +254,26 @@ public class StorageIDResolver {
LOG.warn("storageId not found"); LOG.warn("storageId not found");
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help); throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
} }
storageId = identifyIdAndMemory(storageId); StorageClientInstance client = buildStorageClientInstance(storageId);
IClient iClient = getStorageClientInstance(memory);
String toSEID = null; String toSEID = null;
IClient iClient = null;
storageId = client.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
LOG.info("I'm using the storageId {}",storageId); LOG.info("I'm using the storageId {}",storageId);
try{ try{
iClient = client.getStorageClient().getClient();
toSEID = iClient.getId(storageId); //to Storage Encrypted ID toSEID = iClient.getId(storageId); //to Storage Encrypted ID
LOG.info("Decoded ID"+" = "+ toSEID); LOG.debug("Decoded ID"+" = "+ toSEID);
}catch(Exception e){ }catch(Exception e){
LOG.error("Storage Client Exception when getting file from storage: ", e); LOG.error("Storage Client Exception when getting file from storage: ", e);
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); throw ExceptionManager.internalErrorException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
} }
if(toSEID==null || toSEID.isEmpty()){ if(toSEID==null || toSEID.isEmpty()){
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!"); LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help); throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
} }
//SETTING DEFAULT METADATA //SETTING DEFAULT METADATA
String fileName = ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER; String fileName = ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER;
String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN; String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
@ -316,7 +312,7 @@ public class StorageIDResolver {
if(c>0){ if(c>0){
LOG.info("at least 1 byte read, returning status 200"); LOG.info("at least 1 byte read, returning status 200");
IOUtils.closeQuietly(streamToWrite); IOUtils.closeQuietly(streamToWrite);
response = Response.status(Status.OK); response = Response.status(HttpStatus.SC_OK);
}else }else
throw ExceptionManager.notFoundException(httpRequest, "The file with id: "+storageId+" is missing in the storage", StorageIDResolver.class, help); throw ExceptionManager.notFoundException(httpRequest, "The file with id: "+storageId+" is missing in the storage", StorageIDResolver.class, help);
} }
@ -332,54 +328,38 @@ public class StorageIDResolver {
.header("Content-Type", contentType) .header("Content-Type", contentType)
.header(ConstantsResolver.CONTENT_LENGTH, size) .header(ConstantsResolver.CONTENT_LENGTH, size)
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\""); .header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"");
iClient.forceClose();
return response.build(); return response.build();
} }
/**
* Get a storage-manager client instance. A new storage instance will be instantied only if the memory type is not the same of the previous one.
* In this case the old connection will be closed.
*
* @param memoryType indicates the memory type (Persistent, Volatile or whatever)
* @return the storage client instance
*/
protected static IClient getStorageClientInstance(MemoryType memory) {
if ((!Objects.isNull(storageManagerClient)) && (storageManagerClient.getGcubeMemoryType().toString() == memory.toString())) {
LOG.debug("reusing the same storage-client object");
return storageManagerClient;
}else {
if(!Objects.isNull(storageManagerClient)) {
LOG.debug("going to close an old storage-client instance on "+storageManagerClient.getGcubeMemoryType());
try {
storageManagerClient.forceClose();
LOG.debug("storage-client closed");
}catch(Exception e) {
LOG.warn("Some problem occurred during the close operation:"+e.getMessage()+" Going to open another connection");
}
}
LOG.debug("initializing a new storage-client instance on "+memory);
storageManagerClient=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, STORAGE_ACCESS_TYPE, memory, STORAGE_BACKEND_TYPE).getClient();
return storageManagerClient;
}
}
/** /**
* Set the right memory type extrapolated from the storageid * Builds the storage client instance.
* @param storageId storageid with backend type specification (if present) *
* @return storageId without backend type specification * @param storageId the storage id
* @return the storage client instance
* @throws Exception the exception
*/ */
private static String identifyIdAndMemory(String storageId) { protected static StorageClientInstance buildStorageClientInstance(String storageId) throws Exception{
MemoryType memory=null;
if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){ if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){
LOG.info("identificated a VOLATILE url");
memory=MemoryType.VOLATILE; memory=MemoryType.VOLATILE;
storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, ""); storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, "");
}else {
memory=MemoryType.PERSISTENT;
} }
return storageId;
StorageClient client;
if(memory==null)
client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC);
else
client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory);
return new StorageClientInstance(client, memory, storageId);
} }
/** /**
* Gets the storage metadata file. * Gets the storage metadata file.
* *

View File

@ -1,47 +0,0 @@
package org.gcube.datatransfer.resolver.services;
import java.util.Map;
import java.util.Optional;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.HealthCheckResponse.Status;
import org.eclipse.microprofile.health.Liveness;
/**
* The Class UriResolverHealthCheck.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 15, 2024
*/
@Path("health")
public class UriResolverHealthCheck implements HealthCheck {
@GET
@Path("")
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
public Response check() {
HealthCheckResponse hcr = call();
return Response.ok().entity(hcr).build();
}
/**
* Call.
*
* @return the health check response
*/
@Liveness
@Override
public HealthCheckResponse call() {
return new HealthCheckResponse("uri-resolver", Status.UP, Optional.empty());
}
}

View File

@ -20,45 +20,37 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class UriResolverIndex.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* * Oct 22, 2018
* Mar 24, 2022
*/ */
@Path("index") @Path("index")
public class UriResolverIndex { public class UriResolverIndex {
private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class); private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class);
/**
* Index.
*
* @param req the req
* @return the input stream
* @throws WebApplicationException the web application exception
*/
@GET @GET
@Produces({ MediaType.TEXT_HTML }) @Produces({MediaType.TEXT_HTML})
@Path("") @Path("")
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException { public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
String indexFile = "/WEB-INF/jsp/index.jsp"; String indexFile = "/WEB-INF/jsp/index.jsp";
try { try{
logger.debug(UriResolverIndex.class.getSimpleName() + " called"); logger.info(UriResolverIndex.class.getSimpleName() +" called");
String realPath = req.getServletContext().getRealPath(indexFile); String realPath = req.getServletContext().getRealPath(indexFile);
return new FileInputStream(new File(realPath)); return new FileInputStream(new File(realPath));
} catch (Exception e) { }catch (Exception e) {
if (!(e instanceof WebApplicationException)) { if(!(e instanceof WebApplicationException)){
// UNEXPECTED EXCEPTION managing it as WebApplicationException //UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Index.jsp not found. Please, contact the support!"; String error = "Index.jsp not found. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null); throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
} }
// ALREADY MANAGED AS WebApplicationException //ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
} }

View File

@ -14,26 +14,18 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
/** /**
* The UriResolverInfo get index.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* * Oct 22, 2018
* Mar 24, 2022
*/ */
@Path("info") @Path("info")
public class UriResolverInfo { public class UriResolverInfo {
/**
* Info.
*
* @param req the req
* @return the input stream
* @throws WebApplicationException the web application exception
*/
@GET @GET
@Produces({ MediaType.TEXT_HTML }) @Produces({MediaType.TEXT_HTML})
@Path("") @Path("")
public InputStream info(@Context HttpServletRequest req) throws WebApplicationException { public InputStream info(@Context HttpServletRequest req) throws WebApplicationException{
return new UriResolverIndex().index(req); return new UriResolverIndex().index(req);
} }
} }

View File

@ -14,19 +14,18 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.datatransfer.resolver.UriResolverServices; import org.gcube.datatransfer.resolver.UriResolverServices;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
/** /**
* The UriResolverResources. Show the resources as a JSON * The Class ResourceListingResource.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* * Feb 14, 2019
* Mar 24, 2022
*/ */
@Path("resources") @Path("resources")
@Singleton @Singleton

View File

@ -1,286 +0,0 @@
package org.gcube.datatransfer.resolver.services;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.services.exceptions.NotFoundException;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The WekeoResolver provides a method to wrap the basic authentication from
* D4Science account to WekeoBroker service.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 24, 2022
*/
@Path("wekeo")
public class WekeoResolver {
private static Logger logger = LoggerFactory.getLogger(WekeoResolver.class);
private final static String RUNTIME_WKEO_RESOURCE_NAME = "WekeoDataBroker";
private final static String CATEGORY_WEKEO_TYPE = "OnlineService";
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver";
/**
* Gets the token.
*
* @param req the req
* @return the token
* @throws WebApplicationException the web application exception
*/
@GET
@Path("/gettoken")
@Produces(MediaType.APPLICATION_JSON)
public Response getToken(@Context HttpServletRequest req) throws WebApplicationException {
logger.info(this.getClass().getSimpleName() + " getToken starts...");
try {
String scope = ScopeProvider.instance.get();
logger.info("ScopeProvider has scope: " + scope);
ScopeBean scopeBean = new ScopeBean(scope);
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE");
throw ExceptionManager.unauthorizedException(req,
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
}
StringBuilder wekeoResponse = new StringBuilder();
AccessPoint wekeoAccessPoint = WekeoResolver.readWekeoServiceEndpoint(req, scope);
if (wekeoAccessPoint != null) {
String wekeoUsername = wekeoAccessPoint.username();
String wekeoAddress = wekeoAccessPoint.address();
String wekeoPwd = wekeoAccessPoint.password();
// printing the access point found
if (logger.isDebugEnabled()) {
String msg = String.format("Found the username '%s' and the address '%s' to perform the request",
wekeoUsername, wekeoAddress);
logger.debug(msg);
}
logger.info("The pwd is: " + wekeoPwd);
// decrypting the pwd
if (wekeoPwd != null) {
wekeoPwd = StringEncrypter.getEncrypter().decrypt(wekeoPwd);
logger.info("Decrypted pwd registered into Access Point '" + wekeoAccessPoint.name() + "' is: "
+ wekeoPwd.substring(0, wekeoPwd.length() / 2) + "...");
}
if (wekeoUsername != null && wekeoPwd != null & wekeoAddress != null) {
HttpURLConnection connection = null;
InputStream content = null;
InputStreamReader in = null;
try {
String authString = wekeoUsername + ":" + wekeoPwd;
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
logger.debug("Base64 encoded auth string: " + authStringEnc);
logger.info("Performing the request to: " + wekeoAddress);
URL url = new URL(wekeoAddress);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
content = (InputStream) connection.getInputStream();
in = new InputStreamReader(content);
logger.info("the response code is: " + connection.getResponseCode());
int numCharsRead;
char[] charArray = new char[1024];
StringBuffer sb = new StringBuffer();
logger.debug("reading the response...");
while ((numCharsRead = in.read(charArray)) > 0) {
sb.append(charArray, 0, numCharsRead);
}
wekeoResponse.append(sb.toString());
// System.out.println(wekeoResponse);
} catch (Exception e) {
logger.error(e.getMessage(), e);
String error = String.format("Error on performing request to %s", wekeoAddress);
throw new Exception(error);
} finally {
try {
if (content != null && in != null) {
in.close();
content.close();
}
} catch (Exception e) {
// silent
}
}
} else {
String error = String.format(
"I cannot read the configurations (adress, username,password) from %s in the scope %s",
RUNTIME_WKEO_RESOURCE_NAME, scope);
throw new Exception(error);
}
}
// to be sure
if (wekeoResponse.length() == 0) {
String error = String.format(
"Sorry an error occured on getting the access token from Wekeo. Please, retry the request");
throw new Exception(error);
}
String theResponse = wekeoResponse.toString();
logger.info("returning: \n" + theResponse);
return Response.ok(theResponse).build();
} catch (Exception e) {
// ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e);
throw (WebApplicationException) e;
}
}
/**
* Index.
*
* @param req the req
* @return the input stream
* @throws WebApplicationException the web application exception
*/
@GET
@Produces({ MediaType.TEXT_HTML })
@Path("")
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException {
String indexFile = "/WEB-INF/jsp/wekeo.jsp";
try {
logger.info(this.getClass().getSimpleName() + " index called");
String realPath = req.getServletContext().getRealPath(indexFile);
return new FileInputStream(new File(realPath));
} catch (Exception e) {
if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "wekeo.jsp not found. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
}
// ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e);
throw (WebApplicationException) e;
}
}
/**
* Reads the wekeo endpoint information from IS. {The SE name is: @link
* WekeoResolver#RUNTIME_WKEO_RESOURCE_NAME}
*
* @param req the req
* @param scope the scope
* @return the string
*/
public static AccessPoint readWekeoServiceEndpoint(HttpServletRequest req, String scope) {
String callerScope = null;
try {
callerScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
logger.info("Searching SE " + RUNTIME_WKEO_RESOURCE_NAME + " configurations in the scope: "
+ ScopeProvider.instance.get());
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '" + RUNTIME_WKEO_RESOURCE_NAME + "'");
query.addCondition("$resource/Profile/Category/text() eq '" + CATEGORY_WEKEO_TYPE + "'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> toReturn = client.submit(query);
logger.info("The query returned " + toReturn.size() + " ServiceEndpoint/s");
if (toReturn.size() == 0) {
String errorMessage = String.format(
"Missing the RR with Name '%s' and Category '%s' in the scope '%s'. Please contact the support.",
RUNTIME_WKEO_RESOURCE_NAME, CATEGORY_WEKEO_TYPE, ScopeProvider.instance.get());
logger.error(errorMessage);
throw ExceptionManager.notFoundException(req, errorMessage, WekeoResolver.class, helpURI);
}
String wekeoUsername = null;
String wekeoPwd = null;
ServiceEndpoint se = toReturn.get(0);
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
for (AccessPoint accessPoint : theAccessPoints) {
wekeoUsername = accessPoint.username();
wekeoPwd = accessPoint.password();
if (wekeoUsername != null && wekeoPwd != null) {
logger.info("returning the access point with name: " + accessPoint.name());
return accessPoint;
}
}
return null;
} catch (Exception e) {
if (e instanceof NotFoundException)
throw e;
String errorMessage = "Error occurred on reading the " + RUNTIME_WKEO_RESOURCE_NAME
+ " SE registered in the scope: " + ScopeProvider.instance.get();
logger.error(errorMessage, e);
throw ExceptionManager.internalErrorException(req, errorMessage, WekeoResolver.class, helpURI);
} finally {
if (callerScope != null) {
logger.info("Setting to the callerScope scope: " + callerScope);
ScopeProvider.instance.set(callerScope);
} else {
logger.info("Reset scope");
ScopeProvider.instance.reset();
}
}
}
}

View File

@ -9,10 +9,10 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Builder;
@XmlRootElement(name="error") @XmlRootElement(name="error")

View File

@ -10,10 +10,10 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Builder;
/** /**

View File

@ -58,10 +58,8 @@ public class StorageHubMetadataResponseBuilder {
responseBuilder.header("Content-Location", contentLocation); responseBuilder.header("Content-Location", contentLocation);
//Managing "Content-Type" //Managing "Content-Type"
if (streamDescriptor.getContentType()!= null && !streamDescriptor.getContentType().isEmpty()) { if (streamDescriptor.getContentType()!= null && !streamDescriptor.getContentType().isEmpty())
responseBuilder.header("Content-Type", streamDescriptor.getContentType()); responseBuilder.header("Content-Type", streamDescriptor.getContentType());
}
//Managing "Content-Lenght" //Managing "Content-Lenght"
if(streamDescriptor.getContentLenght()>0) { if(streamDescriptor.getContentLenght()>0) {

View File

@ -120,4 +120,14 @@ public class HttpRequestUtil {
return false; return false;
} }
/**
* The main method.
*
* @param args the arguments
* @throws Exception the exception
*/
public static void main(String[] args) throws Exception {
System.out.println(HttpRequestUtil.urlExists("http://geoserver2.d4science.research-infrastructures.eu/geoserver/wms", true));
}
} }

View File

@ -1,6 +0,0 @@
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,4 @@
<description>URIResolver RESTful</description> <description>URIResolver RESTful</description>
<include>/analytics/create/*</include> <include>/analytics/create/*</include>
<include>/knime/create/*</include> <include>/knime/create/*</include>
<include>/wekeo/gettoken/*</include>
<include>/oat/get/*</include>
<include>/geoportal/export/*</include>
</application> </application>

View File

@ -0,0 +1,22 @@
<!-- EASTER EGG - TO BE REMOVED -->
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<style type="text/css">
body {
background-color: #f8f6f2;
color: #225f97;
font-family: 'Droid Sans', arial, sans-serif;
font-size: 16px;
}
</style>
</head>
<body>
<div>
<img style="-webkit-user-select: none; cursor: zoom-out;"
src="https://www.sportmediaset.mediaset.it/binary/26.$plit/C_29_fotogallery_1024745__ImageGallery__imageGalleryItem_4_image.jpg"
width="2598" height="2074">
</div>
</body>
</html>

View File

@ -1,8 +1,6 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html lang="en-US">
<head> <head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<style type="text/css"> <style type="text/css">
body { body {
background-color: #f8f6f2; background-color: #f8f6f2;
@ -18,11 +16,11 @@ body {
height: 300px; height: 300px;
margin-top: -150px; /*set to a negative number 1/2 of your height*/ margin-top: -150px; /*set to a negative number 1/2 of your height*/
margin-left: -300px; /*set to a negative number 1/2 of your width*/ margin-left: -300px; /*set to a negative number 1/2 of your width*/
/* border: 1px solid #ccc; */ /* border: 1px solid #ccc; */
/* background-color: #9b9b9b; */ /* background-color: #9b9b9b; */
position: fixed; position: fixed;
text-align: center; text-align: center;
/* vertical-align: middle; */ /* vertical-align: middle; */
} }
.myTitle { .myTitle {
@ -39,13 +37,8 @@ body {
<div class="myTitle">The URI Resolver</div> <div class="myTitle">The URI Resolver</div>
<p> <p>
See wiki page at <a See wiki page at <a
href="https://gcube.wiki.gcube-system.org/gcube/index.php/URI_Resolver" href="https://gcube.wiki.gcube-system.org/gcube/index.php/URI_Resolver" target="_blank">gCube Wiki URI
target="_blank">gCube Wiki URI Resolver</a> Resolver</a>
</p>
<p>
See API documentation at <a
href="docs/index.html"
target="_blank">URI Resolver API</a>
</p> </p>
</div> </div>
</body> </body>

View File

@ -1,74 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script type="text/javascript">
function goToURL(relativePath) {
var x = "/wekeo/" + relativePath;
window.open(x, "_blank");
}
</script>
<style type="text/css">
body {
background-color: #f8f6f2;
color: #225f97;
font-family: 'Droid Sans', arial, sans-serif;
font-size: 16px;
}
.mydiv {
top: 50%;
left: 50%;
width: 600px;
height: 300px;
margin-top: -150px; /*set to a negative number 1/2 of your height*/
margin-left: -300px; /*set to a negative number 1/2 of your width*/
/* border: 1px solid #ccc; */
/* background-color: #9b9b9b; */
position: fixed;
text-align: center;
/* vertical-align: middle; */
}
.myTitle {
font-size: 22px;
font-weight: bold;
}
.myListOperations {
margin-top: 20px;
margin-bottom: 40px;
color: #333;
}
.uri-footer {
padding: 20px 20px;
font-size: 14px;
}
</style>
</head>
<body>
<div class="mydiv">
<img alt=""
src="https://www.d4science.org/image/layout_set_logo?img_id=12630" />
<div class="myTitle">The Wekeo Resolver</div>
<div class="myListOperations">
Available Operations:
<p>
# authentication operator
<button onclick="goToURL('gettoken')">Get Token</button>
(gCube AuthN required)
</p>
</div>
<div class="uri-footer">
See wiki page at <a
href="https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver"
target="_blank">gCube Wiki Wekeo Resolver</a>
</div>
</div>
</body>
</html>

View File

@ -1,26 +0,0 @@
.d4science_intro {
top: 0;
z-index: 2000;
position: fixed;
display: block ruby;
padding: 10px;
background: white;
width: 100%;
height: 100px;
}
.navbar-fixed-top {
top: 100px !important;
}
.sidebar {
top: 160px !important;
}
.navbar {
margin-bottom: 40px !important;
}
.main {
top: 90px;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

View File

@ -0,0 +1,34 @@
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
/**
* The Class CatalogueResolverTest.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* May 13, 2019
*/
public class CatalogueResolverTest {
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
try {
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab");
//ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
System.out.println(ckanCatalogueReference.toString());
}catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,4 +1,3 @@
package org.gcube.datatransfer.test;
import static org.gcube.resources.discovery.icclient.ICFactory.client; import static org.gcube.resources.discovery.icclient.ICFactory.client;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;

View File

@ -1,8 +1,3 @@
package gis;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.gcube.common.encryption.StringEncrypter; import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.spatial.data.geonetwork.GeoNetwork; import org.gcube.spatial.data.geonetwork.GeoNetwork;
@ -12,30 +7,25 @@ import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.Configuration; import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.model.Account; import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.Account.Type; import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.opengis.metadata.Metadata;
import it.geosolutions.geonetwork.util.GNSearchRequest; import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse; import it.geosolutions.geonetwork.util.GNSearchResponse;
import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata;
/** /**
* The Class GeonetworkQueryTest.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Aug 31, 2016 * Aug 31, 2016
*/ */
public class GeonetworkQueryTest { public class GeonetworkQueryTest {
private static final int MAX = 30; private static final int MAX = 10;
//private String[] scopes = {"/gcube/devsec/devVRE"}; private static final String UUID = "8a878105-ef06-4b1f-843f-120fc525b22b";
//private String[] scopes = {"/gcube/devsec/StaTabTest"}; //private String[] scopesProd = {"/gcube/devsec/devVRE"};
//private String[] scopes = {"/gcube/devsec/devVRE"}; //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"};
//private String[] scopes = {"/pred4s/preprod/preVRE"};
//private String[] scopes = {"/d4science.research-infrastructures.eu"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"}; //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"};
@ -43,50 +33,30 @@ public class GeonetworkQueryTest {
//private String[] scopesProd = {"/d4science.research-infrastructures.eu"}; //private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject"}; //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas"};
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration"};
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/FrenchTropicalTunaAtlas"};
private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"};
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"};
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon"};
private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab"};
private LoginLevel loginLevel = LoginLevel.CKAN; private LoginLevel loginLevel = LoginLevel.CKAN;
private Type accountType = Type.CKAN; private Type accountType = Type.SCOPE;
private String textToSearch = "geo_fea"; private String textToSearch = "geo_fea";
/**
* Gets the count.
*
* @return the count
* @throws Exception the exception
*/
//@Test //@Test
public void getCount() throws Exception{ public void getCount() throws Exception{
try{ try{
for(String scope:scopes){ for(String scope:scopesProd){
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
GeoNetworkPublisher reader=GeoNetwork.get(); GeoNetworkPublisher reader=GeoNetwork.get();
Configuration config = reader.getConfiguration(); Configuration config = reader.getConfiguration();
Account account=config.getScopeConfiguration().getAccounts().get(accountType); Account account=config.getScopeConfiguration().getAccounts().get(accountType);
// Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
// Account account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
//System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword()); //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword()); System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
System.out.println("USER: "+account.getUser()+", Pwd: "+account.getPassword());
System.out.println("GN: "+config.getGeoNetworkEndpoint());
try{ try{
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword()); String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
System.out.println("Decrypted Password: "+decryptedPassword); System.out.println("Decrypted Password: "+decryptedPassword);
@ -100,96 +70,66 @@ public class GeonetworkQueryTest {
// req.addParam(GNSearchRequest.Param.any,"Thredds"); // req.addParam(GNSearchRequest.Param.any,"Thredds");
GNSearchResponse resp = reader.query(req); GNSearchResponse resp = reader.query(req);
int publicCount=resp.getCount(); int publicCount=resp.getCount();
System.out.println("Public UUIDs are: "+publicCount);
Map<Long,String> publicUUIDs = getUUIDs(resp);
System.out.println("Filled list of Public UUIDs with: "+publicUUIDs.size());
System.out.println("Public layers are: ");
printLayers(publicUUIDs);
reader.login(loginLevel); reader.login(loginLevel);
resp = reader.query(req); int totalCount=reader.query(req).getCount();
int totalCount=resp.getCount();
System.out.println("All UUIDs are: "+totalCount);
Map<Long,String> allUUIDs = getUUIDs(resp);
System.out.println("Filled list of All UUIDs with: "+allUUIDs.size());
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")"); System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
if(totalCount==0)
System.out.println("Private layers are: ");
allUUIDs.keySet().removeAll(publicUUIDs.keySet());
printLayers(allUUIDs);
/*if(totalCount==0)
return; return;
try{ /*try{
int last = totalCount<MAX?totalCount:MAX; int last = totalCount>MAX?totalCount:MAX;
for(int i=0; i<last; i++){ for(int i=0; i<last; i++){
String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID()); String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
System.out.println(i+") UUID: "+resp.getMetadata(i).getUUID() + " ID: "+resp.getMetadata(i).getId()); System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
//System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
} }
}catch(Exception e ){ }catch(Exception e ){
e.printStackTrace(); e.printStackTrace();
}*/ }*/
System.out.println("DONE!!!");
} }
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }
} }
/**
* Prints the layers.
*
* @param layersUUIDs the layers UUI ds
*/
public void printLayers(Map<Long,String> layersUUIDs) {
int index = 0;
for (Long key : layersUUIDs.keySet()) {
index++;
System.out.println(index+") ID: "+key+" - UUID: "+layersUUIDs.get(key));
}
}
/**
* Gets the UUI ds.
*
* @param resp the resp
* @return the UUI ds
*/
public static Map<Long,String> getUUIDs(GNSearchResponse resp){
Map<Long,String> listUUIDs = new HashMap<Long,String>();
Iterator<GNMetadata> iterator = resp.iterator();
while(iterator.hasNext()) {
GNMetadata meta = iterator.next();
//listUUIDs.add(new GN_META_REF(meta.getId(), meta.getUUID()));
listUUIDs.put(meta.getId(), meta.getUUID());
//System.out.println("Added: "+meta.getUUID());
}
return listUUIDs;
}
/**
* Gets the layers by search.
*
* @return the layers by search
* @throws Exception the exception
*/
//@Test //@Test
public void getLayersBySearch() throws Exception{ public void getLayerByUUID() throws Exception{
try{ try{
for(String scope:scopes){ for(String scope:scopesProd){
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
GeoNetworkPublisher reader=GeoNetwork.get(); GeoNetworkPublisher reader=GeoNetwork.get();
Configuration config = reader.getConfiguration();
Account account=config.getScopeConfiguration().getAccounts().get(accountType);
//System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
Metadata meta = reader.getById(UUID);
try{
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
System.out.println("Decrypted Password: "+decryptedPassword);
}catch(Exception e){
System.out.println("ignoring exception during pwd decrypting");
}
System.out.println("SCOPE "+scope+" found meta "+meta);
}
}catch(Exception e){
System.err.println("Error on getting layer by UUID: "+UUID);
e.printStackTrace();
}
}
//@Test
public void getLayersBySearch() throws Exception{
try{
for(String scope:scopesProd){
ScopeProvider.instance.set(scope);
GeoNetworkPublisher reader=GeoNetwork.get();
Configuration config = reader.getConfiguration(); Configuration config = reader.getConfiguration();
Account account=config.getScopeConfiguration().getAccounts().get(accountType); Account account=config.getScopeConfiguration().getAccounts().get(accountType);
@ -238,13 +178,6 @@ public class GeonetworkQueryTest {
} }
/**
* Contains string.
*
* @param txt the txt
* @param value the value
* @return true, if successful
*/
private boolean containsString(String txt, String value){ private boolean containsString(String txt, String value){
return txt.contains(value); return txt.contains(value);
} }
@ -276,93 +209,11 @@ public class GeonetworkQueryTest {
return req; return req;
} }
/**
* The Class GN_META_REF.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* May 20, 2019
*/
public static class GN_META_REF{
Long id;
String uuid;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the uuid.
*
* @return the uuid
*/
public String getUuid() {
return uuid;
}
/**
* Sets the uuid.
*
* @param uuid the new uuid
*/
public void setUuid(String uuid) {
this.uuid = uuid;
}
/**
* Instantiates a new gn meta ref.
*
* @param id the id
* @param uuid the uuid
*/
public GN_META_REF(Long id, String uuid) {
super();
this.id = id;
this.uuid = uuid;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GN_META_REF [id=");
builder.append(id);
builder.append(", uuid=");
builder.append(uuid);
builder.append("]");
return builder.toString();
}
}
/**
* Gets the count prod.
*
* @return the count prod
* @throws Exception the exception
*/
// @Test // @Test
public void getCountProd() throws Exception{ public void getCountProd() throws Exception{
try{ try{
for(String scope:scopes){ for(String scope:scopesProd){
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
GeoNetworkReader reader=GeoNetwork.get(); GeoNetworkReader reader=GeoNetwork.get();
final GNSearchRequest req=new GNSearchRequest(); final GNSearchRequest req=new GNSearchRequest();

View File

@ -1,4 +1,3 @@
package org.gcube.datatransfer.test;
//import javax.servlet.ServletException; //import javax.servlet.ServletException;
// //
//import org.gcube.datatransfer.resolver.GeonetworkRequestDecoder; //import org.gcube.datatransfer.resolver.GeonetworkRequestDecoder;

View File

@ -1,4 +1,3 @@
package org.gcube.datatransfer.test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -49,7 +48,7 @@ public class GeonetworkResolverTest {
/*String scopeValue ="/gcube/devsec/devVRE"; /*String scopeValue ="/gcube/devsec/devVRE";
String remainValue = "/srv/en/mef.export"; String remainValue = "/srv/en/mef.export";
String queryString = "scope=/gcube/devsec/devVRE&remainPath=/srv/en/mef.export&version=2.0.2&request=GetCapabilities&service=CSW"; String queryString = "scope=/gcube/devsec/devVRE&remainPath=/srv/en/mef.export&version=2.0.2&request=GetCapabilities&service=CSW";
ServiceEndpointParameters geonetworkParams = new ServiceEndpointParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", ""); ServerParameters geonetworkParams = new ServerParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", "");
String newQueryString = purgeScopeFromQueryString(scopeValue, queryString); String newQueryString = purgeScopeFromQueryString(scopeValue, queryString);
logger.info("Purged query string from "+scopeValue+" is: "+newQueryString); logger.info("Purged query string from "+scopeValue+" is: "+newQueryString);

View File

@ -1,9 +1,9 @@
package org.gcube.datatransfer.test;
import static org.gcube.resources.discovery.icclient.ICFactory.client; import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -18,7 +18,6 @@ import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox; import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -39,12 +38,12 @@ public class GetAllInfrastructureScopesFromIS {
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()"; protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
/** /**
* Test loading map of scope. * The main method.
*
* @param args the arguments
*/ */
@Test public static void main(String[] args) {
public void testLoadingMapOfScope() {
try { try {
@ -54,16 +53,16 @@ public class GetAllInfrastructureScopesFromIS {
UriResolverSmartGearManagerInit.setRootContextScope(rootScope); UriResolverSmartGearManagerInit.setRootContextScope(rootScope);
LoadingMapOfScopeCache cache = new LoadingMapOfScopeCache(); LoadingMapOfScopeCache cache = new LoadingMapOfScopeCache();
// int i = 0; int i = 0;
// for (String string : cache.getCache().asMap().keySet()) { for (String string : cache.getCache().asMap().keySet()) {
// try { try {
// System.out.println(++i+") Scope Name: "+string + " to full scope: "+LoadingMapOfScopeCache.get(string)); System.out.println(++i+") Scope Name: "+string + " to full scope: "+LoadingMapOfScopeCache.get(string));
// } catch (ExecutionException e) { } catch (ExecutionException e) {
// e.printStackTrace(); e.printStackTrace();
// } }
// } }
String scopeName = "abc"; String scopeName = "devsec";
ScopeBean scopeBean = LoadingMapOfScopeCache.get(scopeName); ScopeBean scopeBean = LoadingMapOfScopeCache.get(scopeName);
String fullScope = scopeBean.toString(); String fullScope = scopeBean.toString();
logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName()); logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());

View File

@ -1,6 +1,6 @@
package org.gcube.datatransfer.test;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem; import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem;
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
import org.gcube.datatransfer.resolver.services.GisResolver; import org.gcube.datatransfer.resolver.services.GisResolver;
/** /**
@ -18,7 +18,7 @@ public class GisResolverTest {
public static void main(String[] args) { public static void main(String[] args) {
GisResolver gisResolver = new GisResolver(); GisResolver gisResolver = new GisResolver();
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
//ServiceEndpointParameters geonetworkParams = getCachedServerParameters(scope); //ServerParameters geonetworkParams = getCachedServerParameters(scope);
try { try {
GisLayerItem gisLayerItem = gisResolver.getGisLayerForLayerUUID(null, scope, gisUUID); GisLayerItem gisLayerItem = gisResolver.getGisLayerForLayerUUID(null, scope, gisUUID);
} catch (Exception e) { } catch (Exception e) {
@ -33,7 +33,7 @@ public class GisResolverTest {
String scope = "/gcube/devsec/devVRE"; String scope = "/gcube/devsec/devVRE";
String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8"; String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
try { try {
ServiceEndpointParameters geonetworkParams = gisResolver.getCachedServerParameters(scope); ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams); String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams);
System.out.println("Final url is: " + wmsRequest); System.out.println("Final url is: " + wmsRequest);
wmsRequest = URLEncoder.encode(wmsRequest, UTF_8); wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);

View File

@ -1,4 +1,3 @@
package org.gcube.datatransfer.test;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,3 @@
package org.gcube.datatransfer.test;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,3 @@
package org.gcube.datatransfer.test;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -1,158 +0,0 @@
package catalogue;
/**
*
*/
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.junit.Test;
import resources.GcoreEndpointReader;
import resources.GetAllInfrastructureScopes;
/**
* The Class CatalogueMatching_SCOPE_CKANCONNECTOR.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 7, 2022
*/
public class CatalogueMatching_SCOPE_CKANCONNECTOR {
// GN CONFIGURATIONS
static String rootScope = "/d4science.research-infrastructures.eu";
// static String rootScope = "/pred4s";
// static String rootScope = "/gcube";
static LoginLevel loginLevel = LoginLevel.CKAN;
static PrintWriter reportPrintWriter;
static PrintWriter errorPrintWriter;
private static int c = 0;
/**
* Test catalogue discovery.
*
* @throws Exception the exception
*/
@Test
public void testCatalogueDiscovery() throws Exception {
try {
FileWriter reportWriter = new FileWriter(rootScope.substring(1, rootScope.length()) + "_report_"
+ CatalogueMatching_SCOPE_CKANCONNECTOR.class.getSimpleName() + ".csv", true);
FileWriter errorWriter = new FileWriter(rootScope.substring(1, rootScope.length()) + "_error_"
+ CatalogueMatching_SCOPE_CKANCONNECTOR.class.getSimpleName() + ".csv", true);
BufferedWriter reportBW = new BufferedWriter(reportWriter);
BufferedWriter errorBW = new BufferedWriter(errorWriter);
reportPrintWriter = new PrintWriter(reportBW);
reportPrintWriter.println("NB.; SCOPE; CKAN_CONNECTOR_URL;");
errorPrintWriter = new PrintWriter(errorBW);
errorPrintWriter.println("NB.; SCOPE; ERROR MESSAGE;");
} catch (Exception e) {
e.printStackTrace();
}
// final Path destination = Paths.get("report_matching_gn_catalogue.csv");
// Files.w(re, destination);
List<String> scopesProd = new ArrayList<String>();
// RuntimeResourceReader readerRR;
try {
// MODE-1
// readerRR = new RuntimeResourceReader(rootScope, platformName, null);
// System.out.println(readerRR.toString());
// System.out.println("Using GN: "+readerRR.getParameters());
// System.out.println("Scopes are: "+readerRR.getScopes().size());
// scopesProd.addAll(readerRR.getScopes());
// MODE-2
Map<String, String> mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope);
scopesProd.addAll(mapScopes.values());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Read " + scopesProd.size() + " VREs from root scope: " + rootScope);
for (String vre : scopesProd) {
System.out.println("VRE: " + vre);
}
int count = 0;
try {
final String ckanResource = "org.gcube.data.access.ckanconnector.CkanConnector";
final String serviceName = "CkanConnector";
final String serviceClass = "DataAccess";
int totalScope = scopesProd.size();
int reportOp = 0;
int errorOp = 0;
for (String scope : scopesProd) {
count++;
System.out.println("#### Operation "+ count+ " of "+totalScope+") Fetching scope: " + scope);
ScopeProvider.instance.set(scope);
GcoreEndpointReader reader = null;
try {
// discovery = new GCatClientDiscovery();
reader = new GcoreEndpointReader(scope, serviceClass, serviceName, ckanResource);
} catch (Exception e) {
System.out.println("gCat not instanciable in the scope: " + scope);
errorOp++;
writeError(errorOp + "; " + scope + " ; " + e.getMessage());
}
if (reader != null) {
reportOp++;
writeReport(reportOp + "; " + scope + " ; " + reader.getEndPoints().get(0) + " ; ");
}
System.out.println("Sleeping...");
Thread.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reportPrintWriter != null)
reportPrintWriter.close();
if (errorPrintWriter != null)
errorPrintWriter.close();
System.out.println("Performed fetching from " + count + " scopes");
System.out.println("FINISHED!!!");
}
}
/**
* Write report.
*
* @param newline the newline
*/
private static synchronized void writeReport(String newline) {
c++;
reportPrintWriter.println(newline);
}
/**
* Write error.
*
* @param newline the newline
*/
private static synchronized void writeError(String newline) {
c++;
errorPrintWriter.println(newline);
}
}

View File

@ -1,267 +0,0 @@
//package gis;
//import it.geosolutions.geonetwork.util.GNSearchRequest;
//import it.geosolutions.geonetwork.util.GNSearchResponse;
//
//import java.io.BufferedInputStream;
//import java.io.BufferedReader;
//import java.io.FileNotFoundException;
//import java.io.FileReader;
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
//import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.DocumentBuilderFactory;
//
//import org.gcube.common.encryption.StringEncrypter;
//import org.gcube.common.scope.api.ScopeProvider;
//import org.gcube.spatial.data.geonetwork.GeoNetwork;
//import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
//import org.gcube.spatial.data.geonetwork.LoginLevel;
//import org.gcube.spatial.data.geonetwork.configuration.Configuration;
//import org.gcube.spatial.data.geonetwork.model.Account;
//import org.gcube.spatial.data.geonetwork.model.Account.Type;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.w3c.dom.Document;
//import org.w3c.dom.Element;
//import org.w3c.dom.NodeList;
//
///**
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// * Aug 31, 2016
// */
//public class ICCATQueryTest {
//
// private static final int MAX = 200;
//
// //private String[] scopes = {"/gcube/devNext/NextNext"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
//
// private static String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
//
// private static LoginLevel loginLevel = LoginLevel.CKAN;
//
// private static Type accountType = Type.SCOPE;
//
// private static String textToSearch = "geo_fea";
//
// private static Logger logger = LoggerFactory.getLogger(ICCATQueryTest.class);
//
// private static enum LAYER_TYPE {PRIVATE, PUBLIC, ALL}
//
//
// public static List<String> getLayers(LAYER_TYPE type) throws Exception{
//
// try{
// for(String scope:scopesProd){
// ScopeProvider.instance.set(scope);
// GeoNetworkPublisher reader=GeoNetwork.get();
//
// Configuration config = reader.getConfiguration();
// Account account=config.getScopeConfiguration().getAccounts().get(accountType);
//
// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
//
// try{
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
// System.out.println("Decrypted Password: "+decryptedPassword);
// }catch(Exception e){
// System.out.println("ignoring exception during pwd decrypting");
// }
//
//
// // req.addParam("keyword", "Thredds");
// final GNSearchRequest req=new GNSearchRequest();
//// req.addParam(GNSearchRequest.Param.any,"Thredds");
// GNSearchResponse resp = reader.query(req);
// int publicCount=resp.getCount();
//
// List<String> publicLayers = new ArrayList<String>();
// for(int i=0; i<publicCount; i++)
// publicLayers.add(resp.getMetadata(i).getUUID());
//
// System.out.println("Public layers are: "+publicLayers.size());
//
// //PERFOMING LOGIN TO GET ALL LAYERS
// reader.login(loginLevel);
// resp = reader.query(req);
// int totalCount=resp.getCount();
// int privateCount = totalCount-publicCount;
//
// System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+privateCount+")");
//
// List<String> privateLayers = new ArrayList<String>();
// for(int i=0; i<totalCount; i++){
//
// String uuid = resp.getMetadata(i).getUUID();
// //System.out.println("Searching UUID: "+uuid);
// if(!publicLayers.contains(uuid)){
// privateLayers.add(uuid);
// }
//
//// String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
//// InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
//// iccatGNUUID.add(toGetFileIdentifier(stream));
//
// //System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
// }
//
// System.out.println("Private layers are: "+privateLayers.size());
//
//
// switch (type) {
// case PUBLIC:
// return publicLayers;
// case PRIVATE:
// return privateLayers;
// case ALL:
// publicLayers.addAll(privateLayers);
// return publicLayers;
// default:
// break;
// }
// }
// }catch(Exception e){
// e.printStackTrace();
// }
// return null;
// }
//
// /**
// * Override summary record.
// *
// * @param doc the doc
// * @param identifier the identifier
// * @return true, if successful
// */
// private static String getFileIdentifierValue(Document doc) {
//
// // <csw:SummaryRecord> list
// NodeList nodes = doc.getElementsByTagName("gmd:MD_Metadata");
// logger.debug("gmd:MD_Metadata are: " + nodes.getLength());
// for (int i = 0; i < nodes.getLength(); i++) {
// Element mdMetadata = (Element) nodes.item(i);
//
// // <dc:identifier>
// NodeList fileIdentifierLst = mdMetadata.getElementsByTagName("gmd:fileIdentifier");
// if(fileIdentifierLst==null || fileIdentifierLst.getLength()==0 || fileIdentifierLst.item(0)==null){
// logger.info("skipping, it has not fileidentifier");
// return null;
// }
//
// Element id = (Element) fileIdentifierLst.item(0);
//
// NodeList gcoLst = id.getElementsByTagName("gco:CharacterString");
// if(gcoLst==null || gcoLst.getLength()==0 || gcoLst.item(0)==null){
// logger.info("skipping, it has not gco:CharacterString");
// return null;
// }
//
// Element gco = (Element) gcoLst.item(0);
// String idValue = gco.getTextContent();
// logger.trace("Summary gmd:fileIdentifier is: " + idValue);
// return idValue;
// }
//
// return null;
// }
//
// /**
// * Removes the summary ids by list ids.
// *
// * @param getRecordsResponse the get records response
// * @param idsToRemove the ids to remove
// * @return the input stream
// * @throws IOException Signals that an I/O exception has occurred.
// */
// public static String toGetFileIdentifier(InputStream getRecordResponse) throws IOException {
//
// try {
// // logger.trace("getRecordsResponse is: "+IOUtils.toString(getRecordsResponse));
// BufferedInputStream bis = new BufferedInputStream(getRecordResponse);
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// dbf.setValidating(false);
// DocumentBuilder db = dbf.newDocumentBuilder();
// Document doc = db.parse(bis);
// return getFileIdentifierValue(doc);
// }
// catch (Exception e) {
// logger.error("An error occurred during removing IDS by List: ", e);
// return null;
// }
// }
//
//
// public static List<String> fileReader() throws FileNotFoundException{
//
// String fileName = "iccat_name_catalogue.csv";
//
//// //read file into stream, try-with-resources
//// try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
////
//// stream.forEach(System.out::println);
////
//// } catch (IOException e) {
//// e.printStackTrace();
//// }
//
// FileReader reportReader = new FileReader(fileName);
// //Stream<String> stream = reportBW.lines();
// List<String> list = new ArrayList<>();
// try (BufferedReader reportBW = new BufferedReader(reportReader)){
//
// list = reportBW.lines().collect(Collectors.toList());
//
// }catch (Exception e) {
// e.printStackTrace();
// }
//
// return list;
// }
//
//
// public static void main(String[] args) {
//
// List<String> listCKAN;
// try {
// listCKAN = fileReader();
// System.out.println("CKAN Layers are: "+listCKAN.size());
//// for (String line : listCKAN) {
//// System.out.println("CKAN UUID: "+line);
//// }
//
// List<String> listLayersUUID = getLayers(LAYER_TYPE.PUBLIC);
// System.out.println("List Layers UUID are: "+listLayersUUID.size());
//// for (String line : listLayersUUID) {
//// System.out.println("PRIVATE GN UUID: "+line);
//// }
//
//
// listCKAN.removeAll(listLayersUUID);
//
// System.out.println("\n\n\nCKAN contains other: "+listCKAN.size());
// for (String line : listCKAN) {
// System.out.println("CKAN UUID: "+line);
// }
//
// }catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
//
//
// }
//}

View File

@ -1,168 +0,0 @@
/**
*
*/
package gis;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.spatial.data.geonetwork.GeoNetwork;
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import resources.GetAllInfrastructureScopes;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 10, 2017
*/
public class LayersMatchingGN_CKAN {
//GN CONFIGURATIONS
public static String rootScope = "/d4science.research-infrastructures.eu";
//static String rootScope = "/pred4s";
// static String rootScope = "/gcube";
public static String platformName = "geonetwork";
public static LoginLevel loginLevel = LoginLevel.ADMIN;
//static Type accountType = Type.SCOPE;
public static String textToSearch = "geo_fea";
public static PrintWriter reportPrintWriter;
public static PrintWriter errorPrintWriter;
public static void main(String[] args) {
try{
FileWriter reportWriter = new FileWriter(rootScope.substring(1,rootScope.length())+"_report_matching_gn_catalogue.csv", true);
FileWriter errorWriter = new FileWriter(rootScope.substring(1,rootScope.length())+"_error_matching_gn_catalogue.csv", true);
BufferedWriter reportBW = new BufferedWriter(reportWriter);
BufferedWriter errorBW = new BufferedWriter(errorWriter);
reportPrintWriter = new PrintWriter(reportBW);
reportPrintWriter.println("NB.; SCOPE; GN Endpoint; TOTAL LAYERS; PUBLIC LAYERS; PRIVATE LAYERS");
errorPrintWriter = new PrintWriter(errorBW);
errorPrintWriter.println("SCOPE;");
}catch(Exception e){
e.printStackTrace();
}
// final Path destination = Paths.get("report_matching_gn_catalogue.csv");
// Files.w(re, destination);
List<String> scopesProd = new ArrayList<String>();
//RuntimeResourceReader readerRR;
try {
//MODE-1
// readerRR = new RuntimeResourceReader(rootScope, platformName, null);
// System.out.println(readerRR.toString());
// System.out.println("Using GN: "+readerRR.getParameters());
// System.out.println("Scopes are: "+readerRR.getScopes().size());
// scopesProd.addAll(readerRR.getScopes());
//MODE-2
Map<String,String> mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope);
scopesProd.addAll(mapScopes.values());
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Read "+scopesProd.size() +" VREs from root scope: "+rootScope);
int i = 0;
for (String vre : scopesProd) {
System.out.println(++i +"; "+vre);
}
System.out.println("Scope found: "+scopesProd.size());
int count = 0;
try{
for(String scope:scopesProd){
count++;
System.out.println("\n\n#"+count+" of "+scopesProd.size()+ " - Fetching scope: "+scope);
ScopeProvider.instance.set(scope);
GeoNetworkPublisher reader = null;
String gnEP = null;
try{
reader=GeoNetwork.get();
gnEP = reader.getConfiguration().getGeoNetworkEndpoint();
}catch (Exception e) {
System.out.println("GeoNetwork not instanciable in the scope: "+scope);
writeError(count+"; "+scope+" ; "+e.getMessage());
}
if(reader!=null){
// Configuration config = reader.getConfiguration();
// Account account=config.getScopeConfiguration().getAccounts().get(accountType);
//
// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
//
// try{
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
// System.out.println("Decrypted Password: "+decryptedPassword);
// }catch(Exception e){
// System.out.println("ignoring exception during pwd decrypting");
// }
// req.addParam("keyword", "Thredds");
final GNSearchRequest req=new GNSearchRequest();
// req.addParam(GNSearchRequest.Param.any,"Thredds");
GNSearchResponse resp = reader.query(req);
int publicCount=resp.getCount();
reader.login(loginLevel);
int totalCount=reader.query(req).getCount();
//System.out.println("SCOPE "+scope+" ; found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
writeReport(count+"; "+scope+" ; "+gnEP+"; "+totalCount+" ; "+publicCount+"; "+(totalCount-publicCount));
if(totalCount==0)
return;
// try{
// int last = totalCount>MAX?totalCount:MAX;
// for(int i=0; i<last; i++){
// String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
// System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
// }
// }catch(Exception e ){
// e.printStackTrace();
// }
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(reportPrintWriter!=null)
reportPrintWriter.close();
if(errorPrintWriter!=null)
errorPrintWriter.close();
System.out.println("Performed fetching from "+count+" scopes");
System.out.println("FINISHED!!!");
}
}
private static void writeReport(String newline){
reportPrintWriter.println(newline);
}
private static void writeError(String newline){
errorPrintWriter.println(newline);
}
}

View File

@ -1,188 +0,0 @@
package gis;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class RuntimeResourceReader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 10, 2017
*/
public class RuntimeResourceReader {
// public static final String GEONETWORK_END_POINT =
// "http://geonetwork.d4science.org/geonetwork";
public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
// private List<String> scopes = new ArrayList<String>();
private List<ServiceEndpointBean> listSE = new ArrayList<ServiceEndpointBean>();
/**
* Instantiates a new runtime resource reader.
*
* @param scope the scope
* @param platformName the platform name
* @param endPoint the end point
* @throws Exception the exception
*/
public RuntimeResourceReader(String scope, String platformName, String category, String endPoint) throws Exception {
read(scope, platformName, category, endPoint);
}
/**
* Read.
*
* @param scope the scope
* @param platformName the platform name
* @param endPoint the end point
* @return the server parameters
* @throws Exception the exception
*/
private List<ServiceEndpointBean> read(String scope, String platformName, String category, String endPoint)
throws Exception {
String originalScope = null;
try {
originalScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(ServiceEndpoint.class);
if (platformName != null)
query.addCondition("$resource/Profile/Platform/Name/text() eq '" + platformName + "'");
if (category != null)
query.addCondition("$resource/Profile/Category/text() eq '" + category + "'");
if (endPoint != null && !endPoint.isEmpty())
query.addCondition("$resource/Profile/AccessPoint/Interface/Endpoint/text() eq '" + endPoint + "'");
// query.addVariable("$prop", "$resource/Profile/AccessPoint/Properties/Property")
// .addCondition("$prop/Name/text() eq 'priority'")
// .addCondition("$prop/Value/text() eq '1'");
logger.info("GeoRuntimeReader, using scope: " + scope + ", to get resource: " + platformName);
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> listServiceEndpoint = client.submit(query);
if (listServiceEndpoint == null || listServiceEndpoint.isEmpty())
throw new Exception("Cannot retrieve the runtime resource: " + platformName);
for (ServiceEndpoint serviceEndpoint : listServiceEndpoint) {
ServiceEndpointBean seb = new ServiceEndpointBean();
seb.setRuntime(serviceEndpoint.profile().runtime());
List<AccessPoint> listAp = new ArrayList<ServiceEndpoint.AccessPoint>();
try {
for (AccessPoint accessPoint : serviceEndpoint.profile().accessPoints()) {
listAp.add(accessPoint);
}
} catch (Exception e) {
System.err.println("Error on reading Access point not found");
}
seb.setListAP(listAp);
listSE.add(seb);
}
} catch (Exception e) {
logger.error("Sorry, an error occurred on reading parameters in Runtime Resources", e);
} finally {
if (originalScope != null && !originalScope.isEmpty()) {
ScopeProvider.instance.set(originalScope);
logger.info("scope provider setted to orginal scope: " + originalScope);
} else {
ScopeProvider.instance.reset();
logger.info("scope provider reset");
}
}
return listSE;
}
public List<ServiceEndpointBean> getListSE() {
return listSE;
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
// String scope = "/pred4s/preprod/preVRE";
// String scope = "/d4science.research-infrastructures.eu/D4OS/GNA";
// String scope = "/gcube/devsec/devVRE";
String scope = "/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps";
// String scope = "/d4science.research-infrastructures.eu/gCubeApps/Esquiline";
// String scope = "/d4science.research-infrastructures.eu/D4OS/ARIADNEplus_Project";
// String platformName = "geonetwork";
// String category = "Gis";
String platformName = "GeoServer";
String category = null;
// String platformName = "postgis";
// String category = "Database";
// String platformName = "postgres";
// String category = "Database";
// String platformName = "mongodb";
// String category = "Database";
// scope = "/pred4s/preprod/preVRE";
// scope = "/d4science.research-infrastructures.eu/D4OS/Blue-Cloud2026Project";
// platformName = "Zenodo";
// category = "Repository";
RuntimeResourceReader reader;
try {
ScopeProvider.instance.set(scope);
reader = new RuntimeResourceReader(scope, platformName, category, null);
for (ServiceEndpointBean seb : reader.getListSE()) {
System.out.println("Found: " + seb);
List<AccessPoint> listAp = seb.getListAP();
for (AccessPoint ap : listAp) {
System.out.println("username: " + ap.username());
System.out.println("password: " + ap.password());
try {
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
System.out.println("Decrypted Password: " + decryptedPassword);
} catch (Exception e) {
System.out.println("ignoring exception during pwd decrypting");
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -1,159 +0,0 @@
/**
*
*/
package gis;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import resources.GetAllInfrastructureScopes;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 10, 2017
*/
public class SE_Harvester_from_IS {
// GN CONFIGURATIONS
public static String rootScope = "/d4science.research-infrastructures.eu";
// static String rootScope = "/pred4s";
// static String rootScope = "/gcube";
public static final String platformName = "geoserver";
public static final String category = "Gis";
public static LoginLevel loginLevel = LoginLevel.ADMIN;
public static PrintWriter reportPrintWriter;
public static PrintWriter errorPrintWriter;
public static HashSet<String> uniqueGNs = new HashSet<String>();
public static void main(String[] args) {
try {
FileWriter reportWriter = new FileWriter(
rootScope.substring(1, rootScope.length()) + "_report_" + platformName + "_harvester.csv", true);
FileWriter errorWriter = new FileWriter(
rootScope.substring(1, rootScope.length()) + "_error_" + platformName + "_harvester.csv", true);
BufferedWriter reportBW = new BufferedWriter(reportWriter);
BufferedWriter errorBW = new BufferedWriter(errorWriter);
reportPrintWriter = new PrintWriter(reportBW);
reportPrintWriter.println("NB.; SCOPE; SE Hosted_On; SE AccessPoint;");
errorPrintWriter = new PrintWriter(errorBW);
errorPrintWriter.println("SCOPE;");
} catch (Exception e) {
e.printStackTrace();
}
// final Path destination = Paths.get("report_matching_gn_catalogue.csv");
// Files.w(re, destination);
List<String> listScopes = new ArrayList<String>();
// RuntimeResourceReader readerRR;
try {
// MODE-1
// readerRR = new RuntimeResourceReader(rootScope, platformName, null);
// System.out.println(readerRR.toString());
// System.out.println("Using GN: "+readerRR.getParameters());
// System.out.println("Scopes are: "+readerRR.getScopes().size());
// scopesProd.addAll(readerRR.getScopes());
// MODE-2
Map<String, String> mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope);
listScopes.addAll(mapScopes.values());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Read " + listScopes.size() + " VREs from root scope: " + rootScope);
int i = 0;
for (String vre : listScopes) {
System.out.println(++i + "; " + vre);
}
System.out.println("Scope found: " + listScopes.size());
try {
searchFor(listScopes, platformName, category);
searchFor(listScopes, "GeoServer", category);
System.out.println("\n\nUnique " + platformName + " addresses");
uniqueGNs.stream().forEach(s -> System.out.println(s));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reportPrintWriter != null)
reportPrintWriter.close();
if (errorPrintWriter != null)
errorPrintWriter.close();
System.out.println("Performed fetching from " + listScopes.size() + " scopes");
System.out.println("FINISHED!!!");
}
}
private static void searchFor(List<String> listScopes, String platformName, String category) {
int count = 0;
int writerCount = 0;
try {
for (String scope : listScopes) {
count++;
System.out.println("\n\n#" + count + " of " + listScopes.size() + " - Fetching scope: " + scope);
RuntimeResourceReader rrr = new RuntimeResourceReader(scope, platformName, category, null);
List<ServiceEndpointBean> listSE = rrr.getListSE();
for (ServiceEndpointBean seb : listSE) {
StringBuilder sb = new StringBuilder();
for (AccessPoint ap : seb.getListAP()) {
sb.append(ap.address());
sb.append(", ");
uniqueGNs.add(ap.address());
}
sb.toString();
writerCount++;
writeReport(
writerCount + "; " + scope + " ; " + seb.getRuntime().hostedOn() + "; " + sb.toString());
}
Thread.sleep(200);
// if(count==10)
// break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void writeReport(String newline) {
reportPrintWriter.println(newline);
}
private static void writeError(String newline) {
errorPrintWriter.println(newline);
}
}

View File

@ -1,60 +0,0 @@
package gis;
import java.io.Serializable;
import java.util.List;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
/**
* The Class ServerParameters.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 16, 2017
*/
public class ServiceEndpointBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 2459971193655529274L;
protected org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime;
protected List<AccessPoint> listAP;
public ServiceEndpointBean() {
// TODO Auto-generated constructor stub
}
public ServiceEndpointBean(org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime, List<AccessPoint> listAP) {
super();
this.runtime = runtime;
this.listAP = listAP;
}
public org.gcube.common.resources.gcore.ServiceEndpoint.Runtime getRuntime() {
return runtime;
}
public List<AccessPoint> getListAP() {
return listAP;
}
public void setRuntime(org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime2) {
this.runtime = runtime2;
}
public void setListAP(List<AccessPoint> listAP) {
this.listAP = listAP;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ServiceEndpoint [runtime=");
builder.append(runtime);
builder.append(", listAP=");
builder.append(listAP);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,24 +0,0 @@
package org.gcube.datatransfer.test;
import org.gcube.datatransfer.resolver.catalogue.resource.CatalogueStaticConfigurations;
public class CatalogueNameExtractor {
String[] CKANs = new String[] {
"https://ckan-grsf-admin2.d4science.org",
"https://ckan.pre.d4science.org/",
"https://ckan-aginfra.d4science.org",
"https://catalogue.d4science.org/",
"https://catalogue-imarine.d4science.org/" };
//@Test
public void extraCatalogueName() {
CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations();
for (int i = 0; i < CKANs.length; i++) {
System.out.println(CKANs[i]);
staticConf.buildRelativeURLToPublicCatalogueGateway(CKANs[i]);
System.out.println("\n\n");
}
}
}

View File

@ -1,54 +0,0 @@
package org.gcube.datatransfer.test;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
import org.gcube.datatransfer.resolver.services.CatalogueResolver;
/**
* The Class CatalogueResolverTest.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* May 13, 2019
*/
public class CatalogueResolverTest {
private static String entityName = "testing_bug_fix_21560_as_public";
private static String entityContext = "ctlg";
private static String vreName = "devVRE";
private static String rootContextScope = "/gcube/devsec/devVRE";
private static String authorizationToken = "";
// @Before
public void init() {
UriResolverSmartGearManagerInit.setRootContextScope(rootContextScope);
}
// @Test
public void testCatalogueResolver() {
ScopeProvider.instance.set(rootContextScope);
SecurityTokenProvider.instance.set(authorizationToken);
CatalogueResolver catalogRes = new CatalogueResolver();
catalogRes.resolveCatalogue(null, entityName, vreName, entityContext);
}
// @Test
public void testCatalogueLoadEndPoints() {
try {
// ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader
.loadCatalogueEndPoints();
System.out.println(ckanCatalogueReference.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,47 +0,0 @@
package org.gcube.datatransfer.test;
import java.util.concurrent.ExecutionException;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DetachedVREsTest {
public static Logger LOG = LoggerFactory.getLogger(DetachedVREsTest.class);
public static String TOKEN = "";
public static String detachedVREName = "BlueBridgeProject";
public static String rootScope = "/gcube";
//@Before
public void initCache() {
}
/**
* Storage hub test.
*
* @throws Exception the exception
*/
//@Test
public void testCacheOfDetachedVREs() throws Exception{
try {
ScopeProvider.instance.set(rootScope);
SecurityTokenProvider.instance.set(TOKEN);
//LoadingMapOfDetachedVRE cache = new LoadingMapOfDetachedVRE();
VRE theDetachedVRE = LoadingMapOfDetachedVRE.get(detachedVREName);
LOG.info("Detached VRE found {}", theDetachedVRE);
}catch (ExecutionException e) {
LOG.info("The Detached VRE for name {} not found",detachedVREName);
}catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,232 +0,0 @@
package org.gcube.datatransfer.test;
//import org.gcube.common.encryption.StringEncrypter;
//import org.gcube.common.scope.api.ScopeProvider;
//import org.gcube.spatial.data.geonetwork.GeoNetwork;
//import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
//import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
//import org.gcube.spatial.data.geonetwork.LoginLevel;
//import org.gcube.spatial.data.geonetwork.configuration.Configuration;
//import org.gcube.spatial.data.geonetwork.model.Account;
//import org.gcube.spatial.data.geonetwork.model.Account.Type;
//import org.opengis.metadata.Metadata;
//
//import it.geosolutions.geonetwork.util.GNSearchRequest;
//import it.geosolutions.geonetwork.util.GNSearchResponse;
//
///**
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// * Aug 31, 2016
// */
//public class GeonetworkQueryTest {
//
// private static final int MAX = 10;
//
// private static final String UUID = "8a878105-ef06-4b1f-843f-120fc525b22b";
//
// //private String[] scopesProd = {"/gcube/devsec/devVRE"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas"};
//
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon"};
// private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab"};
//
// private LoginLevel loginLevel = LoginLevel.CKAN;
//
// private Type accountType = Type.SCOPE;
//
// private String textToSearch = "geo_fea";
//
// //@Test
// public void getCount() throws Exception{
// try{
// for(String scope:scopesProd){
// ScopeProvider.instance.set(scope);
// GeoNetworkPublisher reader=GeoNetwork.get();
//
// Configuration config = reader.getConfiguration();
// Account account=config.getScopeConfiguration().getAccounts().get(accountType);
//
// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
//
// try{
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
// System.out.println("Decrypted Password: "+decryptedPassword);
// }catch(Exception e){
// System.out.println("ignoring exception during pwd decrypting");
// }
//
//
// // req.addParam("keyword", "Thredds");
// final GNSearchRequest req=new GNSearchRequest();
//// req.addParam(GNSearchRequest.Param.any,"Thredds");
// GNSearchResponse resp = reader.query(req);
// int publicCount=resp.getCount();
// reader.login(loginLevel);
// int totalCount=reader.query(req).getCount();
// System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
// if(totalCount==0)
// return;
// /*try{
// int last = totalCount>MAX?totalCount:MAX;
// for(int i=0; i<last; i++){
// String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
// System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
// }
// }catch(Exception e ){
// e.printStackTrace();
// }*/
//
// }
// }catch(Exception e){
// e.printStackTrace();
// }
// }
//
// //@Test
// public void getLayerByUUID() throws Exception{
// try{
// for(String scope:scopesProd){
// ScopeProvider.instance.set(scope);
// GeoNetworkPublisher reader=GeoNetwork.get();
//
// Configuration config = reader.getConfiguration();
// Account account=config.getScopeConfiguration().getAccounts().get(accountType);
//
// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
//
// Metadata meta = reader.getById(UUID);
//
//
// try{
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
// System.out.println("Decrypted Password: "+decryptedPassword);
// }catch(Exception e){
// System.out.println("ignoring exception during pwd decrypting");
// }
//
// System.out.println("SCOPE "+scope+" found meta "+meta);
//
// }
// }catch(Exception e){
// System.err.println("Error on getting layer by UUID: "+UUID);
// e.printStackTrace();
// }
// }
//
//
// //@Test
// public void getLayersBySearch() throws Exception{
// try{
// for(String scope:scopesProd){
// ScopeProvider.instance.set(scope);
// GeoNetworkPublisher reader=GeoNetwork.get();
//
// Configuration config = reader.getConfiguration();
// Account account=config.getScopeConfiguration().getAccounts().get(accountType);
//
// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
//
// try{
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
// System.out.println("Decrypted Password: "+decryptedPassword);
// }catch(Exception e){
// System.out.println("ignoring exception during pwd decrypting");
// }
//
//
// // req.addParam("keyword", "Thredds");
// //final GNSearchRequest req=new GNSearchRequest();
// final GNSearchRequest req = getRequest(true, textToSearch);
//// req.addParam(GNSearchRequest.Param.any,"Thredds");
// GNSearchResponse resp = reader.query(req);
// int publicCount=resp.getCount();
// reader.login(loginLevel);
// int totalCount=reader.query(req).getCount();
// System.out.println("QUERY "+textToSearch);
// System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
//
//// if(totalCount==0)
//// return;
//// try{
//// int last = totalCount>MAX?totalCount:MAX;
////
//// for(int i=0; i<last; i++){
//// //String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
//// GNMetadata xml = resp.getMetadata(i);
//// //System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
//// System.out.println(xml.toString());
//// }
//// }catch(Exception e ){
//// e.printStackTrace();
//// }
//
// }
// }catch(Exception e){
// e.printStackTrace();
// }
// }
//
//
// private boolean containsString(String txt, String value){
// return txt.contains(value);
// }
//
// /**
// * Gets the request.
// *
// * @param sortByTitle the sort by title
// * @param textToSearch the text to search
// * @return the request
// */
// public GNSearchRequest getRequest(boolean sortByTitle, String textToSearch) {
//
// GNSearchRequest req = new GNSearchRequest();
//
// if(sortByTitle)
// req.addConfig(GNSearchRequest.Config.sortBy, "title");
//
// if(textToSearch==null || textToSearch.isEmpty()){
// req.addParam(GNSearchRequest.Param.any, textToSearch);
// System.out.println("search by any text");
// }else{
// req.addParam(GNSearchRequest.Param.title, textToSearch);
// req.addConfig(GNSearchRequest.Config.similarity, "1");
// System.out.println("search by title");
// }
// System.out.println("text to search "+textToSearch);
//
// return req;
// }
//
//
//// @Test
// public void getCountProd() throws Exception{
// try{
// for(String scope:scopesProd){
// ScopeProvider.instance.set(scope);
// GeoNetworkReader reader=GeoNetwork.get();
// final GNSearchRequest req=new GNSearchRequest();
// // req.addParam("keyword", "Thredds");
//// req.addParam(GNSearchRequest.Param.any,"Oscar");
// int publicCount=reader.query(req).getCount();
// reader.login(loginLevel);
// int totalCount=reader.query(req).getCount();
// System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
// }
// }catch (Exception e) {
// e.printStackTrace();
// }
// }
//}

View File

@ -1,116 +0,0 @@
package org.gcube.datatransfer.test;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.Collection;
import java.util.List;
import org.apache.log4j.Logger;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.services.exceptions.NotFoundException;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
/**
* The Class ServiceEndpointReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jan 27, 2022
*/
public class ServiceEndpointReader {
private static final String RESOURCE_NAME = "DEV Geoserver";
private static final String CATEGORY_NAME = "Gis";
private static final String SCOPE = "/gcube/devsec/devVRE";
public static Logger LOG = Logger.getLogger(ServiceEndpointReader.class);
public static void main(String[] args) {
try {
readServiceEndpoint(SCOPE);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Read service endpoint.
*
* @param req the req
* @param scope the scope
* @throws Exception
*/
public static void readServiceEndpoint(String scope) throws Exception{
String callerScope = null;
try{
callerScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
LOG.info("Searching SE "+RESOURCE_NAME +" configurations in the scope: "+ScopeProvider.instance.get());
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '"+ RESOURCE_NAME +"'");
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY_NAME +"'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> toReturn = client.submit(query);
LOG.info("The query returned "+toReturn.size()+ " ServiceEndpoint/s");
if(toReturn.size()==0){
String errorMessage = String.format("Missing the RR with Name '%s' and Category '%s' in the scope '%s'. Please contact the support.",RESOURCE_NAME,CATEGORY_NAME,ScopeProvider.instance.get());
LOG.error(errorMessage);
throw new Exception(errorMessage);
}
String accessPointUsername = null;
String accessPointPwd = null;
ServiceEndpoint se = toReturn.get(0);
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
for (AccessPoint accessPoint : theAccessPoints) {
accessPointUsername = accessPoint.username();
System.out.println("AccessPoint username: "+accessPointPwd);
accessPointPwd = accessPoint.password();
if(accessPointUsername!=null && accessPointPwd!=null) {
LOG.info("returning the access point with name: "+accessPoint.name());
if (accessPointPwd != null) {
accessPointPwd = StringEncrypter.getEncrypter().decrypt(accessPointPwd);
LOG.info("Decrypted pwd registered into Access Point '" + accessPoint.name() + "' is: "
+ accessPointPwd+"...");
System.out.println("AccessPoint pwd is: "+accessPointPwd);
}
}
}
}catch(Exception e){
if(e instanceof NotFoundException)
throw e;
String errorMessage = "Error occurred on reading the "+RESOURCE_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
LOG.error(errorMessage, e);
throw new Exception(errorMessage);
}finally{
if(callerScope!=null){
LOG.info("Setting to the callerScope scope: "+callerScope);
ScopeProvider.instance.set(callerScope);
}else{
LOG.info("Reset scope");
ScopeProvider.instance.reset();
}
}
}
}

View File

@ -1,51 +0,0 @@
package org.gcube.datatransfer.test;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
/**
* The Class CatalogueResolverTest.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* May 13, 2019
*/
public class StorageHubTest {
private static String entityName = "using_e-infrastructures_for_biodiversity_conservation";
private static String entityContext = "ctlg";
private static String vreName = "BlueBridgeProject";
private String rootContextScope = "/d4science.research-infrastructures.eu";
private String authorizationToken = "";
//@Before
public void init() {
UriResolverSmartGearManagerInit.setRootContextScope(rootContextScope);
}
//@Test
public void testStreamDescriptorInfo() {
System.out.println("testStreamDescriptorInfo starts...");
ScopeProvider.instance.set(rootContextScope);
SecurityTokenProvider.instance.set(authorizationToken);
String storageHubId = "E_NGJIUEYvU09sNG1YY0R2VGIyaStWdGhDSW9sSjRNdDRkdVI2RHRGb1BZMVBaVFlzMG1mOU5QUEtFM1hQeE9kbw==";
try{
ItemManagerClient client = AbstractPlugin.item().build();
StreamDescriptor descriptor = client.resolvePublicLink(storageHubId);
System.out.println("Descriptor: "+descriptor);
}catch(Exception e){
e.printStackTrace();
}
}
}

Some files were not shown because too many files have changed in this diff Show More