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.states; felix@2124: felix@2124: import java.util.List; felix@2124: felix@7066: import gnu.trove.TDoubleArrayList; felix@7066: felix@2124: import org.apache.log4j.Logger; felix@2124: teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.artifacts.CallMeta; felix@2124: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; felix@2124: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.StaticWQKmsArtifact; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.model.CrossSectionWaterLineFacet; felix@7653: import org.dive4elements.river.artifacts.model.DataFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.RelativePointFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.WQKms; teichmann@5831: import org.dive4elements.river.artifacts.model.WQKmsFacet; felix@2124: felix@2124: /** felix@2124: * Only state of WQKmsArtifact. felix@2124: */ felix@2124: public class StaticWQKmsState felix@2124: extends DefaultState felix@2124: implements FacetTypes felix@2124: { felix@2124: /** The logger that is used in this state. */ felix@2124: private static Logger logger = Logger.getLogger(StaticWQKmsState.class); felix@2124: felix@2124: felix@2124: /** felix@2124: * From this state can not be continued. felix@2124: */ felix@2124: @Override felix@2124: protected String getUIProvider() { felix@2124: return "noinput"; felix@2124: } felix@2124: felix@2124: felix@2124: /** felix@2124: * Compute, create Facets, do the same stuff as all the other states do. felix@2124: */ felix@2124: protected Object compute( felix@7584: StaticWQKmsArtifact artifact, felix@2124: CallMeta metaLocale, felix@2124: String hash, felix@2124: List facets, felix@2124: Object old felix@2124: ) { felix@2124: String id = getID(); felix@7653: String code = artifact.getDataAsString("ids"); felix@7653: String [] parts = code.split("-"); felix@2124: felix@7653: // Return from cache, if present. felix@2124: WQKms res = old instanceof WQKms felix@2124: ? (WQKms)old felix@7584: : artifact.getWQKms(); felix@2124: felix@2124: WQKms wqkms = res; felix@2124: felix@2124: if (facets == null) { felix@2124: return res; felix@2124: } felix@2124: felix@7653: String wkmsName = wqkms.getName(); felix@7653: felix@7653: Facet wqfacet = new WQKmsFacet( felix@7653: STATIC_WQ, felix@7653: wkmsName); felix@7653: facets.add(wqfacet); felix@7653: felix@7653: if (parts[0].equals("officials_wq")) { felix@7653: // Early stop. We only want wq-points in that case. felix@7653: return res; felix@7653: } felix@7653: felix@2124: /* felix@2124: * TODO: re-enable HEIGHTMARKS_POINTS-thing felix@2124: felix@2124: String name; felix@2124: if (parts[0].equals(HEIGHTMARKS_POINTS)) { felix@2124: name = HEIGHTMARKS_POINTS; felix@2124: } felix@2124: else { felix@2124: name = STATIC_WQKMS; felix@2124: } felix@2124: */ felix@7066: // Spawn Q Facet only if at least one discharge value felix@7066: // is != -1 felix@7066: boolean qEmpty = true; felix@7066: TDoubleArrayList qs = wqkms.allQs(); teichmann@7254: for (int i = 0, Q = qs.size(); i < Q; i++) { felix@7066: if (qs.getQuick(i) != -1d) { felix@7066: qEmpty = false; felix@7066: break; felix@7066: } felix@7066: } felix@2124: felix@7653: // issue1494: Only spawn qfacet if discharges are given felix@7066: if (!qEmpty) { felix@7066: Facet qfacet = new WQKmsFacet( felix@7066: STATIC_WQKMS_Q, felix@7066: wkmsName felix@7066: // TODO re-enable translations. felix@7066: /* felix@7066: Resources.getMsg( felix@7066: metaLocale, felix@7066: wkmsName, felix@7066: wkmsName)*/); felix@7066: facets.add(qfacet); felix@7066: } felix@2124: felix@5799: Facet rpFacet = new RelativePointFacet(wkmsName); felix@5799: facets.add(rpFacet); felix@5799: felix@5799: Facet csFacet = new CrossSectionWaterLineFacet(0, felix@5799: wkmsName); felix@5799: facets.add(csFacet); felix@5799: felix@7653: wkmsName = "W (" + wkmsName + ")"; felix@7653: felix@2124: Facet wfacet = new WQKmsFacet( felix@2124: STATIC_WQKMS_W, felix@2124: wkmsName felix@2124: /* felix@2124: // TODO re-enable translations. felix@2124: Resources.getMsg( felix@2124: metaLocale, felix@2124: wkmsName, felix@2124: wkmsName)*/); felix@2124: facets.add(wfacet); felix@2124: felix@7653: Facet wstfacet = new DataFacet( felix@7653: WST, felix@7653: wkmsName, felix@7653: ComputeType.ADVANCE, hash, id); felix@7653: facets.add(wstfacet); felix@7653: felix@2124: return res; felix@2124: } felix@2124: felix@7653: @Override felix@7653: public Object computeAdvance( felix@7653: D4EArtifact artifact, felix@7653: String hash, felix@7653: CallContext context, felix@7653: List facets, felix@7653: Object old felix@7653: ) { felix@7653: return compute((StaticWQKmsArtifact) artifact, context.getMeta(), felix@7653: hash, facets, old); felix@7653: } felix@2124: felix@2124: /** felix@2124: * Get data, create the facets. felix@2124: * felix@2124: * @param context Ignored. felix@2124: */ felix@2124: @Override felix@2124: public Object computeFeed( teichmann@5867: D4EArtifact artifact, felix@2124: String hash, felix@2124: CallContext context, felix@2124: List facets, felix@2124: Object old felix@2124: ) { felix@2124: return compute((StaticWQKmsArtifact) artifact, context.getMeta(), felix@2124: hash, facets, old); felix@2124: } felix@2124: felix@2124: felix@2124: /** felix@2124: * Create the facets. felix@2124: * @param context Ignored. felix@2124: */ felix@2124: @Override felix@2124: public Object computeInit( teichmann@5867: D4EArtifact artifact, felix@2124: String hash, felix@2124: Object context, felix@2124: CallMeta meta, felix@2124: List facets felix@2124: ) { felix@7653: return compute((StaticWQKmsArtifact) artifact, meta, felix@7653: hash, facets, null); felix@2124: } felix@2124: } felix@2124: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :