ingo@383: package de.intevation.flys.artifacts.states;
ingo@383:
ingo@687: import java.util.List;
ingo@687:
ingo@383: import org.apache.log4j.Logger;
ingo@383:
ingo@692: import de.intevation.artifacts.CallContext;
ingo@692:
ingo@687: import de.intevation.artifactdatabase.state.Facet;
ingo@687:
felix@4848: import de.intevation.flys.artifacts.access.RangeAccess;
ingo@687: import de.intevation.flys.artifacts.FLYSArtifact;
ingo@687: import de.intevation.flys.artifacts.WINFOArtifact;
raimund@2134: import de.intevation.flys.artifacts.ChartArtifact;
sascha@709:
ingo@696: import de.intevation.flys.artifacts.model.DurationCurveFacet;
ingo@692: import de.intevation.flys.artifacts.model.FacetTypes;
ingo@692: import de.intevation.flys.artifacts.model.WQDay;
ingo@687:
sascha@703: import de.intevation.flys.artifacts.model.DataFacet;
sascha@711: import de.intevation.flys.artifacts.model.ReportFacet;
raimund@2134: import de.intevation.flys.artifacts.model.EmptyFacet;
sascha@709: import de.intevation.flys.artifacts.model.CalculationResult;
sascha@709:
sascha@709: import de.intevation.flys.artifacts.resources.Resources;
sascha@703:
felix@1103: import de.intevation.flys.utils.FLYSUtils;
felix@1103:
sascha@703:
ingo@383: /**
ingo@383: * The final state that will be reached after the duration curve calculation
ingo@383: * mode has been chosen.
ingo@383: *
ingo@383: * @author Ingo Weinzierl
ingo@383: */
ingo@692: public class DurationCurveState
ingo@692: extends DefaultState
ingo@692: implements FacetTypes
ingo@692: {
felix@1029: /** The logger that is used in this state. */
ingo@383: private static Logger logger = Logger.getLogger(DurationCurveState.class);
ingo@383:
sascha@660: public DurationCurveState() {
ingo@383: }
ingo@687:
ingo@687:
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@2134: if (artifact instanceof WINFOArtifact) {
raimund@2134: WINFOArtifact winfo = (WINFOArtifact)artifact;
ingo@692:
raimund@2134: CalculationResult res;
sascha@697:
raimund@2134: if (old instanceof CalculationResult) {
raimund@2134: res = (CalculationResult)old;
raimund@2134: }
raimund@2134: else {
raimund@2134: res = winfo.getDurationCurveData();
raimund@2134: }
sascha@705:
raimund@2134: WQDay wqday = (WQDay)res.getData();
sascha@711:
raimund@2134: if (wqday != null && facets != null) {
felix@4848: RangeAccess rangeAccess = new RangeAccess(winfo, context);
felix@2718: // Create an i18ed name for a (w or q) duration curve facet.
raimund@2134: Object[] args = new Object[] {
felix@2718: FLYSUtils.getRiver(winfo).getName(),
felix@4848: rangeAccess.getLocations()[0]
raimund@2134: };
raimund@2134:
raimund@2134: String nameW = Resources.getMsg(
raimund@2134: context.getMeta(),
raimund@2134: "chart.duration.curve.curve.w",
raimund@2134: "",
raimund@2134: args);
raimund@2134:
raimund@2134: String nameQ = Resources.getMsg(
raimund@2134: context.getMeta(),
raimund@2134: "chart.duration.curve.curve.q",
raimund@2134: "",
raimund@2134: args);
raimund@2134:
raimund@2134: Facet w = new DurationCurveFacet(DURATION_W, nameW);
raimund@2134: Facet q = new DurationCurveFacet(DURATION_Q, nameQ);
raimund@2134:
raimund@2134: facets.add(w);
raimund@2134: facets.add(q);
raimund@2134:
raimund@2134: facets.add(new DataFacet(CSV, "CSV data"));
raimund@2178: facets.add(new DataFacet(PDF, "PDF data"));
raimund@2134:
raimund@2134: if (res.getReport().hasProblems()) {
raimund@2134: facets.add(new ReportFacet());
raimund@2134: }
sascha@711: }
raimund@2134:
raimund@2134: return res;
sascha@705: }
raimund@2134: else if (artifact instanceof ChartArtifact) {
raimund@2134: ChartArtifact chart = (ChartArtifact)artifact;
raimund@2134: facets.add(new EmptyFacet());
raimund@2134: return null;
raimund@2134: }
raimund@2134: return null;
ingo@687: }
ingo@383: }
ingo@383: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :