Mercurial > lada > lada-server
changeset 1145:cbdeac32465c
Implemented merge process for orte.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 07 Nov 2016 10:07:39 +0100 |
parents | ee22d0cfbd81 |
children | 5eb9d35aa47a |
files | src/main/java/de/intevation/lada/importer/ObjectMerger.java |
diffstat | 1 files changed, 54 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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; + } }