- Implementing Geoportal Exporter as PDF [#26026]

This commit is contained in:
Francesco Mangiacrapa 2024-04-18 17:03:16 +02:00
parent a63f3bbfaf
commit 62fd269a86
8 changed files with 336 additions and 22 deletions

View File

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -21,7 +25,11 @@
<wb-module deploy-name="uri-resolver-2.10.0-SNAPSHOT">
@ -43,7 +51,11 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -65,7 +77,11 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -87,7 +103,11 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -109,10 +129,20 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="uri-resolver-manager-1.8.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/uri-resolver-manager/uri-resolver-manager">
<dependent-module archiveName="geoportal-data-mapper-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-mapper/geoportal-data-mapper">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="geoportal-client-1.2.2-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-client/geoportal-client">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="geoportal-common-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-common/geoportal-common">
<dependency-type>uses</dependency-type>
</dependent-module>
@ -134,7 +164,11 @@
<property name="context-root" value="uri-resolver"/>
@ -156,7 +190,11 @@
<property name="java-output-path" value="/uri-resolver/target/classes"/>
@ -178,7 +216,11 @@
</wb-module>

View File

@ -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]

30
pom.xml
View File

@ -31,7 +31,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId>
<version>2.4.0</version>
<version>2.5.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -76,7 +76,7 @@
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<artifactId>storagehub-application-persistence</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
<version>[1.0.0, 3.0.0-SNAPSHOT)</version>
<exclusions>
<exclusion>
<groupId>org.gcube.common</groupId>
@ -98,6 +98,12 @@
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
@ -123,7 +129,6 @@
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
@ -250,6 +255,25 @@
<!-- END GIS RESOLVER DEPENDENCIES -->
<dependency>
<groupId>org.gcube.application</groupId>
<artifactId>geoportal-data-mapper</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
<!-- Excluding these beacuse geoportal uses [2-3] ranges conflicting with
[3-4] used by URI-Resovler -->
<exclusions>
<exclusion>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
</exclusion>
<exclusion>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

View File

@ -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<String> 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 = "<html>" + "<head>" + "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"
+ "<style>"
+ "html, body {\n"
+ " margin: 10px;\n"
+ " width: 100%;\n"
+ " height: 100%;\n"
+ " display: table\n"
+ "}\n"
+ "#content {\n"
+ " position: absolute;\n"
+ " left: 50%;\n"
+ " top: 50%;\n"
+ " -webkit-transform: translate(-50%, -50%);\n"
+ " transform: translate(-50%, -50%);\n"
+ " text-align: center;\n"
+ "}"
+ "#message {\n"
+ " color:gray;"
+ " font-size: 24px;"
+ "}"
+ "</style>"
+ "<title>D4Science Geoportal - Action</title>" + "</head>" + "<body>";
html += "<img alt=\"D4Science Logo\" src=\"https://services.d4science.org/image/layout_set_logo?img_id=32727\"><br />";
html += "<div id=\"content\">";
html += "<p style=\"font-size: 18px;\">" + action + "</p>";
if (waiting) {
html += "<img alt=\"D4Science Geoportal Loading...\" src=\"img/loading-gears.gif\"><br />";
}
html += "<br/><p id=\"message\">" + message + "</p>";
html += "</div></body></html>";
return html;
}
}

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

View File

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