Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportWstColumn.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 | 0a5239a1e46e |
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:
5889
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:
5889
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 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
11 import org.dive4elements.river.model.Wst; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
12 import org.dive4elements.river.model.WstColumn; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
13 import org.dive4elements.river.model.River; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
14 import org.dive4elements.river.model.TimeInterval; |
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
|
15 |
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 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
|
17 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
|
18 |
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 import java.util.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
|
20 import java.util.ArrayList; |
7183
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
21 import java.util.Random; |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
202
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
23 import java.math.BigDecimal; |
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
24 |
9726 | 25 import org.apache.logging.log4j.Logger; |
26 import org.apache.logging.log4j.LogManager; | |
499
cce054f27dac
Importer: Only accept main value types 'Q', 'W', 'D' and 'T' by default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
27 |
5000 | 28 |
29 /** Unmapped column of a WST. */ | |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public class ImportWstColumn |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 { |
9726 | 32 private static Logger log = LogManager.getLogger(ImportWstColumn.class); |
499
cce054f27dac
Importer: Only accept main value types 'Q', 'W', 'D' and 'T' by default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
33 |
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
|
34 protected ImportWst wst; |
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 protected String name; |
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 protected String description; |
471
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
37 protected Integer position; |
6504
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
38 protected String source; |
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
|
39 |
2357
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
40 protected ImportTimeInterval timeInterval; |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
41 |
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
|
42 protected List<ImportWstColumnQRange> columnQRanges; |
202
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
43 protected List<ImportWstColumnValue> columnValues; |
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
|
44 |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 protected WstColumn peer; |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 public ImportWstColumn() { |
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
|
48 columnQRanges = new ArrayList<ImportWstColumnQRange>(); |
202
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
49 columnValues = new ArrayList<ImportWstColumnValue>(); |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
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
|
52 public ImportWstColumn( |
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 ImportWst wst, |
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 String name, |
471
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
55 String description, |
6504
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
56 Integer position, |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
57 String source |
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
|
58 ) { |
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 this(); |
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 this.wst = wst; |
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 this.name = name; |
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.description = description; |
471
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
63 this.position = position; |
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
|
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 |
6504
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
66 public ImportWstColumn( |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
67 ImportWst wst, |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
68 String name, |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
69 String description, |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
70 Integer position |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
71 ) { |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
72 this(wst, name, description, position, null); |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
73 } |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
74 |
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
|
75 public ImportWst getWst() { |
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 return wst; |
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 } |
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 |
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 public void setWst(ImportWst wst) { |
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 this.wst = wst; |
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 } |
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 |
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
|
83 public String getName() { |
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
|
84 return name; |
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
|
85 } |
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
|
86 |
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
|
87 public void setName(String name) { |
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
|
88 this.name = name; |
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
|
89 } |
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
|
90 |
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
|
91 public String getDescription() { |
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
|
92 return description; |
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
|
93 } |
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
|
94 |
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
|
95 public void setDescription(String description) { |
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
|
96 this.description = description; |
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
|
97 } |
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
|
98 |
471
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
99 public Integer getPosition() { |
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
100 return position; |
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
101 } |
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
102 |
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
103 public void setPosition(Integer position) { |
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
104 this.position = position; |
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
105 } |
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
106 |
6504
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
107 public String getSource() { |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
108 return source; |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
109 } |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
110 |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
111 public void setSource(String source) { |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
112 this.source = source; |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
113 } |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
114 |
202
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
115 public void addColumnValue(BigDecimal position, BigDecimal w) { |
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
116 columnValues.add( |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
478
diff
changeset
|
117 new ImportWstColumnValue(this, position, w)); |
202
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
118 } |
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
119 |
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
|
120 public void addColumnQRange(ImportWstQRange columnQRange) { |
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
|
121 columnQRanges.add( |
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
|
122 new ImportWstColumnQRange(this, columnQRange)); |
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
|
123 } |
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
|
124 |
5237
feb80b3afc40
ImportWstColumn: Expose columnValues with a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5000
diff
changeset
|
125 |
feb80b3afc40
ImportWstColumn: Expose columnValues with a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5000
diff
changeset
|
126 /** Get the Column Values stored in this column. */ |
feb80b3afc40
ImportWstColumn: Expose columnValues with a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5000
diff
changeset
|
127 public List<ImportWstColumnValue> getColumnValues() { |
feb80b3afc40
ImportWstColumn: Expose columnValues with a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5000
diff
changeset
|
128 return columnValues; |
feb80b3afc40
ImportWstColumn: Expose columnValues with a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5000
diff
changeset
|
129 } |
feb80b3afc40
ImportWstColumn: Expose columnValues with a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5000
diff
changeset
|
130 |
feb80b3afc40
ImportWstColumn: Expose columnValues with a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5000
diff
changeset
|
131 |
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
|
132 public void storeDependencies(River river) { |
500
d50cd3a632e0
Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
499
diff
changeset
|
133 log.info("store column '" + name + "'"); |
7183
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
134 getPeer(river); |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
135 |
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
|
136 for (ImportWstColumnQRange columnQRange: columnQRanges) { |
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
|
137 columnQRange.getPeer(river); |
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
|
138 } |
499
cce054f27dac
Importer: Only accept main value types 'Q', 'W', 'D' and 'T' by default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
139 |
202
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
140 for (ImportWstColumnValue columnValue: columnValues) { |
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
141 columnValue.getPeer(river); |
29a408f80a89
Finished import of WSTs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
142 } |
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
|
143 } |
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
|
144 |
2357
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
145 public ImportTimeInterval getTimeInterval() { |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
146 return timeInterval; |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
147 } |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
148 |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
149 public void setTimeInterval(ImportTimeInterval timeInterval) { |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
150 this.timeInterval = timeInterval; |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
151 } |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
152 |
7183
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
153 public boolean guessWaterLevelIncreasing() { |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
154 |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
155 int N = columnValues.size(); |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
156 |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
157 if (N < 2) { |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
158 return true; |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
159 } |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
160 |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
161 Random r = new Random(); |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
162 int up = 0; |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
163 |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
164 int S = N < 50 ? N : (int)(0.1f * N)+1; |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
165 for (int s = 0; s < S; ++s) { |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
166 int i1, i2; |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
167 do { |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
168 i1 = r.nextInt(N-1); |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
169 i2 = r.nextInt(N-1); |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
170 } while (i1 == i2); |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
171 ImportWstColumnValue b = columnValues.get(i1); |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
172 ImportWstColumnValue a = columnValues.get(i2); |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
173 if (b.getPosition().compareTo(a.getPosition()) < 0) { |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
174 ImportWstColumnValue t = a; a = b; b = t; |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
175 } |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
176 |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
177 if (a.getW().compareTo(b.getW()) < 0) ++up; |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
178 } |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
179 |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
180 return up > S - up; |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
181 } |
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
182 |
5000 | 183 /** Get corresponding mapped wst-column (from database). */ |
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
|
184 public WstColumn getPeer(River river) { |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 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
|
186 Wst w = wst.getPeer(river); |
8856 | 187 Session session = ImporterSession.getInstance() |
188 .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
|
189 Query query = session.createQuery( |
6504
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
190 "from WstColumn where" + |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
191 " wst=:wst and name=:name" + |
7250
8b8a10805c02
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7183
diff
changeset
|
192 " and source=:source" + |
471
3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
202
diff
changeset
|
193 " and position=:position"); |
6504
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
194 query.setParameter("wst", w); |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
195 query.setParameter("name", name); |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
196 query.setParameter("position", position); |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
197 query.setParameter("source", source); |
2357
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
198 |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
199 TimeInterval ti = timeInterval != null |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
200 ? timeInterval.getPeer() |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
201 : null; |
2e18e12fac11
Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
501
diff
changeset
|
202 |
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
|
203 List<WstColumn> columns = 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
|
204 if (columns.isEmpty()) { |
7183
0fe00824bd96
flys/issue1500: The main wst file determines km_up now.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6506
diff
changeset
|
205 log.debug("source: " + source); |
6504
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
206 peer = new WstColumn( |
7664ab97b4c7
Backend: Store source of a wst column if available.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
207 w, name, description, source, position, ti); |
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
|
208 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
|
209 } |
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
|
210 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
|
211 peer = columns.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
|
212 } |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 } |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 return peer; |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 } |
5542
f3b270e5462e
Wst Parser: Another attempt to fix the order of the Q ranges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5237
diff
changeset
|
216 |
196
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 } |
a33c065b95eb
Added importer helper model stubs for WST imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |