Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportMeasurementStation.java @ 7730:e1b831fe435a slt-simplify-cross-sections
Merged default into slt-simplify-cross-sections branch and updated package and class names.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 20 Jan 2014 14:04:20 +0100 |
parents | 4c3ccf2b0304 |
children | aa054f72e887 |
comparison
equal
deleted
inserted
replaced
5084:ca45dd039b54 | 7730:e1b831fe435a |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.importer; | |
10 | |
11 import java.util.List; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 import org.hibernate.Session; | |
15 | |
16 import org.dive4elements.river.model.Gauge; | |
17 import org.dive4elements.river.model.MeasurementStation; | |
18 import org.dive4elements.river.model.Range; | |
19 import org.dive4elements.river.model.River; | |
20 import org.dive4elements.river.model.TimeInterval; | |
21 | |
22 | |
23 public class ImportMeasurementStation { | |
24 | |
25 private static final Logger log = Logger | |
26 .getLogger(ImportMeasurementStation.class); | |
27 | |
28 private MeasurementStation peer; | |
29 | |
30 public String name; | |
31 public Double station; | |
32 public ImportRange range; | |
33 public String measurementType; | |
34 public String riverside; | |
35 public String gauge; | |
36 public ImportTimeInterval observationTimerange; | |
37 public String operator; | |
38 public String description; | |
39 | |
40 public ImportMeasurementStation() { | |
41 } | |
42 | |
43 private Gauge getGaugeFromDB() { | |
44 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
45 | |
46 org.hibernate.Query query = session | |
47 .createQuery("FROM Gauge WHERE name=:name"); | |
48 | |
49 query.setParameter("name", gauge); | |
50 List<Gauge> gauges = query.list(); | |
51 | |
52 return gauges.isEmpty() ? null : gauges.get(0); | |
53 } | |
54 | |
55 public boolean storeDependencies(River river) { | |
56 getPeer(river); | |
57 | |
58 return peer != null; | |
59 } | |
60 | |
61 public Object getPeer(River river) { | |
62 if (peer == null) { | |
63 Gauge gauge = null; | |
64 try { | |
65 gauge = getGaugeFromDB(); | |
66 if (gauge == null) { | |
67 log.warn("No gauge found for measurement station '" + name | |
68 + "'"); | |
69 } | |
70 } | |
71 catch (Exception e) { | |
72 log.error("Exception: " + e.getMessage()); | |
73 } | |
74 | |
75 Range range = null; | |
76 | |
77 if (this.range != null) { | |
78 range = this.range.getPeer(river); | |
79 } | |
80 | |
81 if (range == null) { | |
82 log.warn("No range found for measurement station '" + name + "'"); | |
83 } | |
84 | |
85 TimeInterval observationTimerange = this.observationTimerange | |
86 .getPeer(); | |
87 if (observationTimerange == null) { | |
88 log.warn("No time range found for measurement station '" | |
89 + name + "'"); | |
90 } | |
91 | |
92 Session session = ImporterSession.getInstance() | |
93 .getDatabaseSession(); | |
94 | |
95 org.hibernate.Query query = session | |
96 .createQuery( | |
97 "FROM MeasurementStation " + | |
98 "WHERE river=:river" + | |
99 " AND station=:station " + | |
100 " AND measurement_type=:measurement_type "); | |
101 | |
102 query.setParameter("river", river); | |
103 query.setParameter("station", station); | |
104 query.setParameter("measurement_type", measurementType); | |
105 | |
106 List<MeasurementStation> stations = query.list(); | |
107 | |
108 if (stations.isEmpty()) { | |
109 log.info("create new measurement station '" + name + "'"); | |
110 | |
111 peer = new MeasurementStation(river, name, measurementType, | |
112 riverside, station, range, gauge, this.gauge, | |
113 observationTimerange, operator, description); | |
114 | |
115 session.save(peer); | |
116 } | |
117 } | |
118 | |
119 return peer; | |
120 } | |
121 } |