changeset 604:84d3c5fde5bb

First version of error reports. flys-client/trunk@2211 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 Jun 2011 09:11:54 +0000
parents 8cb98fa4987f
children 9e30c776cbef
files flys-client/ChangeLog flys-client/pom.xml flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java
diffstat 4 files changed, 139 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jun 22 15:34:52 2011 +0000
+++ b/flys-client/ChangeLog	Thu Jun 23 09:11:54 2011 +0000
@@ -1,3 +1,14 @@
+2011-06-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* pom.xml: Added dependency to Apache Commons Lang 2.6 http://commons.apache.org/lang/
+	  Used for proper HTML string escaping.
+
+	* src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java: Generate
+	  error reports as HTML lists.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterList.java: Set report
+	  in corresponding panel.
+
 2011-06-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/services/ReportService.java,
--- a/flys-client/pom.xml	Wed Jun 22 15:34:52 2011 +0000
+++ b/flys-client/pom.xml	Thu Jun 23 09:11:54 2011 +0000
@@ -64,6 +64,11 @@
       <version>4.4</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.6</version>
+    </dependency>
   </dependencies>
   
   <build>
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Wed Jun 22 15:34:52 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Thu Jun 23 09:11:54 2011 +0000
@@ -44,11 +44,13 @@
 import de.intevation.flys.client.client.event.StepForwardEvent;
 import de.intevation.flys.client.client.event.StepForwardHandler;
 import de.intevation.flys.client.client.services.AdvanceService;
+import de.intevation.flys.client.client.services.ReportService;
 import de.intevation.flys.client.client.services.AdvanceServiceAsync;
 import de.intevation.flys.client.client.services.ArtifactService;
 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
 import de.intevation.flys.client.client.services.StepForwardService;
 import de.intevation.flys.client.client.services.StepForwardServiceAsync;
+import de.intevation.flys.client.client.services.ReportServiceAsync;
 
 
 public class ParameterList
@@ -73,6 +75,10 @@
         GWT.create(AdvanceService.class);
 
 
+    protected ReportServiceAsync reportService =
+        GWT.create(ReportService.class);
+
+
     /** The list of ParameterizationChangeHandler.*/
     protected List<ParameterChangeHandler> parameterHandlers;
 
@@ -167,7 +173,6 @@
         left.addMember(report);
 
         reportPanel = new Canvas();
-        //reportPanel.setContents("<strong>I was here!</strong>");
         reportPanel.setHeight("*");
         report.addMember(reportPanel);
 
@@ -583,10 +588,39 @@
         int num = reports != null ? reports.size() : 0;
         GWT.log("Update report modes: " + num);
 
+        if (num == 0) {
+            reportPanel.setContents("");
+            return;
+        }
+
+        Config config = Config.getInstance();
+        String url    = config.getServerUrl();
+        String locale = config.getLocale();
+
+        String cid = c.identifier();
+
         for (ReportMode report: reports) {
             GWT.log("report '" + report.toString() + "'");
+
+            reportService.report(cid, url, locale, report.getName(),
+                new AsyncCallback<String>() {
+                    public void onFailure(Throwable caught) {
+                        SC.warn(caught.getMessage());
+                    }
+
+                    public void onSuccess(String msg) {
+                        setReportMessage(msg);
+                    }
+                });
         }
+    }
 
+    protected void setReportMessage(String msg) {
+        GWT.log("returned from service: " + msg);
+        if (msg == null) {
+            msg = "";
+        }
+        reportPanel.setContents(msg);
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java	Wed Jun 22 15:34:52 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java	Thu Jun 23 09:11:54 2011 +0000
@@ -1,9 +1,24 @@
 package de.intevation.flys.client.server;
 
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 
+import org.apache.commons.lang.StringEscapeUtils;
+
 import de.intevation.flys.client.client.services.ReportService;
 
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.ClientProtocolUtils;
+
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+
 public class ReportServiceImpl
 extends      RemoteServiceServlet
 implements   ReportService
@@ -16,7 +31,79 @@
         String out
     ) {
         System.err.println("report: " + collectionId + " " + out);
-        return out;
+
+        Document request = ClientProtocolUtils.newOutCollectionDocument(
+            collectionId,
+            out,
+            "report");
+
+        InputStream in = null;
+        try {
+            HttpClient client = new HttpClientImpl(url, locale);
+            in = client.collectionOut(request, collectionId, out);
+
+            if (in == null) {
+                System.err.println("report: no report");
+                return null;
+            }
+
+            Document report = XMLUtils.parseDocument(in);
+
+            return buildReport(report);
+        }
+        catch (IOException ioe) {
+            ioe.printStackTrace();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+        finally {
+            if (in != null) {
+                try {
+                    in.close();
+                }
+                catch (IOException ioe) {
+                }
+            }
+        }
+
+        return "error processing error report";
+    }
+
+    protected static String buildReport(Document document) {
+
+        NodeList problems = document.getElementsByTagName("problem");
+
+        StringBuilder global = new StringBuilder();
+        StringBuilder kms    = new StringBuilder();
+
+        for (int i = 0, N = problems.getLength(); i < N; ++i) {
+
+            Element element = (Element)problems.item(i);
+
+            String km  = element.getAttribute("km");
+            String msg = element.getTextContent();
+
+            if (km.length() > 0) {
+                kms.append("<li><strong>")
+                   .append(StringEscapeUtils.escapeHtml(km))
+                   .append("</strong>: ")
+                   .append(StringEscapeUtils.escapeHtml(msg))
+                   .append("</li>");
+            }
+            else {
+                global.append("<li>")
+                      .append(StringEscapeUtils.escapeHtml(msg))
+                      .append("</li>");
+            }
+        }
+
+        StringBuilder sb = new StringBuilder("<ul>")
+            .append(global)
+            .append(kms)
+            .append("</ul>");
+
+        return sb.toString();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org