updated healthcheck and GeoportalJsonResponse
This commit is contained in:
parent
40f417c90b
commit
8d46d0610b
|
@ -3,7 +3,7 @@ package org.gcube.datatransfer.resolver.geoportal.exporter;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GeoportalViewJsonResponse {
|
||||
public class GeoportalJsonResponse {
|
||||
|
||||
//State can be "OK" or "ERROR"
|
||||
String state;
|
|
@ -31,7 +31,7 @@ import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
|||
import org.gcube.common.authorization.utils.user.User;
|
||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
||||
import org.gcube.datatransfer.resolver.geoportal.exporter.FetchPDF;
|
||||
import org.gcube.datatransfer.resolver.geoportal.exporter.GeoportalViewJsonResponse;
|
||||
import org.gcube.datatransfer.resolver.geoportal.exporter.GeoportalJsonResponse;
|
||||
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;
|
||||
|
@ -218,7 +218,7 @@ public class GeoportalExporter {
|
|||
*/
|
||||
@GET
|
||||
@Path("/export/{type}/healthcheck")
|
||||
@Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
|
||||
@Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
public Response healthcheck(@Context HttpServletRequest req, @PathParam(EXPORT_TYPE) String export_type)
|
||||
throws WebApplicationException {
|
||||
|
||||
|
@ -242,12 +242,18 @@ public class GeoportalExporter {
|
|||
|
||||
Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter();
|
||||
boolean checked = pdfExporter.checkConfig();
|
||||
|
||||
GeoportalJsonResponse theJson = new GeoportalJsonResponse();
|
||||
if (checked) {
|
||||
return Response.ok(GeoportalExporter.class.getSimpleName() + " Config OK").build();
|
||||
theJson.setState("OK");
|
||||
theJson.setMessage(GeoportalExporter.class.getSimpleName() + " Config OK in the context: " + context);
|
||||
String jsonResponse = responseToString(theJson);
|
||||
return Response.ok(jsonResponse).type(MediaType.APPLICATION_JSON).build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).entity(GeoportalExporter.class.getSimpleName() + " Config KO")
|
||||
.type(MediaType.TEXT_PLAIN).build();
|
||||
theJson.setState("KO");
|
||||
theJson.setMessage(GeoportalExporter.class.getSimpleName() + " Config "
|
||||
+ Status.NOT_FOUND.getReasonPhrase() + " in the context: " + context);
|
||||
String jsonResponse = responseToString(theJson);
|
||||
return Response.status(Status.NOT_FOUND).entity(jsonResponse).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -268,7 +274,7 @@ public class GeoportalExporter {
|
|||
*/
|
||||
@GET
|
||||
@Path("/view/{jobCode}")
|
||||
@Produces({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML })
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
|
||||
public Response viewJob(@Context HttpServletRequest req, @PathParam(JOB_CODE) String jobCode)
|
||||
throws WebApplicationException {
|
||||
|
||||
|
@ -282,20 +288,18 @@ public class GeoportalExporter {
|
|||
String messagge = null;
|
||||
String state = null;
|
||||
|
||||
GeoportalViewJsonResponse theJson = new GeoportalViewJsonResponse();
|
||||
GeoportalJsonResponse theJson = new GeoportalJsonResponse();
|
||||
theJson.setState(state);
|
||||
theJson.setUrl(theURL);
|
||||
theJson.setMessage(messagge);
|
||||
|
||||
String jsonReponse = null;
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
if (fetchedPDF == null) {
|
||||
theJson.setState(Status.NOT_FOUND.getReasonPhrase());
|
||||
theJson.setMessage("No job found");
|
||||
try {
|
||||
jsonReponse = mapper.writeValueAsString(theJson);
|
||||
jsonReponse = responseToString(theJson);
|
||||
LOG.info("viewJob returning not found: " + jsonReponse);
|
||||
return Response.status(Status.NOT_FOUND).entity(jsonReponse).build();
|
||||
} catch (JsonProcessingException e) {
|
||||
|
@ -333,7 +337,7 @@ public class GeoportalExporter {
|
|||
theJson.setUrl(theURL);
|
||||
theJson.setMessage(messagge);
|
||||
try {
|
||||
jsonReponse = mapper.writeValueAsString(theJson);
|
||||
jsonReponse = responseToString(theJson);
|
||||
LOG.info("viewJob returning OK: " + jsonReponse);
|
||||
return Response.ok(jsonReponse).build();
|
||||
} catch (JsonProcessingException e) {
|
||||
|
@ -351,6 +355,11 @@ public class GeoportalExporter {
|
|||
|
||||
}
|
||||
|
||||
public String responseToString(GeoportalJsonResponse jsonResponse) throws JsonProcessingException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString(jsonResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check path parameter not null.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue