Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationExporter.java @ 9107:41f4bc83aa7a
vegzones improved
author | gernotbelger |
---|---|
date | Tue, 29 May 2018 15:19:03 +0200 |
parents | 7134a4c7d1b6 |
children | 23945061daec |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.uinfo.inundationduration; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; import org.apache.log4j.Logger; import org.dive4elements.river.artifacts.common.GeneralResultType; import org.dive4elements.river.artifacts.common.I18NStrings; import org.dive4elements.river.artifacts.common.JasperReporter; import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; import org.dive4elements.river.artifacts.common.ResultRow; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; import org.dive4elements.river.artifacts.uinfo.commons.AbstractUInfoExporter; import au.com.bytecode.opencsv.CSVWriter; import net.sf.jasperreports.engine.JRException; /** * @author Domenico Nardi Tironi * */ public class InundationDurationExporter extends AbstractUInfoExporter<InundationDurationCalculationResult, InundationDurationCalculationResults> { /** The log used in this exporter. */ private static Logger log = Logger.getLogger(InundationDurationExporter.class); private static final String JASPER_FILE = "/jasper/templates/uinfo.inundationduration.jrxml"; @Override protected Logger getLog() { return log; } @Override protected void writeCSVGlobalMetadata(final CSVWriter writer, final InundationDurationCalculationResults results) { log.info("SalixLineExporter.writeCSVMeta"); super.writeCSVGlobalMetadataDefaults(writer, results); // "# Höhensystem des Flusses: " writeCSVMetaEntry(writer, I18NStrings.CSV_META_HEIGHT_UNIT_RIVER, results.getRiver().getWstUnit()); writer.writeNext(new String[] { "" }); // break line } @Override protected void writeCSVResultMetadata(final CSVWriter writer, final InundationDurationCalculationResults results, final InundationDurationCalculationResult result) { /* * final BedHeightInfo sounding = result.getSounding(); * super.writeCSVSoundingMetadata(writer, sounding); * final WstInfo wst = result.getWst(); * super.writeCSVWaterlevelMetadata(writer, wst); */ } /** * Write the header, with different headings depending on whether at a * gauge or at a location. * * @param river * @param useTkh */ @Override protected void writeCSVHeader(final CSVWriter writer, final InundationDurationCalculationResults results, final RiverInfo river) { log.info("FlowDepthExporter.writeCSVHeader"); final Collection<String> header = new ArrayList<>(11); header.add(msg(GeneralResultType.station.getCsvHeader())); header.add(msgUnit(SInfoResultType.flowdepth.getCsvHeader(), SInfoResultType.flowdepth.getUnit())); header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); header.add(msg(SInfoResultType.waterlevelLabel.getCsvHeader())); header.add(msg(SInfoResultType.gaugeLabel.getCsvHeader())); header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); header.add(msg(SInfoResultType.soundingLabel.getCsvHeader())); header.add(msg(SInfoResultType.location.getCsvHeader())); writer.writeNext(header.toArray(new String[header.size()])); } /** * Format a row of a flow depth result into an array of string, both used by csv and pdf * * @param pdf * * @param useTkh */ @Override protected String[] formatRow(final InundationDurationCalculationResults results, final ResultRow row, final ExportMode mode) { final Collection<String> lines = new ArrayList<>(11); lines.add(row.exportValue(this.context, GeneralResultType.station)); lines.add(row.exportValue(this.context, SInfoResultType.flowdepth)); lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); lines.add(row.exportValue(this.context, SInfoResultType.discharge)); lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel)); lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel)); lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); lines.add(row.exportValue(this.context, SInfoResultType.soundingLabel)); lines.add(row.exportValue(this.context, SInfoResultType.location)); return lines.toArray(new String[lines.size()]); } @Override protected final void addJRMetaData(final MetaAndTableJRDataSource source, final InundationDurationCalculationResults results) { /* general metadata */ super.addJRMetaData(source, results); /* column headings */ source.addMetaData("station_header", GeneralResultType.station.getPdfHeader(this.context.getMeta())); } @Override protected void writePDF(final OutputStream out) { try { final MetaAndTableJRDataSource source = createJRData(this.data); final JasperReporter reporter = new JasperReporter(); reporter.addReport(JASPER_FILE, source); reporter.exportPDF(out); } catch (final JRException je) { getLog().warn("Error generating PDF Report!", je); } } }