changeset 347:16ab243507e0

Let StateEngine compute compatibility matrix based on a list of states. artifacts/trunk@3108 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 28 Oct 2011 10:08:35 +0000
parents 2d525562fae9
children f2277458823e
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java
diffstat 2 files changed, 49 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Oct 21 07:45:33 2011 +0000
+++ b/ChangeLog	Fri Oct 28 10:08:35 2011 +0000
@@ -1,3 +1,12 @@
+2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Let StateEngine compute a compatibiliy matrix based on given State
+	IDs.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java
+	  (getCompatibleFacets): New. Compute output/facet compatibility
+	  matrix based on given states.
+
 2011-10-21  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/resources/sql/org-h2-driver.properties:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java	Fri Oct 21 07:45:33 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java	Fri Oct 28 10:08:35 2011 +0000
@@ -1,5 +1,6 @@
 package de.intevation.artifactdatabase.state;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -7,7 +8,8 @@
 import org.apache.log4j.Logger;
 
 /**
- * The StateEngine stores all states for each Artifact.
+ * The StateEngine stores all states and associated information about
+ * outputs and facets for each Artifact.
  *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
@@ -93,7 +95,7 @@
     /**
      * Returns the state list of an artifact specified by its name.
      *
-     * @param artifact The name of the artifact.
+     * @param artifact The name of the artifact (e.g. "winfo").
      *
      * @return the list of states of this artifact or <i>null</i> if no states
      * are existing for this <i>artifact</i>.
@@ -101,5 +103,40 @@
     public List<State> getStates(String artifact) {
         return states.get(artifact);
     }
+
+
+    /**
+     * Return mapping of output to facets for an artifact in its states.
+     */
+    public Map<String, List<String>> getCompatibleFacets(List<String> aStates) {
+        Map<String, List<String>> compatibilityMatrix =
+            new HashMap<String, List<String>>();
+
+        // For all states that the artifact had seen, add outputs facets.
+        for (String stateId: aStates) {
+
+            State state = allStates.get(stateId);
+            if (state == null) {
+                continue;
+            }
+
+            for (Output output: state.getOutputs()) {
+                List<Facet> outFacets = output.getFacets();
+
+                List<String> oldFacets = compatibilityMatrix.get(output.getName());
+
+                if (oldFacets == null) {
+                    oldFacets = new ArrayList<String>();
+                }
+
+                for (Facet facet: outFacets) {
+                    oldFacets.add(facet.getName());
+                }
+
+                compatibilityMatrix.put(output.getName(), oldFacets);
+            }
+        }
+        return compatibilityMatrix;
+    }
 }
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+// vim:set ts=4 sw=4 et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org