comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents d35f28655fa6
children e74e707ff650
comparison
equal deleted inserted replaced
2987:98c7a46ec5ae 3318:dbe2f85bf160
1 package de.intevation.flys.artifacts.states;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import org.json.JSONArray;
8 import org.json.JSONException;
9
10 import de.intevation.artifacts.CallMeta;
11 import de.intevation.artifacts.CallContext;
12
13 import de.intevation.artifactdatabase.state.Facet;
14
15 import de.intevation.flys.artifacts.FLYSArtifact;
16 import de.intevation.flys.artifacts.ManualPointsArtifact;
17
18 import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
19 import de.intevation.flys.artifacts.model.FacetTypes;
20 import de.intevation.flys.artifacts.model.ManualPointsFacet;
21
22 import de.intevation.flys.artifacts.resources.Resources;
23
24 /**
25 * The only state for an ManualPointArtifact.
26 */
27 public class ManualPointsSingleState
28 extends DefaultState
29 implements FacetTypes
30 {
31 /** Developer-centric description of facet. */
32 public static final String I18N_DESCRIPTION
33 = "facet.longitudinal_section.manualpoint";
34
35 /** Part of data key. */
36 protected static final String DOT_DATA
37 = ".data";
38
39 /** Part of data key. */
40 protected static final String DOT_LINES
41 = ".lines";
42
43 /** The logger that is used in this state. */
44 private static final Logger logger =
45 Logger.getLogger(ManualPointsSingleState.class);
46
47
48 /**
49 * Add ManualPointsFacets to list of Facets.
50 *
51 * @param artifact Ignored.
52 * @param hash Ignored.
53 * @param meta CallMeta to be used for internationalization.
54 * @param facets List to add ManualPointsFacet to.
55 *
56 * @return null.
57 */
58 public Object compute(
59 FLYSArtifact artifact,
60 String hash,
61 CallMeta meta,
62 List<Facet> facets
63 ) {
64 logger.debug("ManualPointsSingleState.compute()");
65 ManualPointsArtifact points = (ManualPointsArtifact) artifact;
66
67 // Add Facet per Diagram type if data given.
68 for (ChartType ct: ChartType.values()) {
69 // Handle points.
70 String pointData = points.getDataAsString(ct + "." + MANUALPOINTS +
71 DOT_DATA);
72 if (pointData != null && !pointData.equals("")
73 && !pointData.equals("[]")) {
74 String fName = ct + "." + MANUALPOINTS;
75 ManualPointsFacet facet = new ManualPointsFacet(
76 0,
77 fName,
78 Resources.getMsg(meta, "manualpoints", "Manual Points"));
79
80 facets.add(facet);
81 }
82 else {
83 //logger.debug("No points for " + ct);
84 }
85
86 // Handle lines.
87 String linesData = points.getDataAsString(ct + "." + MANUALPOINTS +
88 DOT_LINES);
89 if (linesData != null && !linesData.equals("")
90 && !linesData.equals("[]")) {
91 try {
92 JSONArray lines = new JSONArray((String) linesData);
93 for (int i = 0, P = lines.length(); i < P; i++) {
94 JSONArray array = lines.getJSONArray(i);
95 double y = array.getDouble(0);
96 String name = array.getString(1);
97 String fName = ct + "." + MANUALLINE;
98 logger.debug("have facet: " + y + " / " + name + " -> " + fName);
99 CrossSectionWaterLineFacet facet = new CrossSectionWaterLineFacet(
100 i,
101 fName,
102 name);
103
104 facets.add(facet);
105 }
106 }
107 catch(JSONException e){
108 logger.error("Could not decode json.");
109 }
110
111 }
112 else {
113 //logger.debug("No points for " + ct);
114 }
115 }
116
117 return null;
118 }
119
120
121 /** Call compute. */
122 @Override
123 public Object computeInit(
124 FLYSArtifact artifact,
125 String hash,
126 Object context,
127 CallMeta meta,
128 List<Facet> facets
129 ) {
130 return compute(artifact, hash, meta, facets);
131 }
132
133
134 /** Call compute. */
135 @Override
136 public Object computeFeed(
137 FLYSArtifact artifact,
138 String hash,
139 CallContext context,
140 List<Facet> facets,
141 Object old
142 ) {
143 return compute(artifact, hash, context.getMeta(), facets);
144 }
145 }
146 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org