changeset 4225:f4cee1a74605

Merged.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 23 Oct 2012 13:29:13 +0200
parents 8b5133444bcc (current diff) b7535b66490e (diff)
children cb9f22c3553f
files
diffstat 14 files changed, 318 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeTablesOverview.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeTablesOverview.java	Tue Oct 23 13:29:13 2012 +0200
@@ -173,6 +173,16 @@
 
         if (gauges.getLength() > 0) {
             String name = ((Element) gauges.item(0)).getAttribute("name");
+
+            try {
+                long officialNumber = Long.valueOf(name);
+                return Gauge.getGaugeByOfficialNumber(officialNumber);
+            }
+            catch (NumberFormatException nfe) {
+                // it seems, that the client uses the name of the gauge instead
+                // of its official number
+            }
+
             if (name != null && name.length() > 0) {
                 return GaugesFactory.getGauge(name);
             }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Oct 23 13:29:13 2012 +0200
@@ -1060,5 +1060,9 @@
 
     String gauge_discharge_curve_at_export();
 
+    String discharge_timeranges();
+
+    String discharge_chart();
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Oct 23 13:29:13 2012 +0200
@@ -551,3 +551,5 @@
 gauge_url = https://flys-intern.intevation.de/PegelInfo/
 gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/
 gauge_curve_link = Dischargecurve
+discharge_timeranges = DC-Timeranges
+discharge_chart = DC-Chart
\ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Oct 23 13:29:13 2012 +0200
@@ -549,3 +549,5 @@
 gauge_url = https://flys-intern.intevation.de/PegelInfo/
 gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/
 gauge_curve_link = Abflusskurve
+discharge_timeranges = AK-Zeitr\u00e4ume
+discharge_chart = AK-Diagramm
\ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Oct 23 13:29:13 2012 +0200
@@ -550,3 +550,5 @@
 gauge_url = https://flys-intern.intevation.de/PegelInfo/
 gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/
 gauge_curve_link = Dischargecurve
+discharge_timeranges = DC-Timeranges
+discharge_chart = DC-Chart
\ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java	Tue Oct 23 13:29:13 2012 +0200
@@ -24,5 +24,10 @@
      */
     User getCurrentUser(String locale)
     throws AuthenticationException;
+
+    /**
+     * Removes the current user object from the session
+     */
+    void logoutCurrentUser();
 }
 // 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/UserServiceAsync.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java	Tue Oct 23 13:29:13 2012 +0200
@@ -15,5 +15,7 @@
     void getCurrentUser(
         String locale,
         AsyncCallback<User> callback);
+
+    void logoutCurrentUser(AsyncCallback<Void> 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/GaugeTimeRangePanel.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java	Tue Oct 23 13:29:13 2012 +0200
@@ -18,10 +18,13 @@
 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.tab.Tab;
+import com.smartgwt.client.widgets.tab.TabSet;
 
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.ui.range.DischargeInfoDataSource;
+import de.intevation.flys.client.client.widgets.DischargeTablesChart;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
@@ -97,7 +100,7 @@
         String url = config.getServerUrl();
         yearTable.setDataSource(new DischargeInfoDataSource(url, gauge));
 
-        helperContainer.addMember(yearTable);
+        helperContainer.addMember(createHelperPanel());
 
         setMaxUpper(data);
         setMaxLower(data);
@@ -106,6 +109,22 @@
     }
 
 
+    protected Canvas createHelperPanel() {
+        TabSet tabs = new TabSet();
+
+        Tab table = new Tab(MSG.discharge_timeranges());
+        Tab chart = new Tab(MSG.discharge_chart());
+
+        table.setPane(yearTable);
+        chart.setPane(new DischargeTablesChart(artifact));
+
+        tabs.addTab(table, 0);
+        tabs.addTab(chart, 1);
+
+        return tabs;
+    }
+
+
     @Override
     protected void initDefaults(DataList dataList) {
         RangeData data = findRangeData(dataList);
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java	Tue Oct 23 13:29:13 2012 +0200
@@ -3,6 +3,7 @@
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.LocaleInfo;
 import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.util.BooleanCallback;
 import com.smartgwt.client.util.SC;
@@ -14,6 +15,8 @@
 
 import de.intevation.flys.client.client.FLYS;
 import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.services.UserService;
+import de.intevation.flys.client.client.services.UserServiceAsync;
 import de.intevation.flys.client.shared.model.User;
 
 
@@ -49,6 +52,9 @@
     /** The button to open an info panel.*/
     protected Button info;
 
+    protected UserServiceAsync userService =
+        GWT.create(UserService.class);
+
     /**
      * The default constructor for creating a new MainMenu.
      */
@@ -88,7 +94,17 @@
             @Override
             public void onClick(ClickEvent event) {
                 GWT.log("Clicked 'logout' button.");
-                GWT.log("IMPLEMENT the 'logout' function.");
+                userService.logoutCurrentUser(new AsyncCallback<Void>() {
+                    public void onFailure(Throwable caught) {
+                    }
+
+                    public void onSuccess(Void result) {
+                        /* Just reload the page. GGInAFilter is goint to redirect
+                         * to the correct login page */
+                        Window.Location.reload();
+                    }
+                });
+
             }
         });
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java	Tue Oct 23 13:29:13 2012 +0200
@@ -29,7 +29,7 @@
 import de.intevation.flys.client.client.ui.wq.ClickableQDTable;
 import de.intevation.flys.client.client.ui.wq.ClickableWTable;
 import de.intevation.flys.client.client.ui.wq.ClickableWTable.ClickMode;
