changeset 1765:5d8b3880a553

Do not store association of states to facets, let artifacts keep facets in a pure list. flys-artifacts/trunk@3083 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 26 Oct 2011 12:23:47 +0000
parents 87c82499b98f
children 23b99572f725
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/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 9 files changed, 108 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Oct 26 12:03:59 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Oct 26 12:23:47 2011 +0000
@@ -1,3 +1,23 @@
+2011-10-26  Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Resolve association of facets to states in artifacts. This eases
+	merging of outputs and facets and inhibition of unwanted outputs
+	substiantially (at the price of slightly more expensive merging).
+	Also, the semantics of artifacts configuration files (e.g. winfo.xml)
+	is changed (facet elements within an output elements are used for
+	merging).
+
+	* 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/FLYSArtifact.java:
+	  Do not store facets in a map from stateId to list of facets, but in
+	  a pure list instead.
+
 2011-10-26  Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml: Added dc configuration for some data
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java	Wed Oct 26 12:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -63,7 +63,7 @@
 
         if (!fs.isEmpty()) {
             logger.debug("Facets to add in AnnotationsArtifact.initialize .");
-            facets.put(getCurrentStateId(), fs);
+            facets.addAll(fs);
         }
         else {
             logger.debug("No facets to add in AnnotationsArtifact.initialize .");
@@ -173,15 +173,14 @@
                 continue;
             }
 
-            List<Facet>  fs = facets.get(stateId);
-            if (fs == null || fs.size() == 0) {
+            if (facets == null || facets.size() == 0) {
                 logger.debug("No facets found.");
                 continue;
             }
 
-            logger.debug("Found " + fs.size() + " facets in previous states.");
+            logger.debug("Found " + facets.size() + " facets in previous states.");
 
-            List<Output> generated = generateOutputs(list, fs);
+            List<Output> generated = generateOutputs(list, facets);
 
             ProtocolUtils.appendOutputModes(doc, outs, generated);
         }
@@ -194,11 +193,10 @@
                     logger.debug(
                         "Append output modes for state: " + cur.getID());
 
