# HG changeset patch # User Raimund Renkert # Date 1345202737 0 # Node ID 659c1111db13bdd2711fd3b41e38c7ef1df2162c # Parent a1cdf8be9fd0795d7b618d3995714ff059e27869 FixA: Added exporter for AT files. flys-artifacts/trunk@5224 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a1cdf8be9fd0 -r 659c1111db13 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Aug 17 11:25:37 2012 +0000 @@ -1,3 +1,17 @@ +2012-08-17 Raimund Renkert + + * src/main/java/de/intevation/flys/exports/fixings/FixATExport.java: + New. Exporter for FixAnaylsis AT files. + + * src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java: + Add facet for AT export. + + * doc/conf/conf.xml: + Added out generator for fix AT export. + + * doc/conf/artifacts/fixanalysis.xml: + Added outputmode for AT export. + 2012-08-16 Felix Wolfsteller * doc/conf/artifacts/fixanalysis.xml: Add more facets to diff -r a1cdf8be9fd0 -r 659c1111db13 flys-artifacts/doc/conf/artifacts/fixanalysis.xml --- a/flys-artifacts/doc/conf/artifacts/fixanalysis.xml Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/doc/conf/artifacts/fixanalysis.xml Fri Aug 17 11:25:37 2012 +0000 @@ -134,6 +134,11 @@ + + + + + diff -r a1cdf8be9fd0 -r 659c1111db13 flys-artifacts/doc/conf/conf.xml --- a/flys-artifacts/doc/conf/conf.xml Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Fri Aug 17 11:25:37 2012 +0000 @@ -296,6 +296,7 @@ de.intevation.flys.exports.ReportGenerator de.intevation.flys.exports.ATExporter + de.intevation.flys.exports.fixings.FixATExport diff -r a1cdf8be9fd0 -r 659c1111db13 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java Fri Aug 17 11:25:37 2012 +0000 @@ -119,6 +119,8 @@ facets.add( new DataFacet( FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, id)); + facets.add( + new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); int maxId = -100; diff -r a1cdf8be9fd0 -r 659c1111db13 flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixATExport.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixATExport.java Fri Aug 17 11:25:37 2012 +0000 @@ -0,0 +1,99 @@ +package de.intevation.flys.exports.fixings; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import au.com.bytecode.opencsv.CSVWriter; + +import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.access.FixAccess; +import de.intevation.flys.artifacts.math.fitting.Function; +import de.intevation.flys.artifacts.math.fitting.FunctionFactory; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.Parameters; +import de.intevation.flys.artifacts.model.fixings.FixAnalysisResult; +import de.intevation.flys.collections.FLYSArtifactCollection; +import de.intevation.flys.exports.AbstractExporter; +import de.intevation.flys.exports.OutGenerator; +import de.intevation.flys.utils.FLYSUtils; + +public class FixATExport extends AbstractExporter { + + private static Logger logger = + Logger.getLogger(FixATExport.class); + + protected Function function; + protected Parameters parameters; + + + @Override + public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) { + logger.debug("AT Export doOut()."); + Object data = bundle.getData(context); + if (data instanceof CalculationResult) { + CalculationResult cr = (CalculationResult)data; + Object resData = cr.getData(); + if (resData instanceof FixAnalysisResult) { + this.parameters = ((FixAnalysisResult)resData).getParameters(); + } + } + else { + logger.debug("No CalculationResult found for AT export."); + return; + } + FixAccess access = new FixAccess((FLYSArtifact)this.master); + String f = access.getFunction(); + if (f == null || f.length() == 0) { + logger.debug("No function found for AT export."); + return; + } + this.function = FunctionFactory.getInstance().getFunction(f); + } + + @Override + public void generate() throws IOException { + if (this.function == null || this.parameters == null) { + logger.debug("No function or paramters for AT export."); + return; + } + + Writer writer = new OutputStreamWriter(out, DEFAULT_CSV_CHARSET); + + FixATWriter atWriter = new FixATWriter(this.function, this.parameters); + logger.debug("the request: " + XMLUtils.toString(request)); + NodeList nodes = request.getElementsByTagName("km"); + String km = nodes.item(0).getTextContent(); + logger.debug("the km: " + km); + double dkm = Double.valueOf(km); + String river = FLYSUtils.getRivername((FLYSArtifact)master); + atWriter.write(writer, context.getMeta(), river, dkm); + writer.close(); + } + + @Override + protected void writeCSVData(CSVWriter writer) throws IOException { + // The concrete writer is used to write csv data. + } + + @Override + protected void writePDF(OutputStream out) { + // Implement me! + } + + @Override + protected void addData(Object data) { + // Nothing to do here. + } + +}