[Lada-commits] [PATCH 3 of 5] Implemented merge process for orte
Wald Commits
scm-commit at wald.intevation.org
Mon Nov 7 10:10:12 CET 2016
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1478509659 -3600
# Node ID cbdeac32465c09d683ebc992990f97370974525a
# Parent ee22d0cfbd81885a3bbe7785b38f158e24bb16c8
Implemented merge process for orte.
diff -r ee22d0cfbd81 -r cbdeac32465c src/main/java/de/intevation/lada/importer/ObjectMerger.java
--- a/src/main/java/de/intevation/lada/importer/ObjectMerger.java Mon Nov 07 10:06:38 2016 +0100
+++ b/src/main/java/de/intevation/lada/importer/ObjectMerger.java Mon Nov 07 10:07:39 2016 +0100
@@ -145,11 +145,6 @@
return this;
}
- public ObjectMerger mergeOrte(Probe target, List<Ortszuordnung> orte) {
- // TODO implement me
- return this;
- }
-
public ObjectMerger mergeMessungKommentare(
Messung target,
List<KommentarM> kommentare
@@ -212,4 +207,58 @@
}
return this;
}
+
+ public ObjectMerger mergeEntnahmeOrt(
+ int probeId,
+ Ortszuordnung ort
+ ) {
+ QueryBuilder<Ortszuordnung> builder = new QueryBuilder<Ortszuordnung>(
+ repository.entityManager("land"),
+ Ortszuordnung.class);
+ builder.and("probeId", probeId);
+ builder.and("ortszuordnungTyp", "E");
+ List<Ortszuordnung> found =
+ repository.filterPlain(builder.getQuery(), "land");
+ if (found.isEmpty()) {
+ repository.create(ort, "land");
+ return this;
+ }
+ try {
+ for (int i = 0; i < found.size(); i++) {
+ repository.delete(found.get(i), "land");
+ }
+ repository.create(ort, "land");
+ } catch (SecurityException |
+ IllegalStateException |
+ PersistenceException e
+ ) {
+ // Restore orte.
+ logger.debug("exception: ", e);
+ for (int i = 0; i < found.size(); i++) {
+ repository.update(found.get(i), "land");
+ }
+ }
+ return this;
+ }
+
+ public ObjectMerger mergeUrsprungsOrte(
+ int probeId,
+ List<Ortszuordnung> orte
+ ) {
+ QueryBuilder<Ortszuordnung> builder = new QueryBuilder<Ortszuordnung>(
+ repository.entityManager("land"),
+ Ortszuordnung.class);
+ for (int i = 0; i < orte.size(); i++) {
+ builder.and("probeId", probeId);
+ builder.and("ortszuordnungTyp", "U");
+ builder.and("ortId", orte.get(i).getOrtId());
+ List<Ortszuordnung> found =
+ repository.filterPlain(builder.getQuery(), "land");
+ if (found.isEmpty()) {
+ repository.create(orte.get(i), "land");
+ }
+ builder = builder.getEmptyBuilder();
+ }
+ return this;
+ }
}
More information about the Lada-commits
mailing list