annotate backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java @ 8975:a0a0a7f912ab

Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
author mschaefer
date Tue, 03 Apr 2018 10:40:57 +0200
parents 5e38e2924c07
children 392bbcd8a88b
rev   line source
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
2 * Software engineering by Intevation GmbH
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
3 *
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
7 */
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
8
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
9 package org.dive4elements.river.importer;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
10
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
11 import java.util.List;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
12
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
13 import org.apache.log4j.Logger;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
14 import org.dive4elements.river.model.BedHeight;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
15 import org.dive4elements.river.model.BedHeightValue;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
16 import org.hibernate.Query;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
17 import org.hibernate.Session;
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
18
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
19
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
20 public class ImportBedHeightValue {
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
21
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
22 private static final Logger log = Logger.getLogger(ImportBedHeightValue.class);
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
23
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
24
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
25 protected ImportBedHeight bedHeight;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
26
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
27 protected Double station;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
28 protected Double height;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
29 protected Double uncertainty;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
30 protected Double dataGap;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
31 protected Double soundingWidth;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
32 protected Double minHeight;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
33 protected Double maxHeight;
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
34
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
35 protected BedHeightValue peer;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
36
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
37
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
38 public ImportBedHeightValue(final ImportBedHeight bedHeight, final Double station, final Double height, final Double uncertainty, final Double dataGap,
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
39 final Double soundingWidth, final Double minHeight, final Double maxHeight) {
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
40 this.bedHeight = bedHeight;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
41 this.station = station;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
42 this.height = height;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
43 this.uncertainty = uncertainty;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
44 this.dataGap = dataGap;
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
45 this.soundingWidth = soundingWidth;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
46 this.minHeight = minHeight;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
47 this.maxHeight = maxHeight;
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
48 }
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
49
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
50
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
51 public void storeDependencies(final BedHeight bedHeight) {
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
52 getPeer(bedHeight);
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
53 }
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
54
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
55
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
56 /**
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
57 * Add this value to database or return database bound Value, assuring
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
58 * that the BedHeight exists in db already.
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
59 */
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
60 public BedHeightValue getPeer(final BedHeight bedHeight) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
61 if (this.peer != null)
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
62 return this.peer;
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
63
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
64 final Session session = ImporterSession.getInstance().getDatabaseSession();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
65 final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)"
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
66 + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))");
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
67 query.setParameter("bedHeight", bedHeight);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
68 query.setParameter("station", this.station);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
69 final List<BedHeightValue> values = query.list();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
70 if (values.isEmpty()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
71 this.peer = new BedHeightValue(bedHeight, this.station, this.height, this.uncertainty, this.dataGap, this.soundingWidth,
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
72 this.minHeight, this.maxHeight);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
73 session.save(this.peer);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
74 } else {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
75 this.peer = values.get(0);
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
76 }
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
77 return this.peer;
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
78 }
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
79 }
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff changeset
80 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org