-import de.intevation.flys.client.client.ui.wq.QDTable;
+import de.intevation.flys.client.client.widgets.DischargeTablesChart;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
@@ -208,12 +208,15 @@
 
         Tab w = new Tab(MSG.wq_table_w());
         Tab q = new Tab(MSG.wq_table_q());
+        Tab c = new Tab(MSG.chart());
 
         w.setPane(wTable);
         q.setPane(qTable);
+        c.setPane(new DischargeTablesChart(this.artifact));
 
         tabs.addTab(w, 0);
         tabs.addTab(q, 1);
+        tabs.addTab(c, 2);
 
         helperContainer.addMember(tabs);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/widgets/DischargeTablesChart.java	Tue Oct 23 13:29:13 2012 +0200
@@ -0,0 +1,90 @@
+package de.intevation.flys.client.client.widgets;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.ArtifactDescription;
+
+
+public class DischargeTablesChart extends Canvas implements ResizedHandler {
+
+    protected Artifact artifact;
+
+    protected Img img;
+
+    public DischargeTablesChart() {
+        super();
+    }
+
+    public DischargeTablesChart(Artifact artifact) {
+        super();
+        this.artifact = artifact;
+        init();
+    }
+
+    private void init() {
+        addChild(createImage());
+        addResizedHandler(this);
+        setSize("100%", "100%");
+    }
+
+    protected Img createImage() {
+        img = new Img(getUrl());
+        img.setSize("100%", "100%");
+
+        return img;
+    }
+
+    protected String getUrl() {
+        String url = GWT.getModuleBaseURL();
+        url += "dischargetablesoverview";
+        url += "?gauge=" + getGauge();
+        url += "&format=png";
+
+        String[] timerange = getTimerange();
+        url += "&lower=" + timerange[0];
+        url += "&upper=" + timerange[1];
+
+        int width = 600;
+        int height = 400;
+        if (img != null) {
+            width = img.getWidth();
+            height = img.getHeight();
+        }
+
+        url += "&width=" + String.valueOf(width);
+        url += "&height=" + String.valueOf(height);
+
+        // add time millis to 'deactivate' caching
+        url += "&timemillis" + System.currentTimeMillis();
+
+        GWT.log("DischargeTablesService URL = '" + url + "'");
+        return url;
+    }
+
+    protected String getGauge() {
+        ArtifactDescription desc = artifact.getArtifactDescription();
+        return desc.getReferenceGauge();
+    }
+
+    protected String[] getTimerange() {
+        ArtifactDescription desc = artifact.getArtifactDescription();
+        String yearStr = desc.getDataValueAsString("year_range");
+
+        if (yearStr != null && yearStr.length() > 0) {
+            return yearStr.split(";");
+        }
+
+        return new String[2];
+    }
+
+    @Override
+    public void onResized(ResizedEvent event) {
+        GWT.log("resized discharge tables overview chart");
+        img.setSrc(getUrl());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DischargeTablesServiceImpl.java	Tue Oct 23 13:29:13 2012 +0200
@@ -0,0 +1,143 @@
+package de.intevation.flys.client.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;
+
+
+public class DischargeTablesServiceImpl extends HttpServlet {
+
+    private static final Logger logger = Logger
+        .getLogger(DischargeInfoServiceImpl.class);
+
+    private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(
+        DateFormat.MEDIUM, Locale.GERMANY);
+
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
+        logger.info("ChartOutputServiceImpl.doGet");
+
+        String url = getServletContext().getInitParameter("server-url");
+        String locale = req.getParameter("locale");
+
+        prepareHeader(req, resp);
+
+        Document requestDoc = createRequestDoc(req);
+
+        HttpClient client = new HttpClientImpl(url, locale);
+
+        try {
+            OutputStream out = resp.getOutputStream();
+            InputStream stream = (InputStream) client.callService(url,
+                "dischargetablesoverview", requestDoc,
+                new StreamResponseHandler());
+
+            byte[] b = new byte[4096];
+            try {
+                int i;
+                while ((i = stream.read(b)) >= 0) {
+                    out.write(b, 0, i);
+                }
+            }
+            finally {
+                stream.close();
+            }
+        }
+        catch (IOException ioe) {
+            logger.error("Error while fetching discharge tables chart!", ioe);
+        }
+    }
+
+    protected void prepareHeader(HttpServletRequest req,
+        HttpServletResponse resp) {
+        resp.setHeader("Content-Type", "image/png");
+    }
+
+    protected Document createRequestDoc(HttpServletRequest req) {
+        Document request = XMLUtils.newDocument();
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(request,
+            null, null);
+
+        Element service = creator.create("service");
+        Element gauge = creator.create("gauge");
+        Element extent = creator.create("extent");
+        Element format = creator.create("format");
+        Element timerange = creator.create("timerange");
+
+        creator.addAttr(gauge, "name", extractRequestGauge(req));
+        creator.addAttr(extent, "width", extractRequestWidth(req));
+        creator.addAttr(extent, "height", extractRequestHeight(req));
+        creator.addAttr(format, "type", extractRequestFormat(req));
+        creator.addAttr(timerange, "lower", extractRequestLowerTime(req));
+        creator.addAttr(timerange, "upper", extractRequestUpperTime(req));
+
+        request.appendChild(service);
+        service.appendChild(gauge);
+        service.appendChild(extent);
+        service.appendChild(format);
+        service.appendChild(timerange);
+
+        return request;
+    }
+
+    protected String extractRequestGauge(HttpServletRequest req) {
+        return req.getParameter("gauge");
+    }
+
+    protected String extractRequestWidth(HttpServletRequest req) {
+        return req.getParameter("width");
+    }
+
+    protected String extractRequestHeight(HttpServletRequest req) {
+        return req.getParameter("height");
+    }
+
+    protected String extractRequestFormat(HttpServletRequest req) {
+        return req.getParameter("format");
+    }
+
+    protected String extractRequestLowerTime(HttpServletRequest req) {
+        String lowerStr = req.getParameter("lower");
+        try {
+            long lowerMillis = Long.parseLong(lowerStr);
+            Date lower = new Date(lowerMillis);
+
+            return DATE_FORMAT.format(lower);
+        }
+        catch (NumberFormatException nfe) {
+            logger.warn("Cannot parse time millies.", nfe);
+        }
+
+        return null;
+    }
+
+    protected String extractRequestUpperTime(HttpServletRequest req) {
+        String upperStr = req.getParameter("upper");
+        try {
+            long upperMillis = Long.parseLong(upperStr);
+            Date upper = new Date(upperMillis);
+
+            return DATE_FORMAT.format(upper);
+        }
+        catch (NumberFormatException nfe) {
+            logger.warn("Cannot parse time millies.", nfe);
+        }
+
+        return null;
+    }
+}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java	Tue Oct 23 13:29:13 2012 +0200
@@ -1,5 +1,7 @@
 package de.intevation.flys.client.server;
 
+import javax.servlet.http.HttpSession;
+
 import org.w3c.dom.Element;
 
 import org.apache.log4j.Logger;
@@ -60,5 +62,10 @@
         logger.error("No users existing in the server.");
         throw new AuthenticationException(ERROR_NO_USERS);
     }
+
+    public void logoutCurrentUser() {
+        HttpSession session = this.getThreadLocalRequest().getSession();
+        session.setAttribute("user", null);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Tue Oct 23 13:24:16 2012 +0200
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Tue Oct 23 13:29:13 2012 +0200
@@ -267,6 +267,16 @@
     <url-pattern>/flys/chart</url-pattern>
   </servlet-mapping>
 
+  <servlet>
+  	<servlet-name>DischargeTablesOverviewService</servlet-name>
+  	<servlet-class>de.intevation.flys.client.server.DischargeTablesServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+  	<servlet-name>DischargeTablesOverviewService</servlet-name>
+  	<url-pattern>/flys/dischargetablesoverview</url-pattern>
+  </servlet-mapping>
+
   <!-- MapFish Print -->
   <servlet>
     <servlet-name>MapOutputService</servlet-name>

http://dive4elements.wald.intevation.org