ingo@392: package de.intevation.flys.artifacts.states;
ingo@392:
ingo@687: import java.util.List;
ingo@687:
ingo@392: import org.apache.log4j.Logger;
ingo@392:
ingo@692: import de.intevation.artifacts.CallContext;
ingo@692:
ingo@687: import de.intevation.artifactdatabase.state.Facet;
ingo@687:
ingo@687: import de.intevation.flys.artifacts.FLYSArtifact;
ingo@687: import de.intevation.flys.artifacts.WINFOArtifact;
raimund@2132: import de.intevation.flys.artifacts.ChartArtifact;
sascha@703:
ingo@692: import de.intevation.flys.artifacts.model.FacetTypes;
ingo@696: import de.intevation.flys.artifacts.model.WaterlevelFacet;
sascha@703: import de.intevation.flys.artifacts.model.DataFacet;
sascha@711: import de.intevation.flys.artifacts.model.ReportFacet;
raimund@2132: import de.intevation.flys.artifacts.model.EmptyFacet;
ingo@692: import de.intevation.flys.artifacts.model.WQKms;
sascha@709: import de.intevation.flys.artifacts.model.CalculationResult;
sascha@703:
ingo@692: import de.intevation.flys.artifacts.resources.Resources;
ingo@687:
felix@1103: import de.intevation.flys.utils.FLYSUtils;
sascha@703:
ingo@392: /**
ingo@392: * The final state that will be reached after the discharge curve calculation
ingo@392: * mode has been chosen.
ingo@392: *
ingo@392: * @author Ingo Weinzierl
ingo@392: */
ingo@692: public class ComputedDischargeCurveState
ingo@692: extends DefaultState
ingo@692: implements FacetTypes
ingo@692: {
ingo@392: /** The logger that is used in this state.*/
ingo@392: private static Logger logger =
ingo@392: Logger.getLogger(ComputedDischargeCurveState.class);
ingo@392:
sascha@660: public ComputedDischargeCurveState() {
ingo@392: }
ingo@687:
ingo@687:
felix@3265: /**
felix@3265: * Get computed discharge curve data from cache (if available) or
felix@3265: * compute anew. Create Waterlevel and DataFacets.
felix@3265: */
ingo@687: @Override
sascha@697: public Object computeAdvance(
sascha@697: FLYSArtifact artifact,
sascha@697: String hash,
sascha@697: CallContext context,
sascha@742: List facets,
sascha@697: Object old
sascha@697: ) {
raimund@2132: logger.debug("ComputedDischargeCurveState.computeAdvance");
raimund@2132: if(artifact instanceof WINFOArtifact) {
raimund@2132: WINFOArtifact winfo = (WINFOArtifact)artifact;
sascha@709:
raimund@2132: CalculationResult res = old instanceof CalculationResult
raimund@2132: ? (CalculationResult)old
raimund@2132: : winfo.getComputedDischargeCurveData();
sascha@709:
raimund@2132: WQKms [] wqkms = (WQKms [])res.getData();
sascha@709:
raimund@2132: if (facets != null && wqkms.length > 0) {
raimund@2132: for (int i = 0; i < wqkms.length; ++i) {
raimund@2132:
raimund@2132: Object[] args = new Object[] {
raimund@2132: FLYSUtils.getRiver(winfo).getName(),
raimund@2132: wqkms[i].getName()
raimund@2132: };
raimund@2132:
raimund@2132: String name = Resources.getMsg(
raimund@2132: context.getMeta(),
raimund@2132: "chart.computed.discharge.curve.curve.label",
raimund@2132: "",
raimund@2132: args);
raimund@2132:
raimund@2132: facets.add(new WaterlevelFacet(i, COMPUTED_DISCHARGE_Q, name));
raimund@2132: facets.add(new WaterlevelFacet(i, AT, "AT data"));
raimund@2132: }
raimund@2132:
raimund@2132: facets.add(new DataFacet(CSV, "CSV data"));
raimund@2177: facets.add(new DataFacet(PDF, "PDF data"));
raimund@2132:
raimund@2132: if (res.getReport().hasProblems()) {
raimund@2132: facets.add(new ReportFacet());
raimund@2132: }
sascha@697: }
sascha@711:
raimund@2132: return res;
sascha@705: }
raimund@2132: else if(artifact instanceof ChartArtifact) {
raimund@2132: ChartArtifact chart = (ChartArtifact)artifact;
raimund@2132: facets.add(new EmptyFacet());
raimund@2132: return null;
raimund@2132: }
raimund@2132: return null;
ingo@687: }
ingo@392: }
ingo@392: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :