From df64963bc38b3cedd6e3d19b324da358083a31f3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 19 Apr 2024 12:42:20 +0200 Subject: [PATCH] added user agent check --- .../resolver/services/GeoportalExporter.java | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java index bd9a15c..81abda1 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java @@ -98,35 +98,13 @@ public class GeoportalExporter { Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter(); boolean checked = pdfExporter.checkConfig(); -// 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 pdfURL = null; -// if (userAgentName != null) { -// LOG.info("Serving request as User-Agent {}", userAgentName); -// 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 { + if (userAgentName != null) { + LOG.info("Serving request as User-Agent {}", userAgentName); + 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 { LOG.info("Serving request as client..."); FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user); @@ -138,7 +116,7 @@ public class GeoportalExporter { "inline; filename=\"" + pdfRef.getFileName() + "\"") .header("Content-Type", pdfRef.getContentType()); return response.build(); -// } + } } else { return Response.status(Status.NOT_FOUND) .entity(GeoportalExporter.class.getSimpleName() + " Config not found in the context " + context)