comparison artifacts/src/main/java/org/dive4elements/river/artifacts/services/AbstractMainValuesService.java @ 9404:bc9a45d2b1fa

common time range for gauges incl. error messages
author gernotbelger
date Wed, 15 Aug 2018 13:59:09 +0200
parents 82c67b859aa7
children
comparison
equal deleted inserted replaced
9403:e2da9c8a7c57 9404:bc9a45d2b1fa
45 45
46 /** The log that is used by this service. */ 46 /** The log that is used by this service. */
47 private static Logger log = Logger.getLogger(AbstractMainValuesService.class); 47 private static Logger log = Logger.getLogger(AbstractMainValuesService.class);
48 48
49 /** XPath that points to the river definition of the incoming request. */ 49 /** XPath that points to the river definition of the incoming request. */
50 private static final String XPATH_RIVER = "/art:mainvalues/art:river/text()";
51 50
52 /** XPath that points to the start definition of the incoming request. */ 51 /** XPath that points to the start definition of the incoming request. */
53 private static final String XPATH_START = "/art:mainvalues/art:start/text()"; 52 private static final String XPATH_START = "/art:mainvalues/art:start/text()";
54 53
55 /** The XPath that points to the end definition of the incoming request. */ 54 /** The XPath that points to the end definition of the incoming request. */
68 * @param data 67 * @param data
69 * The incoming request data. 68 * The incoming request data.
70 * 69 *
71 * @return the River object. 70 * @return the River object.
72 */ 71 */
73 protected final River getRequestedRiver(final Document data) throws MainValuesServiceException { 72 protected static final River getRequestedRiver(final Document data, final String XPATH_RIVER) throws MainValuesServiceException {
74 log.debug("MainValuesService.getRequestedRiver"); 73 log.debug("MainValuesService.getRequestedRiver");
75 74
76 String riverStr = XMLUtils.xpathString(data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE); 75 String riverStr = XMLUtils.xpathString(data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE);
77 76
78 if (riverStr != null && (riverStr = riverStr.trim()).length() > 0) 77 if (riverStr != null && (riverStr = riverStr.trim()).length() > 0)
79 return RiverFactory.getRiver(riverStr); 78 return RiverFactory.getRiver(riverStr);
80 79
81 throw new MainValuesServiceException("no river found."); 80 throw new MainValuesServiceException("no river found.");
82 } 81 }
83 82
84 protected final Gauge getRequestedGauge(final Document data, final River river) throws MainValuesServiceException { 83 protected static final Gauge getRequestedGauge(final Document data, final River river) throws MainValuesServiceException {
85 84
86 final double[] minmax = getRequestedStartEnd(data, river); 85 final double[] minmax = getRequestedStartEnd(data, river);
87 final Gauge gauge = river.determineRefGauge(minmax, CMP.compare(minmax[0], minmax[1]) != 0); 86 final Gauge gauge = river.determineRefGauge(minmax, CMP.compare(minmax[0], minmax[1]) != 0);
88 if (gauge == null) 87 if (gauge == null)
89 throw new MainValuesServiceException("no gauge found."); 88 throw new MainValuesServiceException("no gauge found.");
103 * @param river 102 * @param river
104 * The river of the request. 103 * The river of the request.
105 * 104 *
106 * @return the start and end point. 105 * @return the start and end point.
107 */ 106 */
108 private double[] getRequestedStartEnd(final Document data, final River river) { 107 public static double[] getRequestedStartEnd(final Document data, final River river) {
109 log.debug("MainValuesService.getStartEnd"); 108 log.debug("MainValuesService.getStartEnd");
110 109
111 final String startStr = XMLUtils.xpathString(data, XPATH_START, ArtifactNamespaceContext.INSTANCE); 110 final String startStr = XMLUtils.xpathString(data, XPATH_START, ArtifactNamespaceContext.INSTANCE);
112 111
113 final String endStr = XMLUtils.xpathString(data, XPATH_END, ArtifactNamespaceContext.INSTANCE); 112 final String endStr = XMLUtils.xpathString(data, XPATH_END, ArtifactNamespaceContext.INSTANCE);
163 * @param gauge 162 * @param gauge
164 * The gauge. 163 * The gauge.
165 * @param context 164 * @param context
166 * The context object. 165 * The context object.
167 */ 166 */
168 private void appendMetaInformation(final Document doc, final Element root, final River river, final Gauge gauge, final Object context) { 167 static void appendMetaInformation(final Document doc, final Element root, final River river, final Gauge gauge, final Object context) {
169 log.debug("MainValuesService.appendMetaInformation"); 168 log.debug("MainValuesService.appendMetaInformation");
170 169
171 final ElementCreator cr = new ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX); 170 final ElementCreator cr = new ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
172 171
173 final Range range = gauge.getRange(); 172 final Range range = gauge.getRange();

http://dive4elements.wald.intevation.org