changeset 846:e47ef0ca8f33

Compile a list of recommendations out of flys-client/trunk@2570 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 24 Aug 2011 16:52:40 +0000
parents 4db672cdacb2
children 25a4bf390757
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactFilter.java flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java flys-client/src/main/java/de/intevation/flys/client/shared/model/OutFilter.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java
diffstat 5 files changed, 103 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Aug 24 16:06:48 2011 +0000
+++ b/flys-client/ChangeLog	Wed Aug 24 16:52:40 2011 +0000
@@ -1,3 +1,14 @@
+2011-08-24	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/ToLoad.java
+	  (toRecommendations): Compile a list of recommendations out of
+	  datacage tree selections. A lot of model conversions. :-/
+
+	* src/main/java/de/intevation/flys/client/shared/model/ArtifactFilter.java,
+	  src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java,
+	  src/main/java/de/intevation/flys/client/shared/model/OutFilter.java:
+	  Added code to convert the models.
+	  
 2011-08-24	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/services/ArtifactService.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactFilter.java	Wed Aug 24 16:06:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactFilter.java	Wed Aug 24 16:52:40 2011 +0000
@@ -4,6 +4,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.List;
 
 public class ArtifactFilter
 implements   Serializable
@@ -42,5 +43,22 @@
         }
         outFilter.add(name, num);
     }
+
+    public String collectIds() {
+        StringBuilder sb = new StringBuilder();
+        for (OutFilter outFilter: outFilters.values()) {
+            outFilter.collectIds(sb);
+        }
+        return sb.toString();
+    }
+
+    public Recommendation.Filter toFilter() {
+        Recommendation.Filter rf = new Recommendation.Filter();
+        for (Map.Entry<String, OutFilter> entry: outFilters.entrySet()) {
+            List<Recommendation.Facet> facets = entry.getValue().toFacets();
+            rf.add(entry.getKey(), facets);
+        }
+        return rf;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java	Wed Aug 24 16:06:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java	Wed Aug 24 16:52:40 2011 +0000
@@ -46,5 +46,18 @@
         FacetFilter o = (FacetFilter)other;
         return equals(o.name, name) && equals(o.ids, ids);
     }
+
+    public void collectIds(StringBuilder sb) {
+        if (ids != null) {
+            if (sb.length() > 0) {
+                sb.append(' ');
+            }
+            sb.append(ids);
+        }
+    }
+
+    public Recommendation.Facet toFacet() {
+        return new Recommendation.Facet(name, ids);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutFilter.java	Wed Aug 24 16:06:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutFilter.java	Wed Aug 24 16:52:40 2011 +0000
@@ -43,5 +43,20 @@
     public void setFacetFilters(List<FacetFilter> facetFilters) {
         this.facetFilters = facetFilters;
     }
+
+    public void collectIds(StringBuilder sb) {
+        for (FacetFilter facetFilter: facetFilters) {
+            facetFilter.collectIds(sb);
+        }
+    }
+
+    public List<Recommendation.Facet> toFacets() {
+        List<Recommendation.Facet> facets =
+            new ArrayList<Recommendation.Facet>(facetFilters.size());
+        for (FacetFilter facetFilter: facetFilters) {
+            facets.add(facetFilter.toFacet());
+        }
+        return facets;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java	Wed Aug 24 16:06:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java	Wed Aug 24 16:52:40 2011 +0000
@@ -1,5 +1,7 @@
 package de.intevation.flys.client.shared.model;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
 
@@ -7,6 +9,8 @@
 
 public class ToLoad implements Serializable
 {
+    public static final String SYNTHETIC_KEY = "key-";
+
     protected Map<String, Map<String, ArtifactFilter>> artifacts;
 
     public ToLoad() {
@@ -16,9 +20,9 @@
     public static final String uniqueKey(Map<?, ?> map) {
         int idx = map.size();
 
-        String key = "key-" + idx;
+        String key = SYNTHETIC_KEY + idx;
         while (map.containsKey(key)) {
-            key = "key-" + ++idx;
+            key = SYNTHETIC_KEY + ++idx;
         }
         return key;
     }
@@ -53,5 +57,45 @@
     public boolean isEmpty() {
         return artifacts.isEmpty();
     }
+
+    public List<Recommendation> toRecommendations() {
+        List<Recommendation> recommendations = new ArrayList<Recommendation>();
+
+        for (Map.Entry<String, Map<String, ArtifactFilter>> all:
+            artifacts.entrySet()
+        ) {
+            String masterArtifact = all.getKey();
+
+            if (masterArtifact.startsWith(SYNTHETIC_KEY)) { // system data
+                masterArtifact = null;
+            }
+
+            for (Map.Entry<String, ArtifactFilter> entry:
+                all.getValue().entrySet()
+            ) {
+                String         factory        = entry.getKey();
+                ArtifactFilter artifactFilter = entry.getValue();
+
+                String                ids;
+                Recommendation.Filter filter;
+
+                if (masterArtifact == null) { // system data
+                    ids    = artifactFilter.collectIds();
+                    filter = null;
+                }
+                else { // user specific
+                    ids    = null;
+                    filter = artifactFilter.toFilter();
+                }
+
+                Recommendation recommendation = new Recommendation(
+                    factory, ids, masterArtifact, filter);
+
+                recommendations.add(recommendation);
+            }
+        }
+
+        return recommendations;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org