teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts; felix@3573: felix@3573: import java.util.ArrayList; felix@3573: import java.util.List; felix@3573: felix@3573: import org.apache.log4j.Logger; felix@3573: felix@3573: import org.w3c.dom.Document; felix@3573: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; felix@3573: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.ArtifactFactory; teichmann@5831: import org.dive4elements.artifacts.CallMeta; teichmann@5831: import org.dive4elements.artifacts.CallContext; felix@3573: teichmann@5831: import org.dive4elements.river.artifacts.model.GaugeFinder; teichmann@5831: import org.dive4elements.river.artifacts.model.GaugeFinderFactory; teichmann@5831: import org.dive4elements.river.artifacts.model.GaugeRange; teichmann@5831: import org.dive4elements.river.artifacts.model.NamedDouble; felix@3573: teichmann@5831: import org.dive4elements.river.artifacts.services.FixingsKMChartService; felix@3573: teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.resources.Resources; felix@3573: felix@3573: felix@3573: /** felix@3573: * Artifact to produce sector markers. felix@3573: */ felix@3573: public class QSectorArtifact teichmann@5867: extends StaticD4EArtifact felix@3573: { teichmann@8202: /** The log for this class. */ teichmann@8202: private static Logger log = Logger.getLogger(QSectorArtifact.class); felix@3573: felix@3573: /** The name of the artifact. */ felix@3573: public static final String ARTIFACT_NAME = "qsector"; felix@3573: felix@3573: felix@3573: /** felix@3573: * Trivial Constructor. felix@3573: */ felix@3573: public QSectorArtifact() { teichmann@8202: log.debug("QSectorArtifact.QSectorArtifact()"); felix@3573: } felix@3573: felix@3573: felix@3573: /** felix@3573: * Gets called from factory, to set things up. felix@3573: */ felix@3573: @Override felix@3573: public void setup( felix@3573: String identifier, felix@3573: ArtifactFactory factory, felix@3573: Object context, felix@3573: CallMeta callMeta, rrenkert@7842: Document data, rrenkert@7842: List loadFacets) felix@3573: { teichmann@8202: log.debug("QSectorArtifact.setup"); rrenkert@7842: super.setup(identifier, factory, context, callMeta, data, loadFacets); felix@3573: initialize(null, context, callMeta); felix@3573: } felix@3573: felix@3573: felix@3573: /** Return the name of this artifact. */ felix@3573: public String getName() { felix@3573: return ARTIFACT_NAME; felix@3573: } felix@3573: felix@3573: felix@3573: /** Get list of NamedDouble s (QSectors). */ felix@3576: public Object getQSectors(double km, CallContext context) { felix@3573: felix@3573: String river = getDataAsString("river"); felix@3573: List qsectors = new ArrayList(); felix@3573: felix@3573: GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); felix@3573: GaugeFinder gf = ggf.getGaugeFinder(river); felix@3573: felix@3573: if (gf == null) { teichmann@8202: log.warn("No gauge finder found for river '" + river + "'"); felix@3573: return null; felix@3573: } felix@3573: felix@3573: GaugeRange gr = gf.find(km); felix@3573: if (gr == null) { teichmann@8202: log.debug("No gauge range found for km " felix@3573: + km + " on river " + river + "."); felix@3573: return null; felix@3573: } felix@3573: teichmann@8202: if (log.isDebugEnabled()) { teichmann@8202: log.debug(gr); felix@3573: } felix@3573: tom@8856: for (int i = 0; tom@8856: i < FixingsKMChartService.I18N_Q_SECTOR_BOARDERS.length; tom@8856: ++i tom@8856: ) { felix@3573: String key = FixingsKMChartService.I18N_Q_SECTOR_BOARDERS[i]; felix@3573: String def = FixingsKMChartService.DEFAULT_Q_SECTOR_BORDERS[i]; felix@3576: String label = Resources.getMsg(context.getMeta(), key, def); felix@3573: felix@3573: qsectors.add(new NamedDouble(label, gr.getSectorBorder(i))); felix@3573: } felix@3573: felix@3573: return qsectors; felix@3573: } felix@3573: felix@3573: felix@3573: /** Setup state and facet. */ felix@3573: @Override tom@8856: protected void initialize( tom@8856: Artifact artifact, tom@8856: Object context, tom@8856: CallMeta meta tom@8856: ) { teichmann@8202: log.debug("QSectorArtifact.initialize"); felix@3573: List fs = new ArrayList(); felix@3573: teichmann@5867: D4EArtifact flys = (D4EArtifact) artifact; felix@3573: importData(flys, "river"); felix@3573: felix@3573: DefaultState state = (DefaultState) getCurrentState(context); felix@3573: state.computeInit(this, hash(), context, meta, fs); felix@3573: if (!fs.isEmpty()) { teichmann@8202: log.debug("Facets to add in QSectorArtifact.initialize ."); bjoern@4497: addFacets(getCurrentStateId(), fs); felix@3573: } felix@3573: else { teichmann@8202: log.debug("No facets to add in QSectorArtifact.initialize (" felix@3573: + state.getID() + ")."); felix@3573: } felix@3573: } felix@3573: } felix@3573: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :