view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedflowdepth/PredefinedFlowDepthFacet.java @ 9195:a4121ec450d6

'ca.'-issue ExportContextCSV+PDF separated uinfo.inundationduration url export
author gernotbelger
date Fri, 29 Jun 2018 14:52:54 +0200
parents c16e90a0baf7
children
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.predefinedflowdepth;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.common.DefaultCalculationResult;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.common.ResultRow;
import org.dive4elements.river.artifacts.model.BlackboardDataFacet;
import org.dive4elements.river.artifacts.model.FacetTypes;
import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
import org.dive4elements.river.model.sinfo.FlowDepthColumn;
import org.dive4elements.river.model.sinfo.FlowDepthValue;

/**
 * Facet for a flow depth value series loaded from the database
 *
 * @author Matthias Schäfer
 */
public class PredefinedFlowDepthFacet extends BlackboardDataFacet implements FacetTypes {

    private static final long serialVersionUID = -5314814229001970855L;

    public PredefinedFlowDepthFacet(final String name, final String description) {
        super(0, name, description);

        this.metaData.put("X", "chart.longitudinal.section.xaxis.label");
        this.metaData.put("Y", "chart.flow_depth.section.yaxis.label");
    }

    /**
     * Returns the data this facet requires.
     *
     * @param artifact
     *            the owner artifact.
     * @param context
     *            the CallContext (ignored).
     *
     * @return
     *         the data as PredefinedFlowDepthQueryCalculationResult
     */
    @Override
    public Object getData(final Artifact artifact, final CallContext context) {

        final PredefinedFlowDepthColumnAccess access = new PredefinedFlowDepthColumnAccess((D4EArtifact) artifact);
        final FlowDepthColumn series = FlowDepthColumn.getColumnById(access.getColumnId());
        final List<FlowDepthValue> values = FlowDepthValue.getValues(series, access.getFrom(true), access.getTo(true));
        final Collection<ResultRow> rows = new ArrayList<>();
        for (final FlowDepthValue value : values) {
            rows.add(ResultRow.create().putValue(GeneralResultType.station, value.getStation()) //
                    .putValue(SInfoResultType.flowdepth, value.getDepth()));
        }
        return new DefaultCalculationResult(series.getName(), rows);
    }

    /**
     * Create a deep copy of this Facet.
     *
     * @return a deep copy.
     */
    @Override
    public PredefinedFlowDepthFacet deepCopy() {
        final PredefinedFlowDepthFacet copy = new PredefinedFlowDepthFacet(this.name, this.description);
        copy.set(this);
        return copy;
    }
}

http://dive4elements.wald.intevation.org