updated GeoportalExporter

This commit is contained in:
Francesco Mangiacrapa 2024-04-22 12:30:49 +02:00
parent e382719f30
commit f3ccc3b134
2 changed files with 17 additions and 12 deletions

View File

@ -57,7 +57,7 @@ public class HTML_Page {
+ " }\n"
+ " }\n"
+ " async function playPDFPoll() {\n"
+ " let response_object = await fetchPDF_URL();\n"
+ " const response_object = await fetchPDF_URL();\n"
+ " let isJsonResponse = isJsonString(response_object);\n"
+ " if (isJsonResponse) {\n"
+ " console.log(\"json response \" + response_object);\n"

View File

@ -32,6 +32,7 @@ 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.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -173,8 +174,8 @@ public class GeoportalExporter {
this.getClass(), helpURI);
}
} else {
return Response.status(Status.NOT_FOUND)
.entity(GeoportalExporter.class.getSimpleName()
return Response
.status(Status.NOT_FOUND).entity(GeoportalExporter.class.getSimpleName()
+ "seems to be not configured in the context: " + context)
.type(MediaType.TEXT_PLAIN).build();
}
@ -230,16 +231,19 @@ public class GeoportalExporter {
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " viewPDF - GET starts...");
LOG.info("param " + PDF_CODE + ": {}", pdfCode);
LOG.info("viewPDF param " + PDF_CODE + ": {}", pdfCode);
FetchPDF fetchedPDF = map.get(pdfCode);
LOG.info("FileReference at code {} is {}", pdfCode, fetchedPDF);
LOG.info("viewPDF FileReference at code {} is {}", pdfCode, fetchedPDF);
JSONObject theJson = new JSONObject();
theJson.put("state", Status.NOT_FOUND.toString());
theJson.put("url", "");
if (fetchedPDF == null) {
LOG.info("returning not found");
return Response.status(Status.NOT_FOUND)
.entity(HTML_Page.getErrorPage("Job not created", "No job found with id " + pdfCode))
.type(MediaType.TEXT_HTML).build();
String json = theJson.toString();
LOG.info("viewPDF returning not found: "+json);
return Response.status(Status.OK).entity(json).build();
}
try {
@ -263,9 +267,10 @@ public class GeoportalExporter {
map.put(pdfCode, null);
}
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("url", theURL);
String json = jsonObject.toString();
theJson.put("state", "OK");
theJson.put("url", theURL);
String json = theJson.toString();
LOG.info("viewPDF returning OK: "+json);
return Response.ok(json).build();
} catch (Exception e) {