diff --git a/.classpath b/.classpath
index d346edf..11f9a7f 100644
--- a/.classpath
+++ b/.classpath
@@ -25,11 +25,11 @@
+
-
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index cac0df4..ca4c66e 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e010660..ee47404 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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]
diff --git a/pom.xml b/pom.xml
index db68757..f977f01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,14 +4,14 @@
maven-parent
org.gcube.tools
- 1.1.0
+ 1.2.0
4.0.0
org.gcube.portlets.user
uri-resolver-manager
- 1.7.0
+ 1.8.0-SNAPSHOT
jar
uri-resolver-manager
The URI Resolver Manager
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java
index fde1b90..a577473 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java
@@ -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.
*
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/entity/Resolver.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/entity/Resolver.java
index a14a426..ba9f750 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/entity/Resolver.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/entity/Resolver.java
@@ -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.
*
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/geoportal/GeoportalExporterAPI.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/geoportal/GeoportalExporterAPI.java
new file mode 100644
index 0000000..065093d
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/geoportal/GeoportalExporterAPI.java
@@ -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);
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/geoportal/GeoportalExporterEndpoint.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/geoportal/GeoportalExporterEndpoint.java
new file mode 100644
index 0000000..5b56a5e
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/geoportal/GeoportalExporterEndpoint.java
@@ -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);
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/RuntimeResourceReader.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/RuntimeResourceReader.java
index f8ff10e..4846598 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/RuntimeResourceReader.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/RuntimeResourceReader.java
@@ -92,21 +92,18 @@ public class RuntimeResourceReader {
while (acIt.hasNext()) {
AccessPoint ap = acIt.next();
-
Group 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 serviceParameters = new ArrayList(properties.size());
-
Iterator iter = properties.iterator();
while (iter.hasNext()) {
-
Property prop = iter.next();
-
serviceParameters.add(new ServiceParameter(prop.value(), true));
}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java
index 0a02321..68f1036 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java
@@ -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);
}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/CatalogueResolverCallBuilder.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/CatalogueResolver.java
similarity index 70%
rename from src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/CatalogueResolverCallBuilder.java
rename to src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/CatalogueResolver.java
index aef6eb8..24c5553 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/CatalogueResolverCallBuilder.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/CatalogueResolver.java
@@ -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 {
@@ -115,7 +115,7 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
/**
* Short link.
*
- * @param theLink the the link
+ * @param theLink the the link
* @param parameters the parameters
* @return the string
* @throws Exception the exception
@@ -125,32 +125,18 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
LOG.info("specific shortLink called");
String linkDecoded = theLink;
-
+
String[] queryStringArray = theLink.split("\\?");
- if(queryStringArray.length>1) {
+ 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);
+ 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.
*
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/GeoportalResolverCallBuilder.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/GeoportalResolver.java
similarity index 80%
rename from src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/GeoportalResolverCallBuilder.java
rename to src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/GeoportalResolver.java
index c919c43..abc5ba9 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/GeoportalResolverCallBuilder.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/GeoportalResolver.java
@@ -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");
@@ -69,12 +87,7 @@ public class GeoportalResolverCallBuilder extends GenericResolver {
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;
@@ -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 {
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/SHUBResolverCallBuilder.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/SHUBResolver.java
similarity index 77%
rename from src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/SHUBResolverCallBuilder.java
rename to src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/SHUBResolver.java
index c204bc4..acb187a 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/SHUBResolverCallBuilder.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/SHUBResolver.java
@@ -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);
}
@@ -38,7 +38,7 @@ public class SHUBResolverCallBuilder extends GenericResolver {
*/
@Override
public String getLink(String baseURI, Map parameters) throws Exception {
- LOG.debug("called getLink: " + baseURI + " parameters: "+parameters);
+ LOG.debug("called getLink: " + baseURI + " parameters: " + parameters);
String toReturn = null;
try {
@@ -48,14 +48,14 @@ public class SHUBResolverCallBuilder extends GenericResolver {
pathURI = String.format("%s/%s", pathURI, idValue);
parameters.remove("id");
}
-
+
toReturn = pathURI;
String queryString = UrlEncoderUtil.encodeQuery(parameters);
- if(!queryString.isEmpty())
+ if (!queryString.isEmpty())
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);
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryString.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryString.java
index 45d1040..8260941 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryString.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryString.java
@@ -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();
}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryStringBuilder.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryStringBuilder.java
index 4177c30..b8f2433 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryStringBuilder.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/resolvers/query/GeoportalResolverQueryStringBuilder.java
@@ -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.
*
@@ -152,6 +224,10 @@ public final class GeoportalResolverQueryStringBuilder {
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;
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/URLShortenerUtil.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/URLShortenerUtil.java
new file mode 100644
index 0000000..9b2e50f
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/URLShortenerUtil.java
@@ -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;
+ }
+}
diff --git a/src/test/java/GeoportalExporterTest.java b/src/test/java/GeoportalExporterTest.java
new file mode 100644
index 0000000..412d1e0
--- /dev/null
+++ b/src/test/java/GeoportalExporterTest.java
@@ -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();
+ }
+
+ }
+}
diff --git a/src/test/java/UriResolverManagerTest.java b/src/test/java/UriResolverManagerTest.java
index e1f1a63..5f9b976 100644
--- a/src/test/java/UriResolverManagerTest.java
+++ b/src/test/java/UriResolverManagerTest.java
@@ -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);
@@ -47,7 +47,7 @@ public class UriResolverManagerTest {
}
- // @Test
+ //@Test
public void testCTLG() {
try {
@@ -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 params = null;
//Method 1
-// Map params = new HashMap();
+// params = new HashMap();
// 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.resolverAs(RESOLVE_AS.PRIVATE);
- Map params = builder.buildQueryParameters();
+ 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 params = null;
+
+ //Method 1
+// params = new HashMap();
+// 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);