comparison flys-backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingle.java @ 5828:dfb26b03b179

Moved directories to org.dive4elements.river
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 11:53:11 +0200
parents flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java@5287440b57b3
children 18619c1e7c2a
comparison
equal deleted inserted replaced
5827:e308d4ecd35a 5828:dfb26b03b179
1 package de.intevation.flys.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 de.intevation.flys.model.BedHeightSingle;
12 import de.intevation.flys.model.BedHeightType;
13 import de.intevation.flys.model.ElevationModel;
14 import de.intevation.flys.model.Range;
15 import de.intevation.flys.model.River;
16
17
18 public class ImportBedHeightSingle implements ImportBedHeight
19 {
20 private static Logger log = Logger.getLogger(ImportBedHeightSingle.class);
21
22 protected Integer year;
23 protected int soundingWidth;
24
25 protected String evaluationBy;
26 protected String description;
27
28 protected ImportRange range;
29 protected ImportBedHeightType type;
30 protected ImportLocationSystem locationSystem;
31 protected ImportElevationModel curElevationModel;
32 protected ImportElevationModel oldElevationModel;
33
34 protected List<ImportBedHeightSingleValue> values;
35
36 protected BedHeightSingle peer;
37
38
39 public ImportBedHeightSingle(String description) {
40 this.description = description;
41 this.values = new ArrayList<ImportBedHeightSingleValue>();
42 }
43
44
45 public String getDescription() {
46 return description;
47 }
48
49 public int getValueCount() {
50 return values.size();
51 }
52
53
54 public void setYear(int year) {
55 this.year = year;
56 }
57
58 public void setTimeInterval(ImportTimeInterval timeInterval) {
59 // do nothing
60 }
61
62 public void setSoundingWidth(int soundingWidth) {
63 this.soundingWidth = soundingWidth;
64 }
65
66 public void setEvaluationBy(String evaluationBy) {
67 this.evaluationBy = evaluationBy;
68 }
69
70 public void setDescription(String description) {
71 this.description = description;
72 }
73
74 public void setRange(ImportRange range) {
75 this.range = range;
76 }
77
78 public void setType(ImportBedHeightType type) {
79 this.type = type;
80 }
81
82 public void setLocationSystem(ImportLocationSystem locationSystem) {
83 this.locationSystem = locationSystem;
84 }
85
86 public void setCurElevationModel(ImportElevationModel curElevationModel) {
87 this.curElevationModel = curElevationModel;
88 }
89
90 public void setOldElevationModel(ImportElevationModel oldElevationModel) {
91 this.oldElevationModel = oldElevationModel;
92 }
93
94 @Override
95 public void addValue(ImportBedHeightValue value) {
96 values.add((ImportBedHeightSingleValue) value);
97 }
98
99 @Override
100 public void storeDependencies(River river) {
101 log.info("Store dependencies for single: '" + getDescription() + "'");
102
103 if (type != null) {
104 type.storeDependencies();
105 }
106
107 if (locationSystem != null) {
108 locationSystem.storeDependencies();
109 }
110
111 if (curElevationModel != null) {
112 curElevationModel.storeDependencies();
113 }
114
115 if (oldElevationModel != null) {
116 oldElevationModel.storeDependencies();
117 }
118
119 BedHeightSingle peer = getPeer(river);
120
121 if (peer != null) {
122 for (ImportBedHeightSingleValue value: values) {
123 value.storeDependencies(peer);
124 }
125 }
126
127 Session session = ImporterSession.getInstance().getDatabaseSession();
128 session.flush();
129 }
130
131 @Override
132 public BedHeightSingle getPeer(River river) {
133 if (peer == null) {
134 BedHeightType theType = type != null ? type.getPeer() : null;
135 ElevationModel theCurModel = curElevationModel.getPeer();
136 Range theRange = range != null ? range.getPeer(river) : null;
137
138 if (theType == null) {
139 log.warn("BHS: No bed height type given. Skip file '" +
140 description + "'");
141 return null;
142 }
143
144 if (theCurModel == null) {
145 log.warn("BHS: No elevation model given. Skip file '" +
146 description + "'");
147 return null;
148 }
149
150 if (theRange == null) {
151 log.warn("BHS: No km-range given: '" +
152 description + "'");
153 }
154
155 Session session = ImporterSession.getInstance().getDatabaseSession();
156
157 Query query = session.createQuery(
158 "from BedHeightSingle where " +
159 "river=:river and year=:year and soundingWidth=:soundingWidth " +
160 "and type=:type and locationSystem=:locationSystem and " +
161 "curElevationModel=:curElevationModel and range=:range");
162
163 query.setParameter("river", river);
164 query.setParameter("year", year);
165 query.setParameter("soundingWidth", soundingWidth);
166 query.setParameter("type", theType);
167 query.setParameter("locationSystem", locationSystem.getPeer());
168 query.setParameter("curElevationModel", theCurModel);
169 query.setParameter("range", range.getPeer(river));
170
171 List<BedHeightSingle> bedHeights = query.list();
172 if (bedHeights.isEmpty()) {
173 log.info("Create new BedHeightSingle DB instance.");
174
175 peer = new BedHeightSingle(
176 river,
177 year,
178 soundingWidth,
179 theType,
180 locationSystem.getPeer(),
181 theCurModel,
182 oldElevationModel != null ? oldElevationModel.getPeer() : null,
183 range.getPeer(river),
184 evaluationBy,
185 description
186 );
187
188 session.save(peer);
189 }
190 else {
191 peer = bedHeights.get(0);
192 }
193 }
194
195 return peer;
196 }
197 }
198 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org