-                    List<Facet>  fs = facets.get(cur.getID());
-                    if (fs != null && fs.size() > 0) {
-                        List<Output> generated = generateOutputs(list, fs);
+                    if (facets != null && facets.size() > 0) {
+                        List<Output> generated = generateOutputs(list, facets);
 
-                        logger.debug("Found " + fs.size() + " current facets.");
+                        logger.debug("Found " + facets.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:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -85,7 +85,6 @@
     /** The constant string that shows that an operation failed. */
     public static final String OPERATION_FAILED = "FAILURE";
 
-
     /** The identifier of the current state. */
     protected String currentStateId;
 
@@ -98,8 +97,8 @@
     /** The data that have been inserted into this artifact. */
     protected Map<String, StateData> data;
 
-    /** The list of facets supported by this artifact. */
-    protected Map<String, List<Facet>> facets;
+    /** The list of facets produced by this artifact. */
+    protected List<Facet> facets;
 
     /**
      * Used to generates "view" on the facets (hides facets not matching the
@@ -114,7 +113,7 @@
     public FLYSArtifact() {
         data             = new TreeMap<String, StateData>();
         previousStateIds = new ArrayList<String>();
-        facets           = new HashMap<String, List<Facet>>();
+        facets           = new ArrayList<Facet>();
     }
 
 
@@ -209,24 +208,22 @@
 
     /**
      * Return a copy of the facet mapping.
-     * @return Mapping of outputnames to facets.
+     * @return Copy of facets list.
      */
-    protected Map<String, List<Facet>> cloneFacets() {
-        Map copy = new HashMap<String, List<Facet>>();
+    protected List<Facet> cloneFacets() {
+        List copy = new ArrayList<Facet>(facets.size());
 
-        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);
+        for (Facet facet: facets) {
+            copy.add(facet.deepCopy());
         }
 
         return copy;
     }
 
 
+    /**
+     * (called from setup).
+     */
     protected void initialize(
         Artifact artifact,
         Object   context,
@@ -547,11 +544,9 @@
         String name  = facet.getName();
         int    index = facet.getIndex();
 
-        for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) {
-            for (Facet f: entry.getValue()) {
-                if (f.getIndex() == index && f.getName().equals(name)) {
-                    return f;
-                }
+        for (Facet f: facets) {
+            if (f.getIndex() == index && f.getName().equals(name)) {
+                return f;
             }
         }
 
@@ -729,6 +724,12 @@
     }
 
 
+    /**
+     * Get all outputs that the Artifact can do in this state (which includes
+     * all previous states).
+     *
+     * @return list of outputs
+     */
     public List<Output> getOutputs(Object context) {
         List<String> stateIds  = getPreviousStateIds();
         List<Output> generated = new ArrayList<Output>();
@@ -744,6 +745,10 @@
     }
 
 
+    /**
+     * Get output(s) for current state.
+     * @return list of outputs for current state.
+     */
     public List<Output> getCurrentOutputs(Object context) {
         DefaultState cur = (DefaultState) getCurrentState(context);
 
@@ -758,6 +763,11 @@
     }
 
 
+    /**
+     * Get output(s) for a specific state.
+     * @param state State of interest
+     * @return list of output(s) for given state.
+     */
     protected List<Output> getOutputForState(DefaultState state) {
         List<Output> list = state.getOutputs();
         if (list == null || list.size() == 0) {
@@ -765,13 +775,12 @@
             return new ArrayList<Output>();
         }
 
-        List<Facet>  fs = facets.get(state.getID());
-        if (fs == null || fs.size() == 0) {
+        if (facets == null || facets.size() == 0) {
             logger.debug("No facets found.");
             return new ArrayList<Output>();
         }
 
-        return generateOutputs(list, fs);
+        return generateOutputs(list, facets);
     }
 
 
@@ -885,6 +894,8 @@
 
 
     /**
+     * Let current state compute and register facets.
+     *
      * @param key key of state
      * @param state state
      * @param type Type of compute
@@ -940,10 +951,10 @@
         finally {
             if (generateFacets) {
                 if (fs.isEmpty()) {
-                    facets.remove(stateID);
+                    facets.removeAll(fs);
                 }
                 else {
-                    facets.put(stateID, fs);
+                    facets.addAll(fs);
                 }
             }
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Wed Oct 26 12:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -71,29 +71,30 @@
         Document        data)
     {
         logger.debug("MainValuesArtifact.setup");
-        state = new StaticState("state.mainvalue.static", "state.mainvalue.static");
-        List<Facet> fs = new ArrayList<Facet>();
-        Facet qfacet = new MainValuesQFacet(Resources.getMsg(callMeta,
-                   "facet.discharge_curves.mainvalues.q",
-                   "facet.discharge_curves.mainvalues.q"));
-        Facet wfacet = new MainValuesWFacet(Resources.getMsg(callMeta,
-                   "facet.discharge_curves.mainvalues.w",
-                   "facet.discharge_curves.mainvalues.w"));
-        fs.add(qfacet);
-        fs.add(wfacet);
-        facets.put(state.getID(), fs);
+        state = new StaticState(
+            "state.mainvalue.static",
+            "state.mainvalue.static");
+        Facet qfacet = new MainValuesQFacet(Resources.getMsg(
+            callMeta,
+            "facet.discharge_curves.mainvalues.q",
+            "facet.discharge_curves.mainvalues.q"));
+        Facet wfacet = new MainValuesWFacet(Resources.getMsg(
+            callMeta,
+            "facet.discharge_curves.mainvalues.w",
+            "facet.discharge_curves.mainvalues.w"));
+        facets.add(qfacet);
+        facets.add(wfacet);
         spawnState();
         super.setup(identifier, factory, context, callMeta, data);
     }
 
     protected State spawnState() {
         state = new StaticState("state.mainvalue.static", "state.mainvalue.static");
-        List<Facet> fs = (List<Facet>) facets.get("state.mainvalue.static");
         DefaultOutput mainValuesOutput2 = new DefaultOutput(
-                    "computed_discharge_curve",
-                    "output.computed_discharge_curve", "image/png",
-                    fs,
-                    "chart");
+            "computed_discharge_curve",
+            "output.computed_discharge_curve", "image/png",
+            facets,
+            "chart");
 
         state.getOutputs().add(mainValuesOutput2);
         return state;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java	Wed Oct 26 12:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -58,11 +58,10 @@
         List<Output> list = state.getOutputs();
 
         if (list != null && list.size() > 0) {
-            List<Facet>  fs = facets.get(state.getID());
-            if (fs != null && fs.size() > 0) {
-                List<Output> generated = generateOutputs(list, fs);
+            if (facets != null && facets.size() > 0) {
+                List<Output> generated = generateOutputs(list, facets);
 
-                logger.debug("Found " + fs.size() + " current facets.");
+                logger.debug("Found " + facets.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:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -72,7 +72,6 @@
             "state.additional_wkms.static",
             "state.additional_wkms.static");
 
-        List<Facet> fs = new ArrayList<Facet>();
         logger.debug(XMLUtils.toString(data));
         String code = XMLUtils.xpathString(
             data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE);
@@ -100,9 +99,7 @@
                             wkmsName,
                             wkmsName));
 
-                    fs.add(facet);
-                    facets.put(state.getID(), fs);
-
+                    facets.add(facet);
                 }
                 catch (Exception e) {}
             }
@@ -121,15 +118,19 @@
         state = new StaticState(
             "state.additional_wkms.static",
             "state.additional_wkms.static");
-        List<Facet> fs = (List<Facet>) facets.get("state.additional_wkms.static");
-        DefaultOutput output = new DefaultOutput(
+        DefaultOutput output1 = new DefaultOutput(
             "w_differences",
             "w_differences.longitudinal_section", "image/png",
-            fs,
+            facets,
             "chart");
-        // TODO: also add longitudinal_section output?
+        DefaultOutput output2 = new DefaultOutput(
+            "longitudinal_section",
+            "longitudinal_section.longitudinal_section", "image/png",
+            facets,
+            "chart");
 
-        state.getOutputs().add(output);
+        state.getOutputs().add(output1);
+        state.getOutputs().add(output2);
         return state;
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Oct 26 12:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -226,6 +226,9 @@
     }
 
 
+    /**
+     * Append output mode nodes to a document.
+     */
     protected void appendOutputModes(
         Document    doc,
         Element     outs,
@@ -253,15 +256,14 @@
                 continue;
             }
 
-            List<Facet>  fs = facets.get(stateId);
-            if (fs == null || fs.size() == 0) {
+            if (facets == null || facets.size() == 0) {
                 logger.debug("No facets for previous state found.");
                 continue;
             }
 
-            logger.debug("Found " + fs.size() + " facets in previous states.");
+            logger.debug("Found " + facets.size() + " facets in previous states.");
 
-            List<Output> generated = generateOutputs(list, fs);
+            List<Output> generated = generateOutputs(list, facets);
 
             ProtocolUtils.appendOutputModes(doc, outs, generated);
         }
@@ -274,11 +276,10 @@
                     logger.debug(
                         "Append output modes for current state: " + cur.getID());
 
-                    List<Facet>  fs = facets.get(cur.getID());
-                    if (fs != null && fs.size() > 0) {
-                        List<Output> generated = generateOutputs(list, fs);
+                    if (facets != null && facets.size() > 0) {
+                        List<Output> generated = generateOutputs(list, facets);
 
-                        logger.debug("Found " + fs.size() + " current facets.");
+                        logger.debug("Found " + facets.size() + " current facets.");
                         if (!generated.isEmpty()) {
                             ProtocolUtils.appendOutputModes(
                                 doc, outs, generated);
@@ -287,7 +288,6 @@
                     else {
                         logger.debug("No facets found for the current state.");
                     }
-
                 }
             }
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java	Wed Oct 26 12:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -17,7 +17,6 @@
 
     public static final String NAME = "wmsbackground";
 
-
     private static final Logger logger =
         Logger.getLogger(WMSBackgroundArtifact.class);
 
@@ -42,7 +41,7 @@
         state.computeInit(this, hash(), context, meta, fs);
 
         if (!fs.isEmpty()) {
-            facets.put(getCurrentStateId(), fs);
+            facets.addAll(fs);
         }
     }
 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java	Wed Oct 26 12:03:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java	Wed Oct 26 12:23:47 2011 +0000
@@ -51,9 +51,11 @@
         Document        data)
     {
         super.setup(identifier, factory, context, callMeta, data);
-        filterFacets.put(
-            "w_differences",
-            filterFacets.get("longitudinal_section"));
+        if(filterFacets != null) {
+            filterFacets.put(
+                "w_differences",
+                filterFacets.get("longitudinal_section"));
+        }
     }
 
     /**
@@ -74,7 +76,7 @@
         state.computeInit(this, hash(), context, meta, fs);
         if (!fs.isEmpty()) { 
             logger.debug("Facets to add in WaterlevelArtifact.initialize ."); 
-            facets.put(getCurrentStateId(), fs); 
+            facets.addAll(fs); 
         } 
         else { 
             logger.debug("No facets to add in WaterlevelArtifact.initialize ("

http://dive4elements.wald.intevation.org