annotate gwt-client/src/main/java/org/dive4elements/river/client/server/CSVExportServiceImpl.java @ 9726:0a5239a1e46e 3.2.x

Upgrade to Log4j 2
author Tom Gottfried <tom@intevation.de>
date Wed, 02 Mar 2022 10:26:50 +0100
parents 238fc722f87a
children
rev   line source
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5861
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5861
diff changeset
6 * documentation coming with Dive4Elements River for details.
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
9 package org.dive4elements.river.client.server;
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
1477
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
11 import java.util.ArrayList;
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import java.util.List;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import java.io.Reader;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import java.io.InputStream;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import java.io.InputStreamReader;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import java.io.IOException;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 import org.w3c.dom.Document;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import org.w3c.dom.Element;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
22 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
23 import org.apache.logging.log4j.LogManager;
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 550
diff changeset
24
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 import au.com.bytecode.opencsv.CSVReader;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
29 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
30 import org.dive4elements.artifacts.common.utils.XMLUtils;
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
32 import org.dive4elements.artifacts.httpclient.http.HttpClient;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
33 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
35 import org.dive4elements.river.client.shared.exceptions.ServerException;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
36 import org.dive4elements.river.client.client.services.CSVExportService;
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 /**
263
f56523bf4c55 Changed the empty table message for helper and data tables.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 259
diff changeset
40 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 */
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 public class CSVExportServiceImpl
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 extends RemoteServiceServlet
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 implements CSVExportService
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7036
diff changeset
46 private static final Logger log =
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
47 LogManager.getLogger(CSVExportServiceImpl.class);
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 550
diff changeset
48
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 550
diff changeset
49
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 public static final String ERROR_NO_EXPORT_FOUND =
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 "error_no_export_found";
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52
550
605debcbb6a0 Adjusted the return values of the CSVExportService, so that GWT can handle those values better.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 263
diff changeset
53 public List<String[]> getCSV(
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 String locale,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 String uuid,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 String name)
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 throws ServerException
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7036
diff changeset
59 log.info("CSVExportServiceImpl.getCSV");
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60
1425
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
61 String url = getServletContext().getInitParameter("server-url");
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
62
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 Document requestDoc = XMLUtils.newDocument();
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 requestDoc,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 ArtifactNamespaceContext.NAMESPACE_URI,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 ArtifactNamespaceContext.NAMESPACE_PREFIX);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69
258
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
70 Element action = ec.create("action");
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
71 ec.addAttr(action, "type", "csv", true);
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
72 ec.addAttr(action, "name", name, true);
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 requestDoc.appendChild(action);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 HttpClient client = new HttpClientImpl(url, locale);
1477
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
77
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 try {
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 InputStream in = client.collectionOut(requestDoc, uuid, "export");
258
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
80 Reader reader = new InputStreamReader (in, "UTF-8");
7036
e25ef8376c14 issue971: Change CSV column separator to ";".
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5993
diff changeset
81 CSVReader csvReader = new CSVReader (reader, ';');
258
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
82
1477
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
83 List<String[]> lines = new ArrayList<String[]>();
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
84 String[] line = null;
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
85
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
86 while ((line = csvReader.readNext()) != null) {
1480
1f2f08211a5f Skip empty lines in CSV service.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1477
diff changeset
87 if (line != null) {
1f2f08211a5f Skip empty lines in CSV service.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1477
diff changeset
88 if (!line[0].startsWith("#") && line.length > 0) {
1f2f08211a5f Skip empty lines in CSV service.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1477
diff changeset
89 if (line[0].replace("'", "").length() > 0) {
1f2f08211a5f Skip empty lines in CSV service.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1477
diff changeset
90 lines.add(line);
1f2f08211a5f Skip empty lines in CSV service.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1477
diff changeset
91 }
1477
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
92 }
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
93 }
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
94 }
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
95
6e694603cde1 Improved the CSVExportService to ignore lines that begin with a '#' character.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1425
diff changeset
96 return lines;
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 catch (IOException ce) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7036
diff changeset
99 log.error(ce.getLocalizedMessage());
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 throw new ServerException(ERROR_NO_EXPORT_FOUND);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org