changeset 692:ae33fdecd9e2

Fixed descriptor validation.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 07 Jul 2015 11:58:46 +0200 (2015-07-07)
parents 46bb231ff9b9
children ca536cd50120
files src/main/java/de/intevation/lada/validation/rules/probe/DeskriptorToUmwelt.java
diffstat 1 files changed, 126 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/validation/rules/probe/DeskriptorToUmwelt.java	Tue Jul 07 11:56:36 2015 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/DeskriptorToUmwelt.java	Tue Jul 07 11:58:46 2015 +0200
@@ -41,6 +41,7 @@
         }
         for (int i = 1; i < mediaDesk.length; i++) {
             if ("00".equals(mediaDesk[i])) {
+                mediaIds.add(-1);
                 continue;
             }
             if (zebs && i < 5) {
@@ -73,26 +74,146 @@
                 ndParent = data.get(0).getId();
             }
         }
-        Violation violation = validateUmwelt(mediaIds, probe);
+        Violation violation = validateUmwelt(mediaIds, probe.getUmwId(), zebs, 0);
         return violation;
     }
 
-    private Violation validateUmwelt(List<Integer> media, LProbe probe) {
+    private Violation validateUmwelt(List<Integer> media, String umwId, boolean isZebs, int ndx) {
         QueryBuilder<DeskriptorUmwelt> builder =
             new QueryBuilder<DeskriptorUmwelt>(
                 repository.entityManager("stamm"), DeskriptorUmwelt.class);
-        for (int i = media.size() - 1; i > 0; i--) {
+
+        if (media.size() == 0) {
+            Violation violation = new Violation();
+            violation.addWarning("umwId", 632);
+            return violation;
+        }
+
+        int size = 1;
+        if (isZebs) {
+            size = 2;
+        }
+        for (int i = size; i >= 0; i--) {
+            if (media.get(i) == -1) {
+                continue;
+            }
             String field = "s" + (i > 9 ? i : "0" + i);
             builder.and(field, media.get(i));
         }
         Response response = repository.filter(builder.getQuery(), "stamm");
         @SuppressWarnings("unchecked")
         List<DeskriptorUmwelt> data = (List<DeskriptorUmwelt>)response.getData();
-        if (data.isEmpty() || !data.get(0).getUmwId().equals(probe.getUmwId())) {
+        if (data.isEmpty()) {
             Violation violation = new Violation();
             violation.addWarning("umwId", 632);
             return violation;
         }
-        return null;
+
+        boolean unique = isUnique(data);
+        if (unique && umwId.equals(data.get(0).getUmwId())) {
+            return null;
+        }
+        else if (unique && !umwId.equals(data.get(0).getUmwId())) {
+            Violation violation = new Violation();
+            violation.addWarning("umwId", 632);
+            return violation;
+        }
+        else {
+            Violation violation = new Violation();
+            violation.addWarning("umwId", 632);
+            boolean found = false;
+            for (int i = 0; i < data.size(); i++) {
+                if (!data.get(i).getUmwId().equals(umwId)) {
+                    continue;
+                }
+                for (int j = size + 1; j < 13; j++) {
+                    switch(j) {
+                        case 2: if (data.get(i).getS02() == null ||
+                                    data.get(i).getS02().equals(media.get(2)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 3: if (data.get(i).getS03() == null ||
+                                    data.get(i).getS03().equals(media.get(3)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 4: if (data.get(i).getS04() == null ||
+                                    data.get(i).getS04().equals(media.get(4)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 5: if (data.get(i).getS05() == null ||
+                                    data.get(i).getS05().equals(media.get(5)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 6: if (data.get(i).getS06() == null ||
+                                    data.get(i).getS06().equals(media.get(6)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 7: if (data.get(i).getS07() == null ||
+                                    data.get(i).getS07().equals(media.get(7)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 8: if (data.get(i).getS08() == null ||
+                                    data.get(i).getS08().equals(media.get(8)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 9: if (data.get(i).getS09() == null ||
+                                    data.get(i).getS09().equals(media.get(9)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 10: if (data.get(i).getS10() == null ||
+                                     data.get(i).getS10().equals(media.get(10)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 11: if (data.get(i).getS11() == null ||
+                                     data.get(i).getS11().equals(media.get(11)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                        case 12: if (data.get(i).getS12() == null ||
+                                     data.get(i).getS12().equals(media.get(12)))
+                                    found = true;
+                                else
+                                    found = false;
+                                break;
+                    }
+                    if (found) {
+                        return null;
+                    }
+                }
+            }
+            return violation;
+        }
+    }
+
+    private boolean isUnique(List<DeskriptorUmwelt> list) {
+        if (list.isEmpty()) {
+            return false;
+        }
+        String element = list.get(0).getUmwId();
+        for (int i = 1; i < list.size(); i++) {
+            if (!element.equals(list.get(i))) {
+                return false;
+            }
+        }
+        return true;
     }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)