Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.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 | 4ee97d914501 |
rev | line source |
---|---|
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.sql.SQLException; |
2832
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
4 import java.util.ArrayList; |
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.apache.log4j.Logger; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.hibernate.Session; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.hibernate.Query; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.hibernate.exception.ConstraintViolationException; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.flys.model.FlowVelocityMeasurement; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.model.River; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 public class ImportFlowVelocityMeasurement { |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
19 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:
2832
diff
changeset
|
20 .getLogger(ImportFlowVelocityMeasurement.class); |
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 private String description; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 private List<ImportFlowVelocityMeasurementValue> values; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 private FlowVelocityMeasurement peer; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 public ImportFlowVelocityMeasurement() { |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 this(null); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 public ImportFlowVelocityMeasurement(String description) { |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 this.description = description; |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
34 this.values = new ArrayList<ImportFlowVelocityMeasurementValue>(); |
2832
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
35 } |
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
36 |
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
37 public void setDescription(String description) { |
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
38 this.description = description; |
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
39 } |
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
40 |
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
41 public void addValue(ImportFlowVelocityMeasurementValue value) { |
ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2831
diff
changeset
|
42 this.values.add(value); |
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
45 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:
2832
diff
changeset
|
46 ConstraintViolationException { |
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 log.debug("store dependencies"); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 FlowVelocityMeasurement peer = getPeer(river); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
51 if (peer != null) { |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
52 for (ImportFlowVelocityMeasurementValue value : values) { |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
53 value.storeDependencies(peer); |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
54 } |
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 public FlowVelocityMeasurement getPeer(River river) { |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 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:
2832
diff
changeset
|
60 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:
2832
diff
changeset
|
61 .getDatabaseSession(); |
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
3943
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
63 Query query = session |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
64 .createQuery("from FlowVelocityMeasurement where " |
a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2832
diff
changeset
|
65 + " river=:river and " + " description=:description"); |
2831
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 query.setParameter("river", river); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 query.setParameter("description", description); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 List<FlowVelocityMeasurement> measurement = query.list(); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 if (measurement.isEmpty()) { |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 peer = new FlowVelocityMeasurement(river, description); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 session.save(peer); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 else { |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 peer = measurement.get(0); |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 return peer; |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |