changeset 1047:1b6adb3971d4 schema-update

Added identifier for probe and messung objects for use in LAF importer.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 09 Sep 2016 15:35:09 +0200
parents 434b46ead134
children 6960275c4609
files src/main/java/de/intevation/lada/importer/Identified.java src/main/java/de/intevation/lada/importer/Identifier.java src/main/java/de/intevation/lada/importer/IdentifierConfig.java src/main/java/de/intevation/lada/importer/MessungIdentifier.java src/main/java/de/intevation/lada/importer/ProbeIdentifier.java
diffstat 5 files changed, 285 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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
+}
--- /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;
+
+}
--- /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@intevation.de">Raimund Renkert</a>
+ */
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target({
+    ElementType.TYPE,
+    ElementType.FIELD,
+    ElementType.METHOD,
+    ElementType.PARAMETER})
+public @interface IdentifierConfig {
+    String type() default "";
+}
+
--- /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;
+
+@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;
+            }
+        }
+    }
+}
--- /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;
+
+@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;
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)