changeset 1231:32e27cb8cfef

Use validation rule on update as well.
author Tom Gottfried <tom@intevation.de>
date Fri, 09 Dec 2016 18:20:22 +0100
parents f48be4a5c6a0
children 93918aca306e
files src/main/java/de/intevation/lada/rest/stamm/OrtService.java
diffstat 1 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Fri Dec 09 18:15:42 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Fri Dec 09 18:20:22 2016 +0100
@@ -330,21 +330,22 @@
         ) {
             return new Response(false, 699, ort);
         }
-        QueryBuilder<Ort> builder =
-            new QueryBuilder<Ort>(
-                repository.entityManager("stamm"),
-                Ort.class
-            );
-        builder.and("ortId", ort.getOrtId());
-        builder.and("netzbetreiberId", ort.getNetzbetreiberId());
 
-        List<Ort> orte =
-            repository.filterPlain(builder.getQuery(), "stamm");
-        if (orte.isEmpty() ||
-            orte.get(0).getId() == ort.getId()) {
-            return repository.update(ort, "stamm");
+        Violation violation = validator.validate(ort);
+        if (violation.hasErrors()) {
+            Response response = new Response(false, 604, ort);
+            response.setErrors(violation.getErrors());
+            response.setWarnings(violation.getWarnings());
+            return response;
         }
-        return new Response(false, 672, null);
+
+        ortFactory.transformCoordinates(ort);
+        Response response = repository.update(ort, "stamm");
+        if(violation.hasWarnings()) {
+            response.setWarnings(violation.getWarnings());
+        }
+
+        return response;
     }
 
     /**
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)