fixed json response
This commit is contained in:
parent
c61bac50ed
commit
9ec1dcf9a0
|
@ -5,9 +5,8 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
public class GeoportalViewJsonResponse {
|
public class GeoportalViewJsonResponse {
|
||||||
|
|
||||||
//State cona be "OK" or "ERROR"
|
//State can be "OK" or "ERROR"
|
||||||
String state;
|
String state;
|
||||||
String url;
|
String url;
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences.SHAR
|
||||||
import org.gcube.application.geoportaldatamapper.exporter.Geoportal_PDF_Exporter;
|
import org.gcube.application.geoportaldatamapper.exporter.Geoportal_PDF_Exporter;
|
||||||
import org.gcube.application.geoportaldatamapper.shared.ExporterProjectSource;
|
import org.gcube.application.geoportaldatamapper.shared.ExporterProjectSource;
|
||||||
import org.gcube.application.geoportaldatamapper.shared.FileReference;
|
import org.gcube.application.geoportaldatamapper.shared.FileReference;
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||||
import org.gcube.common.authorization.utils.user.User;
|
import org.gcube.common.authorization.utils.user.User;
|
||||||
|
@ -33,12 +35,9 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException;
|
import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException;
|
||||||
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
||||||
import org.gcube.datatransfer.resolver.util.Util;
|
import org.gcube.datatransfer.resolver.util.Util;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GeoportalExporter.
|
* The Class GeoportalExporter.
|
||||||
*
|
*
|
||||||
|
@ -246,12 +245,23 @@ public class GeoportalExporter {
|
||||||
theJson.setUrl(theURL);
|
theJson.setUrl(theURL);
|
||||||
theJson.setMessage(messagge);
|
theJson.setMessage(messagge);
|
||||||
|
|
||||||
|
String jsonReponse = null;
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
if (fetchedPDF == null) {
|
if (fetchedPDF == null) {
|
||||||
theJson.setState(Status.NOT_FOUND.getReasonPhrase());
|
theJson.setState(Status.NOT_FOUND.getReasonPhrase());
|
||||||
theJson.setMessage("No job found");
|
theJson.setMessage("No job found");
|
||||||
String json = theJson.toString();
|
try {
|
||||||
LOG.info("viewPDF returning not found: " + json);
|
jsonReponse = mapper.writeValueAsString(theJson);
|
||||||
return Response.status(Status.NOT_FOUND).entity(json).build();
|
LOG.info("viewPDF returning not found: " + jsonReponse);
|
||||||
|
return Response.status(Status.NOT_FOUND).entity(jsonReponse).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw ExceptionManager.internalErrorException(req, "Error when returning "
|
||||||
|
+ GeoportalExporter.class.getSimpleName() + " not found job for " + pdfCode, this.getClass(),
|
||||||
|
helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -265,7 +275,6 @@ public class GeoportalExporter {
|
||||||
state = "ERROR";
|
state = "ERROR";
|
||||||
messagge = "Sorry, an error occurred tryng to create the PDF. Max retries reached";
|
messagge = "Sorry, an error occurred tryng to create the PDF. Max retries reached";
|
||||||
theJson.setState(state);
|
theJson.setState(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
// updating map status
|
// updating map status
|
||||||
map.put(pdfCode, fetchedPDF);
|
map.put(pdfCode, fetchedPDF);
|
||||||
|
@ -281,9 +290,15 @@ public class GeoportalExporter {
|
||||||
theJson.setState(state);
|
theJson.setState(state);
|
||||||
theJson.setUrl(theURL);
|
theJson.setUrl(theURL);
|
||||||
theJson.setMessage(messagge);
|
theJson.setMessage(messagge);
|
||||||
String json = theJson.toString();
|
try {
|
||||||
LOG.info("viewPDF returning OK: " + json);
|
jsonReponse = mapper.writeValueAsString(theJson);
|
||||||
return Response.ok(json).build();
|
LOG.info("viewPDF returning OK: " + jsonReponse);
|
||||||
|
return Response.ok(jsonReponse).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw ExceptionManager.internalErrorException(req,
|
||||||
|
"Error when returning " + GeoportalExporter.class.getSimpleName() + " response for " + pdfCode,
|
||||||
|
this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error on checking job", e);
|
LOG.error("Error on checking job", e);
|
||||||
|
|
Loading…
Reference in New Issue