[Lada-commits] [PATCH 4 of 5] Fixed merging objects during import
Wald Commits
scm-commit at wald.intevation.org
Mon Oct 24 11:55:02 CEST 2016
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1477302870 -7200
# Node ID 341911ecc9e05eb3bb3ae73551e01eaac34c9b14
# Parent 2593ba20487ed00596b4904046d9d4ea51af06d2
Fixed merging objects during import.
diff -r 2593ba20487e -r 341911ecc9e0 src/main/java/de/intevation/lada/importer/ObjectMerger.java
--- a/src/main/java/de/intevation/lada/importer/ObjectMerger.java Mon Oct 24 11:53:55 2016 +0200
+++ b/src/main/java/de/intevation/lada/importer/ObjectMerger.java Mon Oct 24 11:54:30 2016 +0200
@@ -9,19 +9,8 @@
import java.util.List;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
import org.apache.log4j.Logger;
@@ -36,6 +25,7 @@
import de.intevation.lada.util.data.QueryBuilder;
import de.intevation.lada.util.data.Repository;
import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.util.rest.Response;
public class ObjectMerger {
@@ -83,12 +73,12 @@
target.setNebenprobenNr(src.getNebenprobenNr());
}
target.setFertig(src.getFertig());
- target.setGeplant(src.getGeplant());
+ target.setGeplant(src.getGeplant() == null ? false : src.getGeplant());
target.setMessdauer(src.getMessdauer());
target.setMesszeitpunkt(src.getMesszeitpunkt());
target.setMmtId(src.getMmtId());
- target.setStatus(src.getStatus());
- repository.update(target, "land");
+ Response r = repository.update(target, "land");
+ target = (Messung)r.getData();
return this;
}
@@ -123,6 +113,7 @@
found.get(0).setMesswertPzs(zusatzwerte.get(i).getMesswertPzs());
found.get(0).setNwgZuMesswert(zusatzwerte.get(i).getNwgZuMesswert());
repository.update(found.get(0), "land");
+ builder = builder.getEmptyBuilder();
}
return this;
}
@@ -146,9 +137,10 @@
}
else if (found.size() > 1) {
// something is wrong (probeId and mstId and datum should be unique).
- // Continue and skip this zusatzwert.
+ // Continue and skip this kommentar.
continue;
}
+ builder = builder.getEmptyBuilder();
}
return this;
}
@@ -158,7 +150,7 @@
return this;
}
- public ObjectMerger mergeKommentare(
+ public ObjectMerger mergeMessungKommentare(
Messung target,
List<KommentarM> kommentare
) {
@@ -180,6 +172,7 @@
// Continue and skip this zusatzwert.
continue;
}
+ builder = builder.getEmptyBuilder();
}
return this;
}
@@ -195,13 +188,15 @@
List<Messwert> found =
repository.filterPlain(builder.getQuery(), "land");
if (found.isEmpty()) {
+ for (int i = 0; i < messwerte.size(); i++) {
+ repository.create(messwerte.get(i), "land");
+ }
return this;
}
try {
for (int i = 0; i < found.size(); i++) {
repository.delete(found.get(i), "land");
}
- repository.entityManager("land").flush();
for (int i = 0; i < messwerte.size(); i++) {
repository.create(messwerte.get(i), "land");
}
@@ -212,7 +207,7 @@
// Restore messwerte.
logger.debug("exception: ", e);
for (int i = 0; i < found.size(); i++) {
- repository.create(found.get(i), "land");
+ repository.update(found.get(i), "land");
}
}
return this;
More information about the Lada-commits
mailing list