[Lada-commits] [PATCH] Audit trail: handle request with non-existant numeric ID

Wald Commits scm-commit at wald.intevation.org
Wed Mar 22 15:23:04 CET 2017


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1490191415 -3600
# Node ID 6fbfb8f0927a0c3350595d92e5b3defaed1ac18a
# Parent  84bb7e2aecb18a9d188648d42c1efed297b3a36e
Audit trail: handle request with non-existant numeric ID.

diff -r 84bb7e2aecb1 -r 6fbfb8f0927a src/main/java/de/intevation/lada/rest/AuditTrailService.java
--- a/src/main/java/de/intevation/lada/rest/AuditTrailService.java	Fri Mar 17 13:25:57 2017 +0100
+++ b/src/main/java/de/intevation/lada/rest/AuditTrailService.java	Wed Mar 22 15:03:35 2017 +0100
@@ -152,13 +152,19 @@
                 "\"message\":698,\"data\":null}";
             return ret;
         }
+
         Integer pId = null;
+        String ret = "{\"success\": false," +
+            "\"message\":600,\"data\":null}";
         try {
             pId = Integer.valueOf(id);
         }
         catch(NumberFormatException nfe) {
-            String ret = "{\"success\": false," +
-                "\"message\":600,\"data\":null}";
+            return ret;
+        }
+        // Get the plain probe object to have the hauptproben_nr.
+        Probe probe = repository.getByIdPlain(Probe.class, pId, "land");
+        if (probe == null) {
             return ret;
         }
 
@@ -174,9 +180,6 @@
         List<AuditTrailProbe> audit =
             repository.filterPlain(builder.getQuery(), "land");
 
-        // Get the plain probe object to have the hauptproben_nr.
-        // If only subobjects 
-        Probe probe = repository.getByIdPlain(Probe.class, pId, "land");
         // Create an empty JsonObject
         ObjectMapper mapper = new ObjectMapper();
         ObjectNode responseNode = mapper.createObjectNode();
@@ -264,15 +267,21 @@
                 "\"message\":698,\"data\":null}";
             return ret;
         }
+
         Integer mId = null;
+        String ret = "{\"success\": false," +
+            "\"message\":600,\"data\":null}";
         try {
             mId = Integer.valueOf(id);
         }
         catch(NumberFormatException nfe) {
-            String ret = "{\"success\": false," +
-                "\"message\":600,\"data\":null}";
             return ret;
         }
+        Messung messung = repository.getByIdPlain(Messung.class, mId, "land");
+        if (messung == null) {
+            return ret;
+        }
+
         QueryBuilder<AuditTrailMessung> builder =
             new QueryBuilder<AuditTrailMessung>(
                 repository.entityManager("land"),
@@ -284,7 +293,6 @@
         List<AuditTrailMessung> audit =
             repository.filterPlain(builder.getQuery(), "land");
 
-        Messung messung = repository.getByIdPlain(Messung.class, mId, "land");
         // Create an empty JsonObject
         ObjectMapper mapper = new ObjectMapper();
         ObjectNode responseNode = mapper.createObjectNode();


More information about the Lada-commits mailing list