Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/DynamicMainValuesTimeRangeDeterminationServiceImpl.java @ 9412:0fb76f2d4e5b
bundu wst time range globalErrorMsg to client - no error thrown
author | gernotbelger |
---|---|
date | Thu, 16 Aug 2018 11:40:28 +0200 |
parents | bc9a45d2b1fa |
children |
comparison
equal
deleted
inserted
replaced
9411:fe7edef5af47 | 9412:0fb76f2d4e5b |
---|---|
18 import org.dive4elements.artifacts.httpclient.http.HttpClient; | 18 import org.dive4elements.artifacts.httpclient.http.HttpClient; |
19 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; | 19 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; |
20 import org.dive4elements.river.client.client.services.DynamicMainValuesTimeRangeDeterminationService; | 20 import org.dive4elements.river.client.client.services.DynamicMainValuesTimeRangeDeterminationService; |
21 import org.dive4elements.river.client.shared.exceptions.ServerException; | 21 import org.dive4elements.river.client.shared.exceptions.ServerException; |
22 import org.dive4elements.river.client.shared.model.GaugeInfoObject; | 22 import org.dive4elements.river.client.shared.model.GaugeInfoObject; |
23 import org.dive4elements.river.client.shared.model.GaugeInfoObjectImpl; | 23 import org.dive4elements.river.client.shared.model.GaugeInfoResult; |
24 import org.dive4elements.river.client.shared.model.GaugeInfoResultImpl; | |
24 import org.w3c.dom.Document; | 25 import org.w3c.dom.Document; |
25 import org.w3c.dom.Element; | 26 import org.w3c.dom.Element; |
26 import org.w3c.dom.NamedNodeMap; | 27 import org.w3c.dom.NamedNodeMap; |
27 import org.w3c.dom.Node; | 28 import org.w3c.dom.Node; |
28 import org.w3c.dom.NodeList; | 29 import org.w3c.dom.NodeList; |
34 private static final long serialVersionUID = 1L; | 35 private static final long serialVersionUID = 1L; |
35 | 36 |
36 private static final String XPATH_ROOT = "dynamic-mainvalues-input"; | 37 private static final String XPATH_ROOT = "dynamic-mainvalues-input"; |
37 private String globalErrorMsg = null; | 38 private String globalErrorMsg = null; |
38 | 39 |
39 private GaugeInfoObject[] callService(final String serviceName, final Document input, final String locale) throws ServerException { | 40 private GaugeInfoResult callService(final String serviceName, final Document input, final String locale) throws ServerException { |
40 final String url = getServletContext().getInitParameter("server-url"); | 41 final String url = getServletContext().getInitParameter("server-url"); |
41 | 42 |
42 final HttpClient client = new HttpClientImpl(url, locale); | 43 final HttpClient client = new HttpClientImpl(url, locale); |
43 | 44 |
44 try { | 45 try { |
45 final Document result = client.callService(url, serviceName, input); | 46 final Document result = client.callService(url, serviceName, input); |
46 final GaugeInfoObject[] objects = extractDates(result); | 47 return extractDates(result); |
47 if (!this.globalErrorMsg.equals("")) | |
48 throw new ServerException(this.globalErrorMsg); | |
49 // log.debug("Extract wq info objects now."); | |
50 return objects; | |
51 | |
52 } | 48 } |
53 catch (final ConnectionException ce) { | 49 catch (final ConnectionException ce) { |
54 // log.error(ce, ce); | 50 // log.error(ce, ce); |
55 } | 51 } |
56 | 52 |
57 throw new ServerException("error_no_wqinput_found"); | 53 throw new ServerException("error_no_wqinput_found"); |
58 } | 54 } |
59 | 55 |
60 private GaugeInfoObject[] extractDates(final Document result) throws ServerException { | 56 private GaugeInfoResult extractDates(final Document result) throws ServerException { |
61 final List<GaugeInfoObject> results = new ArrayList<GaugeInfoObject>(); | 57 final List<GaugeInfoObject> results = new ArrayList<GaugeInfoObject>(); |
62 final NodeList list = result.getChildNodes(); | 58 final NodeList list = result.getChildNodes(); |
59 final List<GaugeInfoObject> gauges = new ArrayList<GaugeInfoObject>(); | |
63 | 60 |
64 if (list != null && list.getLength() == 1) { | 61 if (list != null && list.getLength() == 1) { |
65 // log.warn("No wq info found."); | 62 // log.warn("No wq info found."); |
66 final Node nodes = list.item(0); | 63 final Node nodes = list.item(0); |
67 final NodeList childNodes = nodes.getChildNodes(); | 64 final NodeList childNodes = nodes.getChildNodes(); |
72 } else { // name equals gauge | 69 } else { // name equals gauge |
73 | 70 |
74 final NamedNodeMap map = node.getAttributes(); | 71 final NamedNodeMap map = node.getAttributes(); |
75 final String gaugeName = getStringFromMap("name", map); | 72 final String gaugeName = getStringFromMap("name", map); |
76 final String error = getStringFromMap("error-message", map); | 73 final String error = getStringFromMap("error-message", map); |
77 final GaugeInfoObject gi = new GaugeInfoObjectImpl(gaugeName, error, getDateFromMap("date-from", map), getDateFromMap("date-to", map)); | 74 final GaugeInfoObject gi = new GaugeInfoObject(gaugeName, error, getDateFromMap("date-from", map), getDateFromMap("date-to", map)); |
78 results.add(gi); | 75 // results.add(gi); |
76 gauges.add(gi); | |
79 } | 77 } |
80 } | 78 } |
81 | 79 |
82 } | 80 } |
83 return results.toArray(new GaugeInfoObject[results.size()]); | 81 |
82 return new GaugeInfoResultImpl(this.globalErrorMsg, gauges.toArray(new GaugeInfoObject[gauges.size()])); | |
83 | |
84 } | 84 } |
85 | 85 |
86 private Date getDateFromMap(final String attrName, final NamedNodeMap map) { | 86 private Date getDateFromMap(final String attrName, final NamedNodeMap map) { |
87 final Node dateNode = map.getNamedItem(attrName); | 87 final Node dateNode = map.getNamedItem(attrName); |
88 if (dateNode != null) | 88 if (dateNode != null) |
96 return node.getNodeValue(); | 96 return node.getNodeValue(); |
97 return null; | 97 return null; |
98 } | 98 } |
99 | 99 |
100 @Override | 100 @Override |
101 public GaugeInfoObject[] getGaugeInfo(final String locale, final String river, final String[] gauges, final int startYear, final int endYear) | 101 public GaugeInfoResult getGaugeInfo(final String locale, final String river, final String[] gauges, final int startYear, final int endYear) |
102 throws ServerException { | 102 throws ServerException { |
103 | 103 |
104 final Document input = createInput(river, gauges, startYear, endYear); | 104 final Document input = createInput(river, gauges, startYear, endYear); |
105 | 105 |
106 return callService("dynamicMainvaluesTimeRangeDetermination", input, locale); | 106 return callService("dynamicMainvaluesTimeRangeDetermination", input, locale); |