Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/SedimentYieldArtifact.java @ 7186:644b2f461272
issue1435: SedimentYieldArtifact: Add functionality.
Now the overriden state can actually access the load.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 27 Sep 2013 14:37:28 +0200 |
parents | 87c32adb7088 |
children | e6f9c831a75f |
comparison
equal
deleted
inserted
replaced
7185:963b8bd54a63 | 7186:644b2f461272 |
---|---|
21 import org.dive4elements.artifacts.Artifact; | 21 import org.dive4elements.artifacts.Artifact; |
22 import org.dive4elements.artifacts.ArtifactFactory; | 22 import org.dive4elements.artifacts.ArtifactFactory; |
23 import org.dive4elements.artifacts.CallMeta; | 23 import org.dive4elements.artifacts.CallMeta; |
24 import org.dive4elements.artifacts.common.utils.XMLUtils; | 24 import org.dive4elements.artifacts.common.utils.XMLUtils; |
25 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | 25 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
26 import org.dive4elements.river.artifacts.model.Calculation; | |
27 import org.dive4elements.river.artifacts.model.CalculationResult; | |
26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; | 28 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; |
27 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFacet; | 29 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFacet; |
28 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFactory; | 30 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFactory; |
31 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadResult; | |
29 import org.dive4elements.river.artifacts.states.StaticState; | 32 import org.dive4elements.river.artifacts.states.StaticState; |
30 | 33 |
31 import org.dive4elements.river.artifacts.model.FacetTypes; | 34 import org.dive4elements.river.artifacts.model.FacetTypes; |
32 | 35 |
33 import org.dive4elements.river.utils.Formatter; | 36 import org.dive4elements.river.utils.Formatter; |
74 public String getName() { | 77 public String getName() { |
75 return NAME; | 78 return NAME; |
76 } | 79 } |
77 | 80 |
78 | 81 |
82 private Object getSedimentLoad() { | |
83 logger.debug("SedimentYieldArtifact.getSedimentLoad"); | |
84 String id = getDataAsString(DATA_NAME); | |
85 String river = getDataAsString("river"); | |
86 | |
87 SedimentLoad myLoad = SedimentLoadFactory.getSedimentLoadWithDataUncached(id, river); | |
88 return new CalculationResult( | |
89 new SedimentLoadResult[] { | |
90 new SedimentLoadResult(1983,2042,myLoad) | |
91 }, new Calculation()); | |
92 } | |
93 | |
94 | |
79 /** Create a new state with bogus output. */ | 95 /** Create a new state with bogus output. */ |
80 protected State spawnState() { | 96 protected State spawnState() { |
81 state = new StaticState(STATIC_STATE_NAME); | 97 state = new StaticState(STATIC_STATE_NAME) { |
98 | |
99 public Object staticCompute(List<Facet> facets) { | |
100 return getSedimentLoad(); | |
101 } | |
102 }; | |
82 List<Facet> fs = getFacets(STATIC_STATE_NAME); | 103 List<Facet> fs = getFacets(STATIC_STATE_NAME); |
83 DefaultOutput output = new DefaultOutput( | 104 DefaultOutput output = new DefaultOutput( |
84 "general", | 105 "general", |
85 "general", | 106 "general", |
86 "image/png", | 107 "image/png", |
104 CallMeta callMeta, | 125 CallMeta callMeta, |
105 Document data) | 126 Document data) |
106 { | 127 { |
107 logger.debug("SedimentYieldArtifact.setup"); | 128 logger.debug("SedimentYieldArtifact.setup"); |
108 | 129 |
130 // Refactor? this happens at another place, too | |
109 // Store id, yield yields. | 131 // Store id, yield yields. |
110 state = new StaticState(STATIC_STATE_NAME); | 132 state = new StaticState(STATIC_STATE_NAME) { |
111 | 133 |
134 public Object staticCompute(List<Facet> facets) { | |
135 return getSedimentLoad(); | |
136 } | |
137 }; | |
112 if (logger.isDebugEnabled()) { | 138 if (logger.isDebugEnabled()) { |
113 logger.debug(XMLUtils.toString(data)); | 139 logger.debug(XMLUtils.toString(data)); |
114 } | 140 } |
115 | 141 |
116 List<Facet> fs = new ArrayList<Facet>(); | 142 List<Facet> fs = new ArrayList<Facet>(); |
117 String code = getDatacageIDValue(data); | 143 String code = getDatacageIDValue(data); |
118 | 144 |
119 // TODO need river, too. | 145 // TODO need river, too. |
120 // | 146 // |
121 if (code != null) { | 147 if (code != null) { |
122 // parse code, interact with factory, add real facets. | 148 String name = SedimentLoadFactory.getSedimentYieldDescription(Integer.valueOf(code)); |
123 // store relevant parts of code as data. | |
124 // TODO no fakes | |
125 String fakeRiver = "Elbe"; | |
126 SedimentLoad myLoad = SedimentLoadFactory.getSedimentLoadWithDataUncached(code, fakeRiver); | |
127 String name = myLoad.getDescription(); | |
128 | 149 |
129 Facet facet = new SedimentLoadFacet( | 150 Facet facet = new SedimentLoadFacet( |
130 0, name, | 151 0, |
131 SEDIMENT_LOAD_COARSE, | 152 SEDIMENT_LOAD_COARSE, |
153 name, | |
132 //???? | 154 //???? |
133 ComputeType.ADVANCE, state.getID(), "hash" | 155 ComputeType.ADVANCE, state.getID(), "hash" |
134 ); | 156 ); |
135 fs.add(facet); | 157 fs.add(facet); |
136 addFacets(state.getID(), fs); | 158 addFacets(state.getID(), fs); |
198 protected void initialize( | 220 protected void initialize( |
199 Artifact artifact, | 221 Artifact artifact, |
200 Object context, | 222 Object context, |
201 CallMeta meta) | 223 CallMeta meta) |
202 { | 224 { |
203 logger.debug("initialize"); | 225 logger.debug("SedimentYieldArtifact.initialize"); |
204 // TODO Copy river data! | 226 importData((D4EArtifact) artifact, "river"); |
205 } | 227 } |
206 } | 228 } |
207 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 229 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |