changeset 807:6f65e70fa11d

Repaired broken recommendation parsing from Artifact's DESCRIBE document (which structure has changed). flys-client/trunk@2391 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 21 Jul 2011 15:23:03 +0000
parents e50da1f74e58
children 3187b268b311
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultRecommendation.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Recommendation.java
diffstat 12 files changed, 131 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/ChangeLog	Thu Jul 21 15:23:03 2011 +0000
@@ -1,3 +1,33 @@
+2011-07-21  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/DefaultRecommendation.java,
+	  src/main/java/de/intevation/flys/client/shared/model/Recommendation.java:
+	  New. The interface and its default implementation that represent
+	  recommendations provided by an Artifact. A recommendation consists at
+	  least of the name of an ArtifactFactory and a list of database ids.
+
+	* src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java:
+	  Read the recommendations from Artifact's DESCRIBE document (which
+	  structure has changed.)
+
+	* src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java,
+	  src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java:
+	  Recommendation are no longer simple strings but Recommendation objects
+	  now. So, the interface to retrieve those recommendations has changed.
+
+	* src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/client/services/ArtifactService.java,
+	  src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java:
+	  This service takes a further string now, which represents the database
+	  ids used to create static artifacts that require data from database.
+
+	* src/main/java/de/intevation/flys/client/client/FLYS.java,
+	  src/main/java/de/intevation/flys/client/client/ui/ParameterList.java,
+	  src/main/java/de/intevation/flys/client/client/ui/CollectionView.java:
+	  Adapted the call of the ArtifactService.
+
+M      src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java
+
 2011-07-20  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java: The
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Thu Jul 21 15:23:03 2011 +0000
@@ -397,7 +397,7 @@
         String url    = config.getServerUrl();
         String locale = config.getLocale();
 
