view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultFacet.java @ 8980:b194fa64506a

SINFO - show results themes according to spec, either raw data or floating mean values. Some improvements to error handling and handling of empty results.
author gernotbelger
date Thu, 05 Apr 2018 18:30:34 +0200
parents a4f1ac81f26d
children 50cc99579a46
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * 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.common;

import org.apache.log4j.Logger;
import org.dive4elements.artifactdatabase.state.Facet;
import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.DataFacet;
import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;

/**
 * Facet of a FlowDepth curve.
 */
public final class SInfoResultFacet extends DataFacet {

    private static final long serialVersionUID = 1L;

    private static Logger log = Logger.getLogger(SInfoResultFacet.class);

    public SInfoResultFacet() {
        // required for clone operation deepCopy()
    }

    public SInfoResultFacet(final int idx, final String name, final String description, final String yAxisLabelKey, final ComputeType type, final String stateId,
            final String hash) {
        super(idx, name, description, type, hash, stateId);
        this.metaData.put("X", "sinfo.chart.km.xaxis.label");
        this.metaData.put("Y", yAxisLabelKey);
    }

    @Override
    public Object getData(final Artifact artifact, final CallContext context) {
        log.debug("Get data for result at index: " + this.index);

        final D4EArtifact flys = (D4EArtifact) artifact;

        final CalculationResult res = (CalculationResult) flys.compute(context, this.hash, this.stateId, this.type, false);

        final AbstractSInfoCalculationResults<?> data = (AbstractSInfoCalculationResults<?>) res.getData();

        return data.getResults().get(this.index);
    }

    /** Copy deeply. */
    @Override
    public Facet deepCopy() {
        // FIXME: why not simply use the full constructor instead?
        final SInfoResultFacet copy = new SInfoResultFacet();
        // FIXME: why does DataFacet does not override set? Bad access to variables of parent!
        copy.set(this);
        copy.type = this.type;
        copy.hash = this.hash;
        copy.stateId = this.stateId;
        return copy;
    }
}

http://dive4elements.wald.intevation.org