changeset 1245:e0b461d4cd8e

Handle wrong parameter format and remove duplicate conditionals.
author Tom Gottfried <tom@intevation.de>
date Fri, 16 Dec 2016 12:13:40 +0100
parents 86ef81592f67
children 204fb75b0c06
files src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java
diffstat 1 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java	Fri Dec 16 12:06:34 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java	Fri Dec 16 12:13:40 2016 +0100
@@ -105,19 +105,19 @@
             repository.entityManager("stamm"),
             Deskriptoren.class);
         builder.and("sn", 0).not();
-        if (params.containsKey("layer") &&
-            !params.containsKey("parents")) {
-            String layer = params.getFirst("layer");
-            builder.and("ebene", layer);
-        }
-        else {
-            String layer = params.getFirst("layer");
-            String parents = params.getFirst("parents");
-            builder.and("ebene", layer);
-            List<String> parentList = new ArrayList<String>();
-            String[] parentArray = parents.split(", ");
-            parentList = Arrays.asList(parentArray);
-            builder.andIn("vorgaenger", parentList);
+        try {
+            builder.and("ebene",
+                Integer.valueOf(params.getFirst("layer")));
+            builder.and("ebene", params.getFirst("layer"));
+            if (params.containsKey("parents")) {
+                String parents = params.getFirst("parents");
+                List<String> parentList = new ArrayList<String>();
+                String[] parentArray = parents.split(", ");
+                parentList = Arrays.asList(parentArray);
+                builder.andIn("vorgaenger", parentList);
+            }
+        } catch (NumberFormatException nfe) {
+            return new Response(false, 612, null);
         }
         return repository.filter(builder.getQuery(), "stamm");
     }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)