diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 3d2a413..f98fdce 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,9 @@ - + + + + + @@ -21,7 +25,11 @@ - + + + + + @@ -43,7 +51,11 @@ - + + + + + @@ -65,7 +77,11 @@ - + + + + + @@ -87,7 +103,11 @@ - + + + + + @@ -109,10 +129,20 @@ - + uses - + + uses + + + uses + + + + + + @@ -134,7 +164,11 @@ - + + + + + @@ -156,7 +190,11 @@ - + + + + + @@ -178,7 +216,11 @@ - + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index ddbad01..60c2135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v2.10.0-SNAPSHOT] -- GeoPortal-Resolver enhancement: share link towards Geoportal Data-Entry facility implemented [#27135] +- GeoPortal-Resolver enhancement: implemented share link towards Geoportal Data-Entry facility [#27135] +- Added Geoportal Exporter as PDF [#26026] ## [v2.9.0] diff --git a/pom.xml b/pom.xml index 3546e52..b86f958 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.gcube.distribution gcube-smartgears-bom - 2.4.0 + 2.5.0 pom import @@ -76,7 +76,7 @@ org.gcube.data-publishing storagehub-application-persistence - [1.0.0, 2.0.0-SNAPSHOT) + [1.0.0, 3.0.0-SNAPSHOT) org.gcube.common @@ -98,6 +98,12 @@ [1.0.0,2.0.0-SNAPSHOT) + + org.gcube.common + authorization-utils + [2.0.0, 3.0.0-SNAPSHOT) + + com.google.guava guava @@ -123,7 +129,6 @@ org.gcube.common storagehub-client-library - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) @@ -250,6 +255,25 @@ + + org.gcube.application + geoportal-data-mapper + [1.0.0, 2.0.0-SNAPSHOT) + + + + org.gcube.contentmanagement + storage-manager-wrapper + + + org.gcube.contentmanagement + storage-manager-core + + + compile + + org.slf4j slf4j-api diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java new file mode 100644 index 0000000..9061f43 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java @@ -0,0 +1,248 @@ +package org.gcube.datatransfer.resolver.services; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.gcube.application.geoportaldatamapper.exporter.Geoportal_PDF_Exporter; +import org.gcube.application.geoportaldatamapper.shared.ExporterProjectSource; +import org.gcube.common.authorization.utils.manager.SecretManager; +import org.gcube.common.authorization.utils.manager.SecretManagerProvider; +import org.gcube.datatransfer.resolver.ConstantsResolver; +import org.gcube.datatransfer.resolver.geoportal.TargetAppGeoportalCodes; +import org.gcube.datatransfer.resolver.services.GeoportalResolver.RESOLVE_AS; +import org.gcube.datatransfer.resolver.services.error.ExceptionManager; +import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class GeoportalExporter. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Apr 16, 2024 + */ +@Path("/geoportal") +public class GeoportalExporter { + + public static final String EXPORT_TYPE = "type"; + + public static final String PATH_PROJECT_ID = GeoportalResolver.PATH_PROJECT_ID; + public static final String PATH_USECASE_ID = GeoportalResolver.PATH_USECASE_ID; + public static final String PATH_VRE_NAME = GeoportalResolver.PATH_VRE_NAME; + + private static final Logger LOG = LoggerFactory.getLogger(GeoportalExporter.class); + private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; + + public enum ACCEPTED_EXPORT_TYPE { + pdf + } + + /** + * Resolve geoportal no app def. + * + * @param req the req + * @param vreName the vre name + * @param exportType the export type + * @param ucdID the ucd ID + * @param projectID the project ID + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path("/export/{type}/{usecase_id}/{project_id}") + public Response export(@Context HttpServletRequest req, @PathParam(EXPORT_TYPE) String export_type, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID) + throws WebApplicationException { + + LOG.info(this.getClass().getSimpleName() + " export - GET starts..."); + LOG.debug("params are: exportType: {}, ucdID: {}, projectID: {}", export_type, ucdID, projectID); + + checkPathParameterNotNull(req, EXPORT_TYPE, export_type); + checkPathParameterNotNull(req, PATH_USECASE_ID, ucdID); + checkPathParameterNotNull(req, PATH_PROJECT_ID, projectID); + + ACCEPTED_EXPORT_TYPE exportType = toKnowExportType(req, export_type); + + try { + + SecretManager cm = SecretManagerProvider.instance.get(); + String context = cm.getContext(); + if (context == null) { + throw ExceptionManager.forbiddenException(req, "Cannot determine context (the scope)", this.getClass(), + helpURI); + } + org.gcube.common.authorization.utils.user.User user = cm.getUser(); + LOG.info("Identified caller {} in context {}", user.getUsername(), context); + + Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter(); + boolean checked = pdfExporter.checkConfig(); + + if (!checked) + return Response.status(Status.NOT_FOUND).build(); + + ExporterProjectSource exporterSource = new ExporterProjectSource(); + RESOLVE_AS resolveAs = RESOLVE_AS.PUBLIC; + // #NB SET USERNAME = null to export with PUBLIC ACCESS + if (!cm.getUser().isApplication()) { + // here the token is of an user + resolveAs = RESOLVE_AS.PRIVATE; + exporterSource.setAccountname(user.getUsername()); + } + + exporterSource.setScope(context); + exporterSource.setProjectID(projectID); + exporterSource.setProfileID(ucdID); + + String vreName = context.substring(context.lastIndexOf("/") + 1, context.length()); + LOG.info("Requesting gis link to vre {}", vreName); + Response theReponseWithLink = new GeoportalResolver().genericResolveLink(req, + TargetAppGeoportalCodes.GEO_DV, vreName, ucdID, projectID, resolveAs.name()); + String theGisLink = theReponseWithLink.getEntity().toString(); + LOG.info("Gis link returned {}", theGisLink); + exporterSource.setGisLink(theGisLink); + + if (checked) { + String entity = entityHTMLMessage("Exporting as PDF...", "The project with " + projectID, true); + return Response.ok(entity).encoding("UTF-8").header(ConstantsResolver.CONTENT_TYPE, "text/html") + .build(); + } else { + return Response.status(Status.NOT_FOUND).entity(GeoportalExporter.class.getSimpleName() + " Config KO") + .type(MediaType.TEXT_PLAIN).build(); + } + + } catch (Exception e) { + LOG.error("Error on performing healthcheck", e); + throw ExceptionManager.internalErrorException(req, + "Error when performing " + GeoportalExporter.class.getSimpleName() + " healthcheck", + this.getClass(), helpURI); + } + + } + + @GET + @Path("/export/{type}/healthcheck") + public Response healthcheck(@Context HttpServletRequest req, @PathParam(EXPORT_TYPE) String export_type) + throws WebApplicationException { + + LOG.info(this.getClass().getSimpleName() + " healthcheck - GET starts..."); + LOG.debug("param is: exportType: {}", export_type); + + checkPathParameterNotNull(req, EXPORT_TYPE, export_type); + + ACCEPTED_EXPORT_TYPE exportType = toKnowExportType(req, export_type); + + try { + + SecretManager cm = SecretManagerProvider.instance.get(); + String context = cm.getContext(); + if (context == null) { + throw ExceptionManager.forbiddenException(req, "Cannot determine context (the scope)", this.getClass(), + helpURI); + } + org.gcube.common.authorization.utils.user.User user = cm.getUser(); + LOG.info("Identified caller {} in context {}", user.getUsername(), context); + +// Set roles = new HashSet<>(); +// roles.addAll(user.getRoles()); + + Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter(); + boolean checked = pdfExporter.checkConfig(); + + if (checked) { + return Response.ok(GeoportalExporter.class.getSimpleName() + " Config OK").build(); + } else { + return Response.status(Status.NOT_FOUND).entity(GeoportalExporter.class.getSimpleName() + " Config KO") + .type(MediaType.TEXT_PLAIN).build(); + } + + } catch (Exception e) { + LOG.error("Error on performing healthcheck", e); + throw ExceptionManager.internalErrorException(req, + "Error when performing " + GeoportalExporter.class.getSimpleName() + " healthcheck", + this.getClass(), helpURI); + } + } + + public void checkPathParameterNotNull(HttpServletRequest req, String parameter, String value) + throws BadRequestException { + if (value == null || value.isEmpty()) { + LOG.error("The path parameter {} not found or empty in the path", parameter); + throw ExceptionManager.badRequestException(req, + "Mandatory path parameter " + parameter + " not found or empty", this.getClass(), helpURI); + } + } + + public ACCEPTED_EXPORT_TYPE toKnowExportType(HttpServletRequest req, String export_type) + throws BadRequestException { + ACCEPTED_EXPORT_TYPE exportType; + try { + exportType = ACCEPTED_EXPORT_TYPE.valueOf(export_type); + } catch (Exception e) { + throw ExceptionManager + .wrongParameterException(req, + "The path parameter " + EXPORT_TYPE + " has a bad value: " + export_type + + ". It must be value of " + ACCEPTED_EXPORT_TYPE.values(), + this.getClass(), helpURI); + } + + return exportType; + } + + /** + * Sets the HTML message. + * + * @param action the action + * @param message the message + * @param waiting the waiting + * @return the string + */ + protected String entityHTMLMessage(String action, String message, boolean waiting) { + + String html = "" + "" + "" + + "" + + "D4Science Geoportal - Action" + "" + ""; + + + html += "\"D4Science
"; + + html += "
"; + html += "

" + action + "

"; + + if (waiting) { + html += "\"D4Science
"; + } + + html += "

" + message + "

"; + html += "
"; + + return html; + } + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 4548385..e063e7b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -54,11 +54,11 @@ public class GeoportalResolver { public static final String GEO = "geo"; // geoportal public static final String GEO_DV = "dv"; // data-viewer - private static final String QP_RESOLVE_AS = "res"; - private static final String PATH_PROJECT_ID = "project_id"; - private static final String PATH_USECASE_ID = "usecase_id"; - private static final String PATH_VRE_NAME = "vre_name"; - private static final String PATH_TARGET_APP = "targetAppId"; + public static final String QP_RESOLVE_AS = "res"; + public static final String PATH_PROJECT_ID = "project_id"; + public static final String PATH_USECASE_ID = "usecase_id"; + public static final String PATH_VRE_NAME = "vre_name"; + public static final String PATH_TARGET_APP = "targetAppId"; private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class); private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; @@ -70,7 +70,7 @@ public class GeoportalResolver { * * Mar 24, 2023 */ - private static enum RESOLVE_AS { + public static enum RESOLVE_AS { PUBLIC, PRIVATE } diff --git a/src/main/webapp/WEB-INF/gcube-app.xml b/src/main/webapp/WEB-INF/gcube-app.xml index fe2bdfd..a8d3fb2 100644 --- a/src/main/webapp/WEB-INF/gcube-app.xml +++ b/src/main/webapp/WEB-INF/gcube-app.xml @@ -7,4 +7,5 @@ /knime/create/* /wekeo/gettoken/* /oat/get/* + /geoportal/export/* \ No newline at end of file diff --git a/src/main/webapp/img/loading-gears.gif b/src/main/webapp/img/loading-gears.gif new file mode 100644 index 0000000..682a20d Binary files /dev/null and b/src/main/webapp/img/loading-gears.gif differ diff --git a/src/test/java/gis/SE_Harvester_from_IS.java b/src/test/java/gis/SE_Harvester_from_IS.java index b6eec61..74434d4 100644 --- a/src/test/java/gis/SE_Harvester_from_IS.java +++ b/src/test/java/gis/SE_Harvester_from_IS.java @@ -22,8 +22,6 @@ import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; import org.gcube.spatial.data.geonetwork.LoginLevel; import org.junit.Test; -import com.itextpdf.text.log.SysoCounter; - /** * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 10, 2017