updated view

This commit is contained in:
Francesco Mangiacrapa 2024-04-19 16:42:17 +02:00
parent 1f2baf3ef7
commit af05c03cef
1 changed files with 33 additions and 17 deletions

View File

@ -31,6 +31,7 @@ import org.gcube.datatransfer.resolver.geoportal.exporter.HTML_Page;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException;
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
import org.gcube.datatransfer.resolver.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -110,10 +111,11 @@ public class GeoportalExporter {
if (userAgentName != null) {
LOG.info("Serving request as User-Agent {}", userAgentName);
final String pollingCode = ucdID + "_" + projectID + "_" + System.currentTimeMillis();
String viewPdfURL = req.getServletPath() + "/view/" + pollingCode;
String serviceViewPDF_URL = String.format("%s/%s/view/%s", Util.getServerURL(req),
req.getContextPath(), pollingCode);
String entity = HTML_Page.entityHTMLMessage("Exporting as PDF...",
"The project with id: " + projectID, true, viewPdfURL);
"The project with id: " + projectID, true, serviceViewPDF_URL);
try {
Thread t = new Thread() {
@ -220,22 +222,36 @@ public class GeoportalExporter {
try {
JsonObject jsonObject = new JsonObject();
FetchPDF fetchedPDF = map.get(pdfCode);
LOG.info("FileReference at code {} is {}", pdfCode, fetchedPDF.getFileRef());
String theURL = null;
if (fetchedPDF.getFileRef()==null) {
fetchedPDF.incrementAttempt();
if(fetchedPDF.getMAX_RETRY()<fetchedPDF.getAttempt()) {
theURL = null;
}else {
theURL = HTML_Page.getErrorPage("Geoportal Error", "Sorry, an error occurred tryng to create the PDF");
}
}else {
theURL = fetchedPDF.getFileRef().getStorageVolatileURL().toString();
}
map.put(pdfCode, fetchedPDF);
LOG.info("FileReference at code {} is {}", pdfCode, fetchedPDF);
if (fetchedPDF == null) {
throw ExceptionManager.notFoundException(req,
GeoportalExporter.class.getSimpleName() + " view with task code " + pdfCode + "not found",
this.getClass(), helpURI);
}
String theURL = null;
// File PDF is not available
if (fetchedPDF.getFileRef() == null) {
fetchedPDF.incrementAttempt();
if (fetchedPDF.getMAX_RETRY() < fetchedPDF.getAttempt()) {
theURL = null;
} else {
theURL = HTML_Page.getErrorPage("Geoportal Error",
"Sorry, an error occurred tryng to create the PDF");
}
// updating map status
map.put(pdfCode, fetchedPDF);
} else {
// File PDF is available
theURL = fetchedPDF.getFileRef().getStorageVolatileURL().toString();
// removing from map
map.put(pdfCode, null);
}
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("url", theURL);
String json = jsonObject.toString();
return Response.ok(json).build();