[Lada-commits] [PATCH 2 of 3] Added identifier for probe and messung objects for use in LAF importer

Wald Commits scm-commit at wald.intevation.org
Fri Sep 9 15:36:14 CEST 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1473428109 -7200
# Branch schema-update
# Node ID 1b6adb3971d4b1466a2a57e58ebd4f918ab2e87f
# Parent  434b46ead134835c151359331fb05700ef29bffe
Added identifier for probe and messung objects for use in LAF importer.

diff -r 434b46ead134 -r 1b6adb3971d4 src/main/java/de/intevation/lada/importer/Identified.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/importer/Identified.java	Fri Sep 09 15:35:09 2016 +0200
@@ -0,0 +1,7 @@
+package de.intevation.lada.importer;
+
+public enum Identified {
+    NEW,
+    UPDATE,
+    REJECT
+}
diff -r 434b46ead134 -r 1b6adb3971d4 src/main/java/de/intevation/lada/importer/Identifier.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/importer/Identifier.java	Fri Sep 09 15:35:09 2016 +0200
@@ -0,0 +1,17 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.importer;
+
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+
+public interface Identifier {
+
+    public Identified find(Object object)
+        throws InvalidTargetObjectTypeException;
+
+}
diff -r 434b46ead134 -r 1b6adb3971d4 src/main/java/de/intevation/lada/importer/IdentifierConfig.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/importer/IdentifierConfig.java	Fri Sep 09 15:35:09 2016 +0200
@@ -0,0 +1,33 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.importer;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+
+/**
+ * Annotation to configure identifier.
+ *
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({
+    ElementType.TYPE,
+    ElementType.FIELD,
+    ElementType.METHOD,
+    ElementType.PARAMETER})
+public @interface IdentifierConfig {
+    String type() default "";
+}
+
diff -r 434b46ead134 -r 1b6adb3971d4 src/main/java/de/intevation/lada/importer/MessungIdentifier.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/importer/MessungIdentifier.java	Fri Sep 09 15:35:09 2016 +0200
@@ -0,0 +1,100 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.importer;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+
+import de.intevation.lada.model.land.Messung;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+
+ at IdentifierConfig(type="Messung")
+public class MessungIdentifier implements Identifier {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Identified find(Object object)
+    throws InvalidTargetObjectTypeException
+    {
+        if (!(object instanceof Messung)) {
+            throw new InvalidTargetObjectTypeException(
+                "Object is not of type Messung");
+        }
+        Messung messung = (Messung)object;
+        QueryBuilder<Messung> builder = new QueryBuilder<Messung>(
+            repository.entityManager("land"),
+            Messung.class
+        );
+
+        // idAlt null and hauptprobenNr not null and mstId not null.
+        if (messung.getIdAlt() == null &&
+            messung.getNebenprobenNr() != null
+        ) {
+            builder.and("probeId", messung.getProbeId());
+            builder.and("nebenprobenNr", messung.getNebenprobenNr());
+            List<Messung> messungen =
+                repository.filterPlain(builder.getQuery(), "land");
+            if (messungen.size() > 1) {
+                // Should never happen. DB has unique constraint for
+                // "nebenprobenNr"
+                return Identified.REJECT;
+            }
+            if (messungen.isEmpty()) {
+                return Identified.NEW;
+            }
+            return Identified.UPDATE;
+        }
+        else if (messung.getIdAlt() != null &&
+            messung.getNebenprobenNr() == null
+        ) {
+            builder.and("probeId", messung.getProbeId());
+            builder.and("idAlt", messung.getIdAlt());
+            List<Messung> messungen =
+                repository.filterPlain(builder.getQuery(), "land");
+            if (messungen.size() > 1) {
+                // Should never happen. DB has unique constraint for "idAlt"
+                return Identified.REJECT;
+            }
+            if (messungen.isEmpty()) {
+                return Identified.NEW;
+            }
+            return Identified.UPDATE;
+        }
+        else {
+            builder.and("probeId", messung.getProbeId());
+            builder.and("idAlt", messung.getIdAlt());
+            List<Messung> messungen =
+                repository.filterPlain(builder.getQuery(), "land");
+            if (messungen.size() > 1) {
+                // Should never happen. DB has unique constraint for "idAlt"
+                return Identified.REJECT;
+            }
+            if (messungen.isEmpty()) {
+                return Identified.NEW;
+            }
+            if (messungen.get(0).getNebenprobenNr().equals(
+                    messung.getNebenprobenNr()) ||
+                messung.getNebenprobenNr().isEmpty() ||
+                messungen.get(0).getNebenprobenNr().isEmpty()
+            ) {
+                return Identified.UPDATE;
+            }
+            else {
+                return Identified.REJECT;
+            }
+        }
+    }
+}
diff -r 434b46ead134 -r 1b6adb3971d4 src/main/java/de/intevation/lada/importer/ProbeIdentifier.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/importer/ProbeIdentifier.java	Fri Sep 09 15:35:09 2016 +0200
@@ -0,0 +1,128 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.importer;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+
+import de.intevation.lada.model.land.Probe;
+import de.intevation.lada.model.land.ZusatzWert;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+
+ at IdentifierConfig(type="Probe")
+public class ProbeIdentifier implements Identifier {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Identified find(Object object)
+    throws InvalidTargetObjectTypeException
+    {
+        if (!(object instanceof Probe)) {
+            throw new InvalidTargetObjectTypeException(
+                "Object is not of type Probe");
+        }
+        Probe probe = (Probe)object;
+        QueryBuilder<Probe> builder = new QueryBuilder<Probe>(
+            repository.entityManager("land"),
+            Probe.class
+        );
+
+        // idAlt null and hauptprobenNr not null and mstId not null.
+        if (probe.getIdAlt() == null &&
+            probe.getHauptprobenNr() != null &&
+            probe.getMstId() != null
+        ) {
+            builder.and("mstId", probe.getMstId());
+            builder.and("hauptprobenNr", probe.getHauptprobenNr());
+            List<Probe> proben = repository.filterPlain(builder.getQuery(), "land");
+            if (proben.size() > 1) {
+                // Should never happen. DB has unique constraint for
+                // "hauptprobenNr"
+                return Identified.REJECT;
+            }
+            if (proben.isEmpty()) {
+                return Identified.NEW;
+            }
+            return Identified.UPDATE;
+        }
+        else if (probe.getIdAlt() != null &&
+            (probe.getHauptprobenNr() == null ||
+            probe.getMstId() == null)
+        ) {
+            builder.and("idAlt", probe.getIdAlt());
+            List<Probe> proben =
+                repository.filterPlain(builder.getQuery(), "land");
+            if (proben.size() > 1) {
+                // Should never happen. DB has unique constraint for "idAlt"
+                return Identified.REJECT;
+            }
+            if (proben.isEmpty()) {
+                return Identified.NEW;
+            }
+            return Identified.UPDATE;
+        }
+        else {
+            builder.and("idAlt", probe.getIdAlt());
+            List<Probe> proben =
+                repository.filterPlain(builder.getQuery(), "land");
+            if (proben.size() > 1) {
+                // Should never happen. DB has unique constraint for "idAlt"
+                return Identified.REJECT;
+            }
+            if (proben.isEmpty()) {
+                return Identified.NEW;
+            }
+            if (proben.get(0).getHauptprobenNr().equals(
+                    probe.getHauptprobenNr()) ||
+                probe.getHauptprobenNr().isEmpty() ||
+                proben.get(0).getHauptprobenNr().isEmpty()
+            ) {
+                return Identified.UPDATE;
+            }
+            else {
+                return Identified.REJECT;
+            }
+        }
+    }
+
+    // TODO move the following functions to the correct class to have a clean
+    // interface impl.
+    public boolean merge(Probe result, Probe tomerge) {
+        result.setBaId(tomerge.getBaId());
+        result.setDatenbasisId(tomerge.getDatenbasisId());
+        result.setErzeugerId(tomerge.getErzeugerId());
+        result.setHauptprobenNr(tomerge.getHauptprobenNr());
+        result.setLaborMstId(tomerge.getLaborMstId());
+        result.setMedia(tomerge.getMedia());
+        result.setMediaDesk(tomerge.getMediaDesk());
+        result.setMittelungsdauer(tomerge.getMittelungsdauer());
+        result.setMplId(tomerge.getMplId());
+        result.setMprId(tomerge.getMprId());
+        result.setProbeentnahmeBeginn(tomerge.getProbeentnahmeBeginn());
+        result.setProbeentnahmeEnde(tomerge.getProbeentnahmeEnde());
+        result.setProbenartId(tomerge.getProbenartId());
+        result.setProbeNehmerId(tomerge.getProbeNehmerId());
+        result.setSolldatumBeginn(tomerge.getSolldatumBeginn());
+        result.setSolldatumEnde(tomerge.getSolldatumEnde());
+        result.setTest(tomerge.getTest());
+        result.setUmwId(tomerge.getUmwId());
+        return true;
+    }
+
+    public boolean mergeZusatzwerte(Probe probe, List<ZusatzWert> zusatzwerte) {
+        return true;
+    }
+}


More information about the Lada-commits mailing list