Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java @ 9650:a2a42a6bac6b
Importer (s/u-info) extensions:
outer try/catch for parse and log of line no,
catching parsing exception if not enough value fields,
parsing error and warning log messages with line number,
detecting and rejecting duplicate data series,
better differentiation between error and warning log messages
author | mschaefer |
---|---|
date | Mon, 23 Mar 2020 14:57:03 +0100 |
parents | 8aa7d9eaaa21 |
children |
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; |
8986
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
14 import org.dive4elements.river.importer.common.StoreMode; |
8559
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.BedHeight; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
16 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
|
17 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
|
18 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
|
19 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
20 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
21 public class ImportBedHeightValue { |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
22 |
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
|
23 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
|
24 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
25 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
26 protected ImportBedHeight bedHeight; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
27 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
28 protected Double station; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
29 protected Double height; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
30 protected Double uncertainty; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
31 protected Double dataGap; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
32 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
|
33 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
|
34 protected Double maxHeight; |
9034
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
35 protected Double[] sectionHeight; |
8559
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 protected BedHeightValue peer; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
38 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
39 |
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
|
40 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
|
41 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
|
42 this.bedHeight = bedHeight; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
43 this.station = station; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
44 this.height = height; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
45 this.uncertainty = uncertainty; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
46 this.dataGap = dataGap; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
47 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
|
48 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
|
49 this.maxHeight = maxHeight; |
9034
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
50 this.sectionHeight = new Double[10]; |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
51 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
52 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
53 |
9034
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
54 public void setSectionHeight(final int index, final Double value) { |
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
55 this.sectionHeight[index - 1] = value; |
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
56 } |
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
57 |
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
|
58 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
|
59 getPeer(bedHeight); |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
60 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
61 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
62 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
63 /** |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
64 * 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
|
65 * 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
|
66 */ |
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
|
67 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
|
68 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
|
69 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
|
70 |
8986
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
71 List<BedHeightValue> values; |
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
|
72 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
8986
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
73 if (this.bedHeight.storeMode == StoreMode.INSERT) |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
74 values = null; |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
75 else { |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
76 final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)" |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
77 + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))"); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
78 query.setParameter("bedHeight", bedHeight); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
79 query.setParameter("station", this.station); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
80 values = query.list(); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
81 } |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
82 if ((values == null) || values.isEmpty()) { |
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
|
83 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
|
84 this.minHeight, this.maxHeight); |
9034
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
85 for (int i = 1; i <= 10; i++) |
8aa7d9eaaa21
Added bed_height_values section heights height01 to height10
mschaefer
parents:
8986
diff
changeset
|
86 this.peer.setSectionHeight(i, this.sectionHeight[i - 1]); |
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
|
87 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
|
88 } 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
|
89 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
|
90 } |
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
|
91 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
|
92 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
93 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
94 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |