Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java @ 4447:a5993b69439b
Add processor to be able to generate curves for WKms values
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 07 Nov 2012 15:52:25 +0100 |
parents | a5b003595d6c |
children | c7ce7c9e405e |
rev | line source |
---|---|
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.sql.SQLException; |
2828
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
4 import java.util.ArrayList; |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.apache.log4j.Logger; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.hibernate.Session; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.hibernate.Query; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.hibernate.exception.ConstraintViolationException; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.flys.model.DischargeZone; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.model.FlowVelocityModel; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.flys.model.River; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 public class ImportFlowVelocityModel { |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
20 private static final Logger log = Logger |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
21 .getLogger(ImportFlowVelocityModel.class); |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 private String description; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 private ImportDischargeZone dischargeZone; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 private List<ImportFlowVelocityModelValue> values; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 private FlowVelocityModel peer; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
2828
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
31 public ImportFlowVelocityModel() { |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
32 values = new ArrayList<ImportFlowVelocityModelValue>(); |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
33 } |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
34 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
35 public ImportFlowVelocityModel(ImportDischargeZone dischargeZone, |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
36 String description) { |
2828
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
37 this(); |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
38 |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 this.dischargeZone = dischargeZone; |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
40 this.description = description; |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
2828
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
43 public void setDischargeZone(ImportDischargeZone dischargeZone) { |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
44 this.dischargeZone = dischargeZone; |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
45 } |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
46 |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
47 public void setDescription(String description) { |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
48 this.description = description; |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
49 } |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
50 |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
51 public void addValue(ImportFlowVelocityModelValue value) { |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
52 this.values.add(value); |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
53 } |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
54 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
55 public void storeDependencies(River river) throws SQLException, |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
56 ConstraintViolationException { |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 log.debug("store dependencies"); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
2828
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
59 if (dischargeZone == null) { |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
60 log.warn("skip flow velocity model: No discharge zone specified."); |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
61 return; |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
62 } |
ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2827
diff
changeset
|
63 |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 dischargeZone.storeDependencies(river); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 FlowVelocityModel peer = getPeer(river); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
68 if (peer != null) { |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
69 int i = 0; |
2833
5b54a648f702
Finished flow velocity data import: finished parsing meta data of model files and repaired broken HQL statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
70 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
71 for (ImportFlowVelocityModelValue value : values) { |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
72 value.storeDependencies(peer); |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
73 i++; |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
74 } |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
75 |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
76 log.info("stored " + i + " flow velocity model values."); |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 public FlowVelocityModel getPeer(River river) { |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 if (peer == null) { |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
82 Session session = ImporterSession.getInstance() |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
83 .getDatabaseSession(); |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 DischargeZone zone = dischargeZone.getPeer(river); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
87 Query query = session.createQuery("from FlowVelocityModel where " |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2833
diff
changeset
|
88 + " river=:river and " + " dischargeZone=:dischargeZone"); |
2827
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 query.setParameter("river", river); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 query.setParameter("dischargeZone", zone); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 List<FlowVelocityModel> model = query.list(); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 if (model.isEmpty()) { |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 peer = new FlowVelocityModel(river, zone); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 session.save(peer); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 else { |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 peer = model.get(0); |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 return peer; |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 } |
85b25e74594f
Added temp classes used during the import process of flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |