Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MainValuesService.java @ 3728:d03e65378b9f
Removed obsolete code. Removed NPE as regular flow control.
flys-artifacts/trunk@5401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 08 Sep 2012 13:36:06 +0000 |
parents | ad54896ec369 |
children | 0c217de0d84b |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MainValuesService.java Sat Sep 08 12:58:58 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MainValuesService.java Sat Sep 08 13:36:06 2012 +0000 @@ -21,7 +21,6 @@ import de.intevation.flys.model.Range; import de.intevation.flys.model.River; -import de.intevation.flys.artifacts.model.MainValuesFactory; import de.intevation.flys.artifacts.model.RiverFactory; @@ -52,6 +51,11 @@ public MainValuesService() { } + private static final Document error(String msg) { + logger.debug(msg); + return XMLUtils.newDocument(); + } + @Override public Document doProcess( @@ -61,23 +65,21 @@ ) { logger.debug("MainValuesService.process"); - try { - River river = getRequestedRiver(data); - double[] minmax = getRequestedStartEnd(data, river); - Gauge gauge = river.determineGauge(minmax[0], minmax[1]); - - logger.debug("Found gauge: " + gauge.getName()); + River river = getRequestedRiver(data); + if (river == null) { + return error("no river found."); + } - List<MainValue> mainValues = getMainValues(river, gauge); + double[] minmax = getRequestedStartEnd(data, river); + Gauge gauge = river.determineGauge(minmax[0], minmax[1]); - return buildDocument(river, gauge, mainValues, context); + if (gauge == null) { + return error("no gauge found."); } - catch (NullPointerException npe) { - logger.error("Could not process the request."); - logger.error(npe, npe); - return XMLUtils.newDocument(); - } + List<MainValue> mainValues = getMainValues(river, gauge); + + return buildDocument(river, gauge, mainValues, context); } @@ -98,17 +100,9 @@ String riverStr = XMLUtils.xpathString( data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE); - if (riverStr == null || riverStr.trim().length() == 0) { - throw new NullPointerException("No river found in the request."); - } - - River river = RiverFactory.getRiver(riverStr); - - if (river == null) { - throw new NullPointerException("No such river found: " + riverStr); - } - - return river; + return riverStr != null && (riverStr = riverStr.trim()).length() > 0 + ? RiverFactory.getRiver(riverStr) + : null; } @@ -132,18 +126,23 @@ String endStr = XMLUtils.xpathString( data, XPATH_END, ArtifactNamespaceContext.INSTANCE); + if (startStr == null || endStr == null) { + return river.determineMinMaxDistance(); + } + try { double start = Double.parseDouble(startStr); double end = Double.parseDouble(endStr); - logger.debug("Found start: " + start); - logger.debug("Found end: " + end); + if (logger.isDebugEnabled()) { + logger.debug("Found start: " + start); + logger.debug("Found end: " + end); + } return new double[] { start, end }; } catch (NumberFormatException nfe) { logger.warn(nfe, nfe); - return river.determineMinMaxDistance(); } } @@ -159,23 +158,20 @@ * @return a document that includes the main values of the specified river * at the specified gauge. */ - protected List<MainValue> getMainValues(River river, Gauge gauge) - throws NullPointerException - { + protected List<MainValue> getMainValues(River river, Gauge gauge) { + if (logger.isDebugEnabled()) { logger.debug("MainValuesService.buildMainValues"); logger.debug("River: " + river.getName()); logger.debug("Gauge: " + gauge.getName()); } - List<MainValue> mainValues = MainValuesFactory.getMainValues(gauge); + List<MainValue> mainValues = gauge.fetchMainValues(); - if (mainValues == null || mainValues.isEmpty()) { - throw new NullPointerException("No main values found."); + if (logger.isDebugEnabled()) { + logger.debug(mainValues.size() + " main values found."); } - logger.debug(mainValues.size() + " main values found."); - return mainValues; }