Compare commits
27 Commits
|
@ -6,6 +6,12 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</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="test" value="true"/>
|
||||||
|
@ -13,13 +19,13 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="src/test/resources"/>
|
|
||||||
<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.nondependency" value=""/>
|
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="/home/francescomangiacrapa/config-work-isti/log4jconfiguration"/>
|
||||||
<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">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
encoding//src/main/java=UTF-8
|
encoding//src/main/java=UTF-8
|
||||||
encoding//src/test/java=UTF-8
|
encoding//src/test/java=UTF-8
|
||||||
|
encoding//src/test/resources=UTF-8
|
||||||
encoding/<project>=UTF-8
|
encoding/<project>=UTF-8
|
||||||
|
|
|
@ -6,6 +6,6 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
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.problem.reportPreviewFeatures=warning
|
||||||
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.8
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.8.0]
|
||||||
|
|
||||||
|
- Enhanced the Geoportal-Resolver. Supported share links to Geoportal Data-Entry app [#27160]
|
||||||
|
- Provided the new endpoint: GeoportalExporter [#27308]
|
||||||
|
|
||||||
|
## [v1.7.0]
|
||||||
|
|
||||||
|
- Integrated the new Geoportal-Resolver [#24842]
|
||||||
|
|
||||||
|
## [v1.6.0] - 2022-07-26
|
||||||
|
|
||||||
|
**New**
|
||||||
|
|
||||||
|
- [#23157] Enhanced to manage the CatalogueResolver with input query string
|
||||||
|
- Moved to gcube-bom.2.0.2
|
||||||
|
|
||||||
|
## [v1.5.0] - 2021-11-05
|
||||||
|
|
||||||
|
#### Enhancement
|
||||||
|
|
||||||
|
* [22385] Integrated with Catalogue Resolver and SHUB Resolver
|
||||||
|
|
||||||
|
## [v1.4.2] - 2021-04-21
|
||||||
|
|
||||||
|
#### Bug fixes
|
||||||
|
|
||||||
|
* [#21240] Generates broken gis-link
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.4.1] - 2020-05-06
|
||||||
|
|
||||||
|
* [Bug #19215] UriResolverManager: request to DL (the shortener) must be encoded
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.4.0] - 2019-11-26
|
||||||
|
|
||||||
|
* Migrated to git
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.3.0] - 2016-09-27
|
||||||
|
|
||||||
|
* [Bug #4941] Removed jumps of scope
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.2.0] - 2016-06-28
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.1.0] - 2016-06-24
|
||||||
|
|
||||||
|
* Removed maven-portal-bom as dependency
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.1.0] - 2015-05-04
|
||||||
|
|
||||||
|
* Updated to support several Access Point for each Resolver
|
||||||
|
|
||||||
|
* Introduced Entry Names in Uri-Resolver-Map
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.0.0] - 2014-10-13
|
||||||
|
|
||||||
|
* First Release
|
||||||
|
|
||||||
|
|
14
changelog.md
14
changelog.md
|
@ -1,14 +0,0 @@
|
||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
||||||
|
|
||||||
## [1-4-1] - 2020-05-06
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
**Fixes**
|
|
||||||
|
|
||||||
[#19215] UriResolverManager: request to DL (the shortener) must be encoded
|
|
||||||
|
|
||||||
|
|
22
pom.xml
22
pom.xml
|
@ -4,24 +4,24 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.2.0</version>
|
||||||
<relativePath />
|
<relativePath />
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>uri-resolver-manager</artifactId>
|
<artifactId>uri-resolver-manager</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>1.8.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>uri-resolver-manager</name>
|
<name>uri-resolver-manager</name>
|
||||||
<description>The URI Resolver Manager</description>
|
<description>The URI Resolver Manager</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>
|
||||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
<name>Francesco Mangiacrapa</name>
|
<name>Francesco Mangiacrapa</name>
|
||||||
|
@ -37,11 +37,9 @@
|
||||||
<properties>
|
<properties>
|
||||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||||
<!-- Convenience property to set the GWT version -->
|
|
||||||
<gwtVersion>2.5.1</gwtVersion>
|
|
||||||
<!-- GWT needs at least java 1.5 -->
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<gcube.bom>2.4.0</gcube.bom>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -49,7 +47,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-bom</artifactId>
|
<artifactId>gcube-bom</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>${gcube.bom}</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -101,13 +99,19 @@
|
||||||
<version>20090211</version>
|
<version>20090211</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- LOGGER -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>1.7.25</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- JUNIT -->
|
<!-- JUNIT -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|
|
@ -14,32 +14,23 @@ import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.exception.NotImplementedException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
|
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader;
|
import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.URLShortenerUtil;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil.URI_PART;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class UriResolverManager.
|
* The Class UriResolverManager.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Sep 6, 2016
|
||||||
* Sep 6, 2016
|
|
||||||
*/
|
*/
|
||||||
public class UriResolverManager {
|
public class UriResolverManager {
|
||||||
|
|
||||||
/**
|
|
||||||
* Time to reload Runtime Resource Configuration
|
|
||||||
*/
|
|
||||||
//public static int RESET_DELAY = 15*60*1000; //15 MINUTES
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Time to reload Runtime Resource Configuration
|
|
||||||
*/
|
|
||||||
//public static int RESET_TIME = RESET_DELAY; //15 MINUTES
|
|
||||||
|
|
||||||
private UriResolverMapReader uriResolverMapReader;
|
private UriResolverMapReader uriResolverMapReader;
|
||||||
private Map<String, Resolver> applicationTypes;
|
private Map<String, Resolver> applicationTypes;
|
||||||
private String applicationType;
|
private String applicationType;
|
||||||
|
@ -77,34 +68,36 @@ public class UriResolverManager {
|
||||||
return usingReader;
|
return usingReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Logger logger = LoggerFactory.getLogger(UriResolverManager.class);
|
public static final Logger LOG = LoggerFactory.getLogger(UriResolverManager.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new uri resolver manager.
|
* Instantiates a new uri resolver manager. Precondition: set the scope into
|
||||||
* Precondition: set the scope into ScopeProvider {@link ScopeProvider#get()}
|
* ScopeProvider {@link ScopeProvider#get()} The scope is used to look up the
|
||||||
* The scope is used to look up the generic resource with name: {@link UriResolverMapReader#URI_RESOLVER_MAP_RESOURCE_NAME}, secondary type: {@link UriResolverMapReader#URIRESOLVERMAP_SECONDARY_TYPE} from IS to map ApplicationType with its Resolver
|
* generic resource with name:
|
||||||
|
* {@link UriResolverMapReader#URI_RESOLVER_MAP_RESOURCE_NAME}, secondary type:
|
||||||
|
* {@link UriResolverMapReader#URIRESOLVERMAP_SECONDARY_TYPE} from IS to map
|
||||||
|
* ApplicationType with its Resolver
|
||||||
*
|
*
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
*/
|
*/
|
||||||
public UriResolverManager() throws UriResolverMapException, IllegalArgumentException{
|
public UriResolverManager() throws UriResolverMapException, IllegalArgumentException {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
logger.info("UriResolverManager is using scope: "+scope+", read from ScopeProvider");
|
LOG.info("UriResolverManager is using scope: " + scope + ", read from ScopeProvider");
|
||||||
|
|
||||||
if(scope == null)
|
if (scope == null)
|
||||||
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
||||||
|
|
||||||
this.uriResolverMapReader = new UriResolverMapReader();
|
this.uriResolverMapReader = new UriResolverMapReader();
|
||||||
this.applicationTypes = uriResolverMapReader.getApplicationTypes();
|
this.applicationTypes = uriResolverMapReader.getApplicationTypes();
|
||||||
//this.setTimerUriResolverReader(RESET_DELAY, RESET_TIME);
|
// this.setTimerUriResolverReader(RESET_DELAY, RESET_TIME);
|
||||||
} catch (UriResolverMapException e){
|
} catch (UriResolverMapException e) {
|
||||||
logger.error("UriResolverMapException: ",e);
|
LOG.error("UriResolverMapException: ", e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("UriResolverManager: ",e);
|
LOG.error("UriResolverManager: ", e);
|
||||||
throw new UriResolverMapException("Map Application Type - Resources not found in IS");
|
throw new UriResolverMapException("Map Application Type - Resources not found in IS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,40 +109,42 @@ public class UriResolverManager {
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
*/
|
*/
|
||||||
public void setApplicationType(String applicationType) throws IllegalArgumentException {
|
public void setApplicationType(String applicationType) throws IllegalArgumentException {
|
||||||
if(!this.applicationTypes.containsKey(applicationType)){
|
if (!this.applicationTypes.containsKey(applicationType)) {
|
||||||
throw new IllegalArgumentException("Application type '"+applicationType +"' not found in Application Types: "+getApplicationTypes());
|
throw new IllegalArgumentException("Application type '" + applicationType
|
||||||
|
+ "' not found in Application Types: " + getApplicationTypes());
|
||||||
|
|
||||||
}
|
}
|
||||||
this.applicationType = applicationType;
|
this.applicationType = applicationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance a UriResolverManager
|
* Instance a UriResolverManager Precondition: set the scope provider
|
||||||
* Precondition: set the scope provider {@link ScopeProvider.instance.get()}
|
* {@link ScopeProvider.instance.get()} The scope is used to look up the generic
|
||||||
* The scope is used to look up the generic resource {@link UriResolverMapReader#URI_RESOLVER_MAP} available in the infrastructure to map ApplicationType with its Resolver
|
* resource {@link UriResolverMapReader#URI_RESOLVER_MAP} available in the
|
||||||
|
* infrastructure to map ApplicationType with its Resolver
|
||||||
*
|
*
|
||||||
* @param applicationType a (valid) key Application Type {@link UriResolverManager#getApplicationTypes()}
|
* @param applicationType a (valid) key Application Type
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* {@link UriResolverManager#getApplicationTypes()}
|
||||||
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
*/
|
*/
|
||||||
public UriResolverManager(String applicationType) throws UriResolverMapException, IllegalArgumentException{
|
public UriResolverManager(String applicationType) throws UriResolverMapException, IllegalArgumentException {
|
||||||
this();
|
this();
|
||||||
setApplicationType(applicationType);
|
setApplicationType(applicationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the link.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
* @param applicationType the application type
|
* @param applicationType the application type
|
||||||
* @param parameters the map of the parameters sent as HTTP query string
|
* @param parameters the map of the parameters sent as HTTP query string
|
||||||
* @param shortLink if true the link is shorted otherwise none
|
* @param shortLink if true the link is shorted otherwise none
|
||||||
* @return the link
|
* @return the link
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
*/
|
*/
|
||||||
public String getLink(String applicationType, Map<String, String> parameters, boolean shortLink) throws IllegalArgumentException, UriResolverMapException{
|
public String getLink(String applicationType, Map<String, String> parameters, boolean shortLink)
|
||||||
|
throws IllegalArgumentException, UriResolverMapException {
|
||||||
this.applicationType = applicationType;
|
this.applicationType = applicationType;
|
||||||
return getLink(parameters, shortLink);
|
return getLink(parameters, shortLink);
|
||||||
}
|
}
|
||||||
|
@ -157,101 +152,132 @@ public class UriResolverManager {
|
||||||
/**
|
/**
|
||||||
* Gets the link.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
* @param parameters the map of the parameters sent as HTTP query string
|
* @param parameters the map of the parameters sent as HTTP query
|
||||||
* @param shortLink if true the link is shorted otherwise none
|
* string
|
||||||
|
* @param queryStringParameters the query string parameters
|
||||||
|
* @param shortLink if true the link is shortened otherwise none
|
||||||
* @return the link
|
* @return the link
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
*/
|
*/
|
||||||
public String getLink(Map<String, String> parameters, boolean shortLink) throws IllegalArgumentException, UriResolverMapException{
|
public String getLink(Map<String, String> parameters, boolean shortLink)
|
||||||
|
throws IllegalArgumentException, UriResolverMapException {
|
||||||
|
|
||||||
if(applicationType==null)
|
if (applicationType == null)
|
||||||
throw new IllegalArgumentException("Application type is null");
|
throw new IllegalArgumentException("Application type is null");
|
||||||
|
|
||||||
Resolver resolver = this.applicationTypes.get(applicationType);
|
Resolver resolver = this.applicationTypes.get(applicationType);
|
||||||
String link;
|
LOG.debug("The resolver found is of kind: "+ resolver.getClass().getSimpleName());
|
||||||
|
String link = null;
|
||||||
|
|
||||||
if(parameters==null)
|
if (parameters == null)
|
||||||
throw new IllegalArgumentException("Input Map parameters is null");
|
throw new IllegalArgumentException("Input Map parameters is null");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//lockReader();
|
// lockReader();
|
||||||
|
|
||||||
if(reader==null){
|
if (reader == null) {
|
||||||
logger.info("Runtime Resource Reader is null, istancing...");
|
LOG.info("Runtime Resource Reader is null, istancing...");
|
||||||
reader = new RuntimeResourceReader(resolver.getResourceName());
|
reader = new RuntimeResourceReader(resolver.getResourceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resolver.getEntryName()==null || resolver.getEntryName().isEmpty()){
|
if (resolver.getEntryName() == null || resolver.getEntryName().isEmpty()) {
|
||||||
logger.warn("The entryname to "+resolver.getResourceName() +" is null or empty, reading first Access Point!!");
|
LOG.warn("The entryname to " + resolver.getResourceName()
|
||||||
|
+ " is null or empty, reading first Access Point!!");
|
||||||
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
||||||
}else{
|
} else {
|
||||||
logger.warn("Reading Access Point for Entry Name: "+resolver.getEntryName());
|
LOG.warn("Reading Access Point for Entry Name: " + resolver.getEntryName());
|
||||||
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
||||||
if(serviceAccessPoint==null)
|
if (serviceAccessPoint == null)
|
||||||
throw new UriResolverMapException("Entry Name "+resolver.getEntryName() +" not found in Resource name: "+resolver.getResourceName());
|
throw new UriResolverMapException("Entry Name " + resolver.getEntryName()
|
||||||
|
+ " not found in Resource name: " + resolver.getResourceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ServiceParameter> resourceParameters = serviceAccessPoint.getServiceParameters();
|
List<ServiceParameter> resourceParameters = serviceAccessPoint.getServiceParameters();
|
||||||
|
LOG.debug("Service parameters are: " + resourceParameters);
|
||||||
//CHECK PARAMETERS
|
// CHECK PARAMETERS
|
||||||
for (ServiceParameter serviceParameter : resourceParameters) {
|
for (ServiceParameter serviceParameter : resourceParameters) {
|
||||||
if(serviceParameter.isMandatory()){
|
if (serviceParameter.isMandatory()) {
|
||||||
if(!parameters.containsKey(serviceParameter.getKey())){
|
if (!parameters.containsKey(serviceParameter.getKey())) {
|
||||||
throw new IllegalArgumentException("Mandatory service key (parameter) '"+serviceParameter.getKey() +"' not found into input map");
|
throw new IllegalArgumentException("Mandatory service key (parameter) '"
|
||||||
|
+ serviceParameter.getKey() + "' not found into input map");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String baseURI = serviceAccessPoint.getServiceUrl();
|
String baseURI = serviceAccessPoint.getServiceUrl();
|
||||||
|
|
||||||
//TO ENCODE THE WHOLE URL
|
|
||||||
// String queryString = UrlEncoderUtil.toQueryString(parameters);
|
|
||||||
// link = baseURI+"?"+queryString;
|
|
||||||
// logger.info("Created HTTP URI request (link): "+link);
|
|
||||||
// link = UrlEncoderUtil.encodeString(link);
|
|
||||||
// logger.info("Encoded it, like: "+link);
|
|
||||||
|
|
||||||
//Enconding only the query string
|
|
||||||
String queryString = UrlEncoderUtil.toQueryString(parameters);
|
|
||||||
String linkDecoded = String.format("%s?%s", baseURI,queryString);
|
|
||||||
String queryStringEncoded = UrlEncoderUtil.encodeString(queryString);
|
|
||||||
link = String.format("%s?%s", baseURI,queryStringEncoded);
|
|
||||||
logger.info("Created HTTP URI request (link): "+link);
|
|
||||||
|
|
||||||
if(shortLink){
|
// SPECIALIZED IMPLEMENTATION OF RESOLVER
|
||||||
try{
|
try {
|
||||||
logger.info("Shortner start..");
|
link = resolver.getLink(baseURI, parameters);
|
||||||
UrlShortener shortener = new UrlShortener();
|
LOG.debug("Read specialized getLink: " + link);
|
||||||
String shortedLink = shortener.shorten(link);
|
if (shortLink) {
|
||||||
logger.info("Shorted link is: "+shortedLink);
|
link = resolver.shortLink(link, parameters);
|
||||||
if(shortedLink!=null && shortedLink.equals(link)) {
|
}
|
||||||
//here the short link and the input link are identical
|
|
||||||
//so the shortening did not work
|
return link;
|
||||||
//I'm returning the decoded link because it is directly consumable via browser
|
} catch (NotImplementedException e) {
|
||||||
logger.debug("Shorted link is equal to input link, returning decoded link: "+linkDecoded);
|
LOG.info("Specialized getLink not implemented, going to default implementation");
|
||||||
link = linkDecoded;
|
}
|
||||||
}else {
|
|
||||||
//here the link is really shorted
|
// GENERIC IMPLEMENTATION OF RESOLVER. DEFAULT IMPLEMENTATION APPLYING...
|
||||||
logger.debug("The link is really shorted, returning it");
|
if (link == null) {
|
||||||
link = shortedLink;
|
// not shortening so returning the link with the query string with only the
|
||||||
|
// parameters encoded
|
||||||
|
LOG.info("Specialized getLink is null, applying DEFAULT implementation via GET request on base URI and encoded query-string");
|
||||||
|
String queryString = UrlEncoderUtil.encodeQuery(parameters);
|
||||||
|
link = String.format("%s?%s", baseURI, queryString);
|
||||||
|
// LOG.info("returning base URI with encoded parameters in the query string: " +
|
||||||
|
// linkEncoded);
|
||||||
|
// return toReturn;
|
||||||
|
} else {
|
||||||
|
LOG.info("Specialized getLink is not null");
|
||||||
|
}
|
||||||
|
|
||||||
|
String linkNotShort = link;
|
||||||
|
LOG.info("Created HTTP link: " + link);
|
||||||
|
// Short link required
|
||||||
|
if (shortLink) {
|
||||||
|
try {
|
||||||
|
LOG.info("Short link requested, so encoding query string is required...");
|
||||||
|
|
||||||
|
URI_PART uriParts = UrlEncoderUtil.getURIParts(link);
|
||||||
|
if (uriParts.getQueryString() != null && !uriParts.getQueryString().isEmpty()) {
|
||||||
|
LOG.info("QueryString part " + uriParts.getQueryString() + " is not null, encoding it");
|
||||||
|
String queryStringEncoded = UrlEncoderUtil.encodeString(uriParts.getQueryString());
|
||||||
|
link = String.format("%s?%s", uriParts.getBaseURI(), queryStringEncoded);
|
||||||
}
|
}
|
||||||
|
LOG.info("Encoded link is: " + link);
|
||||||
}catch(Exception e){
|
LOG.info("Shortner starts..");
|
||||||
logger.warn("An error occurred during link shortening: ",e);
|
String shortenedLink = URLShortenerUtil.shortTheLink(link);
|
||||||
//here I'm returning the decoded link in case of error on shortening it
|
if (shortenedLink != null && shortenedLink.equals(link)) {
|
||||||
link = linkDecoded;
|
// here the short link and the input link are identical
|
||||||
|
// so the shortening did not work
|
||||||
|
// I'm returning the decoded link because it is directly consumable via browser
|
||||||
|
LOG.info("Short link is equal to long link, returning long link: " + linkNotShort);
|
||||||
|
link = linkNotShort;
|
||||||
|
} else {
|
||||||
|
// here the link is really shortened
|
||||||
|
LOG.debug("The link is really short, returning it");
|
||||||
|
link = shortenedLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("An error occurred during link shortening: ", e);
|
||||||
|
// here I'm returning the decoded link in case of error on shortening it
|
||||||
|
link = linkNotShort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e) {
|
||||||
logger.error("Uri Resolver IllegalArgumentException: ", e);
|
LOG.error("Uri Resolver IllegalArgumentException: ", e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Uri Resolver Exception: ", e);
|
LOG.error("Uri Resolver Exception: ", e);
|
||||||
throw new UriResolverMapException("Uri Resolver error: " +e.getMessage());
|
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG.info("Returning HTTP(s) link: " + link);
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +286,7 @@ public class UriResolverManager {
|
||||||
*
|
*
|
||||||
* @return the Application Types available
|
* @return the Application Types available
|
||||||
*/
|
*/
|
||||||
public Set<String> getApplicationTypes(){
|
public Set<String> getApplicationTypes() {
|
||||||
return this.applicationTypes.keySet();
|
return this.applicationTypes.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,37 +296,40 @@ public class UriResolverManager {
|
||||||
* @param resolver the resolver
|
* @param resolver the resolver
|
||||||
* @return the list
|
* @return the list
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public List<ServiceParameter> discoveryServiceParameters(Resolver resolver) throws IllegalArgumentException, Exception{
|
public List<ServiceParameter> discoveryServiceParameters(Resolver resolver)
|
||||||
|
throws IllegalArgumentException, Exception {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
logger.info("SiscoveryServiceParameters is using scope: "+scope+", read from ScopeProvider");
|
LOG.info("DiscoveryServiceParameters is using scope: " + scope + ", read from ScopeProvider");
|
||||||
|
|
||||||
if(scope == null)
|
if (scope == null)
|
||||||
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
||||||
|
|
||||||
if(resolver == null)
|
if (resolver == null)
|
||||||
throw new IllegalArgumentException("Resolver is null, set Resolver");
|
throw new IllegalArgumentException("Resolver is null, set Resolver");
|
||||||
|
|
||||||
RuntimeResourceReader reader = new RuntimeResourceReader(resolver.getResourceName());
|
RuntimeResourceReader reader = new RuntimeResourceReader(resolver.getResourceName());
|
||||||
|
|
||||||
ServiceAccessPoint serviceAccessPoint = null;
|
ServiceAccessPoint serviceAccessPoint = null;
|
||||||
if(resolver.getEntryName()==null || resolver.getEntryName().isEmpty()){
|
if (resolver.getEntryName() == null || resolver.getEntryName().isEmpty()) {
|
||||||
logger.warn("The entryname to "+resolver.getResourceName() +" is null or empty, reading first Access Point!!");
|
LOG.warn("The entryname to " + resolver.getResourceName()
|
||||||
|
+ " is null or empty, reading first Access Point!!");
|
||||||
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
||||||
}else{
|
} else {
|
||||||
logger.info("Reading Access Point for entryname: "+resolver.getEntryName());
|
LOG.info("Reading Access Point for entryname: " + resolver.getEntryName());
|
||||||
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
||||||
if(serviceAccessPoint==null)
|
if (serviceAccessPoint == null)
|
||||||
throw new UriResolverMapException("Entry Name "+resolver.getEntryName() +" not found in Resource name: "+resolver.getResourceName());
|
throw new UriResolverMapException("Entry Name " + resolver.getEntryName()
|
||||||
|
+ " not found in Resource name: " + resolver.getResourceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return serviceAccessPoint.getServiceParameters();
|
return serviceAccessPoint.getServiceParameters();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Uri Resolver error: ", e);
|
LOG.error("Uri Resolver error: ", e);
|
||||||
throw new UriResolverMapException("Uri Resolver error: " +e.getMessage());
|
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +339,7 @@ public class UriResolverManager {
|
||||||
* @param applicationType the application type
|
* @param applicationType the application type
|
||||||
* @return the resolver
|
* @return the resolver
|
||||||
*/
|
*/
|
||||||
public Resolver getResolver(String applicationType){
|
public Resolver getResolver(String applicationType) {
|
||||||
return this.applicationTypes.get(applicationType);
|
return this.applicationTypes.get(applicationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,14 +348,14 @@ public class UriResolverManager {
|
||||||
*
|
*
|
||||||
* @return a map Application Type - Resolver
|
* @return a map Application Type - Resolver
|
||||||
*/
|
*/
|
||||||
public Map<String, Resolver> getCapabilities(){
|
public Map<String, Resolver> getCapabilities() {
|
||||||
return this.applicationTypes;
|
return this.applicationTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the timer uri resolver reader.
|
* Sets the timer uri resolver reader.
|
||||||
*
|
*
|
||||||
* @param delay the delay
|
* @param delay the delay
|
||||||
* @param period the period
|
* @param period the period
|
||||||
*/
|
*/
|
||||||
public void setTimerUriResolverReader(long delay, long period) {
|
public void setTimerUriResolverReader(long delay, long period) {
|
||||||
|
@ -338,45 +367,31 @@ public class UriResolverManager {
|
||||||
timer.schedule(new TimerTask() {
|
timer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.info("Timer Reset Runtime Resource running..");
|
LOG.info("Timer Reset Runtime Resource running..");
|
||||||
int counters = countReaders();
|
int counters = countReaders();
|
||||||
if(counters==0){
|
if (counters == 0) {
|
||||||
logger.info("Reader not locked, resetting");
|
LOG.info("Reader not locked, resetting");
|
||||||
reader = null;
|
reader = null;
|
||||||
}else
|
} else
|
||||||
logger.info("Reader locked, counters is/are:"+counters+", skipping");
|
LOG.info("Reader locked, counters is/are:" + counters + ", skipping");
|
||||||
|
|
||||||
}
|
}
|
||||||
}, delay, period);
|
}, delay, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel timer uri resolver reader.
|
* Cancel timer uri resolver reader.
|
||||||
*/
|
*/
|
||||||
public void cancelTimerUriResolverReader(){
|
public void cancelTimerUriResolverReader() {
|
||||||
if(timer!=null)
|
if (timer != null)
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalid uri resolver reader.
|
* Invalid uri resolver reader.
|
||||||
*/
|
*/
|
||||||
public void invalidUriResolverReader(){
|
public void invalidUriResolverReader() {
|
||||||
reader = null;
|
reader = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
UriResolverManager manager = new UriResolverManager();
|
|
||||||
System.out.println(manager.getCapabilities());
|
|
||||||
System.out.println(manager.getApplicationTypes());
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.exception.NotImplementedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class Resolver.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 4, 2015
|
||||||
|
*/
|
||||||
|
public class GenericResolver implements Resolver {
|
||||||
|
|
||||||
|
private String resourceName;
|
||||||
|
private String entryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new resolver.
|
||||||
|
*
|
||||||
|
* @param resourceName the resource name
|
||||||
|
* @param entryName the entry name
|
||||||
|
*/
|
||||||
|
public GenericResolver(String resourceName, String entryName) {
|
||||||
|
super();
|
||||||
|
this.resourceName = resourceName;
|
||||||
|
this.entryName = entryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the resource name.
|
||||||
|
*
|
||||||
|
* @return the resourceName
|
||||||
|
*/
|
||||||
|
public String getResourceName() {
|
||||||
|
return resourceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the entry name.
|
||||||
|
*
|
||||||
|
* @return the entryName
|
||||||
|
*/
|
||||||
|
public String getEntryName() {
|
||||||
|
return entryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the resource name.
|
||||||
|
*
|
||||||
|
* @param resourceName the resourceName to set
|
||||||
|
*/
|
||||||
|
public void setResourceName(String resourceName) {
|
||||||
|
this.resourceName = resourceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the entry name.
|
||||||
|
*
|
||||||
|
* @param entryName the entryName to set
|
||||||
|
*/
|
||||||
|
public void setEntryName(String entryName) {
|
||||||
|
this.entryName = entryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the link.
|
||||||
|
*
|
||||||
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
|
||||||
|
throw new NotImplementedException("getLink method not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short link.
|
||||||
|
*
|
||||||
|
* @param theLink the the link
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the string
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String shortLink(String theLink, Map<String, String> parameters) throws Exception {
|
||||||
|
throw new NotImplementedException("shortLink method not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("Resolver [resourceName=");
|
||||||
|
builder.append(resourceName);
|
||||||
|
builder.append(", entryName=");
|
||||||
|
builder.append(entryName);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,78 +1,63 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.portlets.user.uriresolvermanager.entity;
|
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Resolver.
|
* The Interface Resolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* May 4, 2015
|
*
|
||||||
|
* Nov 5, 2021
|
||||||
*/
|
*/
|
||||||
public class Resolver {
|
public interface Resolver {
|
||||||
|
|
||||||
private String resourceName;
|
//Code used to implement specific (so override) the method 'getLink' of the Resolver
|
||||||
private String entryName;
|
public static enum RESOLVER_ENTRYNAME {
|
||||||
|
CTLG("ctlg"), SMP("smp"), SHUB("shub"), GEO("geo"), GIS("gis");
|
||||||
/**
|
|
||||||
* Instantiates a new resolver.
|
String entryName;
|
||||||
*
|
|
||||||
* @param resourceName the resource name
|
RESOLVER_ENTRYNAME(String entryName) {
|
||||||
* @param entryName the entry name
|
this.entryName = entryName;
|
||||||
*/
|
}
|
||||||
public Resolver(String resourceName, String entryName) {
|
|
||||||
super();
|
public String getEntryName() {
|
||||||
this.resourceName = resourceName;
|
return entryName;
|
||||||
this.entryName = entryName;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the resource name.
|
* Gets the resource name.
|
||||||
*
|
*
|
||||||
* @return the resourceName
|
* @return the resource name
|
||||||
*/
|
*/
|
||||||
public String getResourceName() {
|
public String getResourceName();
|
||||||
return resourceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the entry name.
|
* Gets the entry name.
|
||||||
*
|
*
|
||||||
* @return the entryName
|
* @return the entry name
|
||||||
*/
|
*/
|
||||||
public String getEntryName() {
|
public String getEntryName();
|
||||||
return entryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the resource name.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
* @param resourceName the resourceName to set
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public void setResourceName(String resourceName) {
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception;
|
||||||
this.resourceName = resourceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the entry name.
|
* Short link.
|
||||||
*
|
*
|
||||||
* @param entryName the entryName to set
|
* @param theLink the the link
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the string
|
||||||
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public void setEntryName(String entryName) {
|
public String shortLink(String theLink, Map<String, String> parameters) throws Exception;
|
||||||
this.entryName = entryName;
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Object#toString()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("Resolver [resourceName=");
|
|
||||||
builder.append(resourceName);
|
|
||||||
builder.append(", entryName=");
|
|
||||||
builder.append(entryName);
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class NotImplementedException.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Nov 5, 2021
|
||||||
|
*/
|
||||||
|
public class NotImplementedException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -7350078577553202213L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new not implemented exception.
|
||||||
|
*/
|
||||||
|
public NotImplementedException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new not implemented exception.
|
||||||
|
*
|
||||||
|
* @param message the message
|
||||||
|
*/
|
||||||
|
public NotImplementedException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.geoportal;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.URLShortenerUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeoportalExporterAPI.
|
||||||
|
*
|
||||||
|
* The endpoints provided by GeoportalExporter service in the URI-Resolver
|
||||||
|
* service
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 23, 2024
|
||||||
|
*/
|
||||||
|
public class GeoportalExporterAPI {
|
||||||
|
|
||||||
|
private GeoportalExporterEndpoint endpoint;
|
||||||
|
private ServiceAccessPoint serviceAccessPoint;
|
||||||
|
|
||||||
|
private final String QUERY_PARAMETER_AS_URL = "as-url";
|
||||||
|
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(GeoportalExporterAPI.class);
|
||||||
|
|
||||||
|
public static String DEFAULT_TYPE = "pdf";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geoportal exporter API.
|
||||||
|
*
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public GeoportalExporterAPI() throws Exception {
|
||||||
|
this.endpoint = new GeoportalExporterEndpoint();
|
||||||
|
this.serviceAccessPoint = this.endpoint.getServiceAccessPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export project.
|
||||||
|
*
|
||||||
|
* @param type the type
|
||||||
|
* @param ucdID the ucd ID
|
||||||
|
* @param projectID the project ID
|
||||||
|
* @param asDirectURLToPDFFile the as direct URL to PDF file
|
||||||
|
* @return the url
|
||||||
|
* @throws MalformedURLException the malformed URL exception
|
||||||
|
*/
|
||||||
|
public URL exportProject(String type, String ucdID, String projectID, boolean asDirectURLToPDFFile)
|
||||||
|
throws MalformedURLException {
|
||||||
|
if (type == null || type.isEmpty())
|
||||||
|
type = DEFAULT_TYPE;
|
||||||
|
|
||||||
|
String api = String.format("%s/export/%s/%s/%s", serviceAccessPoint.getServiceUrl(), type, ucdID, projectID);
|
||||||
|
if (asDirectURLToPDFFile)
|
||||||
|
api += "?" + QUERY_PARAMETER_AS_URL + "=" + asDirectURLToPDFFile;
|
||||||
|
|
||||||
|
LOG.info("returning exportProject API: " + api);
|
||||||
|
return new URL(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export project.
|
||||||
|
*
|
||||||
|
* @param type the type
|
||||||
|
* @param ucdID the ucd ID
|
||||||
|
* @param projectID the project ID
|
||||||
|
* @param asDirectURLToPDFFile the as direct URL to PDF file
|
||||||
|
* @param shortLink the short link
|
||||||
|
* @return the string
|
||||||
|
* @throws MalformedURLException the malformed URL exception
|
||||||
|
*/
|
||||||
|
public String exportProject(String type, String ucdID, String projectID, boolean asDirectURLToPDFFile,
|
||||||
|
boolean shortLink) throws MalformedURLException {
|
||||||
|
URL theURL = exportProject(type, ucdID, projectID, asDirectURLToPDFFile);
|
||||||
|
|
||||||
|
String theShortLink = null;
|
||||||
|
if (theURL != null) {
|
||||||
|
theShortLink = URLShortenerUtil.shortTheLink(theURL.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return theShortLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View job.
|
||||||
|
*
|
||||||
|
* @param jobCode the job code
|
||||||
|
* @return the url
|
||||||
|
* @throws MalformedURLException the malformed URL exception
|
||||||
|
*/
|
||||||
|
public URL viewJob(String jobCode) throws MalformedURLException {
|
||||||
|
String api = String.format("%s/view/%s", serviceAccessPoint.getServiceUrl(), jobCode);
|
||||||
|
LOG.info("returning viewJob API: " + api);
|
||||||
|
return new URL(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Healthcheck.
|
||||||
|
*
|
||||||
|
* @param type the type
|
||||||
|
* @return the url
|
||||||
|
* @throws MalformedURLException the malformed URL exception
|
||||||
|
*/
|
||||||
|
public URL healthcheck(String type) throws MalformedURLException {
|
||||||
|
if (type == null || type.isEmpty())
|
||||||
|
type = DEFAULT_TYPE;
|
||||||
|
String api = String.format("%s/export/%s/healthcheck", serviceAccessPoint.getServiceUrl(), type);
|
||||||
|
LOG.info("returning healthcheck API: " + api);
|
||||||
|
return new URL(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.geoportal;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
|
||||||
|
|
||||||
|
public class GeoportalExporterEndpoint {
|
||||||
|
|
||||||
|
public final String URI_RESOLVER_RESOURCE_NAME = "HTTP-URI-Resolver";
|
||||||
|
public final String ENTRY_POINT_NAME = "geoportal_exp";
|
||||||
|
|
||||||
|
|
||||||
|
public GeoportalExporterEndpoint() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceAccessPoint getServiceAccessPoint()throws Exception {
|
||||||
|
RuntimeResourceReader runtimeRR = new RuntimeResourceReader(URI_RESOLVER_RESOURCE_NAME);
|
||||||
|
return runtimeRR.getServiceAccessPointForEntryName(ENTRY_POINT_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,12 +22,10 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class RuntimeResourceReader.
|
* The Class RuntimeResourceReader.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Apr 30, 2015
|
||||||
* Apr 30, 2015
|
|
||||||
*/
|
*/
|
||||||
public class RuntimeResourceReader {
|
public class RuntimeResourceReader {
|
||||||
|
|
||||||
|
@ -39,7 +37,6 @@ public class RuntimeResourceReader {
|
||||||
|
|
||||||
private String entryName;
|
private String entryName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new runtime resource reader.
|
* Instantiates a new runtime resource reader.
|
||||||
*
|
*
|
||||||
|
@ -54,74 +51,77 @@ public class RuntimeResourceReader {
|
||||||
/**
|
/**
|
||||||
* Read resource.
|
* Read resource.
|
||||||
*
|
*
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
* @param resourceName the resource name
|
* @param resourceName the resource name
|
||||||
* @return the application URI
|
* @return the application URI
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
private void readResource(String resourceName) throws Exception {
|
private void readResource(String resourceName) throws Exception {
|
||||||
|
|
||||||
try{
|
try {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
logger.info("Tentative read resource: "+resourceName+", scope: "+scope);
|
logger.info("Trying to read resource: " + resourceName + ", in the scope: " + scope);
|
||||||
|
|
||||||
this.resourceName = resourceName;
|
this.resourceName = resourceName;
|
||||||
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
|
query.addCondition("$resource/Profile/Name/string() eq '" + resourceName + "'");
|
||||||
|
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
List<ServiceEndpoint> r = client.submit(query);
|
List<ServiceEndpoint> r = client.submit(query);
|
||||||
if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource with name: "+resourceName +" in the scope: "+scope);
|
if (r == null || r.isEmpty())
|
||||||
|
throw new Exception(
|
||||||
|
"Cannot retrieve the runtime resource with name: " + resourceName + " in the scope: " + scope);
|
||||||
|
|
||||||
ServiceEndpoint se = r.get(0);
|
ServiceEndpoint se = r.get(0);
|
||||||
if(se.profile()==null){
|
if (se.profile() == null) {
|
||||||
String msg = "Runtime reosource with resource name: "+resourceName +" is null in the scope: "+scope;
|
String msg = "Runtime reosource with resource name: " + resourceName + " is null in the scope: "
|
||||||
|
+ scope;
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
throw new Exception(msg);
|
throw new Exception(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
Group<AccessPoint> accessPoints = se.profile().accessPoints();
|
Group<AccessPoint> accessPoints = se.profile().accessPoints();
|
||||||
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
|
if (accessPoints.size() == 0)
|
||||||
|
throw new Exception("Accesspoint in resource " + resourceName + " not found");
|
||||||
|
|
||||||
Iterator<AccessPoint> acIt = accessPoints.iterator();
|
Iterator<AccessPoint> acIt = accessPoints.iterator();
|
||||||
serviceAccessPoints = new ArrayList<ServiceAccessPoint>(accessPoints.size());
|
serviceAccessPoints = new ArrayList<ServiceAccessPoint>(accessPoints.size());
|
||||||
|
|
||||||
while(acIt.hasNext()){
|
while (acIt.hasNext()) {
|
||||||
|
|
||||||
AccessPoint ap = acIt.next();
|
AccessPoint ap = acIt.next();
|
||||||
|
|
||||||
Group<Property> properties = ap.properties();
|
Group<Property> properties = ap.properties();
|
||||||
|
|
||||||
if(properties.size()==0){
|
if (properties.size() == 0) {
|
||||||
logger.warn("Properties in resource "+resourceName+" not found");
|
logger.warn("Properties in resource " + resourceName + " not found for ap: "+ap.name());
|
||||||
}else{
|
serviceAccessPoints.add(new ServiceAccessPoint(ap.name(), ap.address(), null));
|
||||||
|
} else {
|
||||||
|
|
||||||
List<ServiceParameter> serviceParameters = new ArrayList<ServiceParameter>(properties.size());
|
List<ServiceParameter> serviceParameters = new ArrayList<ServiceParameter>(properties.size());
|
||||||
|
|
||||||
Iterator<Property> iter = properties.iterator();
|
Iterator<Property> iter = properties.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
|
|
||||||
Property prop = iter.next();
|
Property prop = iter.next();
|
||||||
|
|
||||||
serviceParameters.add(new ServiceParameter(prop.value(), true));
|
serviceParameters.add(new ServiceParameter(prop.value(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceAccessPoints.add(new ServiceAccessPoint(ap.name(), ap.address(), serviceParameters));
|
serviceAccessPoints.add(new ServiceAccessPoint(ap.name(), ap.address(), serviceParameters));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// parameters.setUser(ap.username()); //username
|
|
||||||
//
|
|
||||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
|
||||||
//
|
|
||||||
// parameters.setPassword(decryptedPassword); //password
|
|
||||||
// Group<Property> properties = ap.properties();
|
|
||||||
|
|
||||||
}catch (Exception e) {
|
}
|
||||||
logger.error("Sorry, an error occurred on reading the resource "+resourceName+ " Runtime Resource",e);
|
logger.debug("Found properties: " + serviceAccessPoints);
|
||||||
throw new Exception("Sorry, an error occurred on reading the resource "+resourceName+ " Runtime Reosurce");
|
// parameters.setUser(ap.username()); //username
|
||||||
|
// String decryptedPassword =
|
||||||
|
// StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||||
|
// parameters.setPassword(decryptedPassword); //password
|
||||||
|
// Group<Property> properties = ap.properties();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Sorry, an error occurred on reading the resource " + resourceName + " Runtime Resource", e);
|
||||||
|
throw new Exception(
|
||||||
|
"Sorry, an error occurred on reading the resource " + resourceName + " Runtime Reosurce");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +131,10 @@ public class RuntimeResourceReader {
|
||||||
* @param entryName the entry name
|
* @param entryName the entry name
|
||||||
* @return the service access point for entry name
|
* @return the service access point for entry name
|
||||||
*/
|
*/
|
||||||
public ServiceAccessPoint getServiceAccessPointForEntryName(String entryName){
|
public ServiceAccessPoint getServiceAccessPointForEntryName(String entryName) {
|
||||||
|
|
||||||
for (ServiceAccessPoint serviceAccessPoint : serviceAccessPoints) {
|
for (ServiceAccessPoint serviceAccessPoint : serviceAccessPoints) {
|
||||||
if(serviceAccessPoint.getEntryName().equals(entryName))
|
if (serviceAccessPoint.getEntryName().equals(entryName))
|
||||||
return serviceAccessPoint;
|
return serviceAccessPoint;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -167,7 +167,9 @@ public class RuntimeResourceReader {
|
||||||
return serviceAccessPoints;
|
return serviceAccessPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -184,8 +186,6 @@ public class RuntimeResourceReader {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
// try {
|
// try {
|
||||||
// RuntimeResourceReader rr = new RuntimeResourceReader("/gcube", "Gis-Resolver");
|
// RuntimeResourceReader rr = new RuntimeResourceReader("/gcube", "Gis-Resolver");
|
||||||
|
|
|
@ -12,7 +12,11 @@ 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.portlets.user.uriresolvermanager.entity.GenericResolver;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.CatalogueResolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.GeoportalResolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.SHUBResolver;
|
||||||
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;
|
||||||
|
@ -21,12 +25,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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class UriResolverMapReader.
|
* The Class UriResolverMapReader.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 4, 2015
|
||||||
* May 4, 2015
|
|
||||||
*/
|
*/
|
||||||
public class UriResolverMapReader {
|
public class UriResolverMapReader {
|
||||||
|
|
||||||
|
@ -36,14 +38,14 @@ public class UriResolverMapReader {
|
||||||
public static final String URIRESOLVERMAP_SECONDARY_TYPE = "UriResolverMap";
|
public static final String URIRESOLVERMAP_SECONDARY_TYPE = "UriResolverMap";
|
||||||
public static final String URI_RESOLVER_MAP_RESOURCE_NAME = "Uri-Resolver-Map";
|
public static final String URI_RESOLVER_MAP_RESOURCE_NAME = "Uri-Resolver-Map";
|
||||||
|
|
||||||
// private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
|
// private Logger LOG = LoggerFactory.getLogger(UriResolverMapReader.class);
|
||||||
//TODO TEMP SOLUTION IN ORDER TO PRINT USING ALSO LOG4J INTO GEOEXPLORER PORTLET
|
// TODO TEMP SOLUTION IN ORDER TO PRINT USING ALSO LOG4J INTO GEOEXPLORER
|
||||||
|
// PORTLET
|
||||||
private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
|
private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
|
||||||
private String secondaryType;
|
private String secondaryType;
|
||||||
private String scope;
|
private String scope;
|
||||||
private String resourceName;
|
private String resourceName;
|
||||||
private Map<String, Resolver> applicationTypes; //A map ApplicationType - Resolver
|
private Map<String, Resolver> applicationTypes; // A map ApplicationType - Resolver
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new uri resolver map reader.
|
* Instantiates a new uri resolver map reader.
|
||||||
|
@ -57,67 +59,87 @@ public class UriResolverMapReader {
|
||||||
readProfileFromInfrastrucure();
|
readProfileFromInfrastrucure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method looks up the generic resource among the ones available in the infrastructure using scope provider {@link ScopeProvider.instance.get()}
|
* this method looks up the generic resource among the ones available in the
|
||||||
* resource name {@value #URI_RESOLVER_MAP_RESOURCE_NAME} and secondaryType {@value #URIRESOLVERMAP_SECONDARY_TYPE}
|
* infrastructure using scope provider {@link ScopeProvider.instance.get()}
|
||||||
|
* resource name {@value #URI_RESOLVER_MAP_RESOURCE_NAME} and secondaryType
|
||||||
|
* {@value #URIRESOLVERMAP_SECONDARY_TYPE}
|
||||||
*
|
*
|
||||||
* @return the applicationProfile profile
|
* @return the applicationProfile profile
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
private void readProfileFromInfrastrucure() throws Exception {
|
private void readProfileFromInfrastrucure() throws Exception {
|
||||||
|
|
||||||
String queryString = getGcubeGenericQueryString(secondaryType, resourceName);
|
String queryString = getGcubeGenericQueryString(secondaryType, resourceName);
|
||||||
|
|
||||||
logger.info("Trying to fetch in the scope: "+ScopeProvider.instance.get()+" the Generic Resouce with name: "+resourceName + " secondary type: "+secondaryType);
|
logger.info("Trying to fetch in the scope: " + ScopeProvider.instance.get() + " the Generic Resouce with name: "
|
||||||
logger.info(queryString);
|
+ resourceName + " secondary type: " + secondaryType);
|
||||||
try {
|
logger.info(queryString);
|
||||||
|
try {
|
||||||
|
|
||||||
Query q = new QueryBox(queryString);
|
Query q = new QueryBox(queryString);
|
||||||
logger.debug("new query box works");
|
logger.debug("new query box works");
|
||||||
|
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
logger.info("submitting query is: "+queryString);
|
logger.info("submitting query is: " + queryString);
|
||||||
List<String> appUriResolverMap = client.submit(q);
|
List<String> appUriResolverMap = client.submit(q);
|
||||||
logger.debug("submit query works");
|
logger.debug("submit query works");
|
||||||
|
|
||||||
if (appUriResolverMap == null || appUriResolverMap.size() == 0){
|
if (appUriResolverMap == null || appUriResolverMap.size() == 0) {
|
||||||
logger.error("ApplicationProfile with secondaryType: "+secondaryType+" and name: "+resourceName+" is not registered in the infrastructure, scope: "+ScopeProvider.instance.get());
|
logger.error("ApplicationProfile with secondaryType: " + secondaryType + " and name: " + resourceName
|
||||||
throw new ApplicationProfileException("ApplicationProfile with secondaryType: "+secondaryType+" and name: "+resourceName+" is not registered in the scope: "+ScopeProvider.instance.get());
|
+ " is not registered in the infrastructure, scope: " + ScopeProvider.instance.get());
|
||||||
}else {
|
throw new ApplicationProfileException(
|
||||||
logger.info("Building map applications type - resource");
|
"ApplicationProfile with secondaryType: " + secondaryType + " and name: " + resourceName
|
||||||
logger.debug("Building new DocumentBuilder..");
|
+ " is not registered in the scope: " + ScopeProvider.instance.get());
|
||||||
String elem = appUriResolverMap.get(0);
|
} else {
|
||||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
logger.info("Building map applications type - resource");
|
||||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
logger.debug("Building new DocumentBuilder..");
|
||||||
logger.debug("Building new XPathHelper..");
|
String elem = appUriResolverMap.get(0);
|
||||||
XPathHelper helper = new XPathHelper(node);
|
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
List<String> currValue = null;
|
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||||
logger.debug("Evaluating XPath..");
|
logger.debug("Building new XPathHelper..");
|
||||||
currValue = helper.evaluate("/Resource/Profile/Body/access_point/application_type/text()");
|
XPathHelper helper = new XPathHelper(node);
|
||||||
if (currValue != null && currValue.size() > 0) {
|
List<String> currValue = null;
|
||||||
logger.info("Application Types are: "+currValue.size());
|
logger.debug("Evaluating XPath..");
|
||||||
applicationTypes = new HashMap<String, Resolver>(currValue.size());
|
currValue = helper.evaluate("/Resource/Profile/Body/access_point/application_type/text()");
|
||||||
|
if (currValue != null && currValue.size() > 0) {
|
||||||
|
logger.info("Application Types are: " + currValue.size());
|
||||||
|
applicationTypes = new HashMap<String, Resolver>(currValue.size());
|
||||||
// List<String> appTypes = currValue;
|
// List<String> appTypes = currValue;
|
||||||
//FOR EACH APPLICATION TYPE
|
// FOR EACH APPLICATION TYPE
|
||||||
for (String at : currValue) {
|
for (String at : currValue) {
|
||||||
logger.info("Application Type "+at);
|
logger.info("Application Type " + at);
|
||||||
// currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
// currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
||||||
List<String> resources = helper.evaluate("/Resource/Profile/Body/access_point[application_type='"+at+"']/resource/text()");
|
List<String> resources = helper.evaluate(
|
||||||
List<String> entryNames = helper.evaluate("/Resource/Profile/Body/access_point[application_type='"+at+"']/entryname/text()");
|
"/Resource/Profile/Body/access_point[application_type='" + at + "']/resource/text()");
|
||||||
if(resources!=null && resources.size()>0){
|
List<String> entryNames = helper.evaluate(
|
||||||
Resolver resolver = new Resolver(resources.get(0), entryNames.get(0));
|
"/Resource/Profile/Body/access_point[application_type='" + at + "']/entryname/text()");
|
||||||
applicationTypes.put(at, resolver);
|
if (resources != null && resources.size() > 0) {
|
||||||
logger.info("Stored: "+at +" -> Resolver: "+ resolver);
|
String resoureName = resources.get(0);
|
||||||
}else
|
String entryName = entryNames.get(0);
|
||||||
logger.warn("Skipping Type "+at+" mapping to runtime resource not found!");
|
Resolver resolver;
|
||||||
}
|
if (entryName.equalsIgnoreCase(Resolver.RESOLVER_ENTRYNAME.CTLG.getEntryName())) {
|
||||||
|
resolver = new CatalogueResolver(resoureName, entryName);
|
||||||
|
} else if (entryName.equalsIgnoreCase(Resolver.RESOLVER_ENTRYNAME.SHUB.getEntryName())) {
|
||||||
|
resolver = new SHUBResolver(resoureName, entryName);
|
||||||
|
} else if (entryName.equalsIgnoreCase(Resolver.RESOLVER_ENTRYNAME.GEO.getEntryName())) {
|
||||||
|
resolver = new GeoportalResolver(resoureName, entryName);
|
||||||
|
} else {
|
||||||
|
resolver = new GenericResolver(resoureName, entryName);
|
||||||
|
}
|
||||||
|
applicationTypes.put(at, resolver);
|
||||||
|
logger.info("Stored: " + at + " -> Resolver: " + resolver);
|
||||||
|
} else
|
||||||
|
logger.warn("Skipping Type " + at + " mapping to runtime resource not found!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error while trying to fetch Generic Resource with secondaryType: "+secondaryType+" and name "+resourceName+" from the infrastructure", e);
|
logger.error("Error while trying to fetch Generic Resource with secondaryType: " + secondaryType
|
||||||
throw new ApplicationProfileException("Error while trying to fetch Generic Resourc with secondaryType: "+secondaryType+" and name "+resourceName+" from the infrastructure");
|
+ " and name " + resourceName + " from the infrastructure", e);
|
||||||
|
throw new ApplicationProfileException("Error while trying to fetch Generic Resourc with secondaryType: "
|
||||||
|
+ secondaryType + " and name " + resourceName + " from the infrastructure");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -126,15 +148,14 @@ public class UriResolverMapReader {
|
||||||
* Gets the gcube generic query string.
|
* Gets the gcube generic query string.
|
||||||
*
|
*
|
||||||
* @param secondaryType the secondary type
|
* @param secondaryType the secondary type
|
||||||
* @param name the name
|
* @param name the name
|
||||||
* @return the gcube generic query string
|
* @return the gcube generic query string
|
||||||
*/
|
*/
|
||||||
public static String getGcubeGenericQueryString(String secondaryType, String name){
|
public static String getGcubeGenericQueryString(String secondaryType, String name) {
|
||||||
|
|
||||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
return "for $profile in collection('/db/Profiles/GenericResource')//Resource "
|
||||||
"where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' and $profile/Profile/Name/string() " +
|
+ "where $profile/Profile/SecondaryType/string() eq '" + secondaryType
|
||||||
" eq '" + name + "'" +
|
+ "' and $profile/Profile/Name/string() " + " eq '" + name + "'" + "return $profile";
|
||||||
"return $profile";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +177,6 @@ public class UriResolverMapReader {
|
||||||
return secondaryType;
|
return secondaryType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the scope.
|
* Gets the scope.
|
||||||
*
|
*
|
||||||
|
@ -175,7 +195,9 @@ public class UriResolverMapReader {
|
||||||
return resourceName;
|
return resourceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,183 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.URLShortenerUtil;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class CatalogueResolver.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 4, 2024
|
||||||
|
*/
|
||||||
|
public class CatalogueResolver extends GenericResolver {
|
||||||
|
|
||||||
|
private static final int _60SEC = 60000;
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolver.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new catalogue resolver wrapper.
|
||||||
|
*
|
||||||
|
* @param resourceName the resource name
|
||||||
|
* @param entryName the entry name
|
||||||
|
*/
|
||||||
|
public CatalogueResolver(String resourceName, String entryName) {
|
||||||
|
super(resourceName, entryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the link.
|
||||||
|
*
|
||||||
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
|
||||||
|
LOG.debug("called getLink: " + baseURI + " parameters: " + parameters);
|
||||||
|
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
String theResponse = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
URL urlObj = new URL(baseURI);
|
||||||
|
con = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
|
// con.setRequestProperty("Accept", "application/json");
|
||||||
|
|
||||||
|
con.setDoOutput(true);
|
||||||
|
con.setReadTimeout(_60SEC);
|
||||||
|
con.setConnectTimeout(_60SEC);
|
||||||
|
|
||||||
|
JSONObject jObj = new org.json.JSONObject();
|
||||||
|
for (String key : parameters.keySet()) {
|
||||||
|
jObj.put(key, parameters.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (queryStringParameters != null) {
|
||||||
|
// String queryString = UrlEncoderUtil.toQueryString(queryStringParameters);
|
||||||
|
// jObj.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
||||||
|
// }
|
||||||
|
|
||||||
|
String toJSON = jObj.toString();
|
||||||
|
LOG.info("Submitting JSON: " + toJSON);
|
||||||
|
Integer code = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
OutputStream os = con.getOutputStream();
|
||||||
|
os.write(toJSON.getBytes("UTF-8"));
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
code = con.getResponseCode();
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
|
||||||
|
if (!((200 <= code) && (code <= 208))) {
|
||||||
|
throw new Exception(CatalogueResolver.class.getSimpleName()+" returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
LOG.error(CatalogueResolver.class.getSimpleName()+" returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error(CatalogueResolver.class.getSimpleName() + " error: ", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (con != null)
|
||||||
|
con.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG.info("Got Link: " + theResponse);
|
||||||
|
return theResponse;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short link.
|
||||||
|
*
|
||||||
|
* @param theLink the the link
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the string
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String shortLink(String theLink, Map<String, String> parameters) throws Exception {
|
||||||
|
LOG.info("specific shortLink called");
|
||||||
|
|
||||||
|
String linkDecoded = theLink;
|
||||||
|
|
||||||
|
String[] queryStringArray = theLink.split("\\?");
|
||||||
|
if (queryStringArray.length > 1) {
|
||||||
|
String queryString = queryStringArray[1];
|
||||||
|
String queryStringEncoded = UrlEncoderUtil.encodeQuery(queryString);
|
||||||
|
theLink = String.format("%s?%s", queryStringArray[0], queryStringEncoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
LOG.info("Encoded link is: " + theLink);
|
||||||
|
LOG.info("Shortner starts..");
|
||||||
|
String shortLink = URLShortenerUtil.shortTheLink(theLink);
|
||||||
|
LOG.info("Shorted link is: " + shortLink);
|
||||||
|
if (shortLink != null && shortLink.equals(theLink)) {
|
||||||
|
// here the short link and the input link are identical
|
||||||
|
// so the shortening did not work
|
||||||
|
// I'm returning the decoded link because it is directly consumable via browser
|
||||||
|
LOG.debug("Shorted link is equal to input link, returning decoded link: " + linkDecoded);
|
||||||
|
theLink = linkDecoded;
|
||||||
|
} else {
|
||||||
|
// here the link is really shorted
|
||||||
|
LOG.debug("The link is really short, returning it");
|
||||||
|
theLink = shortLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("An error occurred during link shortening: ", e);
|
||||||
|
// here I'm returning the decoded link in case of error on shortening it
|
||||||
|
theLink = linkDecoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
return theLink;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read response.
|
||||||
|
*
|
||||||
|
* @param ris the ris
|
||||||
|
* @return the string
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
private String readResponse(InputStream ris) throws IOException {
|
||||||
|
// Receive the response from the server
|
||||||
|
InputStream in = new BufferedInputStream(ris);
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,230 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.TARGET_GEOPORTAL_APP;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeoportalResolver.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 4, 2024
|
||||||
|
*/
|
||||||
|
public class GeoportalResolver extends GenericResolver {
|
||||||
|
|
||||||
|
private static final int _60SEC = 60000;
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geoportal resolver call builder.
|
||||||
|
*
|
||||||
|
* @param resourceName the resource name
|
||||||
|
* @param entryName the entry name
|
||||||
|
*/
|
||||||
|
public GeoportalResolver(String resourceName, String entryName) {
|
||||||
|
super(resourceName, entryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the link.
|
||||||
|
*
|
||||||
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
|
||||||
|
LOG.debug("called getLink: " + baseURI + " parameters: " + parameters);
|
||||||
|
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
String theResponse = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
String targetApp = parameters.get(GeoportalResolverQueryStringBuilder.TARGET_APP_AS_PARAMETER);
|
||||||
|
|
||||||
|
if (targetApp != null) {
|
||||||
|
LOG.debug("targetApp is not null: " + targetApp);
|
||||||
|
baseURI = String.format("%s/%s", baseURI, targetApp);
|
||||||
|
parameters.remove(GeoportalResolverQueryStringBuilder.TARGET_APP_AS_PARAMETER);
|
||||||
|
LOG.debug("removed target app from parameters and added to URI as /" + targetApp);
|
||||||
|
}else {
|
||||||
|
//Applying default
|
||||||
|
targetApp = TARGET_GEOPORTAL_APP.GEO_DV.getTargetPath();
|
||||||
|
LOG.info(GeoportalResolverQueryStringBuilder.TARGET_APP_AS_PARAMETER +" is null using default: " + targetApp);
|
||||||
|
baseURI = String.format("%s/%s", baseURI, targetApp);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Request to URL: " + baseURI);
|
||||||
|
|
||||||
|
URL urlObj = new URL(baseURI);
|
||||||
|
con = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
|
// con.setRequestProperty("Accept", "application/json");
|
||||||
|
|
||||||
|
con.setDoOutput(true);
|
||||||
|
con.setReadTimeout(_60SEC);
|
||||||
|
con.setConnectTimeout(_60SEC);
|
||||||
|
|
||||||
|
JSONObject jObj = new org.json.JSONObject();
|
||||||
|
for (String key : parameters.keySet()) {
|
||||||
|
jObj.put(key, parameters.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJSON = jObj.toString();
|
||||||
|
LOG.info("Submitting JSON: " + toJSON);
|
||||||
|
Integer code = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
OutputStream os = con.getOutputStream();
|
||||||
|
os.write(toJSON.getBytes("UTF-8"));
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
code = con.getResponseCode();
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
|
||||||
|
if (!((200 <= code) && (code <= 208))) {
|
||||||
|
throw new Exception(GeoportalResolver.class.getSimpleName()+ " returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
LOG.error(GeoportalResolver.class.getSimpleName()+ " returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error(GeoportalResolver.class.getSimpleName() + " error: ", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (con != null)
|
||||||
|
con.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG.info("Got Link: " + theResponse);
|
||||||
|
return theResponse;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short link.
|
||||||
|
*
|
||||||
|
* @param theLink the the link
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the string
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String shortLink(String theLink, Map<String, String> parameters) throws Exception {
|
||||||
|
LOG.info("specific shortLink called");
|
||||||
|
|
||||||
|
String linkDecoded = theLink;
|
||||||
|
|
||||||
|
String[] queryStringArray = theLink.split("\\?");
|
||||||
|
if (queryStringArray.length > 1) {
|
||||||
|
String queryString = queryStringArray[1];
|
||||||
|
String queryStringEncoded = UrlEncoderUtil.encodeQuery(queryString);
|
||||||
|
theLink = String.format("%s?%s", queryStringArray[0], queryStringEncoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (parameters != null) {
|
||||||
|
// LOG.debug("Trying to read the parameter: " + CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER);
|
||||||
|
// String queryStringParmeters = parameters.get(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER);
|
||||||
|
// if (queryStringParmeters != null) {
|
||||||
|
// LOG.debug(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER + " found");
|
||||||
|
// queryString = UrlEncoderUtil.encodeQuery(queryStringParmeters);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
|
// LOG.debug(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER + " encoded is: " + queryString);
|
||||||
|
// if (queryString != null) {
|
||||||
|
// String queryStringEncoded = UrlEncoderUtil.encodeString(queryString);
|
||||||
|
// theLink = String.format("%s?%s", theLink, queryStringEncoded);
|
||||||
|
// }
|
||||||
|
LOG.info("Encoded link is: " + theLink);
|
||||||
|
LOG.info("Shortner starts..");
|
||||||
|
String shortLink = shortTheLink(theLink);
|
||||||
|
LOG.info("Shorted link is: " + shortLink);
|
||||||
|
if (shortLink != null && shortLink.equals(theLink)) {
|
||||||
|
// here the short link and the input link are identical
|
||||||
|
// so the shortening did not work
|
||||||
|
// I'm returning the decoded link because it is directly consumable via browser
|
||||||
|
LOG.debug("Shorted link is equal to input link, returning decoded link: " + linkDecoded);
|
||||||
|
theLink = linkDecoded;
|
||||||
|
} else {
|
||||||
|
// here the link is really shorted
|
||||||
|
LOG.debug("The link is really short, returning it");
|
||||||
|
theLink = shortLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("An error occurred during link shortening: ", e);
|
||||||
|
// here I'm returning the decoded link in case of error on shortening it
|
||||||
|
theLink = linkDecoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
return theLink;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short the link.
|
||||||
|
*
|
||||||
|
* @param link the link
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
private String shortTheLink(String link) {
|
||||||
|
|
||||||
|
String toReturnLink = link;
|
||||||
|
try {
|
||||||
|
UrlShortener shortener = new UrlShortener();
|
||||||
|
String shortedLink = shortener.shorten(link);
|
||||||
|
LOG.info("Shorted link is: " + shortedLink);
|
||||||
|
toReturnLink = shortedLink;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
|
||||||
|
}
|
||||||
|
return toReturnLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read response.
|
||||||
|
*
|
||||||
|
* @param ris the ris
|
||||||
|
* @return the string
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
private String readResponse(InputStream ris) throws IOException {
|
||||||
|
// Receive the response from the server
|
||||||
|
InputStream in = new BufferedInputStream(ris);
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,22 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
||||||
* @Oct 14, 2014
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GisResolverManager implements LinkResolver{
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.gcube.portlets.user.uriresolvermanager.LinkResolver#getLink()
|
|
||||||
*/
|
|
||||||
public String getLink() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
||||||
* @Oct 14, 2014
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface LinkResolver {
|
|
||||||
String getLink();
|
|
||||||
}
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class SHUBResolver.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 4, 2024
|
||||||
|
*/
|
||||||
|
public class SHUBResolver extends GenericResolver {
|
||||||
|
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(SHUBResolver.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new catalogue resolver wrapper.
|
||||||
|
*
|
||||||
|
* @param resourceName the resource name
|
||||||
|
* @param entryName the entry name
|
||||||
|
*/
|
||||||
|
public SHUBResolver(String resourceName, String entryName) {
|
||||||
|
super(resourceName, entryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the link.
|
||||||
|
*
|
||||||
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
|
||||||
|
LOG.debug("called getLink: " + baseURI + " parameters: " + parameters);
|
||||||
|
String toReturn = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
String idValue = parameters.get("id");
|
||||||
|
String pathURI = baseURI;
|
||||||
|
if (idValue != null) {
|
||||||
|
pathURI = String.format("%s/%s", pathURI, idValue);
|
||||||
|
parameters.remove("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
toReturn = pathURI;
|
||||||
|
String queryString = UrlEncoderUtil.encodeQuery(parameters);
|
||||||
|
if (!queryString.isEmpty())
|
||||||
|
toReturn = String.format("%s?%s", pathURI, queryString);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error(SHUBResolver.class.getSimpleName() + " error: ", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
LOG.info("Got Link: " + toReturn);
|
||||||
|
return toReturn;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class CatalogueResolverQueryString.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 26, 2022
|
||||||
|
*/
|
||||||
|
public class CatalogueResolverQueryString {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum MODERATION_OP.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 26, 2022
|
||||||
|
*/
|
||||||
|
public static enum MODERATION_OP {
|
||||||
|
show
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String itemName;
|
||||||
|
private String itemId;
|
||||||
|
private String itemStatus;
|
||||||
|
private MODERATION_OP moderation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new catalogue resolver query string.
|
||||||
|
*
|
||||||
|
* @param builder the builder
|
||||||
|
*/
|
||||||
|
CatalogueResolverQueryString(CatalogueResolverQueryStringBuilder builder) {
|
||||||
|
this.itemName = builder.getItemName();
|
||||||
|
this.itemId = builder.getItemId();
|
||||||
|
this.itemStatus = builder.getItemStatus();
|
||||||
|
this.moderation = builder.getModeration();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item id.
|
||||||
|
*
|
||||||
|
* @return the item id
|
||||||
|
*/
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the moderation.
|
||||||
|
*
|
||||||
|
* @return the moderation
|
||||||
|
*/
|
||||||
|
public MODERATION_OP getModeration() {
|
||||||
|
return moderation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item name.
|
||||||
|
*
|
||||||
|
* @return the item name
|
||||||
|
*/
|
||||||
|
public String getItemName() {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item status.
|
||||||
|
*
|
||||||
|
* @return the item status
|
||||||
|
*/
|
||||||
|
public String getItemStatus() {
|
||||||
|
return itemStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("CatalogueResolverQueryString [itemName=");
|
||||||
|
builder.append(itemName);
|
||||||
|
builder.append(", itemId=");
|
||||||
|
builder.append(itemId);
|
||||||
|
builder.append(", itemStatus=");
|
||||||
|
builder.append(itemStatus);
|
||||||
|
builder.append(", moderation=");
|
||||||
|
builder.append(moderation);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,176 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryString.MODERATION_OP;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class CatalogueResolverQueryStringBuilder.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 26, 2022
|
||||||
|
*/
|
||||||
|
public final class CatalogueResolverQueryStringBuilder {
|
||||||
|
|
||||||
|
// DEFAULT PARAMETERS
|
||||||
|
public static final String DEFAULT_STATUS = "pending";
|
||||||
|
public static final String DEFAULT_MODERATION_OP = MODERATION_OP.show.name();
|
||||||
|
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolverQueryStringBuilder.class);
|
||||||
|
public static final String MODERATION_PARAMETER = "moderation";
|
||||||
|
public static final String ITEM_NAME_PARAMETER = "item_name";
|
||||||
|
public static final String ITEM_ID_PARAMETER = "item_id";
|
||||||
|
public static final String STATUS_PARAMETER = "status";
|
||||||
|
|
||||||
|
public static final String QUERY_STRING_PARAMETER = "query_string";
|
||||||
|
|
||||||
|
private final String itemName;
|
||||||
|
private String itemId;
|
||||||
|
private String itemStatus;
|
||||||
|
private MODERATION_OP moderation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new catalogue resolver query string builder.
|
||||||
|
*
|
||||||
|
* @param itemName the item name
|
||||||
|
*/
|
||||||
|
public CatalogueResolverQueryStringBuilder(String itemName) {
|
||||||
|
this.itemName = itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item id.
|
||||||
|
*
|
||||||
|
* @param itemId the item id
|
||||||
|
* @return the catalogue resolver query string builder
|
||||||
|
*/
|
||||||
|
public CatalogueResolverQueryStringBuilder itemId(String itemId) {
|
||||||
|
this.itemId = itemId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moderation.
|
||||||
|
*
|
||||||
|
* @param moderation the moderation
|
||||||
|
* @return the catalogue resolver query string builder
|
||||||
|
*/
|
||||||
|
public CatalogueResolverQueryStringBuilder moderation(MODERATION_OP moderation) {
|
||||||
|
this.moderation = moderation;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item status.
|
||||||
|
*
|
||||||
|
* @param itemStatus the item status
|
||||||
|
* @return the catalogue resolver query string builder
|
||||||
|
*/
|
||||||
|
public CatalogueResolverQueryStringBuilder itemStatus(String itemStatus) {
|
||||||
|
this.itemStatus = itemStatus;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item name.
|
||||||
|
*
|
||||||
|
* @return the item name
|
||||||
|
*/
|
||||||
|
public String getItemName() {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item id.
|
||||||
|
*
|
||||||
|
* @return the item id
|
||||||
|
*/
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item status.
|
||||||
|
*
|
||||||
|
* @return the item status
|
||||||
|
*/
|
||||||
|
public String getItemStatus() {
|
||||||
|
return itemStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the moderation.
|
||||||
|
*
|
||||||
|
* @return the moderation
|
||||||
|
*/
|
||||||
|
public MODERATION_OP getModeration() {
|
||||||
|
return moderation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the query parameters.
|
||||||
|
*
|
||||||
|
* @return the map
|
||||||
|
*/
|
||||||
|
public Map<String, String> buildQueryParameters() {
|
||||||
|
|
||||||
|
CatalogueResolverQueryString crQS = new CatalogueResolverQueryString(this);
|
||||||
|
|
||||||
|
if (crQS.getItemName() == null || crQS.getItemName().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The " + ITEM_NAME_PARAMETER + " cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> query = new HashMap<String, String>();
|
||||||
|
query.put(ITEM_NAME_PARAMETER, crQS.getItemName());
|
||||||
|
|
||||||
|
if (crQS.getItemId() != null) {
|
||||||
|
query.put(ITEM_ID_PARAMETER, crQS.getItemId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getItemStatus() != null) {
|
||||||
|
query.put(STATUS_PARAMETER, crQS.getItemStatus());
|
||||||
|
} else {
|
||||||
|
query.put(STATUS_PARAMETER, DEFAULT_STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getModeration() != null) {
|
||||||
|
query.put(MODERATION_PARAMETER, crQS.getModeration().name());
|
||||||
|
} else {
|
||||||
|
query.put(MODERATION_PARAMETER, DEFAULT_MODERATION_OP);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the query parameters to query string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public String buildQueryParametersToQueryString() {
|
||||||
|
|
||||||
|
Map<String, String> mapParameters = buildQueryParameters();
|
||||||
|
return UrlEncoderUtil.toQueryString(mapParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the query obj.
|
||||||
|
*
|
||||||
|
* @return the catalogue resolver query string
|
||||||
|
*/
|
||||||
|
public CatalogueResolverQueryString buildQueryObj() {
|
||||||
|
|
||||||
|
return new CatalogueResolverQueryString(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeoportalResolverQueryString.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 27, 2023
|
||||||
|
*/
|
||||||
|
public class GeoportalResolverQueryString {
|
||||||
|
|
||||||
|
private final String itemType;
|
||||||
|
private String itemId;
|
||||||
|
private String gcubeScope;
|
||||||
|
private String resolveAs;
|
||||||
|
private String targetApp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geoportal resolver query string.
|
||||||
|
*
|
||||||
|
* @param builder the builder
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryString(GeoportalResolverQueryStringBuilder builder) {
|
||||||
|
this.itemType = builder.getItemType();
|
||||||
|
this.itemId = builder.getItemId();
|
||||||
|
this.gcubeScope = builder.getGcubeScope();
|
||||||
|
this.resolveAs = builder.getResolveAs() != null ? builder.getResolveAs().getParamValue() : null;
|
||||||
|
this.targetApp = builder.getTargetApp() != null ? builder.getTargetApp().getTargetPath() : null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item type.
|
||||||
|
*
|
||||||
|
* @return the item type
|
||||||
|
*/
|
||||||
|
public String getItemType() {
|
||||||
|
return itemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item id.
|
||||||
|
*
|
||||||
|
* @return the item id
|
||||||
|
*/
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the gcube scope.
|
||||||
|
*
|
||||||
|
* @return the gcube scope
|
||||||
|
*/
|
||||||
|
public String getGcubeScope() {
|
||||||
|
return gcubeScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the resolver as.
|
||||||
|
*
|
||||||
|
* @return the resolver as
|
||||||
|
*/
|
||||||
|
public String getResolveAs() {
|
||||||
|
return resolveAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the target app.
|
||||||
|
*
|
||||||
|
* @return the target app
|
||||||
|
*/
|
||||||
|
public String getTargetApp() {
|
||||||
|
return targetApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("GeoportalResolverQueryString [itemType=");
|
||||||
|
builder.append(itemType);
|
||||||
|
builder.append(", itemId=");
|
||||||
|
builder.append(itemId);
|
||||||
|
builder.append(", gcubeScope=");
|
||||||
|
builder.append(gcubeScope);
|
||||||
|
builder.append(", resolveAs=");
|
||||||
|
builder.append(resolveAs);
|
||||||
|
builder.append(", targetApp=");
|
||||||
|
builder.append(targetApp);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,236 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeoportalResolverQueryStringBuilder.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 27, 2023
|
||||||
|
*/
|
||||||
|
public final class GeoportalResolverQueryStringBuilder {
|
||||||
|
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(GeoportalResolverQueryStringBuilder.class);
|
||||||
|
public static final String ITEM_TYPE_PARAMETER = "item_type";
|
||||||
|
public static final String ITEM_ID_PARAMETER = "item_id";
|
||||||
|
public static final String GCUBE_SCOPE_PARAMETER = "gcube_scope";
|
||||||
|
public static final String RESOLVE_AS_PARAMETER = "res";
|
||||||
|
public static final String TARGET_APP_AS_PARAMETER = "target_app";
|
||||||
|
|
||||||
|
private String itemType;
|
||||||
|
private String itemId;
|
||||||
|
private String gcubeScope;
|
||||||
|
private RESOLVE_AS resolveAs;
|
||||||
|
private TARGET_GEOPORTAL_APP targetApp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum RESOLVE_AS_PARAMETER.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 28, 2023
|
||||||
|
*/
|
||||||
|
public static enum RESOLVE_AS {
|
||||||
|
PUBLIC("public"), PRIVATE("private");
|
||||||
|
|
||||||
|
String paramValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new resolve as.
|
||||||
|
*
|
||||||
|
* @param paramValue the param value
|
||||||
|
*/
|
||||||
|
RESOLVE_AS(String paramValue) {
|
||||||
|
this.paramValue = paramValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the param value.
|
||||||
|
*
|
||||||
|
* @return the param value
|
||||||
|
*/
|
||||||
|
public String getParamValue() {
|
||||||
|
return paramValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum TARGET_GEOPORTAL_APP.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 3, 2024
|
||||||
|
*/
|
||||||
|
public static enum TARGET_GEOPORTAL_APP {
|
||||||
|
|
||||||
|
GEO_DV("dv", "Geoportal Data-Viewer"), GEO_DE("de", "Geoportal Data-Entry");
|
||||||
|
|
||||||
|
private String targetPath;
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new target geoportal app.
|
||||||
|
*
|
||||||
|
* @param targetPath the target path
|
||||||
|
* @param applicationName the application name
|
||||||
|
*/
|
||||||
|
private TARGET_GEOPORTAL_APP(String targetPath, String applicationName) {
|
||||||
|
this.targetPath = targetPath;
|
||||||
|
this.applicationName = applicationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the target path.
|
||||||
|
*
|
||||||
|
* @return the target path
|
||||||
|
*/
|
||||||
|
public String getTargetPath() {
|
||||||
|
return targetPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the application name.
|
||||||
|
*
|
||||||
|
* @return the application name
|
||||||
|
*/
|
||||||
|
public String getApplicationName() {
|
||||||
|
return applicationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geoportal resolver query string builder.
|
||||||
|
*
|
||||||
|
* @param itemType the item type
|
||||||
|
* @param itemId the item id
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryStringBuilder(String itemType, String itemId) {
|
||||||
|
this.itemType = itemType;
|
||||||
|
this.itemId = itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope.
|
||||||
|
*
|
||||||
|
* @param gcubeScope the gcube scope
|
||||||
|
* @return the geoportal resolver query string builder
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryStringBuilder scope(String gcubeScope) {
|
||||||
|
this.gcubeScope = gcubeScope;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolver as.
|
||||||
|
*
|
||||||
|
* @param resolveAs the resolve as
|
||||||
|
* @return the geoportal resolver query string builder
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryStringBuilder resolverAs(RESOLVE_AS resolveAs) {
|
||||||
|
this.resolveAs = resolveAs;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target app.
|
||||||
|
*
|
||||||
|
* @param targetApp the target app
|
||||||
|
* @return the geoportal resolver query string builder
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryStringBuilder targetApp(TARGET_GEOPORTAL_APP targetApp) {
|
||||||
|
this.targetApp = targetApp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item type.
|
||||||
|
*
|
||||||
|
* @return the item type
|
||||||
|
*/
|
||||||
|
public String getItemType() {
|
||||||
|
return itemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item id.
|
||||||
|
*
|
||||||
|
* @return the item id
|
||||||
|
*/
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the gcube scope.
|
||||||
|
*
|
||||||
|
* @return the gcube scope
|
||||||
|
*/
|
||||||
|
public String getGcubeScope() {
|
||||||
|
return gcubeScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the resolve as.
|
||||||
|
*
|
||||||
|
* @return the resolve as
|
||||||
|
*/
|
||||||
|
public RESOLVE_AS getResolveAs() {
|
||||||
|
return resolveAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the target app.
|
||||||
|
*
|
||||||
|
* @return the target app
|
||||||
|
*/
|
||||||
|
public TARGET_GEOPORTAL_APP getTargetApp() {
|
||||||
|
return targetApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the query parameters.
|
||||||
|
*
|
||||||
|
* @return the map
|
||||||
|
*/
|
||||||
|
public Map<String, String> buildQueryParameters() {
|
||||||
|
|
||||||
|
GeoportalResolverQueryString crQS = new GeoportalResolverQueryString(this);
|
||||||
|
|
||||||
|
if (crQS.getItemType() == null || crQS.getItemType().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The " + ITEM_TYPE_PARAMETER + " cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getItemId() == null || crQS.getItemId().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The " + ITEM_ID_PARAMETER + " cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getGcubeScope() == null || crQS.getGcubeScope().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The " + GCUBE_SCOPE_PARAMETER + " cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> query = new HashMap<String, String>();
|
||||||
|
query.put(ITEM_TYPE_PARAMETER, crQS.getItemType());
|
||||||
|
query.put(ITEM_ID_PARAMETER, crQS.getItemId());
|
||||||
|
query.put(GCUBE_SCOPE_PARAMETER, crQS.getGcubeScope());
|
||||||
|
if (crQS.getResolveAs() != null) {
|
||||||
|
query.put(RESOLVE_AS_PARAMETER, crQS.getResolveAs());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(crQS.getTargetApp() != null) {
|
||||||
|
query.put(TARGET_APP_AS_PARAMETER, crQS.getTargetApp());
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.util;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class URLShortenerUtil {
|
||||||
|
|
||||||
|
private static Logger LOG = LoggerFactory.getLogger(URLShortenerUtil.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short the link.
|
||||||
|
*
|
||||||
|
* @param link the link
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public static String shortTheLink(String link) {
|
||||||
|
|
||||||
|
String toReturnLink = link;
|
||||||
|
try {
|
||||||
|
UrlShortener shortener = new UrlShortener();
|
||||||
|
String shortedLink = shortener.shorten(link);
|
||||||
|
LOG.info("Short link is: " + shortedLink);
|
||||||
|
toReturnLink = shortedLink;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
|
||||||
|
}
|
||||||
|
return toReturnLink;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,13 +5,11 @@ package org.gcube.portlets.user.uriresolvermanager.util;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
/**
|
||||||
* The Class UrlEncoderUtil.
|
* The Class UrlEncoderUtil.
|
||||||
*
|
*
|
||||||
|
@ -62,7 +60,7 @@ public class UrlEncoderUtil {
|
||||||
String encodedQuery = "";
|
String encodedQuery = "";
|
||||||
|
|
||||||
if (theString == null || theString.isEmpty())
|
if (theString == null || theString.isEmpty())
|
||||||
return theString;
|
return encodedQuery;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
encodedQuery = URLEncoder.encode(theString, charset);
|
encodedQuery = URLEncoder.encode(theString, charset);
|
||||||
|
@ -153,22 +151,52 @@ public class UrlEncoderUtil {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static URI_PART getURIParts(String uri) {
|
||||||
* The main method.
|
|
||||||
*
|
|
||||||
* @param args the arguments
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
// System.out.println(UrlEncoderUtil.encodeQuery("request=GetStyles", "layers=test Name", "service=WMS", "version=1.1.1"));
|
if (uri == null || uri.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
String[] uriSections = uri.split("\\?");
|
||||||
|
if (uriSections.length == 1) {
|
||||||
|
return new URI_PART(uriSections[0], null);
|
||||||
|
} else if (uriSections.length == 2) {
|
||||||
|
return new URI_PART(uriSections[0], uriSections[1]);
|
||||||
|
}
|
||||||
|
|
||||||
parameters.put("request", "GetStyles");
|
return null;
|
||||||
parameters.put("layers", "test Name");
|
|
||||||
parameters.put("version", "1.1.1");
|
|
||||||
|
|
||||||
System.out.println(UrlEncoderUtil.encodeQuery(parameters));
|
}
|
||||||
|
|
||||||
|
public static class URI_PART {
|
||||||
|
String baseURI;
|
||||||
|
String queryString;
|
||||||
|
|
||||||
|
public URI_PART() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI_PART(String baseURI, String queryString) {
|
||||||
|
this.baseURI = baseURI;
|
||||||
|
this.queryString = queryString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBaseURI() {
|
||||||
|
return baseURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQueryString() {
|
||||||
|
return queryString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("URI_PART [baseURI=");
|
||||||
|
builder.append(baseURI);
|
||||||
|
builder.append(", queryString=");
|
||||||
|
builder.append(queryString);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/resources/
|
|
@ -0,0 +1,42 @@
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.geoportal.GeoportalExporterAPI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* @Oct 20, 2014
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GeoportalExporterTest {
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testGeoportalExporterEndppoint() {
|
||||||
|
UriResolverManager manager;
|
||||||
|
try {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
|
GeoportalExporterAPI geAPI = new GeoportalExporterAPI();
|
||||||
|
|
||||||
|
boolean asURL = true;
|
||||||
|
URL exportProjectURL = geAPI.exportProject("pdf", "profiledConcessioni", "661d2c6f8804530afb90b132", asURL);
|
||||||
|
System.out.println("exportProjectURL: "+exportProjectURL);
|
||||||
|
URL healthcheckURL = geAPI.healthcheck("pdf");
|
||||||
|
System.out.println("healthcheckURL: "+healthcheckURL);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -54,7 +54,7 @@ public class HttpRequestUtil {
|
||||||
}else
|
}else
|
||||||
logger.warn("status code is "+code+" - on url connection: "+urlConn);
|
logger.warn("status code is "+code+" - on url connection: "+urlConn);
|
||||||
|
|
||||||
// logger.trace("result: "+result);
|
// LOG.trace("result: "+result);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.error("error - not a http request!");
|
logger.error("error - not a http request!");
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -15,23 +13,54 @@ public class UriResolverManagerMain {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/gcube");
|
|
||||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
String theLink = "https://data.dev.d4science.org/ctlg/devVRE/sarda-sarda";
|
||||||
System.out.println(resolver.getCapabilities());
|
String[] queryStringArray = theLink.split("\\?");
|
||||||
System.out.println(resolver.getApplicationTypes());
|
if(queryStringArray.length>1) {
|
||||||
|
String queryString = queryStringArray[1];
|
||||||
|
String queryStringEncoded = UrlEncoderUtil.encodeQuery(queryString);
|
||||||
|
theLink = String.format("%s?%s", queryStringArray[0], queryStringEncoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(theLink);
|
||||||
|
|
||||||
|
// ScopeProvider.instance.set("/gcube");
|
||||||
|
// UriResolverManager resolver = new UriResolverManager("GIS");
|
||||||
|
// System.out.println(resolver.getCapabilities());
|
||||||
|
// System.out.println(resolver.getApplicationTypes());
|
||||||
// System.out.println(resolver.discoveryServiceParameters(resolver.getResolver("SMP-ID")));
|
// System.out.println(resolver.discoveryServiceParameters(resolver.getResolver("SMP-ID")));
|
||||||
|
|
||||||
// Map<String, String> params = new HashMap<String, String>();
|
// Map<String, String> params = new HashMap<String, String>();
|
||||||
// params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
|
// params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
|
||||||
// params.put("scope", "/gcube/devsec/devVRE");
|
// params.put("scope", "/gcube/devsec/devVRE");
|
||||||
// String shortLink = resolver.getLink(params, true);
|
// String shortLink = resolver.getLink(params, true);
|
||||||
// System.out.println(shortLink); //true, link is shorted otherwise none
|
//// System.out.println(shortLink); //true, link is shorted otherwise none
|
||||||
} catch (UriResolverMapException e) {
|
// } catch (UriResolverMapException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
// } catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main method.
|
||||||
|
*
|
||||||
|
* @param args the arguments
|
||||||
|
*/
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
//
|
||||||
|
//// System.out.println(UrlEncoderUtil.encodeQuery("request=GetStyles", "layers=test Name", "service=WMS", "version=1.1.1"));
|
||||||
|
//
|
||||||
|
// HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
//
|
||||||
|
// parameters.put("request", "GetStyles");
|
||||||
|
// parameters.put("layers", "test Name");
|
||||||
|
// parameters.put("version", "1.1.1");
|
||||||
|
//
|
||||||
|
// System.out.println(UrlEncoderUtil.encodeQuery(parameters));
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||||
import org.junit.Test;
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryStringBuilder;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder;
|
||||||
/**
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS;
|
||||||
*
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.TARGET_GEOPORTAL_APP;
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
@ -19,86 +21,280 @@ import org.junit.Test;
|
||||||
public class UriResolverManagerTest {
|
public class UriResolverManagerTest {
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void testUriResolverManger(){
|
public void testUriResolverManger() {
|
||||||
UriResolverManager manager;
|
UriResolverManager manager;
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
manager = new UriResolverManager();
|
manager = new UriResolverManager();
|
||||||
System.out.println(manager.getCapabilities());
|
System.out.println("Capabilities: " + manager.getCapabilities());
|
||||||
System.out.println(manager.getApplicationTypes());
|
System.out.println("ApplicationTypes: " + manager.getApplicationTypes());
|
||||||
|
for (String applicationType : manager.getApplicationTypes()) {
|
||||||
|
Resolver resolver = manager.getResolver(applicationType);
|
||||||
|
System.out.println("ApplicationType: " + applicationType + " has: " + resolver);
|
||||||
|
List<ServiceParameter> serviceParameters = manager.discoveryServiceParameters(resolver);
|
||||||
|
System.out.println("Parameters: " + serviceParameters);
|
||||||
|
}
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testCTLG() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
|
UriResolverManager resolver;
|
||||||
|
resolver = new UriResolverManager("CTLG");
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("gcube_scope", "/gcube/devsec/devVRE");
|
||||||
|
params.put("entity_context", "dataset");
|
||||||
|
params.put("entity_name", "sarda-sarda");
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void testGIS() {
|
public void testCTLGWithQueryString() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/pred4s/preprod/preVRE");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
UriResolverManager resolver;
|
||||||
|
resolver = new UriResolverManager("CTLG");
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900");
|
params.put("gcube_scope", "/gcube/devsec/devVRE");
|
||||||
params.put("scope", "/pred4s/preprod/preVRE");
|
params.put("entity_context", "dataset");
|
||||||
|
params.put("entity_name", "sarda-sarda");
|
||||||
|
params.put("query_string", "param1=value1&parm2=value2");
|
||||||
|
// METHOD 1 - Query String as parameter of the getLink method
|
||||||
String shortLink = resolver.getLink(params, true);
|
String shortLink = resolver.getLink(params, true);
|
||||||
System.out.println(shortLink); //true, link is shorted otherwise none
|
|
||||||
|
// METHOD 2 - Query String as parameter passed in the params
|
||||||
|
// String queryString = QueryStringUtil.toQueryString(queryStringParameters);
|
||||||
|
// params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
||||||
|
System.out.println(shortLink);
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
|
public void testCTLGGenerateLinkForModeration() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
|
UriResolverManager resolver;
|
||||||
|
resolver = new UriResolverManager("CTLG");
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("gcube_scope", "/gcube/devsec/devVRE");
|
||||||
|
params.put("entity_context", "organization");
|
||||||
|
params.put("entity_name", "devvre");
|
||||||
|
|
||||||
|
CatalogueResolverQueryStringBuilder builder = new CatalogueResolverQueryStringBuilder(
|
||||||
|
"test-moderation-1649068829317");
|
||||||
|
//builder.itemStatus("approved").moderation(MODERATION_OP.show);
|
||||||
|
|
||||||
|
String queryString = builder.buildQueryParametersToQueryString();
|
||||||
|
params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
||||||
|
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testGeoportalCreateDataEntryLink() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
String scope = "/gcube/devsec/devVRE";
|
||||||
|
// String scope = "/pred4s/preprod/preVRE";
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
String gcubeScope = scope;
|
||||||
|
String itemId = "6384aaac308f5c28c5ee0888";
|
||||||
|
String itemType = "profiledConcessioni";
|
||||||
|
|
||||||
|
UriResolverManager resolver = new UriResolverManager("GEO");
|
||||||
|
Map<String, String> params = null;
|
||||||
|
|
||||||
|
//Method 1
|
||||||
|
// params = new HashMap<String, String>();
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.GCUBE_SCOPE_PARAMETER, gcubeScope);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.ITEM_ID_PARAMETER, itemId);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.ITEM_TYPE_PARAMETER, itemType);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.RESOLVE_AS_PARAMETER, GeoportalResolverQueryStringBuilder.RESOLVE_AS.PUBLIC.getParamValue());
|
||||||
|
|
||||||
|
//Method 2
|
||||||
|
GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder(itemType,itemId);
|
||||||
|
builder.scope(gcubeScope);
|
||||||
|
builder.resolverAs(RESOLVE_AS.PUBLIC);
|
||||||
|
builder.targetApp(TARGET_GEOPORTAL_APP.GEO_DE);
|
||||||
|
// builder.resolverAs(RESOLVE_AS.PRIVATE);
|
||||||
|
params = builder.buildQueryParameters();
|
||||||
|
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testGeoportalCreateDataViewerLink() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
String scope = "/gcube/devsec/devVRE";
|
||||||
|
// String scope = "/pred4s/preprod/preVRE";
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
String gcubeScope = scope;
|
||||||
|
String itemId = "6384aaac308f5c28c5ee0888";
|
||||||
|
String itemType = "profiledConcessioni";
|
||||||
|
|
||||||
|
UriResolverManager resolver = new UriResolverManager("GEO");
|
||||||
|
Map<String, String> params = null;
|
||||||
|
|
||||||
|
//Method 1
|
||||||
|
// params = new HashMap<String, String>();
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.GCUBE_SCOPE_PARAMETER, gcubeScope);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.ITEM_ID_PARAMETER, itemId);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.ITEM_TYPE_PARAMETER, itemType);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.RESOLVE_AS_PARAMETER, GeoportalResolverQueryStringBuilder.RESOLVE_AS.PUBLIC.getParamValue());
|
||||||
|
|
||||||
|
//Method 2
|
||||||
|
GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder(itemType,itemId);
|
||||||
|
builder.scope(gcubeScope);
|
||||||
|
builder.resolverAs(RESOLVE_AS.PUBLIC);
|
||||||
|
//builder.targetApp(TARGET_GEOPORTAL_APP.GEO_DV);
|
||||||
|
builder.resolverAs(RESOLVE_AS.PRIVATE);
|
||||||
|
params = builder.buildQueryParameters();
|
||||||
|
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test IS OK
|
||||||
|
public void testSHUB() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
|
UriResolverManager resolver;
|
||||||
|
resolver = new UriResolverManager("SHUB");
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("id", "1dac6703-8eb0-4838-83a8-5006f5074e9b");
|
||||||
|
params.put("content-disposition", "inline");
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
public void testGIS() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
String scope = "/pred4s/preprod/preVRE";
|
||||||
|
String UUID = "da165110-88fd-11da-a88f-000d939bc5d8";
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
UriResolverManager resolver = new UriResolverManager("GIS");
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("gis-UUID", UUID);
|
||||||
|
params.put("scope", scope);
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
public void testSMP() {
|
public void testSMP() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
UriResolverManager resolver = new UriResolverManager("SMP");
|
UriResolverManager resolver = new UriResolverManager("SMP");
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("smp-uri","smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
|
params.put("smp-uri",
|
||||||
|
"smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
|
||||||
params.put("fileName", "wikipediaLogo");
|
params.put("fileName", "wikipediaLogo");
|
||||||
params.put("contentType", "");
|
params.put("contentType", "");
|
||||||
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none
|
String shortLink = resolver.getLink(params, true); // true, link is shorted otherwise none
|
||||||
System.out.println(shortLink);
|
System.out.println(shortLink);
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread safe
|
* Thread safe
|
||||||
*/
|
*/
|
||||||
// @Test
|
// @Test
|
||||||
public void testSMPID(){
|
public void testSMPID() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
UriResolverManager resolver;
|
UriResolverManager resolver;
|
||||||
resolver = new UriResolverManager("SMP-ID");
|
resolver = new UriResolverManager("SMP-ID");
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("geo-exp","553f9265e4b0567b75021fce");
|
params.put("geo-exp", "553f9265e4b0567b75021fce");
|
||||||
// params.put("fileName", "dog");
|
// params.put("fileName", "dog");
|
||||||
// params.put("contentType", "image/jpg");
|
// params.put("contentType", "image/jpg");
|
||||||
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none
|
String shortLink = resolver.getLink(params, true); // true, link is shorted otherwise none
|
||||||
System.out.println(shortLink);
|
System.out.println(shortLink);
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,45 +302,45 @@ public class UriResolverManagerTest {
|
||||||
/**
|
/**
|
||||||
* Thread safe
|
* Thread safe
|
||||||
*/
|
*/
|
||||||
//@Test
|
// @Test
|
||||||
public void test2(){
|
public void test2() {
|
||||||
|
|
||||||
|
// create thread to print counter value
|
||||||
|
Thread t = new Thread(new Runnable() {
|
||||||
|
|
||||||
//create thread to print counter value
|
@Override
|
||||||
Thread t = new Thread(new Runnable() {
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
|
||||||
@Override
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
public void run() {
|
UriResolverManager resolver;
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
|
||||||
UriResolverManager resolver;
|
|
||||||
resolver = new UriResolverManager("GIS");
|
resolver = new UriResolverManager("GIS");
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("gis-UUID", "eb1a1b63-f324-47ee-9522-b8f5803e19ec");
|
params.put("gis-UUID", "eb1a1b63-f324-47ee-9522-b8f5803e19ec");
|
||||||
params.put("scope", "/gcube/devsec/devVRE");
|
params.put("scope", "/gcube/devsec/devVRE");
|
||||||
String shortLink = resolver.getLink(params, true);
|
String shortLink = resolver.getLink(params, true);
|
||||||
System.out.println(shortLink); //true, link is shorted otherwise none
|
System.out.println(shortLink); // true, link is shorted otherwise none
|
||||||
|
|
||||||
System.out.println("Thread "+Thread.currentThread().getId() +" reading counter is: " + resolver.countReaders());
|
System.out.println("Thread " + Thread.currentThread().getId() + " reading counter is: "
|
||||||
Thread.sleep(1000);
|
+ resolver.countReaders());
|
||||||
} catch (InterruptedException ex) {
|
Thread.sleep(1000);
|
||||||
ex.printStackTrace();
|
} catch (InterruptedException ex) {
|
||||||
}catch (UriResolverMapException e) {
|
ex.printStackTrace();
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
|
@ -13,3 +13,4 @@
|
||||||
/log4j.properties
|
/log4j.properties
|
||||||
/pred4s.gcubekey
|
/pred4s.gcubekey
|
||||||
/preprod.gcubekey
|
/preprod.gcubekey
|
||||||
|
/devVRE.gcubekey
|
||||||
|
|
Loading…
Reference in New Issue