annotate backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoad.java @ 8841:e8d2042c9639

Add missing copyright headers.
author Tom Gottfried <tom@intevation.de>
date Fri, 12 Jan 2018 12:04:05 +0100
parents 17db08570637
children ff27548d078c
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
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
36 public ImportSedimentLoad (
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) {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 Session session = ImporterSession.getInstance().getDatabaseSession();
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
76
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
77 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
78 ? "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
79 : "sqTimeInterval = :sqTimeInterval";
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
80 Query query = session.createQuery(
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
81 "from SedimentLoad where " +
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
82 " grainFraction = :grainFraction and " +
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
83 " timeInterval = :timeInterval and " +
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
84 " description = :description and " +
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
85 " kind = :kind and " +
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
86 sqtquery);
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
87
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
88 GrainFraction gf = grainFraction.getPeer();
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89 TimeInterval ti = timeInterval.getPeer();
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91 TimeInterval sqti = sqTimeInterval != null
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 ? sqTimeInterval.getPeer()
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
93 : null;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95 query.setParameter("grainFraction", gf);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96 query.setParameter("timeInterval", ti);
8056
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
97
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
98 if (sqti != null) {
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
99 query.setParameter("sqTimeInterval", sqti);
d86cc6a17b7a Importer: Import sediment load at measurement stations.
Tom Gottfried <tom@intevation.de>
parents: 8028
diff changeset
100 }
8028
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
101 query.setParameter("description", description);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102 query.setParameter("kind", kind);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104 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
105 if (loads.isEmpty()) {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
106 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
107 session.save(peer);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
108 }
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
109 else {
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
110 peer = loads.get(0);
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
111 }
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 return peer;
aa054f72e887 Added importer models for sediment load and sediment load values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
115 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org