# HG changeset patch # User Andre Heinecke # Date 1370862363 -7200 # Node ID 34f3934349138640bbdc3942f5cc05d4adfd29c4 # Parent db97448f21b7742af15f46b9c8cab499fe416136 Implement pdf export for bedheight differences diff -r db97448f21b7 -r 34f393434913 artifacts/doc/conf/artifacts/minfo.xml --- a/artifacts/doc/conf/artifacts/minfo.xml Mon Jun 10 13:04:48 2013 +0200 +++ b/artifacts/doc/conf/artifacts/minfo.xml Mon Jun 10 13:06:03 2013 +0200 @@ -280,9 +280,7 @@ - diff -r db97448f21b7 -r 34f393434913 artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/DifferencesState.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/DifferencesState.java Mon Jun 10 13:04:48 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/DifferencesState.java Mon Jun 10 13:06:03 2013 +0200 @@ -104,6 +104,7 @@ CallMeta meta = context.getMeta(); newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); + newFacets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); for (int idx = 0; idx < results.length; idx++) { if (results[idx] instanceof BedDiffYearResult) { newFacets.add(new BedDiffYearFacet( diff -r db97448f21b7 -r 34f393434913 artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java --- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java Mon Jun 10 13:04:48 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java Mon Jun 10 13:06:03 2013 +0200 @@ -7,13 +7,33 @@ import java.text.NumberFormat; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Locale; +import java.util.Date; +import java.text.DateFormat; import org.apache.log4j.Logger; +import org.apache.commons.lang.StringUtils; + +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JRException; + import org.dive4elements.artifacts.CallContext; +import org.dive4elements.artifacts.CallMeta; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.BedDifferencesAccess; +import org.dive4elements.artifacts.common.utils.Config; +import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.artifacts.model.CalculationResult; import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult; +import org.dive4elements.river.artifacts.model.minfo.BedDifferenceJRDataSource; import org.dive4elements.river.exports.AbstractExporter; import org.dive4elements.river.utils.Formatter; +import org.dive4elements.river.utils.RiverUtils; + import org.w3c.dom.Document; import au.com.bytecode.opencsv.CSVWriter; @@ -27,18 +47,30 @@ private static Logger logger = Logger.getLogger(BedDifferenceExporter.class); - private static final String CSV_HEADER_KM = "export.minfo.beddifference.km"; + private static final String CSV_HEADER_KM = + "export.minfo.beddifference.km"; + private static final String CSV_HEADER_DIFF = "export.minfo.beddifference.diff"; + public static final String JASPER_FILE = + "export.minfo.beddifference.pdf.file"; + + public static final String PDF_TITLE= + "export.minfo.beddifference.pdf.title"; + + public static final String PDF_HEADER_MODE= + "export.minfo.beddifference.pdf.mode"; + private BedDifferencesResult[] results; @Override public void init(Document request, OutputStream out, CallContext context) { - logger.debug("BedQualityExporter.init"); + logger.debug("init"); super.init(request, out, context); results = new BedDifferencesResult[0]; } + @Override protected void writeCSVData(CSVWriter writer) throws IOException { writeCSVHeader(writer); @@ -56,12 +88,6 @@ } @Override - protected void writePDF(OutputStream out) { - // TODO implement me! - - } - - @Override protected void addData(Object data) { if (!(data instanceof CalculationResult)) { logger.warn("Invalid data type."); @@ -76,6 +102,35 @@ results = (BedDifferencesResult[])d; } + protected void addMetaData(BedDifferenceJRDataSource source) { + CallMeta meta = context.getMeta(); + + D4EArtifact arti = (D4EArtifact) master; + + source.addMetaData ("river", RiverUtils.getRivername(arti)); + + Locale locale = Resources.getLocale(meta); + DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); + + source.addMetaData("date", df.format(new Date())); + + source.addMetaData("calculation", Resources.getMsg( + locale, + PDF_HEADER_MODE, + "Bedheight difference")); + + // Now the dynamic parts + + BedDifferencesAccess access = new BedDifferencesAccess(arti); + source.addMetaData("ye_mode", Resources.getMsg(locale, + "state.minfo." + access.getYearEpoch(), + access.getYearEpoch())); + + source.addMetaData("differences", StringUtils.join( + access.getDifferenceArtifactNamePairs(), "\n")); + } + + protected void writeCSVHeader(CSVWriter writer) { logger.debug("writeCSVHeader()"); @@ -86,4 +141,48 @@ } writer.writeNext(header.toArray(new String[header.size()])); } + + protected BedDifferenceJRDataSource createJRData() { + BedDifferenceJRDataSource source = new BedDifferenceJRDataSource(); + + addMetaData(source); + NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); + NumberFormat mf = Formatter.getMeterFormat(context); + for (BedDifferencesResult result: results) { + double[][] kms = result.getDifferencesData(); + for (int j = 0; j < kms[0].length; j++) { + source.addData(new String[] { + kmf.format(kms[0][j]), mf.format(kms[1][j])}); + } + } + return source; + } + + @Override + protected void writePDF(OutputStream out) { + logger.debug("write PDF"); + BedDifferenceJRDataSource source = createJRData(); + + String jasperFile = Resources.getMsg( + context.getMeta(), + JASPER_FILE, + "/jasper/beddifference_en.jasper"); + String confPath = Config.getConfigDirectory().toString(); + + + Map parameters = new HashMap(); + parameters.put("ReportTitle", Resources.getMsg( + context.getMeta(), PDF_TITLE, "Exported Data")); + try { + JasperPrint print = JasperFillManager.fillReport( + confPath + jasperFile, + parameters, + source); + JasperExportManager.exportReportToPdfStream(print, out); + } + catch(JRException je) { + logger.warn("Error generating PDF Report!", je); + } + } + } diff -r db97448f21b7 -r 34f393434913 artifacts/src/main/resources/messages.properties --- a/artifacts/src/main/resources/messages.properties Mon Jun 10 13:04:48 2013 +0200 +++ b/artifacts/src/main/resources/messages.properties Mon Jun 10 13:06:03 2013 +0200 @@ -402,6 +402,9 @@ export.minfo.bedquality.bed_sub = Bed Diameter Sublayer export.minfo.beddifference.km = km export.minfo.beddifference.diff = m +export.minfo.beddifference.pdf.file = /jasper/beddifference_en.jasper +export.minfo.beddifference.pdf.title = Bedheight Difference +export.minfo.beddifference.pdf.mode = Bedheight Difference floodmap.wmsbackground = Background Map floodmap.riveraxis = River Axis diff -r db97448f21b7 -r 34f393434913 artifacts/src/main/resources/messages_de.properties --- a/artifacts/src/main/resources/messages_de.properties Mon Jun 10 13:04:48 2013 +0200 +++ b/artifacts/src/main/resources/messages_de.properties Mon Jun 10 13:06:03 2013 +0200 @@ -403,6 +403,9 @@ export.minfo.bedquality.bed_sub = Sohldurchmesser Unterschicht export.minfo.beddifference.km = Fluss-km export.minfo.beddifference.diff = m +export.minfo.beddifference.pdf.file = /jasper/beddifference.jasper +export.minfo.beddifference.pdf.title = Sohlh\u00f6hendifferenz +export.minfo.beddifference.pdf.mode = Sohlh\u00f6hendifferenz floodmap.wmsbackground = Hintergrundkarte floodmap.riveraxis = Flussachse diff -r db97448f21b7 -r 34f393434913 artifacts/src/main/resources/messages_de_DE.properties --- a/artifacts/src/main/resources/messages_de_DE.properties Mon Jun 10 13:04:48 2013 +0200 +++ b/artifacts/src/main/resources/messages_de_DE.properties Mon Jun 10 13:06:03 2013 +0200 @@ -399,6 +399,9 @@ export.minfo.bedquality.bed_sub = Sohldurchmesser Unterschicht export.minfo.beddifference.km = Fluss-km export.minfo.beddifference.diff = m +export.minfo.beddifference.pdf.file = /jasper/beddifference.jasper +export.minfo.beddifference.pdf.title = Sohlh\u00f6hendifferenz +export.minfo.beddifference.pdf.mode = Sohlh\u00f6hendifferenz floodmap.wmsbackground = Hintergrundkarte floodmap.riveraxis = Flussachse diff -r db97448f21b7 -r 34f393434913 artifacts/src/main/resources/messages_en.properties --- a/artifacts/src/main/resources/messages_en.properties Mon Jun 10 13:04:48 2013 +0200 +++ b/artifacts/src/main/resources/messages_en.properties Mon Jun 10 13:06:03 2013 +0200 @@ -404,6 +404,9 @@ export.minfo.bedquality.bed_sub = Bed Diameter Sublayer export.minfo.beddifference.km = km export.minfo.beddifference.diff = m +export.minfo.beddifference.pdf.file = /jasper/beddifference_en.jasper +export.minfo.beddifference.pdf.title = Bedheight Difference +export.minfo.beddifference.pdf.mode = Bedheight Difference floodmap.wmsbackground = Background Map floodmap.riveraxis = River Axis diff -r db97448f21b7 -r 34f393434913 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java Mon Jun 10 13:04:48 2013 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java Mon Jun 10 13:06:03 2013 +0200 @@ -604,6 +604,8 @@ String bed_difference_height_year(); + String bedheight_difference_export(); + String fix_waterlevel_export(); // ERRORS diff -r db97448f21b7 -r 34f393434913 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties Mon Jun 10 13:04:48 2013 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties Mon Jun 10 13:06:03 2013 +0200 @@ -258,6 +258,7 @@ bed_difference_year = Bedheight Differences bed_difference_epoch = Epoch Bedheight Differences bed_difference_height_year = Bedheight Differences per year +bedheight_difference_export = Bedheight Differences Export exportATTooltip = Export as AT file diff -r db97448f21b7 -r 34f393434913 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties Mon Jun 10 13:04:48 2013 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties Mon Jun 10 13:06:03 2013 +0200 @@ -258,6 +258,7 @@ bed_difference_year = Sohlh\u00f6hendifferenz bed_difference_epoch = Sohlh\u00f6hendifferenz (Epoche) bed_difference_height_year = Sohlh\u00f6hendifferenz pro Jahr +bedheight_difference_export = Sohlh\u00f6hendifferenz Export waterlevel_export = Wasserstand/Wasserspiegellagen Export waterlevel_report = Wasserstand/Wasserspiegellagen Bericht diff -r db97448f21b7 -r 34f393434913 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties Mon Jun 10 13:04:48 2013 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties Mon Jun 10 13:06:03 2013 +0200 @@ -256,6 +256,7 @@ bed_difference_year = Bedheight Differences bed_difference_epoch = Epoch Bedheight Differences bed_difference_height_year = Bedheight Difference per year +bedheight_difference_export = Bedheight Differences Export exportATTooltip = Export as AT file