Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureFacet.java @ 9377:e8d65cecc950
Renaming (predefined...) and own package for database loaded S-Info series of collisions and infrastructure height
author | mschaefer |
---|---|
date | Mon, 06 Aug 2018 11:48:49 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/InfrastructureFacet.java@a4121ec450d6 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureFacet.java Mon Aug 06 11:48:49 2018 +0200 @@ -0,0 +1,81 @@ +/** 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.predefinedinfrastructure; + +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.Infrastructure; +import org.dive4elements.river.model.sinfo.InfrastructureValue; + +/** + * Facet for a infrastructure value series loaded from the database + * + * @author Matthias Schäfer + */ +public class PredefinedInfrastructureFacet extends BlackboardDataFacet implements FacetTypes { + + private static final long serialVersionUID = 1; + + public PredefinedInfrastructureFacet(final String name, final String description, final String yAxisLabel) { + super(0, name, description); + + this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); + this.metaData.put("Y", yAxisLabel); + } + + /** + * Returns the data this facet requires. + * + * @param artifact + * the owner artifact. + * @param context + * the CallContext (ignored). + * + * @return + * the data as InfrastructureQueryCalculationResult + */ + @Override + public Object getData(final Artifact artifact, final CallContext context) { + + final PredefinedInfrastructureAccess access = new PredefinedInfrastructureAccess((D4EArtifact) artifact); + final Infrastructure series = Infrastructure.getSeries(access.getId()); + final List<InfrastructureValue> values = InfrastructureValue.getValues(series, access.getFrom(true), access.getTo(true)); + final Collection<ResultRow> rows = new ArrayList<>(); + for (final InfrastructureValue value : values) { + rows.add(ResultRow.create().putValue(GeneralResultType.station, value.getStation()) // + .putValue(SInfoResultType.infrastructureHeight, value.getHeight())); + } + return new DefaultCalculationResult(series.getFilename(), rows); + } + + /** + * Create a deep copy of this Facet. + * + * @return a deep copy. + */ + @Override + public PredefinedInfrastructureFacet deepCopy() { + final PredefinedInfrastructureFacet copy = new PredefinedInfrastructureFacet(this.name, this.description, this.metaData.get("Y")); + copy.set(this); + return copy; + } +} \ No newline at end of file