Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/importer/MessungIdentifier.java @ 1097:186d602e031a
Merged branch schema-update into default.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 14 Oct 2016 18:17:42 +0200 |
parents | |
children | 2593ba20487e |
comparison
equal
deleted
inserted
replaced
1096:565c8a67034d | 1097:186d602e031a |
---|---|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | |
6 * the documentation coming with IMIS-Labordaten-Application for details. | |
7 */ | |
8 package de.intevation.lada.importer; | |
9 | |
10 import java.util.List; | |
11 | |
12 import javax.inject.Inject; | |
13 import javax.management.modelmbean.InvalidTargetObjectTypeException; | |
14 | |
15 import de.intevation.lada.model.land.Messung; | |
16 import de.intevation.lada.util.annotation.RepositoryConfig; | |
17 import de.intevation.lada.util.data.QueryBuilder; | |
18 import de.intevation.lada.util.data.Repository; | |
19 import de.intevation.lada.util.data.RepositoryType; | |
20 | |
21 @IdentifierConfig(type="Messung") | |
22 public class MessungIdentifier implements Identifier { | |
23 | |
24 @Inject | |
25 @RepositoryConfig(type=RepositoryType.RO) | |
26 private Repository repository; | |
27 | |
28 @Override | |
29 public Identified find(Object object) | |
30 throws InvalidTargetObjectTypeException | |
31 { | |
32 if (!(object instanceof Messung)) { | |
33 throw new InvalidTargetObjectTypeException( | |
34 "Object is not of type Messung"); | |
35 } | |
36 Messung messung = (Messung)object; | |
37 QueryBuilder<Messung> builder = new QueryBuilder<Messung>( | |
38 repository.entityManager("land"), | |
39 Messung.class | |
40 ); | |
41 | |
42 // idAlt null and hauptprobenNr not null and mstId not null. | |
43 if (messung.getIdAlt() == null && | |
44 messung.getNebenprobenNr() != null | |
45 ) { | |
46 builder.and("probeId", messung.getProbeId()); | |
47 builder.and("nebenprobenNr", messung.getNebenprobenNr()); | |
48 List<Messung> messungen = | |
49 repository.filterPlain(builder.getQuery(), "land"); | |
50 if (messungen.size() > 1) { | |
51 // Should never happen. DB has unique constraint for | |
52 // "nebenprobenNr" | |
53 return Identified.REJECT; | |
54 } | |
55 if (messungen.isEmpty()) { | |
56 return Identified.NEW; | |
57 } | |
58 return Identified.UPDATE; | |
59 } | |
60 else if (messung.getIdAlt() != null && | |
61 messung.getNebenprobenNr() == null | |
62 ) { | |
63 builder.and("probeId", messung.getProbeId()); | |
64 builder.and("idAlt", messung.getIdAlt()); | |
65 List<Messung> messungen = | |
66 repository.filterPlain(builder.getQuery(), "land"); | |
67 if (messungen.size() > 1) { | |
68 // Should never happen. DB has unique constraint for "idAlt" | |
69 return Identified.REJECT; | |
70 } | |
71 if (messungen.isEmpty()) { | |
72 return Identified.NEW; | |
73 } | |
74 return Identified.UPDATE; | |
75 } | |
76 else { | |
77 builder.and("probeId", messung.getProbeId()); | |
78 builder.and("idAlt", messung.getIdAlt()); | |
79 List<Messung> messungen = | |
80 repository.filterPlain(builder.getQuery(), "land"); | |
81 if (messungen.size() > 1) { | |
82 // Should never happen. DB has unique constraint for "idAlt" | |
83 return Identified.REJECT; | |
84 } | |
85 if (messungen.isEmpty()) { | |
86 return Identified.NEW; | |
87 } | |
88 if (messungen.get(0).getNebenprobenNr().equals( | |
89 messung.getNebenprobenNr()) || | |
90 messung.getNebenprobenNr().isEmpty() || | |
91 messungen.get(0).getNebenprobenNr().isEmpty() | |
92 ) { | |
93 return Identified.UPDATE; | |
94 } | |
95 else { | |
96 return Identified.REJECT; | |
97 } | |
98 } | |
99 } | |
100 } |