comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityState.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/minfo/BedQualityState.java@f8217f1fef2e
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.states.minfo;
2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.List;
6
7 import org.apache.log4j.Logger;
8
9 import org.dive4elements.artifactdatabase.state.Facet;
10 import org.dive4elements.artifacts.CallContext;
11 import org.dive4elements.artifacts.CallMeta;
12 import org.dive4elements.river.artifacts.FLYSArtifact;
13 import org.dive4elements.river.artifacts.access.BedQualityAccess;
14 import org.dive4elements.river.artifacts.model.CalculationResult;
15 import org.dive4elements.river.artifacts.model.DataFacet;
16 import org.dive4elements.river.artifacts.model.DateRange;
17 import org.dive4elements.river.artifacts.model.FacetTypes;
18 import org.dive4elements.river.artifacts.model.minfo.BedDensityFacet;
19 import org.dive4elements.river.artifacts.model.minfo.BedDiameterFacet;
20 import org.dive4elements.river.artifacts.model.minfo.BedDiameterResult;
21 import org.dive4elements.river.artifacts.model.minfo.BedParametersResult;
22 import org.dive4elements.river.artifacts.model.minfo.BedPorosityFacet;
23 import org.dive4elements.river.artifacts.model.minfo.BedQualityCalculation;
24 import org.dive4elements.river.artifacts.model.minfo.BedQualityDiameterResult;
25 import org.dive4elements.river.artifacts.model.minfo.BedQualityResult;
26 import org.dive4elements.river.artifacts.model.minfo.BedloadDiameterFacet;
27 import org.dive4elements.river.artifacts.model.minfo.BedloadDiameterResult;
28 import org.dive4elements.river.artifacts.resources.Resources;
29 import org.dive4elements.river.artifacts.states.DefaultState;
30
31
32 public class BedQualityState extends DefaultState implements FacetTypes {
33
34 private static final long serialVersionUID = 1L;
35
36 private static final Logger logger = Logger
37 .getLogger(BedQualityState.class);
38
39 public static final String I18N_TOPLAYER = "bedquality.toplayer";
40 public static final String I18N_SUBLAYER = "bedquality.sublayer";
41
42 public static final String I18N_FACET_BED_POROSITY_TOPLAYER = "facet.bedquality.bed.porosity.toplayer";
43 public static final String I18N_FACET_BED_POROSITY_SUBLAYER = "facet.bedquality.bed.porosity.sublayer";
44 public static final String I18N_FACET_BED_DENSITY_TOPLAYER = "facet.bedquality.bed.density.toplayer";
45 public static final String I18N_FACET_BED_DENSITY_SUBLAYER = "facet.bedquality.bed.density.sublayer";
46 public static final String I18N_FACET_BED_DIAMETER_TOPLAYER = "facet.bedquality.bed.diameter.toplayer";
47 public static final String I18N_FACET_BED_DIAMETER_SUBLAYER = "facet.bedquality.bed.diameter.sublayer";
48 public static final String I18N_FACET_BEDLOAD_DIAMETER = "facet.bedquality.bedload.diameter";
49
50 @Override
51 public Object computeAdvance(FLYSArtifact artifact, String hash,
52 CallContext context, List<Facet> facets, Object old) {
53 logger.debug("BedQualityState.computeAdvance");
54
55 List<Facet> newFacets = new ArrayList<Facet>();
56
57 BedQualityAccess access = new BedQualityAccess(artifact, context);
58
59 CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old
60 : new BedQualityCalculation().calculate(access);
61
62 if (facets == null || res == null) {
63 return res;
64 }
65
66 BedQualityResult[] results = (BedQualityResult[]) res.getData();
67
68 if (results == null || results.length == 0) {
69 logger.warn("Calculation computed no results!");
70 return res;
71 }
72
73 generateFacets(context, newFacets, results, getID(), hash);
74 logger.debug("Created " + newFacets.size() + " new Facets.");
75
76 facets.addAll(newFacets);
77
78 return res;
79 }
80
81 protected void generateFacets(CallContext context, List<Facet> newFacets,
82 BedQualityResult[] results, String stateId, String hash) {
83 logger.debug("BedQualityState.generateFacets");
84
85 CallMeta meta = context.getMeta();
86
87 newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id));
88 for (int idx = 0; idx < results.length; idx++) {
89 BedQualityResult result = results[idx];
90 DateRange range = result.getDateRange();
91 BedDiameterResult[] bedDiameter = result.getBedResults();
92 for (int j = 0; j < bedDiameter.length; j++) {
93 newFacets.add(new BedDiameterFacet((idx << 8) + j,
94 BED_QUALITY_BED_DIAMETER_TOPLAYER,
95 createDiameterTopLayerDescription(
96 meta,
97 bedDiameter[j],
98 range),
99 ComputeType.ADVANCE, stateId, hash));
100
101 newFacets.add(new BedDiameterFacet((idx << 8) +j,
102 BED_QUALITY_BED_DIAMETER_SUBLAYER,
103 createDiameterSubLayerDescription(
104 meta,
105 bedDiameter[j],
106 range),
107 ComputeType.ADVANCE, stateId, hash));
108 }
109 BedloadDiameterResult[] bedloadDiameter = result.getBedloadResults();
110 for (int j = 0; j < bedloadDiameter.length; j++) {
111 newFacets.add(new BedloadDiameterFacet(
112 (idx << 8) + j,
113 BED_QUALITY_BEDLOAD_DIAMETER,
114 createDiameterDescription(
115 meta, bedloadDiameter[j]),
116 ComputeType.ADVANCE,
117 stateId,
118 hash));
119
120 }
121 BedParametersResult[] bedParameters = result.getParameters();
122 for (int j = 0; j < bedParameters.length; j++) {
123 newFacets.add(new BedPorosityFacet((idx << 8) + j,
124 BED_QUALITY_POROSITY_TOPLAYER,
125 createPorosityTopLayerDescription(
126 meta,
127 bedParameters[j],
128 range),
129 ComputeType.ADVANCE, stateId, hash));
130
131 newFacets.add(new BedPorosityFacet((idx << 8) + j,
132 BED_QUALITY_POROSITY_SUBLAYER,
133 createPorositySubLayerDescription(
134 meta,
135 bedParameters[j],
136 range),
137 ComputeType.ADVANCE, stateId, hash));
138
139 newFacets.add(new BedDensityFacet((idx << 8) + j,
140 BED_QUALITY_SEDIMENT_DENSITY_TOPLAYER,
141 createDensityTopLayerDescription(
142 meta,
143 bedParameters[j],
144 range),
145 ComputeType.ADVANCE, stateId, hash));
146
147 newFacets.add(new BedDensityFacet((idx << 8) + j,
148 BED_QUALITY_SEDIMENT_DENSITY_SUBLAYER,
149 createDensitySubLayerDescription(
150 meta,
151 bedParameters[j],
152 range),
153 ComputeType.ADVANCE, stateId, hash));
154 }
155 }
156 }
157
158 protected String createPorosityTopLayerDescription(CallMeta meta,
159 BedParametersResult result, DateRange range) {
160 Date from = range != null ? range.getFrom() : new Date();
161 Date to = range != null ? range.getTo() : new Date();
162
163 String toplayer = Resources.getMsg(meta, I18N_TOPLAYER, I18N_TOPLAYER);
164 return Resources.getMsg(meta, I18N_FACET_BED_POROSITY_TOPLAYER,
165 I18N_FACET_BED_POROSITY_TOPLAYER, new Object[] { from, to, toplayer });
166 }
167
168 protected String createPorositySubLayerDescription(CallMeta meta,
169 BedParametersResult result, DateRange range) {
170 Date from = range != null ? range.getFrom() : new Date();
171 Date to = range != null ? range.getTo() : new Date();
172
173 String sublayer = Resources.getMsg(meta, I18N_SUBLAYER, I18N_SUBLAYER);
174 return Resources.getMsg(meta, I18N_FACET_BED_POROSITY_SUBLAYER,
175 I18N_FACET_BED_POROSITY_SUBLAYER, new Object[] { from, to, sublayer });
176 }
177
178 protected String createDensityTopLayerDescription(CallMeta meta,
179 BedParametersResult result, DateRange range) {
180 Date from = range != null ? range.getFrom() : new Date();
181 Date to = range != null ? range.getTo() : new Date();
182
183 String toplayer = Resources.getMsg(meta, I18N_TOPLAYER, I18N_TOPLAYER);
184 return Resources.getMsg(meta, I18N_FACET_BED_DENSITY_TOPLAYER,
185 I18N_FACET_BED_DENSITY_TOPLAYER, new Object[] { from, to, toplayer });
186 }
187
188 protected String createDensitySubLayerDescription(CallMeta meta,
189 BedParametersResult result, DateRange range) {
190 Date from = range != null ? range.getFrom() : new Date();
191 Date to = range != null ? range.getTo() : new Date();
192
193 String sublayer = Resources.getMsg(meta, I18N_SUBLAYER, I18N_SUBLAYER);
194 return Resources.getMsg(meta, I18N_FACET_BED_DENSITY_SUBLAYER,
195 I18N_FACET_BED_DENSITY_SUBLAYER, new Object[] { from, to, sublayer });
196 }
197
198 protected String createDiameterTopLayerDescription(CallMeta meta,
199 BedDiameterResult result, DateRange range) {
200 Date from = range != null ? range.getFrom() : new Date();
201 Date to = range != null ? range.getTo() : new Date();
202
203 String toplayer = Resources.getMsg(meta, I18N_TOPLAYER, I18N_TOPLAYER);
204
205 return Resources.getMsg(meta, I18N_FACET_BED_DIAMETER_TOPLAYER,
206 I18N_FACET_BED_DIAMETER_TOPLAYER, new Object[] { result.getType(),
207 from, to, toplayer });
208 }
209
210 protected String createDiameterSubLayerDescription(CallMeta meta,
211 BedDiameterResult result, DateRange range) {
212 Date from = range != null ? range.getFrom() : new Date();
213 Date to = range != null ? range.getTo() : new Date();
214
215 String sublayer = Resources.getMsg(meta, I18N_SUBLAYER, I18N_SUBLAYER);
216 return Resources.getMsg(meta, I18N_FACET_BED_DIAMETER_SUBLAYER,
217 I18N_FACET_BED_DIAMETER_SUBLAYER, new Object[] { result.getType(),
218 from, to, sublayer });
219 }
220
221 protected String createDiameterDescription(CallMeta meta,
222 BedQualityDiameterResult result) {
223 return Resources.getMsg(meta, I18N_FACET_BEDLOAD_DIAMETER,
224 I18N_FACET_BEDLOAD_DIAMETER, new Object[] { result.getType() });
225 }
226 }
227 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org