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 6330ce4..a8ba0fe 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java @@ -50,7 +50,7 @@ import org.slf4j.LoggerFactory; @Path("geoportal") public class GeoportalExporter { - private static final String PDF_CODE = "pdfCode"; + private static final String JOB_CODE = "jobCode"; public static final String EXPORT_TYPE = "type"; @@ -83,6 +83,7 @@ public class GeoportalExporter { * @param export_type the export type * @param ucdID the ucd ID * @param projectID the project ID + * @param asURL the as URL * @return the response * @throws WebApplicationException the web application exception */ @@ -96,7 +97,8 @@ public class GeoportalExporter { String userAgentName = req.getHeader("User-Agent"); LOG.info(this.getClass().getSimpleName() + " export - GET starts..."); - LOG.debug("params are: exportType: {}, ucdID: {}, projectID: {}", export_type, ucdID, projectID); + LOG.info("Params: [" + EXPORT_TYPE + ": {}, " + PATH_USECASE_ID + ": {}, " + PATH_PROJECT_ID + ": {}]", + export_type, ucdID, projectID); checkPathParameterNotNull(req, EXPORT_TYPE, export_type); checkPathParameterNotNull(req, PATH_USECASE_ID, ucdID); @@ -106,9 +108,10 @@ public class GeoportalExporter { try { getAsURL = Boolean.parseBoolean(asURL); } catch (Exception e) { - // TODO: handle exception } + LOG.info(QUERY_PARAMETER_AS_URL + "is: {}", export_type, ucdID, getAsURL); + checkExportType(req, export_type); boolean checked = false; @@ -143,18 +146,18 @@ public class GeoportalExporter { try { if (userAgentName != null) { LOG.info("Serving request as User-Agent {}", userAgentName); - final String pollingCode = ucdID + "_" + projectID + "_" + System.currentTimeMillis(); - final FetchPDF fetchPDF = new FetchPDF(null, pollingCode, 0); - map.put(pollingCode, fetchPDF); + final String jobCode = ucdID + "_" + projectID + "_" + System.currentTimeMillis(); + final FetchPDF fetchPDF = new FetchPDF(null, jobCode, 0); + map.put(jobCode, fetchPDF); try { Thread t = new Thread() { @Override public void run() { LOG.info("exportAsPDF called in thread..."); FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user); - LOG.info("exportAsPDF setFileRef in thread for code: " + pollingCode); + LOG.info("exportAsPDF setFileRef in thread for code: " + jobCode); fetchPDF.setFileRef(pdfRef); - map.put(pollingCode, fetchPDF); + map.put(jobCode, fetchPDF); } }; @@ -165,7 +168,7 @@ public class GeoportalExporter { } String serviceViewPDF_URL = String.format("%s/%s/view/%s", Util.getServerURL(req), "geoportal", - pollingCode); + jobCode); String entity = HTML_Page.entityHTMLMessage("Exporting as PDF...", "The project with id: " + projectID, true, serviceViewPDF_URL); @@ -177,7 +180,7 @@ public class GeoportalExporter { FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user); if (!getAsURL) { - //returning as stream + // returning as stream InputStream input = pdfRef.getStorageVolatileURL().openStream(); StreamingOutput so = new SingleFileStreamingOutput(input); @@ -186,8 +189,8 @@ public class GeoportalExporter { "inline; filename=\"" + pdfRef.getFileName() + "\"") .header("Content-Type", pdfRef.getContentType()); return response.build(); - }else { - //returning as URI; + } else { + // returning as URI; return Response.seeOther(pdfRef.getStorageVolatileURL().toURI()).build(); } } @@ -256,7 +259,7 @@ public class GeoportalExporter { } /** - * View PDF. + * View job. * * @param req the req * @param pdfCode the pdf code @@ -264,16 +267,16 @@ public class GeoportalExporter { * @throws WebApplicationException the web application exception */ @GET - @Path("/view/{pdfCode}") + @Path("/view/{jobCode}") @Produces({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML }) - public Response viewPDF(@Context HttpServletRequest req, @PathParam(PDF_CODE) String pdfCode) + public Response viewJob(@Context HttpServletRequest req, @PathParam(JOB_CODE) String pdfCode) throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " viewPDF - GET starts..."); - LOG.info("viewPDF param " + PDF_CODE + ": {}", pdfCode); + LOG.info("viewJob param " + JOB_CODE + ": {}", pdfCode); FetchPDF fetchedPDF = map.get(pdfCode); - LOG.info("viewPDF FileReference at code {} is {}", pdfCode, fetchedPDF); + LOG.info("viewJob FileReference at code {} is {}", pdfCode, fetchedPDF); String theURL = null; String messagge = null; @@ -293,7 +296,7 @@ public class GeoportalExporter { theJson.setMessage("No job found"); try { jsonReponse = mapper.writeValueAsString(theJson); - LOG.info("viewPDF returning not found: " + jsonReponse); + LOG.info("viewJob returning not found: " + jsonReponse); return Response.status(Status.NOT_FOUND).entity(jsonReponse).build(); } catch (JsonProcessingException e) { throw ExceptionManager.internalErrorException(req, "Error when returning " @@ -331,7 +334,7 @@ public class GeoportalExporter { theJson.setMessage(messagge); try { jsonReponse = mapper.writeValueAsString(theJson); - LOG.info("viewPDF returning OK: " + jsonReponse); + LOG.info("viewJob returning OK: " + jsonReponse); return Response.ok(jsonReponse).build(); } catch (JsonProcessingException e) { throw ExceptionManager.internalErrorException(req,