export_to_pdf #8
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -14,7 +15,6 @@ import javax.ws.rs.WebApplicationException;
|
|||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
|
||||
|
@ -97,8 +97,8 @@ public class GeoportalExporter {
|
|||
String userAgentName = req.getHeader("User-Agent");
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " export - GET starts...");
|
||||
LOG.info("Params: [" + EXPORT_TYPE + ": {}, " + PATH_USECASE_ID + ": {}, " + PATH_PROJECT_ID + ": {}, " + QUERY_PARAMETER_AS_URL + ": {}]",
|
||||
export_type, ucdID, projectID, asURL);
|
||||
LOG.info("Params: [" + EXPORT_TYPE + ": {}, " + PATH_USECASE_ID + ": {}, " + PATH_PROJECT_ID + ": {}, "
|
||||
+ QUERY_PARAMETER_AS_URL + ": {}]", export_type, ucdID, projectID, asURL);
|
||||
|
||||
checkPathParameterNotNull(req, EXPORT_TYPE, export_type);
|
||||
checkPathParameterNotNull(req, PATH_USECASE_ID, ucdID);
|
||||
|
@ -141,8 +141,20 @@ public class GeoportalExporter {
|
|||
+ " seems to be not configured in the context: " + context,
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
if (checked) {
|
||||
|
||||
if (getAsURL) {
|
||||
try {
|
||||
LOG.info("Serving request as getAsURL...");
|
||||
FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user);
|
||||
return Response.ok(pdfRef.getStorageVolatileURL().toURI()).build();
|
||||
} catch (URISyntaxException e) {
|
||||
LOG.error("Error on performing export by url", e);
|
||||
throw ExceptionManager.internalErrorException(req,
|
||||
"Sorry, error occurred when generating the project URL", this.getClass(), helpURI);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (userAgentName != null) {
|
||||
LOG.info("Serving request as User-Agent {}", userAgentName);
|
||||
|
@ -178,21 +190,15 @@ public class GeoportalExporter {
|
|||
} else {
|
||||
LOG.info("Serving request as client...");
|
||||
FileReference pdfRef = exportAsPDF(req, ucdID, projectID, null, context, user);
|
||||
// returning as stream
|
||||
InputStream input = pdfRef.getStorageVolatileURL().openStream();
|
||||
StreamingOutput so = new SingleFileStreamingOutput(input);
|
||||
|
||||
if (!getAsURL) {
|
||||
// returning as stream
|
||||
InputStream input = pdfRef.getStorageVolatileURL().openStream();
|
||||
StreamingOutput so = new SingleFileStreamingOutput(input);
|
||||
return Response.ok(so)
|
||||
.header(ConstantsResolver.CONTENT_DISPOSITION,
|
||||
"inline; filename=\"" + pdfRef.getFileName() + "\"")
|
||||
.header("Content-Type", pdfRef.getContentType()).build();
|
||||
|
||||
ResponseBuilder response = Response.ok(so)
|
||||
.header(ConstantsResolver.CONTENT_DISPOSITION,
|
||||
"inline; filename=\"" + pdfRef.getFileName() + "\"")
|
||||
.header("Content-Type", pdfRef.getContentType());
|
||||
return response.build();
|
||||
} else {
|
||||
// returning as URI;
|
||||
return Response.ok(pdfRef.getStorageVolatileURL().toURI()).build();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error on performing export", e);
|
||||
|
|
Loading…
Reference in New Issue