Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportWstQRange.java @ 9729:7e767c0c9a6d 3.2.x
Improve importer start
_ Consider no given info gew files as error instead of starting to
process an empty list.
_ Reduce code duplication.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 07 Jul 2022 11:19:08 +0200 |
parents | 5e38e2924c07 |
children |
rev | line source |
---|---|
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
9 package org.dive4elements.river.importer; |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
11 import java.math.BigDecimal; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
12 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
13 import org.dive4elements.river.model.WstQRange; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
14 import org.dive4elements.river.model.River; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
15 import org.dive4elements.river.model.Range; |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
16 |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
17 import org.hibernate.Session; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
18 import org.hibernate.Query; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
19 |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
20 import java.util.List; |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 public class ImportWstQRange |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 { |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
24 protected ImportRange range; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
25 protected BigDecimal q; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
26 |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 protected WstQRange peer; |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public ImportWstQRange() { |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
32 public ImportWstQRange( |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
33 ImportRange range, |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
34 BigDecimal q |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
35 ) { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
36 this.range = range; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
37 this.q = q; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
38 } |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
39 |
6320
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
40 public ImportWstQRange( |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
41 BigDecimal a, |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
42 BigDecimal b, |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
43 BigDecimal q |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
44 ) { |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
45 this.range = new ImportRange(a, b); |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
46 this.q = q; |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
47 } |
6cdafb6feee1
issue1335: Set a single (0) QRange for Waterlevel diffs from csv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5992
diff
changeset
|
48 |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
49 public ImportRange getRange() { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
50 return range; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
51 } |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
52 |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
53 public void setRange(ImportRange range) { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
54 this.range = range; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
55 } |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
56 |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
57 public BigDecimal getQ() { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
58 return q; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
59 } |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
60 |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
61 public void setQ(BigDecimal q) { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
62 this.q = q; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
63 } |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
64 |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
65 public WstQRange getPeer(River river) { |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 if (peer == null) { |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
67 Range r = range.getPeer(river); |
8856 | 68 Session session = ImporterSession.getInstance() |
69 .getDatabaseSession(); | |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
70 Query query = session.createQuery( |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
71 "from WstQRange where " + |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
72 "range=:range and q=:q"); |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
73 query.setParameter("range", r); |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
74 query.setParameter("q", q); |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
75 List<WstQRange> wstQRanges = query.list(); |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
76 if (wstQRanges.isEmpty()) { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
77 peer = new WstQRange(r, q); |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
78 session.save(peer); |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
79 } |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
80 else { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
81 peer = wstQRanges.get(0); |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
196
diff
changeset
|
82 } |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 return peer; |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 } |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |