mschaefer@9115: /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde mschaefer@9115: * Software engineering by mschaefer@9115: * Björnsen Beratende Ingenieure GmbH mschaefer@9115: * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt mschaefer@9115: * mschaefer@9115: * This file is Free Software under the GNU AGPL (>=v3) mschaefer@9115: * and comes with ABSOLUTELY NO WARRANTY! Check out the mschaefer@9115: * documentation coming with Dive4Elements River for details. mschaefer@9115: */ mschaefer@9115: mschaefer@9115: package org.dive4elements.river.artifacts.sinfo.flood_duration; mschaefer@9115: mschaefer@9115: import java.util.ArrayList; mschaefer@9115: import java.util.Collection; mschaefer@9115: import java.util.List; mschaefer@9115: mschaefer@9115: import org.dive4elements.artifacts.Artifact; mschaefer@9115: import org.dive4elements.artifacts.CallContext; mschaefer@9115: import org.dive4elements.river.artifacts.D4EArtifact; mschaefer@9115: import org.dive4elements.river.artifacts.common.GeneralResultType; mschaefer@9115: import org.dive4elements.river.artifacts.common.ResultRow; mschaefer@9115: import org.dive4elements.river.artifacts.model.BlackboardDataFacet; mschaefer@9115: import org.dive4elements.river.artifacts.model.FacetTypes; mschaefer@9115: import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; mschaefer@9115: import org.dive4elements.river.model.sinfo.Infrastructure; mschaefer@9115: import org.dive4elements.river.model.sinfo.InfrastructureValue; mschaefer@9115: mschaefer@9115: /** mschaefer@9115: * Facet for a infrastructure value series loaded from the database mschaefer@9115: * mschaefer@9115: * @author Matthias Schäfer mschaefer@9115: */ mschaefer@9115: public class InfrastructureFacet extends BlackboardDataFacet implements FacetTypes { mschaefer@9115: mschaefer@9115: private static final long serialVersionUID = 1; mschaefer@9115: mschaefer@9115: public InfrastructureFacet(final String name, final String description, final String yAxisLabel) { mschaefer@9115: super(0, name, description); mschaefer@9115: mschaefer@9115: this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); mschaefer@9115: this.metaData.put("Y", yAxisLabel); mschaefer@9115: } mschaefer@9115: mschaefer@9115: /** mschaefer@9115: * Returns the data this facet requires. mschaefer@9115: * mschaefer@9115: * @param artifact mschaefer@9115: * the owner artifact. mschaefer@9115: * @param context mschaefer@9115: * the CallContext (ignored). mschaefer@9115: * mschaefer@9115: * @return mschaefer@9115: * the data as InfrastructureQueryCalculationResult mschaefer@9115: */ mschaefer@9115: @Override mschaefer@9115: public Object getData(final Artifact artifact, final CallContext context) { mschaefer@9115: mschaefer@9115: final InfrastructureAccess access = new InfrastructureAccess((D4EArtifact) artifact); mschaefer@9115: final Infrastructure series = Infrastructure.getSeries(access.getId()); mschaefer@9115: final List values = InfrastructureValue.getValues(series, access.getFrom(true), access.getTo(true)); mschaefer@9115: final Collection rows = new ArrayList<>(); mschaefer@9115: for (final InfrastructureValue value : values) { mschaefer@9115: rows.add(ResultRow.create().putValue(GeneralResultType.station, value.getStation()) // mschaefer@9115: .putValue(SInfoResultType.infrastructureHeight, value.getHeight())); mschaefer@9115: } mschaefer@9115: return new InfrastructureQueryCalculationResult(series.getFilename(), rows); mschaefer@9115: } mschaefer@9115: mschaefer@9115: /** mschaefer@9115: * Create a deep copy of this Facet. mschaefer@9115: * mschaefer@9115: * @return a deep copy. mschaefer@9115: */ mschaefer@9115: @Override mschaefer@9115: public InfrastructureFacet deepCopy() { mschaefer@9115: final InfrastructureFacet copy = new InfrastructureFacet(this.name, this.description, this.metaData.get("Y")); mschaefer@9115: copy.set(this); mschaefer@9115: return copy; mschaefer@9115: } mschaefer@9115: }