renamed viewPDF to viewJob

This commit is contained in:
Francesco Mangiacrapa 2024-04-22 17:29:11 +02:00
parent dc3ea29ff3
commit 0263fd2235
1 changed files with 22 additions and 19 deletions

View File

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