Updated Geoportal_Exporter, added FileReference
This commit is contained in:
parent
9db79f5091
commit
8740bf05de
|
@ -41,6 +41,7 @@ import org.gcube.application.geoportaldatamapper.exporter.gis.Recalculate_WGS84_
|
|||
import org.gcube.application.geoportaldatamapper.reader.MapBoxEndpointReader;
|
||||
import org.gcube.application.geoportaldatamapper.reader.ServiceAccessPoint;
|
||||
import org.gcube.application.geoportaldatamapper.shared.ExporterProjectSource;
|
||||
import org.gcube.application.geoportaldatamapper.shared.FileReference;
|
||||
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
|
||||
import org.gcube.spatial.data.geoutility.shared.wfs.WFSParameter;
|
||||
import org.gcube.spatial.data.geoutility.wfs.WFSQueryBuilder;
|
||||
|
@ -148,9 +149,9 @@ public class Geoportal_PDF_Exporter {
|
|||
* @return the string
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public String createPDFFile(ExporterProjectSource exportSource) throws Exception {
|
||||
public FileReference createPDFFile(ExporterProjectSource exportSource) throws Exception {
|
||||
|
||||
String pdfFileURL = null;
|
||||
FileReference fileRef = new FileReference();
|
||||
|
||||
PDFExporterConfig pdfExporterConfigs = readPDFExporterConfigsFromGR();
|
||||
PageNumber pagenumber = null;
|
||||
|
@ -170,12 +171,13 @@ public class Geoportal_PDF_Exporter {
|
|||
ProjectsCaller clientProjects = GeoportalClientCaller.projects();
|
||||
Project theProject = clientProjects.getProjectByID(exportSource.getProfileID(),
|
||||
exportSource.getProjectID());
|
||||
|
||||
if(exportSource.getProfileTitle()==null || exportSource.getProfileTitle().isEmpty()) {
|
||||
UseCaseDescriptor usecasedesc = GeoportalClientCaller.useCaseDescriptors().getUCDForId(exportSource.getProfileID());
|
||||
|
||||
if (exportSource.getProfileTitle() == null || exportSource.getProfileTitle().isEmpty()) {
|
||||
UseCaseDescriptor usecasedesc = GeoportalClientCaller.useCaseDescriptors()
|
||||
.getUCDForId(exportSource.getProfileID());
|
||||
exportSource.setProfileTitle(usecasedesc.getName());
|
||||
}
|
||||
|
||||
|
||||
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
||||
projectBuilder.relationships(false);
|
||||
|
||||
|
@ -272,7 +274,8 @@ public class Geoportal_PDF_Exporter {
|
|||
if (theProjectDV.getSpatialReference() != null) {
|
||||
String geoJSON = theProjectDV.getSpatialReference().getGeoJSON();
|
||||
if (geoJSON != null && !geoJSON.isEmpty()) {
|
||||
String downMapBoxImg = linkToMarkerURLViaMapBoxStaticMap(geoJSON, 7, mapSizeWithCentroid, listSAP.get(0));
|
||||
String downMapBoxImg = linkToMarkerURLViaMapBoxStaticMap(geoJSON, 7, mapSizeWithCentroid,
|
||||
listSAP.get(0));
|
||||
if (downMapBoxImg != null) {
|
||||
Image backgroundImage = toImageFromLink(downMapBoxImg, 250);
|
||||
if (backgroundImage != null) {
|
||||
|
@ -288,9 +291,9 @@ public class Geoportal_PDF_Exporter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Getting API MapBox Access Point
|
||||
ServiceAccessPoint sap = listSAP.size()>1?listSAP.get(1):listSAP.get(0);
|
||||
|
||||
// Getting API MapBox Access Point
|
||||
ServiceAccessPoint sap = listSAP.size() > 1 ? listSAP.get(1) : listSAP.get(0);
|
||||
|
||||
for (SectionView section : projectView.getListSections()) {
|
||||
document = appendSubDocumentToPDF(document, section, section.getListSubDocuments(),
|
||||
|
@ -328,17 +331,20 @@ public class Geoportal_PDF_Exporter {
|
|||
LOG.trace("mongo pdf ID: " + tempFile.getId());
|
||||
LOG.trace("mongo pdf filename: " + tempFile.getFilename());
|
||||
|
||||
pdfFileURL = String.format("%s?contentType=%s&fileName=%s&content-disposition=%s", storageURL,
|
||||
"application/pdf", tempFile.getFilename(), "inline");
|
||||
String contentType = "application/pdf";
|
||||
String pdfFileURL = String.format("%s?contentType=%s&fileName=%s&content-disposition=%s", storageURL,
|
||||
contentType, tempFile.getFilename(), "inline");
|
||||
LOG.info("returning pdf URL: " + pdfFileURL);
|
||||
|
||||
|
||||
// TEST save file locally
|
||||
fileRef.setStorageVolatileURL(new URL(pdfFileURL));
|
||||
fileRef.setFileName(tempFile.getFilename());
|
||||
fileRef.setContentType(contentType);
|
||||
|
||||
// TEST save file locally
|
||||
// File targetFile = new File(projectTitleSanitized + ".pdf");
|
||||
// java.nio.file.Files.copy(in, targetFile.toPath(),
|
||||
// StandardCopyOption.REPLACE_EXISTING); LOG.info("targetFile at: " +
|
||||
// targetFile.getAbsolutePath());
|
||||
|
||||
|
||||
IOUtils.closeQuietly(in);
|
||||
} catch (Exception e) {
|
||||
|
@ -356,7 +362,7 @@ public class Geoportal_PDF_Exporter {
|
|||
}
|
||||
}
|
||||
|
||||
return pdfFileURL;
|
||||
return fileRef;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -722,23 +728,25 @@ public class Geoportal_PDF_Exporter {
|
|||
wmsLink = URLParserUtil.setValueOfParameter("format", wmsLink, "image/png", true);
|
||||
String source_bbox = URLParserUtil.extractValueOfParameterFromURL("bbox", wmsLink);
|
||||
String wmsVersion = URLParserUtil.extractValueOfParameterFromURL("version", wmsLink);
|
||||
|
||||
|
||||
double bboxOffset = 0.0;
|
||||
LOG.trace("source_bbox: " + source_bbox);
|
||||
Recalculate_WGS84_Offset source_Projection = new Recalculate_WGS84_Offset(wmsVersion, source_bbox, bboxOffset);
|
||||
Recalculate_WGS84_Offset source_Projection = new Recalculate_WGS84_Offset(wmsVersion,
|
||||
source_bbox, bboxOffset);
|
||||
|
||||
LOG.trace("source width: " + source_Projection.getAspectratioWidth());
|
||||
LOG.trace("source heigth: " + source_Projection.getAspectratioHeight());
|
||||
LOG.trace("source ratio: " + source_Projection.getRatio_Width_Height());
|
||||
LOG.trace("source bbox: " + source_Projection.getBboxWithOffset());
|
||||
|
||||
//Calculate best BBOX offset
|
||||
|
||||
// Calculate best BBOX offset
|
||||
bboxOffset = BBOXConverter.bestBBOXOffset(wmsVersion, source_bbox);
|
||||
|
||||
//bboxOffset = 0.0001;
|
||||
|
||||
LOG.debug("applying offset: "+bboxOffset);
|
||||
Recalculate_WGS84_Offset recalculate_Projection = new Recalculate_WGS84_Offset(wmsVersion, source_bbox, bboxOffset);
|
||||
|
||||
// bboxOffset = 0.0001;
|
||||
|
||||
LOG.debug("applying offset: " + bboxOffset);
|
||||
Recalculate_WGS84_Offset recalculate_Projection = new Recalculate_WGS84_Offset(
|
||||
wmsVersion, source_bbox, bboxOffset);
|
||||
|
||||
LOG.trace("offset width: " + recalculate_Projection.getAspectratioWidth());
|
||||
LOG.trace("offset heigth: " + recalculate_Projection.getAspectratioHeight());
|
||||
|
@ -748,13 +756,14 @@ public class Geoportal_PDF_Exporter {
|
|||
int aspectratioWidth = recalculate_Projection.getAspectratioWidth();
|
||||
int aspectratioHeight = recalculate_Projection.getAspectratioHeight();
|
||||
String recaulculateBBOX = recalculate_Projection.getBboxWithOffset();
|
||||
|
||||
|
||||
// Layer with aspect ratio on width/height according to bbox width/height
|
||||
wmsLink = URLParserUtil.setValueOfParameter("width", wmsLink, aspectratioWidth + "",
|
||||
true);
|
||||
wmsLink = URLParserUtil.setValueOfParameter("height", wmsLink, aspectratioHeight + "",
|
||||
true);
|
||||
String wmsLinkTol = URLParserUtil.setValueOfParameter("bbox", wmsLink, recaulculateBBOX, false);
|
||||
String wmsLinkTol = URLParserUtil.setValueOfParameter("bbox", wmsLink, recaulculateBBOX,
|
||||
false);
|
||||
wmsLinkTol += "&TRANSPARENT=TRUE";
|
||||
LOG.trace("wmsLink aspect ratio link: " + wmsLink);
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package org.gcube.application.geoportaldatamapper.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
|
||||
public class FileReference implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5398263987693453776L;
|
||||
|
||||
private URL storageVolatileURL;
|
||||
private String fileName;
|
||||
private String contentType;
|
||||
|
||||
public FileReference() {
|
||||
|
||||
}
|
||||
|
||||
public URL getStorageVolatileURL() {
|
||||
return storageVolatileURL;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setStorageVolatileURL(URL storageVolatileURL) {
|
||||
this.storageVolatileURL = storageVolatileURL;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("FileReference [storageVolatileURL=");
|
||||
builder.append(storageVolatileURL);
|
||||
builder.append(", fileName=");
|
||||
builder.append(fileName);
|
||||
builder.append(", contentType=");
|
||||
builder.append(contentType);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue