Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java @ 2809:f283212966e8
Finished work on MINFO bed heights (single).
flys-backend/trunk@4221 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 12 Apr 2012 10:42:46 +0000 |
parents | b57c95094b68 |
children | 8926571e47fb |
comparison
equal
deleted
inserted
replaced
2808:b57c95094b68 | 2809:f283212966e8 |
---|---|
1 package de.intevation.flys.importer; | 1 package de.intevation.flys.importer; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.List; | 4 import java.util.List; |
5 | 5 |
6 import java.sql.SQLException; | |
7 | |
6 import org.apache.log4j.Logger; | 8 import org.apache.log4j.Logger; |
7 | 9 |
10 import org.hibernate.Session; | |
11 import org.hibernate.Query; | |
12 import org.hibernate.exception.ConstraintViolationException; | |
13 | |
14 import de.intevation.flys.model.BedHeightSingle; | |
15 import de.intevation.flys.model.BedHeightType; | |
16 import de.intevation.flys.model.ElevationModel; | |
17 import de.intevation.flys.model.Range; | |
8 import de.intevation.flys.model.River; | 18 import de.intevation.flys.model.River; |
9 | 19 |
10 | 20 |
11 public class ImportBedHeightSingle | 21 public class ImportBedHeightSingle |
12 { | 22 { |
24 protected ImportElevationModel curElevationModel; | 34 protected ImportElevationModel curElevationModel; |
25 protected ImportElevationModel oldElevationModel; | 35 protected ImportElevationModel oldElevationModel; |
26 | 36 |
27 protected List<ImportBedHeightSingleValue> values; | 37 protected List<ImportBedHeightSingleValue> values; |
28 | 38 |
39 protected BedHeightSingle peer; | |
40 | |
29 | 41 |
30 public ImportBedHeightSingle(String description) { | 42 public ImportBedHeightSingle(String description) { |
31 this.description = description; | 43 this.description = description; |
32 this.values = new ArrayList<ImportBedHeightSingleValue>(); | 44 this.values = new ArrayList<ImportBedHeightSingleValue>(); |
33 } | 45 } |
34 | 46 |
35 | 47 |
36 public String getDescription() { | 48 public String getDescription() { |
37 return description; | 49 return description; |
50 } | |
51 | |
52 public List<ImportBedHeightSingleValue> getValues() { | |
53 return values; | |
38 } | 54 } |
39 | 55 |
40 | 56 |
41 public void setYear(int year) { | 57 public void setYear(int year) { |
42 this.year = year; | 58 this.year = year; |
76 | 92 |
77 public void addValue(ImportBedHeightSingleValue value) { | 93 public void addValue(ImportBedHeightSingleValue value) { |
78 values.add(value); | 94 values.add(value); |
79 } | 95 } |
80 | 96 |
81 public void storeDependencies(River river) { | 97 public void storeDependencies(River river) |
98 throws SQLException, ConstraintViolationException | |
99 { | |
82 log.info("Store dependencies for single: '" + getDescription() + "'"); | 100 log.info("Store dependencies for single: '" + getDescription() + "'"); |
83 log.error("TODO: IMPLEMENT ME!"); | 101 |
102 if (type != null) { | |
103 type.storeDependencies(); | |
104 } | |
105 | |
106 if (locationSystem != null) { | |
107 locationSystem.storeDependencies(); | |
108 } | |
109 | |
110 if (curElevationModel != null) { | |
111 curElevationModel.storeDependencies(); | |
112 } | |
113 | |
114 if (oldElevationModel != null) { | |
115 oldElevationModel.storeDependencies(); | |
116 } | |
117 | |
118 BedHeightSingle peer = getPeer(river); | |
119 | |
120 for (ImportBedHeightSingleValue value: values) { | |
121 value.storeDependencies(peer); | |
122 } | |
123 } | |
124 | |
125 public BedHeightSingle getPeer(River river) { | |
126 if (peer == null) { | |
127 BedHeightType theType = type != null ? type.getPeer() : null; | |
128 ElevationModel theCurModel = curElevationModel.getPeer(); | |
129 Range theRange = range != null ? range.getPeer(river) : null; | |
130 | |
131 if (theType == null || theCurModel == null || theRange == null) { | |
132 log.warn("Skip invalid file '" + description + "'"); | |
133 return null; | |
134 } | |
135 | |
136 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
137 | |
138 Query query = session.createQuery( | |
139 "from BedHeightSingle where " + | |
140 "river=:river and year=:year and soundingWidth=:soundingWidth " + | |
141 "and type=:type and locationSystem=:locationSystem and " + | |
142 "curElevationModel=:curElevationModel and range=:range"); | |
143 | |
144 query.setParameter("river", river); | |
145 query.setParameter("year", year); | |
146 query.setParameter("soundingWidth", soundingWidth); | |
147 query.setParameter("type", theType); | |
148 query.setParameter("locationSystem", locationSystem.getPeer()); | |
149 query.setParameter("curElevationModel", theCurModel); | |
150 query.setParameter("range", range.getPeer(river)); | |
151 | |
152 List<BedHeightSingle> bedHeights = query.list(); | |
153 if (bedHeights.isEmpty()) { | |
154 log.info("Create new BedHeightSingle DB instance."); | |
155 | |
156 peer = new BedHeightSingle( | |
157 river, | |
158 year, | |
159 soundingWidth, | |
160 theType, | |
161 locationSystem.getPeer(), | |
162 theCurModel, | |
163 oldElevationModel != null ? oldElevationModel.getPeer() : null, | |
164 range.getPeer(river), | |
165 evaluationBy, | |
166 description | |
167 ); | |
168 | |
169 session.save(peer); | |
170 } | |
171 else { | |
172 peer = bedHeights.get(0); | |
173 } | |
174 } | |
175 | |
176 return peer; | |
84 } | 177 } |
85 } | 178 } |
86 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 179 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |