annotate backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoad.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents ff27548d078c
children 392bbcd8a88b
rev   line source
8841
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
1 /* Copyright (C) 2014 by Bundesanstalt für Gewässerkunde
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
2 * Software engineering by Intevation GmbH
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
3 *
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
6 * documentation coming with Dive4Elements River for details.
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
7 */
e8d2042c9639 Add missing copyright headers.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
8
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 package org.dive4elements.river.importer;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 import java.util.List;
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
12 import java.util.ArrayList;
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14 import org.dive4elements.river.model.GrainFraction;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 import org.dive4elements.river.model.SedimentLoad;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16 import org.dive4elements.river.model.TimeInterval;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 import org.hibernate.Query;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18 import org.hibernate.Session;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 public class ImportSedimentLoad
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 private SedimentLoad peer;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 private ImportGrainFraction grainFraction;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 private ImportTimeInterval timeInterval;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 private ImportTimeInterval sqTimeInterval;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 private String description;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28 private Integer kind;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
30 private List<ImportSedimentLoadValue> values;
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
31
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 public ImportSedimentLoad() {
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
33 this.values = new ArrayList<ImportSedimentLoadValue>();
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
34 }
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
35
8842
ff27548d078c Whitespace cosmetics.
Tom Gottfried <tom@intevation.de>
parents: 8841
diff changeset
36 public ImportSedimentLoad(
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
37 ImportGrainFraction grainFraction,
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
38 ImportTimeInterval timeInterval,
8059
bde5f5ec7c72 SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
Tom Gottfried <tom@intevation.de>
parents: 8056
diff changeset
39 ImportTimeInterval sqTimeInterval,
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
40 String description,
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
41 Integer kind
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
42 ) {
8059
bde5f5ec7c72 SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
Tom Gottfried <tom@intevation.de>
parents: 8056
diff changeset
43 this.grainFraction = grainFraction;
bde5f5ec7c72 SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
Tom Gottfried <tom@intevation.de>
parents: 8056
diff changeset
44 this.timeInterval = timeInterval;
bde5f5ec7c72 SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
Tom Gottfried <tom@intevation.de>
parents: 8056
diff changeset
45 this.sqTimeInterval = sqTimeInterval;
bde5f5ec7c72 SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
Tom Gottfried <tom@intevation.de>
parents: 8056
diff changeset
46 this.description = description;
bde5f5ec7c72 SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
Tom Gottfried <tom@intevation.de>
parents: 8056
diff changeset
47 this.kind = kind;
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
48
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
49 this.values = new ArrayList<ImportSedimentLoadValue>();
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
50 }
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
51
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
52 public void addValue(ImportSedimentLoadValue value) {
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
53 values.add(value);
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 public void storeDependencies() {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57 grainFraction.getPeer();
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
58 timeInterval.getPeer();
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
59
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
60 if (sqTimeInterval != null) {
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
61 sqTimeInterval.getPeer();
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
62 }
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
63
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
64 getPeer();
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
65
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
66 for (ImportSedimentLoadValue value : values) {
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
67 value.storeDependencies(peer);
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
68 }
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
69
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
72 public SedimentLoad getPeer() {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74 if (peer == null) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8842
diff changeset
75 Session session = ImporterSession.getInstance()
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8842
diff changeset
76 .getDatabaseSession();
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
77
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8081
diff changeset
78 String sqtquery = sqTimeInterval == null
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8081
diff changeset
79 ? "sq_time_interval_id is null"
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8081
diff changeset
80 : "sqTimeInterval = :sqTimeInterval";
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
81 Query query = session.createQuery(
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
82 "from SedimentLoad where " +
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
83 " grainFraction = :grainFraction and " +
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
84 " timeInterval = :timeInterval and " +
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
85 " description = :description and " +
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
86 " kind = :kind and " +
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
87 sqtquery);
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
88
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89 GrainFraction gf = grainFraction.getPeer();
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90 TimeInterval ti = timeInterval.getPeer();
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 TimeInterval sqti = sqTimeInterval != null
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
93 ? sqTimeInterval.getPeer()
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 : null;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96 query.setParameter("grainFraction", gf);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97 query.setParameter("timeInterval", ti);
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
98
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
99 if (sqti != null) {
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
100 query.setParameter("sqTimeInterval", sqti);
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
101 }
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102 query.setParameter("description", description);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103 query.setParameter("kind", kind);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
105 List<SedimentLoad> loads = query.list();
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
106 if (loads.isEmpty()) {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
107 peer = new SedimentLoad(gf, ti, sqti, description, kind);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
108 session.save(peer);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
109 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
110 else {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
111 peer = loads.get(0);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
113 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
114
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
115 return peer;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
116 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
117 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org