Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportFlowVelocityModel.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-backend/src/main/java/org/dive4elements/river/importer/ImportFlowVelocityModel.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.hibernate.Session; | |
9 import org.hibernate.Query; | |
10 | |
11 import org.dive4elements.river.model.DischargeZone; | |
12 import org.dive4elements.river.model.FlowVelocityModel; | |
13 import org.dive4elements.river.model.River; | |
14 | |
15 | |
16 public class ImportFlowVelocityModel { | |
17 | |
18 private static final Logger log = Logger | |
19 .getLogger(ImportFlowVelocityModel.class); | |
20 | |
21 private String description; | |
22 | |
23 private ImportDischargeZone dischargeZone; | |
24 | |
25 private List<ImportFlowVelocityModelValue> values; | |
26 | |
27 private FlowVelocityModel peer; | |
28 | |
29 public ImportFlowVelocityModel() { | |
30 values = new ArrayList<ImportFlowVelocityModelValue>(); | |
31 } | |
32 | |
33 public ImportFlowVelocityModel(String description) { | |
34 this(); | |
35 | |
36 this.description = description; | |
37 } | |
38 | |
39 public ImportFlowVelocityModel(ImportDischargeZone dischargeZone, | |
40 String description) { | |
41 this(); | |
42 | |
43 this.dischargeZone = dischargeZone; | |
44 this.description = description; | |
45 } | |
46 | |
47 public void setDischargeZone(ImportDischargeZone dischargeZone) { | |
48 this.dischargeZone = dischargeZone; | |
49 } | |
50 | |
51 public void setDescription(String description) { | |
52 this.description = description; | |
53 } | |
54 | |
55 public void addValue(ImportFlowVelocityModelValue value) { | |
56 this.values.add(value); | |
57 } | |
58 | |
59 public void storeDependencies(River river) { | |
60 log.debug("store dependencies"); | |
61 | |
62 if (dischargeZone == null) { | |
63 log.warn("skip flow velocity model: No discharge zone specified."); | |
64 return; | |
65 } | |
66 | |
67 dischargeZone.storeDependencies(river); | |
68 | |
69 FlowVelocityModel peer = getPeer(river); | |
70 | |
71 if (peer != null) { | |
72 int i = 0; | |
73 | |
74 for (ImportFlowVelocityModelValue value : values) { | |
75 value.storeDependencies(peer); | |
76 i++; | |
77 } | |
78 | |
79 log.info("stored " + i + " flow velocity model values."); | |
80 } | |
81 } | |
82 | |
83 public FlowVelocityModel getPeer(River river) { | |
84 if (peer == null) { | |
85 Session session = ImporterSession.getInstance() | |
86 .getDatabaseSession(); | |
87 | |
88 DischargeZone zone = dischargeZone.getPeer(river); | |
89 | |
90 Query query = session.createQuery("from FlowVelocityModel where " | |
91 + " dischargeZone=:dischargeZone"); | |
92 | |
93 query.setParameter("dischargeZone", zone); | |
94 | |
95 List<FlowVelocityModel> model = query.list(); | |
96 | |
97 if (model.isEmpty()) { | |
98 peer = new FlowVelocityModel(zone, description); | |
99 session.save(peer); | |
100 } | |
101 else { | |
102 peer = model.get(0); | |
103 } | |
104 } | |
105 | |
106 return peer; | |
107 } | |
108 } | |
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |