Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java @ 1621:6d3c1f4d0e8c
Tagged RELEASE 2.5 of flys-artifacts.
flys-artifacts/trunk@2793 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 19 Sep 2011 18:46:44 +0000 |
parents | 47ecf98f09eb |
children | b9b47af71564 |
line wrap: on
line source
package de.intevation.flys.artifacts.states; import java.util.List; import org.apache.log4j.Logger; import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifacts.Artifact; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.math.WKmsOperation; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WKms; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.artifactdatabase.data.StateData; import de.intevation.flys.utils.FLYSUtils; public class WDifferencesState extends DefaultState implements FacetTypes { /** The logger that is used in this state. */ private static Logger logger = Logger.getLogger(WDifferencesState.class); public WDifferencesState() { } /** Specify to display nothing (this is kind of a "final" state). */ @Override protected String getUIProvider() { return "noinput"; } @Override public boolean validate(Artifact artifact) throws IllegalArgumentException { FLYSArtifact flys = (FLYSArtifact) artifact; StateData data = flys.getData("diffids"); if (data == null) { throw new IllegalArgumentException("diffids is empty"); } // TODO: Also validate format. return true; } @Override public Object computeAdvance( FLYSArtifact artifact, String hash, CallContext context, List<Facet> facets, Object old ) { WINFOArtifact winfo = (WINFOArtifact)artifact; String id = getID(); // Load the Artifacts/facets that we want to subtract and display. // Expected format is: // [42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;0]#[1231f2-....] String datas[] = winfo.getDataAsString("diffids").split("#"); // Validate the Data-Strings. for (String s: datas) { if (!WaterlevelSelectState.isValueValid(winfo.getDataAsString("diffids"))) { // TODO: escalate. } } if (datas.length != 2) { // TODO crash with style ; } String uuid1 = WaterlevelSelectState.strip(datas[0]).split(";")[0]; String uuid2 = WaterlevelSelectState.strip(datas[1]).split(";")[0]; WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact( uuid1, context); WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact( uuid2, context); if (flys1 == null) { logger.warn("One of the artifacts (1) for diff calculation could not be loaded"); } if (flys2 == null) { logger.warn("One of the artifacts (2) for diff calculation could not be loaded"); } WKms wkms = null; String facetName = "diff ()"; if (flys1 != null && flys2 != null) { // TODO also check size. // TODO also need index of wqkms. WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().getData(); WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().getData(); wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]); facetName = "W ("+minuend[0].getName() + ") - W (" + subtrahend[0].getName()+")"; logger.warn("Did a WKMSSubtraction"); // Add these datasets also as facets ("absolutes"). /* Facet minuendAbsFacet = new WaterlevelFacet(0, LONGITUDINAL_W, "Minuend: W (_todo_)", ComputeType.ADVANCE, id, hash); Facet subtrahendAbsFacet = new WaterlevelFacet(1, LONGITUDINAL_W, "Subtrahend: W (_todo_)", ComputeType.ADVANCE, id, hash); */ //facets.add(minuendAbsFacet); //facets.add(subtrahendAbsFacet); } if (facets != null) { // TODO: pass computetype and state id. //, ComputeType.ADVANCE, getID(), hash)); facets.add(new DataFacet(W_DIFFERENCES, facetName)); facets.add(new DataFacet(CSV, "CSV data")); } else { logger.debug("Not adding facets in WDifferencesState."); } return wkms; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :