changeset 1771:c62ff9e72cea

Restore mapping of state id to facets (revert, rev 3083 and 3088). flys-artifacts/trunk@3092 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Oct 2011 09:32:05 +0000
parents e8a98eee816d
children 460374a08c44
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java
diffstat 10 files changed, 116 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Oct 27 09:32:05 2011 +0000
@@ -1,3 +1,27 @@
+2011-10-27	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Restore mapping of state id to facets (essentially revert, revision
+	3083 and 3088).
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  (getInitialFacetActivity): Be more explicit on which facets to
+	  introduce inactivated.
+
+	* src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java:
+	  Minor refactoring, declare a string final static.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
+	  Restore association from state id to facets.
+
 2011-10-26	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -63,7 +63,7 @@
 
         if (!fs.isEmpty()) {
             logger.debug("Facets to add in AnnotationsArtifact.initialize .");
-            facets.addAll(fs);
+            facets.put(getCurrentStateId(), fs);
         }
         else {
             logger.debug("No facets to add in AnnotationsArtifact.initialize .");
@@ -173,14 +173,15 @@
                 continue;
             }
 
-            if (facets == null || facets.size() == 0) {
+            List<Facet> fs = facets.get(stateId);
+            if (fs == null || fs.size() == 0) {
                 logger.debug("No facets found.");
                 continue;
             }
 
-            logger.debug("Found " + facets.size() + " facets in previous states.");
+            logger.debug("Found " + fs.size() + " facets in previous states.");
 
-            List<Output> generated = generateOutputs(list, facets);
+            List<Output> generated = generateOutputs(list, fs);
 
             ProtocolUtils.appendOutputModes(doc, outs, generated);
         }
@@ -193,10 +194,11 @@
                     logger.debug(
                         "Append output modes for state: " + cur.getID());
 
