annotate src/main/java/de/intevation/lada/factory/ProbeFactory.java @ 1083:99c6c644773b

Use Intervall-class for generation of yearly Probe objects. All intervalls are now based on this class and obsolete methods were removed.
author Tom Gottfried <tom@intevation.de>
date Tue, 11 Oct 2016 16:38:04 +0200
parents b782a10c5b28
children 186d602e031a
rev   line source
691
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
2 * Software engineering by Intevation GmbH
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
3 *
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
4 * This file is Free Software under the GNU GPL (v>=3)
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
7 */
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 package de.intevation.lada.factory;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import java.sql.Timestamp;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import java.util.ArrayList;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import java.util.Calendar;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import java.util.Date;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import java.util.List;
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
15 import java.util.Hashtable;
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import javax.inject.Inject;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
981
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
19 import org.apache.log4j.Logger;
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
20
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import de.intevation.lada.model.land.LKommentarP;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 import de.intevation.lada.model.land.LMessung;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 import de.intevation.lada.model.land.LMesswert;
810
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
24 import de.intevation.lada.model.land.LOrtszuordnung;
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 import de.intevation.lada.model.land.LProbe;
897
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
26 import de.intevation.lada.model.land.LStatusProtokoll;
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 import de.intevation.lada.model.land.Messprogramm;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 import de.intevation.lada.model.land.MessprogrammMmt;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 import de.intevation.lada.model.land.MessungTranslation;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 import de.intevation.lada.model.land.ProbeTranslation;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
31 import de.intevation.lada.model.stamm.DeskriptorUmwelt;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
32 import de.intevation.lada.model.stamm.Deskriptoren;
810
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
33 import de.intevation.lada.model.stamm.Ort;
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 import de.intevation.lada.util.annotation.RepositoryConfig;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 import de.intevation.lada.util.data.QueryBuilder;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 import de.intevation.lada.util.data.Repository;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 import de.intevation.lada.util.data.RepositoryType;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 import de.intevation.lada.util.rest.Response;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39
691
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
40 /**
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
41 * This factory creates probe objects and its children using a messprogramm
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
42 * as template.
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
43 *
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
44 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
45 */
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 public class ProbeFactory {
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
48 // Day of year representing February 28
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
49 private static final int FEBRUARY_28 = 58;
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
50
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
51 private static Hashtable<String, int[]> fieldsTable;
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
52
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
53 public ProbeFactory() {
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
54 int[] T = { Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR, 1 };
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
55 int[] W = { Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR, 7 };
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
56 int[] W2 = { Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR, 14 };
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
57 int[] W4 = { Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR, 28 };
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
58
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
59 int[] M = { Calendar.MONTH, Calendar.DAY_OF_MONTH, 1 };
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
60 int[] Q = { Calendar.MONTH, Calendar.DAY_OF_MONTH, 3 };
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
61 int[] H = { Calendar.MONTH, Calendar.DAY_OF_MONTH, 6 };
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
62
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
63 int[] J = { Calendar.YEAR, Calendar.DAY_OF_YEAR, 1 };
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
64
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
65 this.fieldsTable = new Hashtable<String, int[]>();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
66
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
67 this.fieldsTable.put("T", T);
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
68 this.fieldsTable.put("W", W);
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
69 this.fieldsTable.put("W2", W2);
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
70 this.fieldsTable.put("W4", W4);
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
71 this.fieldsTable.put("M", M);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
72 this.fieldsTable.put("Q", Q);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
73 this.fieldsTable.put("H", H);
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
74 this.fieldsTable.put("J", J);
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
75 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
76
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
77 private class Intervall {
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
78 private final int teilVon;
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
79 private final int teilBis;
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
80 private final int offset;
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
81
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
82 private final int intervallField;
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
83 private final int subIntField;
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
84 private final int intervallFactor;
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
85
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
86 private Calendar from;
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
87
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
88 public Intervall(
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
89 Messprogramm messprogramm,
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
90 Calendar start
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
91 ) {
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
92 this.teilVon = messprogramm.getTeilintervallVon();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
93 this.teilBis = messprogramm.getTeilintervallBis();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
94 this.offset = messprogramm.getIntervallOffset();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
95
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
96 this.intervallField = fieldsTable
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
97 .get(messprogramm.getProbenintervall())[0];
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
98 this.subIntField = fieldsTable
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
99 .get(messprogramm.getProbenintervall())[1];
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
100 this.intervallFactor = fieldsTable
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
101 .get(messprogramm.getProbenintervall())[2];
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
102
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
103 this.from = (Calendar)start.clone();
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
104
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
105 /* Align with beginning of next interval
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
106 * like first day of next quarter or Monday of next week.*/
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
107 if (intervallField == Calendar.DAY_OF_YEAR
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
108 && intervallFactor % 7 == 0
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
109 ) {
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
110 if (from.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
111 from.add(Calendar.WEEK_OF_YEAR, 1);
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
112 from.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
113 }
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
114 } else {
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
115 int startIntField = start.get(intervallField);
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
116 from.set(
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
117 intervallField,
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
118 startIntField + startIntField % intervallFactor
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
119 );
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
120 }
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
121 from = adjustSubIntField(from, teilVon);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
122 if (start.after(from)) {
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
123 // to next intervall if start not at first day of intervall
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
124 this.roll();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
125 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
126 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
127
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
128 /**
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
129 * Return given calendar adjusted to start of intervall (e.g. first
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
130 * day in quarter) plus offset and given amount of days.
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
131 *
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
132 * @param cal Calendar to be adjusted
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
133 * @param int amount of days to be added (plus offset)
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
134 *
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
135 * @return the adjusted Calendar object.
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
136 */
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
137 private Calendar adjustSubIntField(Calendar cal, int teil) {
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
138 int intValue = cal.get(intervallField);
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
139 int adjust = offset;
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
140
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
141 if (intervallField != subIntField) {
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
142 intValue = intValue - intValue % intervallFactor;
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
143 cal.set(intervallField, intValue);
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
144
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
145 if (subIntField == Calendar.DAY_OF_YEAR) {
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
146 // Adjust in leap year
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
147 teil += startInLeapYear() && teil > FEBRUARY_28
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
148 ? 1
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
149 : 0;
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
150 }
1079
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
151 } else {
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
152 adjust += intValue - 1;
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
153 }
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
154
e544d76a311f Use Intervall class for generation of weekly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1078
diff changeset
155 int subIntValue = adjust + Math.min(teil, getDuration());
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
156 cal.set(subIntField, subIntValue);
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
157
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
158 return cal;
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
159 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
160
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
161 /**
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
162 * @return sum of actual maxima for subIntField from beginning of
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
163 * actual intervall for the next intervallFactor values intervallField
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
164 * or just intervallFactor, if subIntField == intervallField.
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
165 */
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
166 private int getDuration() {
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
167 if (subIntField == intervallField) {
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
168 return intervallFactor;
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
169 }
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
170 int duration = 0;
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
171 Calendar tmp = (Calendar)from.clone();
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
172
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
173 /* reset to beginning of intervall, e.g. first day of quarter
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
174 * to compensate possible overflow if
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
175 * teilVon > maximum of intervallField: */
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
176 int intValue = from.get(intervallField);
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
177 tmp.set(
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
178 intervallField,
1075
b5314ea024c6 Use Intervall class for daily Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1074
diff changeset
179 intValue - intValue % intervallFactor
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
180 );
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
181 tmp.set(subIntField, tmp.getActualMinimum(subIntField));
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
182
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
183 for (int i = 0; i < intervallFactor; i++) {
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
184 duration += tmp.getActualMaximum(subIntField);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
185 tmp.add(intervallField, 1);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
186 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
187 return duration;
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
188 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
189
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
190 public Date getFrom() {
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
191 return from.getTime();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
192 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
193
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
194 public Date getTo() {
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
195 Calendar to = (Calendar)from.clone();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
196 to = adjustSubIntField(to, teilBis);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
197 return to.getTime();
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
198 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
199
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
200 public boolean startInLeapYear() {
1077
7143cd96d3de Calendar.DAY_OF_YEAR is 1-based.
Tom Gottfried <tom@intevation.de>
parents: 1075
diff changeset
201 return from.getActualMaximum(Calendar.DAY_OF_YEAR) > 365;
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
202 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
203
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
204 public int getStartDOY() {
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
205 return from.get(Calendar.DAY_OF_YEAR);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
206 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
207
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
208 public void roll() {
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
209 from.add(intervallField, intervallFactor);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
210 from = adjustSubIntField(from, teilVon);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
211 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
212
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
213 }
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
214 // end Intervall class
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
215
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
216
981
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
217 @Inject Logger logger;
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
218
691
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
219 /**
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
220 * The data repository
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
221 */
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
222 @Inject
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
223 @RepositoryConfig(type = RepositoryType.RW)
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
224 private Repository repository;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
225
691
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
226 /**
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
227 * Create a list of probe objects
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
228 *
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
229 * @param id Messprogramm id
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
230 * @param from The start date
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
231 * @param to The end date
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
232 *
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
233 * @return List of probe objects.
46bb231ff9b9 Documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 685
diff changeset
234 */
1072
703b370c3b34 Authorize generation of Probe objects by Messprogramm.
Tom Gottfried <tom@intevation.de>
parents: 1064
diff changeset
235 public List<LProbe> create(Messprogramm messprogramm, Long from, Long to) {
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
236 Calendar start = Calendar.getInstance();
1061
f3331174b1ae Avoid detour via Date object.
Tom Gottfried <tom@intevation.de>
parents: 1060
diff changeset
237 start.setTimeInMillis(from);
1074
90bc64e74e4a Adjust end to end of the day.
Tom Gottfried <tom@intevation.de>
parents: 1073
diff changeset
238
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
239 Calendar end = Calendar.getInstance();
1061
f3331174b1ae Avoid detour via Date object.
Tom Gottfried <tom@intevation.de>
parents: 1060
diff changeset
240 end.setTimeInMillis(to);
1074
90bc64e74e4a Adjust end to end of the day.
Tom Gottfried <tom@intevation.de>
parents: 1073
diff changeset
241 /* Adjust to end of the day as we want to generate Probe objects
90bc64e74e4a Adjust end to end of the day.
Tom Gottfried <tom@intevation.de>
parents: 1073
diff changeset
242 * before or at this day. */
90bc64e74e4a Adjust end to end of the day.
Tom Gottfried <tom@intevation.de>
parents: 1073
diff changeset
243 end.set(Calendar.HOUR_OF_DAY, 23);
90bc64e74e4a Adjust end to end of the day.
Tom Gottfried <tom@intevation.de>
parents: 1073
diff changeset
244 end.set(Calendar.MINUTE, 59);
90bc64e74e4a Adjust end to end of the day.
Tom Gottfried <tom@intevation.de>
parents: 1073
diff changeset
245 end.set(Calendar.SECOND, 59);
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
246
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
247 int gueltigVon = messprogramm.getGueltigVon();
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
248 int gueltigBis = messprogramm.getGueltigBis();
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
249
981
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
250 List<LProbe> proben = new ArrayList<LProbe>();
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
251
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
252 for (Intervall intervall = new Intervall(messprogramm, start);
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
253 intervall.getFrom().before(end.getTime());
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
254 intervall.roll()
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
255 ) {
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
256 /* Leap year adaption of validity period.
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
257 * It is assumed here (and should be enforced by the data model)
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
258 * that gueltigVon and gueltigBis are always given relative to
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
259 * a non-leap year. E.g. a value of 59 is assumed to denote
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
260 * March 1 and thus has to be adapted in a leap year. */
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
261 int leapDay = intervall.startInLeapYear() ? 1 : 0;
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
262 int actualGueltigVon =
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
263 gueltigVon > FEBRUARY_28
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
264 ? gueltigVon + leapDay
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
265 : gueltigVon;
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
266 int actualGueltigBis =
1083
99c6c644773b Use Intervall-class for generation of yearly Probe objects.
Tom Gottfried <tom@intevation.de>
parents: 1081
diff changeset
267 gueltigBis > FEBRUARY_28
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
268 ? gueltigBis + leapDay
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
269 : gueltigBis;
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
270
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
271 int solldatumBeginnDOY = intervall.getStartDOY();
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
272
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
273 if ((
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
274 // Validity within one year
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
275 actualGueltigVon < actualGueltigBis
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
276 && solldatumBeginnDOY >= actualGueltigVon
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
277 && solldatumBeginnDOY <= actualGueltigBis
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
278 ) || (
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
279 // Validity over turn of the year
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
280 actualGueltigVon > actualGueltigBis
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
281 && (solldatumBeginnDOY >= actualGueltigVon
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
282 || solldatumBeginnDOY <= actualGueltigBis)
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
283 )
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
284 ) {
1060
cf5a2de206e3 Improve readability for easier debugging.
Tom Gottfried <tom@intevation.de>
parents: 1059
diff changeset
285 LProbe probe = createObjects(
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
286 messprogramm,
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
287 intervall.getFrom(),
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
288 intervall.getTo()
1062
0fbcaefc565b Make generation of monthly Probes respect actual lenght of months.
Tom Gottfried <tom@intevation.de>
parents: 1061
diff changeset
289 );
981
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
290 if (probe != null) {
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
291 proben.add(probe);
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
292 }
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
293 }
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
294 }
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
295
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
296 return proben;
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
297 }
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
298
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
299 /**
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
300 * Create a single probe object.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
301 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
302 * @param messprogramm The messprogramm containing probe details
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
303 * @param startDate The date for 'solldatumbeginn'
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
304 * @param endDate The date for 'solldatumende'
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
305 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
306 * @return The new probe object.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
307 */
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
308 private LProbe createObjects(
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
309 Messprogramm messprogramm,
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
310 Date startDate,
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
311 Date endDate
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
312 ) {
981
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
313 QueryBuilder<LProbe> builderProbe =
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
314 new QueryBuilder<LProbe>(
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
315 repository.entityManager("land"),
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
316 LProbe.class);
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
317 builderProbe.and("mprId", messprogramm.getId());
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
318 builderProbe.and("solldatumBeginn", startDate);
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
319 builderProbe.and("solldatumEnde", endDate);
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
320
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
321 List<LProbe> proben =
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
322 repository.filterPlain(builderProbe.getQuery(), "land");
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
323
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
324 if (!proben.isEmpty()) {
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
325 return null;
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
326 }
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
327 LProbe probe = new LProbe();
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
328 probe.setBaId(messprogramm.getBaId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
329 probe.setDatenbasisId(messprogramm.getDatenbasisId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
330 probe.setMediaDesk(messprogramm.getMediaDesk());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
331 probe.setMstId(messprogramm.getMstId());
896
c94a07959060 Use the laborMstId in generated probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 810
diff changeset
332 probe.setLaborMstId(messprogramm.getLaborMstId());
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
333 probe.setNetzbetreiberId(messprogramm.getNetzbetreiberId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
334 probe.setProbenartId(messprogramm.getProbenartId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
335 probe.setProbeNehmerId(messprogramm.getProbeNehmerId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
336 probe.setSolldatumBeginn(new Timestamp(startDate.getTime()));
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
337 probe.setSolldatumEnde(new Timestamp(endDate.getTime()));
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
338 probe.setTest(messprogramm.getTest());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
339 probe.setUmwId(messprogramm.getUmwId());
981
84f17f460969 Refactored probe generation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 914
diff changeset
340 probe.setMprId(messprogramm.getId());
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
341 repository.create(probe, "land");
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
342 ProbeTranslation translation = new ProbeTranslation();
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
343 translation.setProbeId(probe);
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
344 repository.create(translation, "land");
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
345
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
346 if (messprogramm.getProbeKommentar() != null &&
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
347 !messprogramm.getProbeKommentar().equals("")) {
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
348 LKommentarP kommentar = new LKommentarP();
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
349 kommentar.setDatum(new Timestamp(new Date().getTime()));
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
350 kommentar.setProbeId(probe.getId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
351 kommentar.setText(messprogramm.getProbeKommentar());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
352 kommentar.setErzeuger(messprogramm.getMstId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
353
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
354 repository.create(kommentar, "land");
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
355 }
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
356
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
357 QueryBuilder<MessprogrammMmt> builder =
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
358 new QueryBuilder<MessprogrammMmt>(
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
359 repository.entityManager("land"),
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
360 MessprogrammMmt.class);
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
361 builder.and("messprogrammId", messprogramm.getId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
362 Response response = repository.filter(builder.getQuery(), "land");
685
3118fbbe6292 Fixed or supressed warnings.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 684
diff changeset
363 @SuppressWarnings("unchecked")
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
364 List<MessprogrammMmt> mmts = (List<MessprogrammMmt>)response.getData();
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
365 for (MessprogrammMmt mmt : mmts) {
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
366 LMessung messung = new LMessung();
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
367 messung.setFertig(false);
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
368 messung.setGeplant(true);
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
369 messung.setMmtId(mmt.getMmtId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
370 messung.setNebenprobenNr(
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
371 messprogramm.getNetzbetreiberId() + mmt.getMmtId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
372 messung.setProbeId(probe.getId());
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
373 repository.create(messung, "land");
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
374 MessungTranslation mTranslation = new MessungTranslation();
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
375 mTranslation.setMessungsId(messung);
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
376 repository.create(mTranslation, "land");
897
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
377
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
378 LStatusProtokoll status = new LStatusProtokoll();
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
379 status.setDatum(new Timestamp(new Date().getTime()));
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
380 status.setMessungsId(messung.getId());
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
381 status.setErzeuger(probe.getMstId());
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
382 status.setStatusStufe(1);
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
383 status.setStatusWert(0);
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
384 repository.create(status, "land");
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
385 messung.setStatus(status.getId());
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
386 repository.update(messung, "land");
67c3d22372e4 Add the initial status to generated messung objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 896
diff changeset
387
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
388 for (int mw : mmt.getMessgroessen()) {
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
389 LMesswert wert = new LMesswert();
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
390 wert.setMessgroesseId(mw);
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
391 wert.setMessungsId(messung.getId());
914
54e83373bfae We need a wider range to allow arbitrary input formated +-9.99e+-99
Tom Gottfried <tom@intevation.de>
parents: 897
diff changeset
392 wert.setMesswert(0d);
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
393 wert.setMehId(1);
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
394 repository.create(wert, "land");
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
395 }
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
396 }
698
cd22674b4673 Fixed ort generation from messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 697
diff changeset
397 if (messprogramm.getOrtId() != null &&
cd22674b4673 Fixed ort generation from messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 697
diff changeset
398 !messprogramm.getOrtId().equals("")) {
810
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
399 LOrtszuordnung ort = new LOrtszuordnung();
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
400 ort.setOrtszuordnungTyp("E");
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
401 ort.setProbeId(probe.getId());
810
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
402 QueryBuilder<Ort> ortBuilder = new QueryBuilder<Ort>(
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
403 repository.entityManager("stamm"), Ort.class);
698
cd22674b4673 Fixed ort generation from messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 697
diff changeset
404 ortBuilder.and("id", messprogramm.getOrtId());
1060
cf5a2de206e3 Improve readability for easier debugging.
Tom Gottfried <tom@intevation.de>
parents: 1059
diff changeset
405 Response ortResponse = repository.filter(
cf5a2de206e3 Improve readability for easier debugging.
Tom Gottfried <tom@intevation.de>
parents: 1059
diff changeset
406 ortBuilder.getQuery(), "stamm");
685
3118fbbe6292 Fixed or supressed warnings.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 684
diff changeset
407 @SuppressWarnings("unchecked")
810
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
408 List<Ort> orte = (List<Ort>) ortResponse.getData();
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
409 if (orte != null && !orte.isEmpty()) {
810
092e673cbb8d Added and updated model, services, etc for to fit the new db schema.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 735
diff changeset
410 ort.setOrtId(Long.valueOf(orte.get(0).getId()));
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
411 }
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
412 repository.create(ort, "land");
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
413 }
680
a5e6580e8016 Reload the created probe object to have the 'probeIdAlt' field available.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 656
diff changeset
414 // Reolad the probe to have the old id
1060
cf5a2de206e3 Improve readability for easier debugging.
Tom Gottfried <tom@intevation.de>
parents: 1059
diff changeset
415 probe = (LProbe)repository.getById(
cf5a2de206e3 Improve readability for easier debugging.
Tom Gottfried <tom@intevation.de>
parents: 1059
diff changeset
416 LProbe.class, probe.getId(), "land").getData();
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
417 return probe;
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
418 }
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
419
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
420 /**
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
421 * Search for the umwelt id using the 'deskriptor'.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
422 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
423 * @param probe The probe object.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
424 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
425 * @return The updated probe object.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
426 */
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
427 public LProbe findUmweltId(LProbe probe) {
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
428 String[] mediaDesk = probe.getMediaDesk().split(" ");
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
429 if (mediaDesk.length <= 1) {
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
430 return probe;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
431 }
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
432 probe.setUmwId(findUmwelt(mediaDesk));
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
433 return probe;
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
434 }
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
435
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
436 /**
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
437 * Search for the media description using the 'deskriptor'.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
438 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
439 * @param probe The probe object
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
440 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
441 * @return The updated probe object.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
442 */
709
e502e1af6256 added autofill Mediadescription
Marco Lechner, Bundesamt fuer Strahlenschutz, SW 2.1 <mlechner@bfs.de>
parents: 698
diff changeset
443 public LProbe findMediaDesk(LProbe probe) {
713
d8e421d9d7ec Fixed possible NPE.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 711
diff changeset
444 Object result = repository.queryFromString(
d8e421d9d7ec Fixed possible NPE.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 711
diff changeset
445 "SELECT get_media_from_media_desk( :mediaDesk );", "stamm")
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
446 .setParameter("mediaDesk", probe.getMediaDesk())
713
d8e421d9d7ec Fixed possible NPE.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 711
diff changeset
447 .getSingleResult();
d8e421d9d7ec Fixed possible NPE.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 711
diff changeset
448 probe.setMedia(result != null ? result.toString() : "");
709
e502e1af6256 added autofill Mediadescription
Marco Lechner, Bundesamt fuer Strahlenschutz, SW 2.1 <mlechner@bfs.de>
parents: 698
diff changeset
449 return probe;
e502e1af6256 added autofill Mediadescription
Marco Lechner, Bundesamt fuer Strahlenschutz, SW 2.1 <mlechner@bfs.de>
parents: 698
diff changeset
450 }
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
451
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
452 /**
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
453 * Search for the umwelt id using the 'deskriptor'.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
454 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
455 * @param messprogramm The messprogramm
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
456 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
457 * @return The updated messprogramm.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
458 */
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
459 public Messprogramm findUmweltId(Messprogramm messprogramm) {
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
460 String[] mediaDesk = messprogramm.getMediaDesk().split(" ");
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
461 if (mediaDesk.length <= 1) {
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
462 return messprogramm;
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
463 }
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
464 messprogramm.setUmwId(findUmwelt(mediaDesk));
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
465 return messprogramm;
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
466 }
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
467
1064
8ec6a2a31171 Generalize generation of Proben for (multiples of) months.
Tom Gottfried <tom@intevation.de>
parents: 1062
diff changeset
468
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
469 /**
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
470 * Find the umwelt id for a given deskriptor.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
471 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
472 * @param mediaDesk The deskriptor string
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
473 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
474 * @return The umwelt id or an empty string.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
475 */
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
476 private String findUmwelt(String[] mediaDesk) {
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
477 List<Integer> mediaIds = new ArrayList<Integer>();
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
478 boolean zebs = false;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
479 Integer parent = null;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
480 Integer hdParent = null;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
481 Integer ndParent = null;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
482 if ("01".equals(mediaDesk[1])) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
483 zebs = true;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
484 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
485 for (int i = 1; i < mediaDesk.length; i++) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
486 if ("00".equals(mediaDesk[i])) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
487 mediaIds.add(-1);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
488 continue;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
489 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
490 if (zebs && i < 5) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
491 parent = hdParent;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
492 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
493 else if (!zebs && i < 3) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
494 parent = hdParent;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
495 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
496 else {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
497 parent = ndParent;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
498 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
499 QueryBuilder<Deskriptoren> builder = new QueryBuilder<Deskriptoren>(
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
500 repository.entityManager("stamm"), Deskriptoren.class);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
501 if (parent != null) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
502 builder.and("vorgaenger", parent);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
503 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
504 builder.and("sn", mediaDesk[i]);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
505 builder.and("ebene", i - 1);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
506 Response response = repository.filter(builder.getQuery(), "stamm");
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
507 @SuppressWarnings("unchecked")
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
508 List<Deskriptoren> data = (List<Deskriptoren>)response.getData();
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
509 if (data.isEmpty()) {
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
510 return "";
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
511 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
512 hdParent = data.get(0).getId();
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
513 mediaIds.add(data.get(0).getId());
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
514 if (i == 2) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
515 ndParent = data.get(0).getId();
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
516 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
517 }
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
518 return getUmwelt(mediaIds, zebs);
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
519 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
520
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
521 /**
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
522 * Find the umwelt id in the database using media deskriptor ids.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
523 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
524 * @param media The list of media ids.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
525 * @param isZebs Flag for type of the deskriptor.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
526 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
527 * @return The umwelt id or an empty string.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
528 */
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
529 private String getUmwelt(List<Integer> media, boolean isZebs) {
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
530 QueryBuilder<DeskriptorUmwelt> builder =
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
531 new QueryBuilder<DeskriptorUmwelt>(
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
532 repository.entityManager("stamm"), DeskriptorUmwelt.class);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
533
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
534 if (media.size() == 0) {
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
535 return "";
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
536 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
537
735
bcaf30a871ef Set fixed size for first deskriptoren request.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 732
diff changeset
538 int size = 1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
539 for (int i = size; i >= 0; i--) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
540 if (media.get(i) == -1) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
541 continue;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
542 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
543 String field = "s" + (i > 9 ? i : "0" + i);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
544 builder.and(field, media.get(i));
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
545 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
546 Response response = repository.filter(builder.getQuery(), "stamm");
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
547 @SuppressWarnings("unchecked")
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
548 List<DeskriptorUmwelt> data = (List<DeskriptorUmwelt>)response.getData();
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
549 if (data.isEmpty()) {
732
83acc3b63354 Fixed size of main descriptor fields and return 'null' instead of "" for empty
Raimund Renkert <raimund.renkert@intevation.de>
parents: 713
diff changeset
550 return null;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
551 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
552
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
553 boolean unique = isUnique(data);
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
554 if (unique) {
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
555 return data.get(0).getUmwId();
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
556 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
557 else {
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
558 int found = -1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
559 for (int i = 0; i < data.size(); i++) {
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
560 int matches = 0;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
561 int lastMatch = 0;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
562 for (int j = size + 1; j < 12; j++) {
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
563 switch(j) {
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
564 case 2: if (media.get(2).equals(data.get(i).getS02()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
565 matches += 1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
566 break;
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
567 case 3: if (media.get(3).equals(data.get(i).getS03()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
568 matches += 1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
569 break;
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
570 case 4: if (media.get(4).equals(data.get(i).getS04()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
571 matches += 1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
572 break;
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
573 case 5: if (media.get(5).equals(data.get(i).getS05()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
574 matches +=1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
575 break;
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
576 case 6: if (media.get(6).equals(data.get(i).getS06()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
577 matches += 1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
578 break;
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
579 case 7: if (media.get(7).equals(data.get(i).getS07()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
580 matches += 1;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
581 break;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
582 case 8: if (media.get(8).equals(data.get(i).getS08()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
583 matches += 1;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
584 break;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
585 case 9: if (media.get(9).equals(data.get(i).getS09()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
586 matches += 1;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
587 break;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
588 case 10: if (media.get(10).equals(data.get(i).getS10()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
589 matches += 1;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
590 break;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
591 case 11: if (media.get(11).equals(data.get(i).getS11()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
592 matches += 1;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
593 break;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
594 case 12: if (media.get(12).equals(data.get(i).getS12()))
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
595 matches += 1;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
596 break;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
597 }
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
598 if (matches > lastMatch) {
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
599 lastMatch = matches;
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
600 found = i;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
601 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
602 }
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
603 if (found >= 0) {
697
8c486052264c Refactored finding the umwelt id to be able to use it for messprogramme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 696
diff changeset
604 return data.get(found).getUmwId();
696
97ccdf45a4a3 Find the correct umweltbereich.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 695
diff changeset
605 }
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
606 }
732
83acc3b63354 Fixed size of main descriptor fields and return 'null' instead of "" for empty
Raimund Renkert <raimund.renkert@intevation.de>
parents: 713
diff changeset
607 return null;
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
608 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
609 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
610
711
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
611 /**
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
612 * Determine if the entries in the list have the same umwelt id.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
613 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
614 * @param list A list of DescriptorUmwelt objects.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
615 *
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
616 * @return true if the objects have the same umwelt id else false.
3ec358698b4d Code style and documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 709
diff changeset
617 */
695
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
618 private boolean isUnique(List<DeskriptorUmwelt> list) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
619 if (list.isEmpty()) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
620 return false;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
621 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
622 String element = list.get(0).getUmwId();
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
623 for (int i = 1; i < list.size(); i++) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
624 if (!element.equals(list.get(i))) {
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
625 return false;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
626 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
627 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
628 return true;
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
629 }
b8afbf6c1b5d Find the umw_id for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 691
diff changeset
630
656
866d05db7a6a Added probe factory. This factory creates probe objects(and its childs) from
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
631 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)