Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculationResult.java @ 9170:9b2e46090099
tkh cast exception fix
gigantic refactoring 2
author | gernotbelger |
---|---|
date | Thu, 21 Jun 2018 14:32:11 +0200 |
parents | 23945061daec |
children | a4121ec450d6 |
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.sinfo.tkhstate; import java.util.ArrayList; import java.util.Collection; import org.dive4elements.river.artifacts.common.ExportContextCSV; import org.dive4elements.river.artifacts.common.GeneralResultType; import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; import org.dive4elements.river.artifacts.common.ResultRow; import org.dive4elements.river.artifacts.sinfo.common.AbstractTkhCalculationResult; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; import org.dive4elements.river.artifacts.sinfo.util.WstInfo; /** * Contains the results of a {@link FloodDurationCalculation}. * * @author Gernot Belger */ final class TkhCalculationResult extends AbstractTkhCalculationResult<TkhCalculationResults> { private static final long serialVersionUID = 1L; private static final String JASPER_FILE = "/jasper/templates/sinfo.tkh.jrxml"; private enum ExportMode { pdf, csv } public TkhCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<ResultRow> rows) { super(label, wst, hasTkh, rows); } @Override public void writeCSVHeader(final ExportContextCSV exportContextCSV, final TkhCalculationResults results, final RiverInfo river) { final Collection<String> header = new ArrayList<>(11); header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.tkh)); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.soilkind)); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.meanBedHeight, river.getWstUnit())); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit())); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge)); final String descriptionHeader = results.getDescriptionHeader(); if (descriptionHeader != null) header.add(descriptionHeader); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); } @Override protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final TkhCalculationResults results) { exportContextCSV.writeCSVWaterlevelMetadata(super.getWst());// TODO: move to super exportContextCSV.writeBlankLine(); } @Override protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final TkhCalculationResults results, final ResultRow row) { return this.formatRow(exportContextCSV, results, row, ExportMode.csv); } @Override protected String[] formatPDFRow(final ExportContextCSV exportContextPDF, final TkhCalculationResults results, final ResultRow row) { return this.formatRow(exportContextPDF, results, row, ExportMode.pdf); } @Override protected String getJasperFile() { return JASPER_FILE; } @Override protected void addJRTableHeader(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source, final TkhCalculationResults results) { /* column headings */ exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station); exportContextPDF.addJRMetadata(source, "tkh_header", SInfoResultType.tkh); exportContextPDF.addJRMetadata(source, "tkhkind_header", SInfoResultType.soilkind); exportContextPDF.addJRMetadata(source, "bedheight_header", SInfoResultType.meanBedHeight); exportContextPDF.addJRMetadata(source, "waterlevel_header", SInfoResultType.waterlevel); exportContextPDF.addJRMetadata(source, "discharge_header", SInfoResultType.discharge); // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates). final String descriptionHeader = results.getDescriptionHeader(); final String waterlevelNameHeader = descriptionHeader == null ? exportContextPDF.msgPdf(SInfoResultType.waterlevelLabel) : descriptionHeader; exportContextPDF.addJRMetadata(source, "waterlevel_name_header", waterlevelNameHeader); exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); } private String[] formatRow(final ExportContextCSV exportContext, final TkhCalculationResults results, final ResultRow row, final ExportMode mode) { final Collection<String> lines = new ArrayList<>(11); lines.add(exportContext.formatRowValue(row, GeneralResultType.station)); lines.add(exportContext.formatRowValue(row, SInfoResultType.tkh)); lines.add(exportContext.formatRowValue(row, SInfoResultType.soilkind)); lines.add(exportContext.formatRowValue(row, SInfoResultType.meanBedHeight)); lines.add(exportContext.formatRowValue(row, SInfoResultType.waterlevel)); lines.add(exportContext.formatRowValue(row, SInfoResultType.discharge)); // REMARK: always export this column in pdf-mode, because WInfo also does it (no need for two jasper-templates). if (results.getDescriptionHeader() != null || mode == ExportMode.pdf) lines.add(exportContext.formatRowValue(row, SInfoResultType.waterlevelLabel)); lines.add(exportContext.formatRowValue(row, SInfoResultType.gaugeLabel)); lines.add(exportContext.formatRowValue(row, SInfoResultType.location)); return lines.toArray(new String[lines.size()]); } }