-                    if (facets != null && facets.size() > 0) {
-                        List<Output> generated = generateOutputs(list, facets);
+                    List<Facet> fs = facets.get(cur.getID());
+                    if (fs != null && fs.size() > 0) {
+                        List<Output> generated = generateOutputs(list, fs);
 
-                        logger.debug("Found " + facets.size() + " current facets.");
+                        logger.debug("Found " + fs.size() + " current facets.");
                         if (!generated.isEmpty()) {
                             ProtocolUtils.appendOutputModes(
                                 doc, outs, generated);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -97,8 +97,8 @@
     /** The data that have been inserted into this artifact. */
     protected Map<String, StateData> data;
 
-    /** The list of facets produced by this artifact. */
-    protected List<Facet> facets;
+    /** Mapping of state names to created facets. */
+    protected Map<String, List<Facet>> facets;
 
     /**
      * Used to generates "view" on the facets (hides facets not matching the
@@ -113,7 +113,7 @@
     public FLYSArtifact() {
         data             = new TreeMap<String, StateData>();
         previousStateIds = new ArrayList<String>();
-        facets           = new ArrayList<Facet>();
+        facets           = new HashMap<String, List<Facet>>();
     }
 
 
@@ -208,13 +208,18 @@
 
     /**
      * Return a copy of the facet mapping.
-     * @return Copy of facets list.
+     * @return Mapping of state-ids to facets.
      */
-    protected List<Facet> cloneFacets() {
-        List copy = new ArrayList<Facet>(facets.size());
+    protected Map<String, List<Facet>> cloneFacets() {
+        Map copy = new HashMap<String, List<Facet>>();
 
-        for (Facet facet: facets) {
-            copy.add(facet.deepCopy());
+        for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) {
+            List<Facet> facets      = entry.getValue();
+            List<Facet> facetCopies = new ArrayList<Facet>(facets.size());
+            for (Facet facet: facets) {
+                facetCopies.add(facet.deepCopy());
+            }
+            copy.put(entry.getKey(), facetCopies);
         }
 
         return copy;
@@ -223,6 +228,7 @@
 
     /**
      * (called from setup).
+     * @param artifact master-artifact (if any, otherwise initialize is not called).
      */
     protected void initialize(
         Artifact artifact,
@@ -540,13 +546,21 @@
     }
 
 
+    /**
+     * Get facet as stored internally, with equalling name and index than given
+     * facet.
+     * @param facet that defines index and name of facet searched.
+     * @return facet instance or null if not found.
+     */
     public Facet getNativeFacet(Facet facet) {
         String name  = facet.getName();
         int    index = facet.getIndex();
 
-        for (Facet f: facets) {
-            if (f.getIndex() == index && f.getName().equals(name)) {
-                return f;
+        for (Map.Entry<String, List<Facet>> facetList: facets.entrySet()) {
+            for (Facet f: facetList.getValue()) {
+                if (f.getIndex() == index && f.getName().equals(name)) {
+                    return f;
+                }
             }
         }
 
@@ -775,12 +789,14 @@
             return new ArrayList<Output>();
         }
 
-        if (facets == null || facets.size() == 0) {
+        List<Facet> fs = facets.get(state.getID());
+
+        if (fs == null || fs.size() == 0) {
             logger.debug("No facets found.");
             return new ArrayList<Output>();
         }
 
-        return generateOutputs(list, facets);
+        return generateOutputs(list, fs);
     }
 
 
@@ -951,10 +967,10 @@
         finally {
             if (generateFacets) {
                 if (fs.isEmpty()) {
-                    facets.removeAll(fs);
+                    facets.remove(stateID);
                 }
                 else {
-                    facets.addAll(fs);
+                    facets.put(stateID, fs);
                 }
             }
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -47,6 +47,9 @@
     /** The name of the artifact. */
     public static final String ARTIFACT_NAME = "mainvalue";
 
+    /** The name of the static state for this artifact. */
+    public static final String STATIC_STATE_NAME = "state.mainvalue.static";
+
     /** One and only state to be in. */
     protected transient State state = null;
 
@@ -72,8 +75,8 @@
     {
         logger.debug("MainValuesArtifact.setup");
         state = new StaticState(
-            "state.mainvalue.static",
-            "state.mainvalue.static");
+            STATIC_STATE_NAME,
+            STATIC_STATE_NAME);
         Facet qfacet = new MainValuesQFacet(Resources.getMsg(
             callMeta,
             "facet.discharge_curves.mainvalues.q",
@@ -82,18 +85,28 @@
             callMeta,
             "facet.discharge_curves.mainvalues.w",
             "facet.discharge_curves.mainvalues.w"));
-        facets.add(qfacet);
-        facets.add(wfacet);
+
+        List<Facet> fs = new ArrayList<Facet>();
+        fs.add(qfacet);
+        fs.add(wfacet);
+
+        facets.put(state.getID(), fs);
         spawnState();
         super.setup(identifier, factory, context, callMeta, data);
     }
 
+
+    /**
+     * Create "the" state.
+     */
     protected State spawnState() {
-        state = new StaticState("state.mainvalue.static", "state.mainvalue.static");
+        state = new StaticState(STATIC_STATE_NAME, STATIC_STATE_NAME);
+        List<Facet> fs = (List<Facet>) facets.get(STATIC_STATE_NAME);
+
         DefaultOutput mainValuesOutput2 = new DefaultOutput(
             "computed_discharge_curve",
             "output.computed_discharge_curve", "image/png",
-            facets,
+            fs,
             "chart");
 
         state.getOutputs().add(mainValuesOutput2);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -77,7 +77,7 @@
                 state.computeInit(this, hash(), context, callMeta, fs);
 
                 if (!fs.isEmpty()) {
-                    facets.addAll(fs);
+                    facets.put(getCurrentStateId(), fs);
                 }
             }
             catch (NumberFormatException nfe) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -58,10 +58,11 @@
         List<Output> list = state.getOutputs();
 
         if (list != null && list.size() > 0) {
-            if (facets != null && facets.size() > 0) {
-                List<Output> generated = generateOutputs(list, facets);
+            List<Facet> fs = facets.get(state.getID());
+            if (fs != null && fs.size() > 0) {
+                List<Output> generated = generateOutputs(list, fs);
 
-                logger.debug("Found " + facets.size() + " current facets.");
+                logger.debug("Found " + fs.size() + " current facets.");
                 if (!generated.isEmpty()) {
                     ProtocolUtils.appendOutputModes(
                         doc, outs, generated);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -43,6 +43,10 @@
     public static final String XPATH_DATA =
         "/art:action/art:ids/@value";
 
+    public static final String STATIC_STATE_NAME =
+        "state.additional_wkms.static";
+
+
     /** One and only state to be in. */
     protected transient State state = null;
 
@@ -69,9 +73,10 @@
         logger.debug("StaticWKmsArtifact.setup");
 
         state = new StaticState(
-            "state.additional_wkms.static",
-            "state.additional_wkms.static");
+            STATIC_STATE_NAME,
+            STATIC_STATE_NAME);
 
+        List<Facet> fs = new ArrayList<Facet>();
         logger.debug(XMLUtils.toString(data));
         String code = XMLUtils.xpathString(
             data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE);
@@ -98,8 +103,8 @@
                             callMeta,
                             wkmsName,
                             wkmsName));
-
-                    facets.add(facet);
+                    fs.add(facet);
+                    facets.put(state.getID(), fs);
                 }
                 catch (Exception e) {}
             }
@@ -116,17 +121,18 @@
      */
     protected State spawnState() {
         state = new StaticState(
-            "state.additional_wkms.static",
-            "state.additional_wkms.static");
+            STATIC_STATE_NAME,
+            STATIC_STATE_NAME);
+        List<Facet> fs = facets.get(STATIC_STATE_NAME);
         DefaultOutput output1 = new DefaultOutput(
             "w_differences",
             "w_differences.longitudinal_section", "image/png",
-            facets,
+            fs,
             "chart");
         DefaultOutput output2 = new DefaultOutput(
             "longitudinal_section",
             "longitudinal_section.longitudinal_section", "image/png",
-            facets,
+            fs,
             "chart");
 
         state.getOutputs().add(output1);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -256,14 +256,16 @@
                 continue;
             }
 
-            if (facets == null || facets.size() == 0) {
+            List<Facet> fs = facets.get(stateId);
+
+            if (fs == null || fs.size() == 0) {
                 logger.debug("No facets for previous state found.");
                 continue;
             }
 
-            logger.debug("Found " + facets.size() + " facets in previous states.");
+            logger.debug("Found " + fs.size() + " facets in previous states.");
 
-            List<Output> generated = generateOutputs(list, facets);
+            List<Output> generated = generateOutputs(list, fs);
 
             ProtocolUtils.appendOutputModes(doc, outs, generated);
         }
@@ -276,10 +278,12 @@
                     logger.debug(
                         "Append output modes for current state: " + cur.getID());
 
-                    if (facets != null && facets.size() > 0) {
-                        List<Output> generated = generateOutputs(list, facets);
+                    List<Facet> fs = facets.get(cur.getID());
 
-                        logger.debug("Found " + facets.size() + " current facets.");
+                    if (fs != null && fs.size() > 0) {
+                        List<Output> generated = generateOutputs(list, fs);
+
+                        logger.debug("Found " + fs.size() + " current facets.");
                         if (!generated.isEmpty()) {
                             ProtocolUtils.appendOutputModes(
                                 doc, outs, generated);
@@ -1284,10 +1288,10 @@
      * @param index     index of the facet.
      */
     public int getInitialFacetActivity(String facetName, int index) {
-        return facetName.endsWith("q")
+        return (facetName.startsWith("longitudinal_section")
+                && facetName.endsWith("q"))
                ? 0
                : 1;
     }
-
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -41,7 +41,7 @@
         state.computeInit(this, hash(), context, meta, fs);
 
         if (!fs.isEmpty()) {
-            facets.addAll(fs);
+            facets.put(getCurrentStateId(), fs);
         }
     }
 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -76,7 +76,7 @@
         state.computeInit(this, hash(), context, meta, fs);
         if (!fs.isEmpty()) { 
             logger.debug("Facets to add in WaterlevelArtifact.initialize ."); 
-            facets.addAll(fs); 
+            facets.put(getCurrentStateId(), fs); 
         } 
         else { 
             logger.debug("No facets to add in WaterlevelArtifact.initialize ("

http://dive4elements.wald.intevation.org