Merge pull request 'feature_27135' (!4) from feature_27135 into master

Reviewed-on: #4
This commit is contained in:
Francesco Mangiacrapa 2024-06-28 15:07:35 +02:00
commit 9ebf7ff900
18 changed files with 442 additions and 115 deletions

View File

@ -25,11 +25,11 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</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">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/francescomangiacrapa/config-work-isti/log4jconfiguration"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -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.enumIdentifier=error
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.source=1.8

View File

@ -3,6 +3,11 @@
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-SNAPSHOT]
- 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]

View File

@ -4,14 +4,14 @@
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath />
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<version>1.7.0</version>
<version>1.8.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>uri-resolver-manager</name>
<description>The URI Resolver Manager</description>

View File

@ -18,9 +18,9 @@ import org.gcube.portlets.user.uriresolvermanager.exception.NotImplementedExcept
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
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.URI_PART;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -167,6 +167,7 @@ public class UriResolverManager {
throw new IllegalArgumentException("Application type is null");
Resolver resolver = this.applicationTypes.get(applicationType);
LOG.debug("The resolver found is of kind: "+ resolver.getClass().getSimpleName());
String link = null;
if (parameters == null)
@ -249,7 +250,7 @@ public class UriResolverManager {
}
LOG.info("Encoded link is: " + link);
LOG.info("Shortner starts..");
String shortenedLink = shortTheLink(link);
String shortenedLink = URLShortenerUtil.shortTheLink(link);
if (shortenedLink != null && shortenedLink.equals(link)) {
// here the short link and the input link are identical
// so the shortening did not work
@ -280,20 +281,6 @@ public class UriResolverManager {
return link;
}
private String shortTheLink(String sourceLink) {
String toReturnLink = sourceLink;
try {
UrlShortener shortener = new UrlShortener();
String shortLink = shortener.shorten(sourceLink);
LOG.info("Short link is: " + shortLink);
toReturnLink = shortLink;
} catch (Exception e) {
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
}
return toReturnLink;
}
/**
* Gets the application types.
*

View File

@ -11,6 +11,21 @@ import java.util.Map;
*/
public interface Resolver {
//Code used to implement specific (so override) the method 'getLink' of the Resolver
public static enum RESOLVER_ENTRYNAME {
CTLG("ctlg"), SMP("smp"), SHUB("shub"), GEO("geo"), GIS("gis");
String entryName;
RESOLVER_ENTRYNAME(String entryName) {
this.entryName = entryName;
}
public String getEntryName() {
return entryName;
}
}
/**
* Gets the resource name.
*

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -92,21 +92,18 @@ public class RuntimeResourceReader {
while (acIt.hasNext()) {
AccessPoint ap = acIt.next();
Group<Property> properties = ap.properties();
if (properties.size() == 0) {
logger.warn("Properties in resource " + resourceName + " not found");
logger.warn("Properties in resource " + resourceName + " not found for ap: "+ap.name());
serviceAccessPoints.add(new ServiceAccessPoint(ap.name(), ap.address(), null));
} else {
List<ServiceParameter> serviceParameters = new ArrayList<ServiceParameter>(properties.size());
Iterator<Property> iter = properties.iterator();
while (iter.hasNext()) {
Property prop = iter.next();
serviceParameters.add(new ServiceParameter(prop.value(), true));
}

View File

@ -14,8 +14,9 @@ import org.gcube.common.resources.gcore.utils.XPathHelper;
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.resolvers.CatalogueResolverCallBuilder;
import org.gcube.portlets.user.uriresolvermanager.resolvers.SHUBResolverCallBuilder;
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.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
@ -117,10 +118,12 @@ public class UriResolverMapReader {
String resoureName = resources.get(0);
String entryName = entryNames.get(0);
Resolver resolver;
if (entryName.equalsIgnoreCase("ctlg")) {
resolver = new CatalogueResolverCallBuilder(resoureName, entryName);
} else if (entryName.equalsIgnoreCase("shub")) {
resolver = new SHUBResolverCallBuilder(resoureName, entryName);
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);
}

View File

@ -11,23 +11,23 @@ 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.gcube.portlets.user.urlshortener.UrlShortener;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class CatalogueResolverCallBuilder.
* The Class CatalogueResolver.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 5, 2021
* Apr 4, 2024
*/
public class CatalogueResolverCallBuilder extends GenericResolver {
public class CatalogueResolver extends GenericResolver {
private static final int _60SEC = 60000;
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolverCallBuilder.class);
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolver.class);
/**
* Instantiates a new catalogue resolver wrapper.
@ -35,7 +35,7 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
* @param resourceName the resource name
* @param entryName the entry name
*/
public CatalogueResolverCallBuilder(String resourceName, String entryName) {
public CatalogueResolver(String resourceName, String entryName) {
super(resourceName, entryName);
}
@ -88,16 +88,16 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
theResponse = readResponse(con.getInputStream());
if (!((200 <= code) && (code <= 208))) {
throw new Exception("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
throw new Exception(CatalogueResolver.class.getSimpleName()+" returned code: " + code + ". Response is: " + theResponse);
}
} catch (IOException e) {
theResponse = readResponse(con.getInputStream());
LOG.error("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
LOG.error(CatalogueResolver.class.getSimpleName()+" returned code: " + code + ". Response is: " + theResponse);
throw e;
}
} catch (Exception e) {
LOG.error(CatalogueResolverCallBuilder.class.getSimpleName() + " error: ", e);
LOG.error(CatalogueResolver.class.getSimpleName() + " error: ", e);
throw e;
} finally {
try {
@ -133,24 +133,10 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
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);
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
@ -174,26 +160,6 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
}
/**
* 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.
*

View File

@ -11,6 +11,8 @@ 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;
@ -18,16 +20,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class GeoportalResolverCallBuilder.
* The Class GeoportalResolver.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 27, 2023
* Apr 4, 2024
*/
public class GeoportalResolverCallBuilder extends GenericResolver {
public class GeoportalResolver extends GenericResolver {
private static final int _60SEC = 60000;
public static final Logger LOG = LoggerFactory.getLogger(GeoportalResolverCallBuilder.class);
public static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class);
/**
* Instantiates a new geoportal resolver call builder.
@ -35,7 +37,7 @@ public class GeoportalResolverCallBuilder extends GenericResolver {
* @param resourceName the resource name
* @param entryName the entry name
*/
public GeoportalResolverCallBuilder(String resourceName, String entryName) {
public GeoportalResolver(String resourceName, String entryName) {
super(resourceName, entryName);
}
@ -55,6 +57,22 @@ public class GeoportalResolverCallBuilder extends GenericResolver {
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");
@ -70,11 +88,6 @@ public class GeoportalResolverCallBuilder extends GenericResolver {
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;
@ -88,16 +101,16 @@ public class GeoportalResolverCallBuilder extends GenericResolver {
theResponse = readResponse(con.getInputStream());
if (!((200 <= code) && (code <= 208))) {
throw new Exception("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
throw new Exception(GeoportalResolver.class.getSimpleName()+ " returned code: " + code + ". Response is: " + theResponse);
}
} catch (IOException e) {
theResponse = readResponse(con.getInputStream());
LOG.error("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
LOG.error(GeoportalResolver.class.getSimpleName()+ " returned code: " + code + ". Response is: " + theResponse);
throw e;
}
} catch (Exception e) {
LOG.error(GeoportalResolverCallBuilder.class.getSimpleName() + " error: ", e);
LOG.error(GeoportalResolver.class.getSimpleName() + " error: ", e);
throw e;
} finally {
try {

View File

@ -8,15 +8,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class SHUBResolverCallBuilder.
* The Class SHUBResolver.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 8, 2021
* Apr 4, 2024
*/
public class SHUBResolverCallBuilder extends GenericResolver {
public class SHUBResolver extends GenericResolver {
public static final Logger LOG = LoggerFactory.getLogger(SHUBResolverCallBuilder.class);
public static final Logger LOG = LoggerFactory.getLogger(SHUBResolver.class);
/**
* Instantiates a new catalogue resolver wrapper.
@ -24,7 +24,7 @@ public class SHUBResolverCallBuilder extends GenericResolver {
* @param resourceName the resource name
* @param entryName the entry name
*/
public SHUBResolverCallBuilder(String resourceName, String entryName) {
public SHUBResolver(String resourceName, String entryName) {
super(resourceName, entryName);
}
@ -55,7 +55,7 @@ public class SHUBResolverCallBuilder extends GenericResolver {
toReturn = String.format("%s?%s", pathURI, queryString);
} catch (Exception e) {
LOG.error(SHUBResolverCallBuilder.class.getSimpleName() + " error: ", e);
LOG.error(SHUBResolver.class.getSimpleName() + " error: ", e);
throw e;
}
LOG.info("Got Link: " + toReturn);

View File

@ -13,6 +13,7 @@ public class GeoportalResolverQueryString {
private String itemId;
private String gcubeScope;
private String resolveAs;
private String targetApp;
/**
* Instantiates a new geoportal resolver query string.
@ -24,6 +25,7 @@ public class GeoportalResolverQueryString {
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;
}
@ -63,6 +65,15 @@ public class GeoportalResolverQueryString {
return resolveAs;
}
/**
* Gets the target app.
*
* @return the target app
*/
public String getTargetApp() {
return targetApp;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -74,6 +85,8 @@ public class GeoportalResolverQueryString {
builder.append(gcubeScope);
builder.append(", resolveAs=");
builder.append(resolveAs);
builder.append(", targetApp=");
builder.append(targetApp);
builder.append("]");
return builder.toString();
}

View File

@ -23,11 +23,13 @@ public final class GeoportalResolverQueryStringBuilder {
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.
@ -60,6 +62,51 @@ public final class GeoportalResolverQueryStringBuilder {
}
}
/**
* 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.
*
@ -93,6 +140,17 @@ public final class GeoportalResolverQueryStringBuilder {
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.
*
@ -120,10 +178,24 @@ public final class GeoportalResolverQueryStringBuilder {
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.
*
@ -153,6 +225,10 @@ public final class GeoportalResolverQueryStringBuilder {
query.put(RESOLVE_AS_PARAMETER, crQS.getResolveAs());
}
if(crQS.getTargetApp() != null) {
query.put(TARGET_APP_AS_PARAMETER, crQS.getTargetApp());
}
return query;
}

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -11,7 +11,7 @@ import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapExcept
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.junit.Test;
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.TARGET_GEOPORTAL_APP;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
@ -26,7 +26,7 @@ public class UriResolverManagerTest {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
manager = new UriResolverManager();
System.out.println("Capabiities: " + manager.getCapabilities());
System.out.println("Capabilities: " + manager.getCapabilities());
System.out.println("ApplicationTypes: " + manager.getApplicationTypes());
for (String applicationType : manager.getApplicationTypes()) {
Resolver resolver = manager.getResolver(applicationType);
@ -129,20 +129,21 @@ public class UriResolverManagerTest {
//@Test
public void testGeoportalCreateLink() {
public void testGeoportalCreateDataEntryLink() {
try {
ScopeProvider.instance.set("/gcube");
UriResolverManager resolver;
String gcubeScope = "/gcube/devsec/devVRE";
String itemId = "63d011c4dcac4551b9a6b930";
String scope = "/gcube/devsec/devVRE";
// String scope = "/pred4s/preprod/preVRE";
ScopeProvider.instance.set(scope);
String gcubeScope = scope;
String itemId = "6384aaac308f5c28c5ee0888";
String itemType = "profiledConcessioni";
resolver = new UriResolverManager("GEO");
UriResolverManager resolver = new UriResolverManager("GEO");
Map<String, String> params = null;
//Method 1
// Map<String, String> params = new HashMap<String, String>();
// 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);
@ -152,8 +153,50 @@ public class UriResolverManagerTest {
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);
Map<String, String> params = builder.buildQueryParameters();
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);