Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java @ 8133:45b1d71110c3
Correctly handle not creating facets and error reports.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 25 Aug 2014 20:01:44 +0200 |
parents | 353f93d5d9f7 |
children | c200b76145ce |
comparison
equal
deleted
inserted
replaced
8132:58e3fed51e9e | 8133:45b1d71110c3 |
---|---|
136 @Override | 136 @Override |
137 public Object computeAdvance(D4EArtifact artifact, String hash, | 137 public Object computeAdvance(D4EArtifact artifact, String hash, |
138 CallContext context, List<Facet> facets, Object old) { | 138 CallContext context, List<Facet> facets, Object old) { |
139 logger.debug("SedimentLoadDataCalculate.computeAdvance"); | 139 logger.debug("SedimentLoadDataCalculate.computeAdvance"); |
140 | 140 |
141 List<Facet> newFacets = new ArrayList<Facet>(); | |
142 | |
143 SedimentLoadAccess access = new SedimentLoadAccess(artifact); | 141 SedimentLoadAccess access = new SedimentLoadAccess(artifact); |
144 | 142 |
145 CalculationResult res = old instanceof CalculationResult | 143 CalculationResult res = old instanceof CalculationResult |
146 ? (CalculationResult) old | 144 ? (CalculationResult) old |
147 : new SedimentLoadDataCalculation().calculate(access); | 145 : new SedimentLoadDataCalculation().calculate(access); |
149 | 147 |
150 if (res == null) { | 148 if (res == null) { |
151 logger.error ("No calculation result."); | 149 logger.error ("No calculation result."); |
152 } | 150 } |
153 | 151 |
152 if (facets == null) { | |
153 /* No need to create facets as they already exist in this case. */ | |
154 return res; | |
155 } | |
156 | |
157 Calculation report = res.getReport(); | |
158 | |
159 if (report != null && report.hasProblems()) { | |
160 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); | |
161 logger.warn ("Problems : " + report.problemsToString()); | |
162 } | |
163 | |
154 Object raw = res.getData(); | 164 Object raw = res.getData(); |
155 if (raw == null) { | 165 if (raw == null) { |
156 logger.warn("No result data."); | 166 logger.warn("No result data."); |
157 Calculation report = res.getReport(); | |
158 if (report != null) { | |
159 logger.warn ("Problems : " + report.problemsToString()); | |
160 } | |
161 return res; | 167 return res; |
162 } | 168 } |
163 | 169 |
164 SedimentLoadDataResult sdRes; | 170 SedimentLoadDataResult sdRes; |
165 if (raw instanceof SedimentLoadDataResult) { | 171 if (raw instanceof SedimentLoadDataResult) { |
166 sdRes = (SedimentLoadDataResult) raw; | 172 sdRes = (SedimentLoadDataResult) raw; |
167 } else { | 173 } else { |
168 logger.error ("Unknown result"); | 174 logger.error ("Unknown result"); |
169 return null; | 175 return null; |
170 } | 176 } |
177 String unit = access.getUnit().replace("_per_","/"); | |
171 | 178 |
172 int i = 0; | 179 int i = 0; |
173 for (Fraction fract: sdRes.getFractions()) { | 180 for (Fraction fract: sdRes.getFractions()) { |
174 logger.debug("Adding facet for fraction: " + fract.getName()); | 181 logger.debug("Adding facet for fraction: " + fract.getName()); |
175 newFacets.add(new SedimentLoadDataFacet(i++, fract.getName(), | 182 facets.add(new SedimentLoadDataFacet(i++, fract.getName(), |
176 fract.getUnit(), ComputeType.ADVANCE, id, hash, context)); | 183 unit, ComputeType.ADVANCE, id, hash, context)); |
177 } | 184 } |
178 | 185 |
179 newFacets.add( | 186 facets.add( |
180 new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | 187 new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); |
181 | |
182 if (facets != null) { | |
183 facets.addAll(newFacets); | |
184 } else { | |
185 facets = newFacets; | |
186 } | |
187 | 188 |
188 /* XXX: THIS IS ALL BROKEN | 189 /* XXX: THIS IS ALL BROKEN |
189 | 190 |
190 SedimentLoadResult[] results = (SedimentLoadResult[]) res.getData(); | 191 SedimentLoadResult[] results = (SedimentLoadResult[]) res.getData(); |
191 | 192 |