comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java @ 2810:04eeb45df27b

Implemented model classes and importer classes for bed height epochs. flys-backend/trunk@4222 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 12 Apr 2012 12:50:49 +0000
parents 33f40b23edd8
children 8926571e47fb
comparison
equal deleted inserted replaced
2809:f283212966e8 2810:04eeb45df27b
1 package de.intevation.flys.importer; 1 package de.intevation.flys.importer;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import java.sql.SQLException;
2 7
3 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
4 9
10 import org.hibernate.Session;
11 import org.hibernate.Query;
12 import org.hibernate.exception.ConstraintViolationException;
13
14 import de.intevation.flys.model.BedHeightEpoch;
15 import de.intevation.flys.model.ElevationModel;
16 import de.intevation.flys.model.Range;
5 import de.intevation.flys.model.River; 17 import de.intevation.flys.model.River;
18 import de.intevation.flys.model.TimeInterval;
6 19
7 20
8 public class ImportBedHeightEpoch 21 public class ImportBedHeightEpoch
9 { 22 {
10 private static Logger log = Logger.getLogger(ImportBedHeightEpoch.class); 23 private static Logger log = Logger.getLogger(ImportBedHeightEpoch.class);
11 24
25 protected String evaluationBy;
12 protected String description; 26 protected String description;
27
28 protected ImportTimeInterval timeInterval;
29 protected ImportRange range;
30 protected ImportElevationModel curElevationModel;
31 protected ImportElevationModel oldElevationModel;
32
33 protected List<ImportBedHeightEpochValue> values;
34
35 protected BedHeightEpoch peer;
13 36
14 37
15 public ImportBedHeightEpoch(String description) { 38 public ImportBedHeightEpoch(String description) {
16 this.description = description; 39 this.description = description;
40 this.values = new ArrayList<ImportBedHeightEpochValue>();
17 } 41 }
18 42
19 43
20 public String getDescription() { 44 public String getDescription() {
21 return description; 45 return description;
22 } 46 }
23 47
24 48
25 public void storeDependencies(River river) { 49 public List<ImportBedHeightEpochValue> getValues() {
50 return values;
51 }
52
53
54 public void setEvaluationBy(String evaluationBy) {
55 this.evaluationBy = evaluationBy;
56 }
57
58 public void setDescription(String description) {
59 this.description = description;
60 }
61
62 public void setRange(ImportRange range) {
63 this.range = range;
64 }
65
66 public void setCurElevationModel(ImportElevationModel curElevationModel) {
67 this.curElevationModel = curElevationModel;
68 }
69
70 public void setOldElevationModel(ImportElevationModel oldElevationModel) {
71 this.oldElevationModel = oldElevationModel;
72 }
73
74 public void addValue(ImportBedHeightEpochValue value) {
75 values.add(value);
76 }
77
78
79 public void storeDependencies(River river)
80 throws SQLException, ConstraintViolationException
81 {
26 log.info("Store dependencies for epoch: '" + getDescription() + "'"); 82 log.info("Store dependencies for epoch: '" + getDescription() + "'");
27 log.error("TODO: IMPLEMENT ME!"); 83
84 if (curElevationModel != null) {
85 curElevationModel.storeDependencies();
86 }
87
88 if (oldElevationModel != null) {
89 oldElevationModel.storeDependencies();
90 }
91
92 BedHeightEpoch peer = getPeer(river);
93
94 log.debug("store values now...");
95
96 for (ImportBedHeightEpochValue value: values) {
97 value.storeDependencies(peer);
98 }
99 }
100
101
102 public BedHeightEpoch getPeer(River river) {
103 if (peer == null) {
104 ElevationModel theCurModel = curElevationModel != null
105 ? curElevationModel.getPeer()
106 : null;
107
108 TimeInterval theTime = timeInterval != null
109 ? timeInterval.getPeer()
110 : null;
111
112 Range theRange = range != null ? range.getPeer(river) : null;
113
114 if (theCurModel == null || theRange == null || theTime == null) {
115 log.warn("Skip invalid file '" + description + "'");
116 return null;
117 }
118
119 Session session = ImporterSession.getInstance().getDatabaseSession();
120
121 Query query = session.createQuery(
122 "from BedHeightEpoch where " +
123 " river=:river and " +
124 " timeInterval=:timeInterval and " +
125 " curElevationModel=:curElevationModel and " +
126 " range=:range and " +
127 " evaluationBy=: evaluationBy and " +
128 " description=:description");
129
130 query.setParameter("river", river);
131 query.setParameter("timeInterval", theTime);
132 query.setParameter("curElevationModel", theCurModel);
133 query.setParameter("range", theRange);
134 query.setParameter("evaluationBy", evaluationBy);
135 query.setParameter("description", description);
136
137 List<BedHeightEpoch> bedHeights = query.list();
138
139 if (bedHeights.isEmpty()) {
140 log.info("Create new BedHeightEpoch DB instance.");
141
142 peer = new BedHeightEpoch(
143 river,
144 theTime,
145 theRange,
146 theCurModel,
147 oldElevationModel != null ? oldElevationModel.getPeer() : null,
148 evaluationBy,
149 description
150 );
151 }
152 else {
153 peer = bedHeights.get(0);
154 }
155 }
156
157 return peer;
28 } 158 }
29 } 159 }
30 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 160 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org