-        artifactService.create(url, locale, factory, null,
+        artifactService.create(url, locale, factory, null, null,
             new AsyncCallback<Artifact>() {
                 public void onFailure(Throwable caught) {
                     GWT.log("Could not create the new artifact.");
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java	Thu Jul 21 15:23:03 2011 +0000
@@ -28,7 +28,8 @@
         String serverUrl,
         String locale,
         String factory,
-        String uuid
+        String uuid,
+        String ids
     ) throws ServerException;
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java	Thu Jul 21 15:23:03 2011 +0000
@@ -18,6 +18,7 @@
         String locale,
         String factory,
         String uuid,
+        String ids,
         AsyncCallback<Artifact> callback);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Thu Jul 21 15:23:03 2011 +0000
@@ -22,6 +22,7 @@
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.ExportMode;
 import de.intevation.flys.client.shared.model.OutputMode;
+import de.intevation.flys.client.shared.model.Recommendation;
 import de.intevation.flys.client.shared.model.ReportMode;
 import de.intevation.flys.client.shared.model.User;
 
@@ -313,10 +314,10 @@
         Artifact art             = event.getNewValue();
         ArtifactDescription desc = art.getArtifactDescription();
         OutputMode[] outs        = desc.getOutputModes();
-        String[] recommended     = desc.getRecommendedArtifacts();
+        Recommendation[] recom   = desc.getRecommendations();
 
-        if (recommended != null) {
-            loadRecommendedArtifacts(recommended);
+        if (recom != null) {
+            loadRecommendedArtifacts(recom);
         }
 
         setArtifact(art);
@@ -536,17 +537,26 @@
     }
 
 
-    protected void loadRecommendedArtifacts(String[] factories) {
+    protected void loadRecommendedArtifacts(Recommendation[] recommendations) {
         Config config               = Config.getInstance();
         final String url            = config.getServerUrl();
         final String locale         = config.getLocale();
         final Collection collection = getCollection();
         final Artifact master       = getArtifact();
 
-        for (String factory: factories) {
-            GWT.log("Load recommended artifact: " + factory);
+        if (master == null || recommendations == null) {
+            GWT.log("WARNING: Currently no master artifact set or no recom.");
+            return;
+        }
 
-            createArtifactService.create(url, locale, factory, master.getUuid(),
+        for (Recommendation recommendation: recommendations) {
+            final String factory = recommendation.getFactory();
+            final String ids     = recommendation.getIDs();
+
+            GWT.log("Load recommended artifact with factory: " + factory);
+
+            createArtifactService.create(
+                url, locale, factory, master.getUuid(), ids,
                 new AsyncCallback<Artifact>() {
 
                     public void onFailure(Throwable caught) {
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Thu Jul 21 15:23:03 2011 +0000
@@ -351,7 +351,7 @@
                 final Data[] feedData  = new Data[] { data[1] };
 
                 artifactService.create(
-                    url, locale, module.toLowerCase(), null,
+                    url, locale, module.toLowerCase(), null, null,
                     new AsyncCallback<Artifact>() {
                         public void onFailure(Throwable caught) {
                             GWT.log("Could not create the new artifact.");
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Thu Jul 21 15:23:03 2011 +0000
@@ -21,7 +21,9 @@
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.DefaultOutputMode;
+import de.intevation.flys.client.shared.model.DefaultRecommendation;
 import de.intevation.flys.client.shared.model.OutputMode;
+import de.intevation.flys.client.shared.model.Recommendation;
 import de.intevation.flys.client.shared.model.WQDataItem;
 
 
@@ -48,7 +50,7 @@
     public static final String XPATH_STATIC_ITEM_NODE = "art:item";
 
     public static final String XPATH_RECOMMENDED_ARTIFACTS =
-        "/art:result/art:recommended-artifacts/art:artifact-factory";
+        "/art:result/art:recommended-artifacts/*[@factory]";
 
     /**
      * This method creates the {@link ArtifactDescription} of the DESCRIBE
@@ -78,7 +80,7 @@
         DataList[] old       = extractOldData(staticNode);
         String[] states      = extractReachableStates(reachable);
         OutputMode[] outs    = extractOutputModes(outputs);
-        String[] recommended = extractRecommendedArtifacts(doc);
+        Recommendation[] rec = extractRecommendedArtifacts(doc);
 
         return new DefaultArtifactDescription(
             old,
@@ -86,7 +88,7 @@
             state,
             states,
             outs,
-            recommended);
+            rec);
     }
 
 
@@ -472,7 +474,7 @@
     }
 
 
-    protected static String[] extractRecommendedArtifacts(Document doc) {
+    protected static Recommendation[] extractRecommendedArtifacts(Document doc){
         System.out.println("ArtifactDescriptionFactory - extract recommended.");
 
         NodeList list = (NodeList) XMLUtils.xpath(
@@ -483,18 +485,19 @@
 
         int num = list != null ? list.getLength() : 0;
 
-        String[] factories = new String[num];
+        Recommendation[] rec = new Recommendation[num];
 
         for (int i = 0; i < num; i++) {
-            Element e = (Element) list.item(i);
-            String  f = e.getAttribute("name");
+            Element e       = (Element) list.item(i);
+            String  factory = e.getAttribute("factory");
+            String  index   = e.getAttribute("db-ids");
 
-            if (f != null && f.length() > 0) {
-                factories[i] = f;
+            if (factory != null && factory.length() > 0) {
+                rec[i] = new DefaultRecommendation(factory, index);
             }
         }
 
-        return factories;
+        return rec;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java	Thu Jul 21 15:23:03 2011 +0000
@@ -31,10 +31,11 @@
 
 
     public Artifact create(
-        String    serverUrl,
-        String    locale,
-        String    factory,
-        String    uuid)
+        String serverUrl,
+        String locale,
+        String factory,
+        String uuid,
+        String ids)
     throws ServerException
     {
         System.out.println("ArtifactServiceImpl.create");
@@ -42,7 +43,7 @@
         Document create = null;
 
         if (uuid != null && uuid.length() > 0) {
-            create = ClientProtocolUtils.newCreateDocument(factory, uuid);
+            create = ClientProtocolUtils.newCreateDocument(factory, uuid, ids);
         }
         else {
             create = ClientProtocolUtils.newCreateDocument(factory);
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java	Thu Jul 21 15:23:03 2011 +0000
@@ -59,6 +59,6 @@
      *
      * @return the recommended artifacts.
      */
-    public String[] getRecommendedArtifacts();
+    public Recommendation[] getRecommendations();
 }
 // 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/DefaultArtifactDescription.java	Wed Jul 20 13:31:20 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java	Thu Jul 21 15:23:03 2011 +0000
@@ -25,8 +25,8 @@
     /** The output modes of this state.*/
     protected OutputMode[] outputModes;
 
-    /** A list of artifact factories suggested by the server.*/
-    protected String[] recommendedArtifacts;
+    /** A list of recommendations suggested by the server.*/
+    protected Recommendation[] recommendations;
 
 
     public DefaultArtifactDescription() {
@@ -64,16 +64,16 @@
      * @param outputModes The available output modes of this artifact.
      */
     public DefaultArtifactDescription(
-        DataList[]   old,
-        DataList     current,
-        String       state,
-        String[]     reachableStates,
-        OutputMode[] outputModes,
-        String[]     recommendedArtifacts)
+        DataList[]       old,
+        DataList         current,
+        String           state,
+        String[]         reachableStates,
+        OutputMode[]     outputModes,
+        Recommendation[] recommendations)
     {
         this(old, current, state, reachableStates);
-        this.outputModes          = outputModes;
-        this.recommendedArtifacts = recommendedArtifacts;
+        this.outputModes     = outputModes;
+        this.recommendations = recommendations;
     }
 
 
@@ -102,8 +102,8 @@
     }
 
 
-    public String[] getRecommendedArtifacts() {
-        return recommendedArtifacts;
+    public Recommendation[] getRecommendations() {
+        return recommendations;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultRecommendation.java	Thu Jul 21 15:23:03 2011 +0000
@@ -0,0 +1,32 @@
+package de.intevation.flys.client.shared.model;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DefaultRecommendation implements Recommendation {
+
+    protected String factory;
+    protected String ids;
+
+
+    public DefaultRecommendation() {
+    }
+
+
+    public DefaultRecommendation(String factory, String ids) {
+        this.factory = factory;
+        this.ids     = ids;
+    }
+
+
+    public String getFactory() {
+        return factory;
+    }
+
+
+    public String getIDs() {
+        return ids;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Recommendation.java	Thu Jul 21 15:23:03 2011 +0000
@@ -0,0 +1,15 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface Recommendation extends Serializable {
+
+    String getFactory();
+
+    String getIDs();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org