aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-gwt-api
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-13 21:55:49 +0000
committerGodin <mandrikov@gmail.com>2010-12-13 21:55:49 +0000
commitd104ca20751117924dc7e74a9cf13445926b0acc (patch)
tree4ddaaf560ff2c6d8adeb03d643d5e5b015846604 /sonar-gwt-api
parentd52d82788c75ca8f67270b247105d3350b22f4e8 (diff)
downloadsonarqube-d104ca20751117924dc7e74a9cf13445926b0acc.tar.gz
sonarqube-d104ca20751117924dc7e74a9cf13445926b0acc.zip
SONAR-833: New Web Service to get history of measures (time machine)
Diffstat (limited to 'sonar-gwt-api')
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java34
1 files changed, 14 insertions, 20 deletions
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java
index 68ffda4ed06..f4c1cea3f3e 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java
@@ -1,34 +1,28 @@
package org.sonar.wsclient.gwt.unmarshallers;
-import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
import org.sonar.gwt.JsonUtils;
import org.sonar.wsclient.services.TimeMachineData;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
-public class TimeMachineUnmarshaller implements Unmarshaller<TimeMachineData> {
+public class TimeMachineUnmarshaller extends AbstractUnmarshaller<TimeMachineData> {
- public TimeMachineData toModel(JavaScriptObject json) {
- JSONObject map = new JSONObject(json);
- Map<Date, List<String>> data = new HashMap<Date, List<String>>();
- for (String dateTimeStr : map.keySet()) {
- JSONArray array = map.get(dateTimeStr).isArray();
- List<String> measures = new ArrayList<String>();
- for (int i = 0; i < JsonUtils.getArraySize(array); i++) {
- // We can't use JsonUtils.getArray here, because it returns JSONObject instead of JSONValue
- JSONValue elem = array.get(i);
- measures.add(JsonUtils.getAsString(elem));
- }
- data.put(JsonUtils.parseDateTime(dateTimeStr), measures);
+ protected TimeMachineData parse(JSONObject json) {
+ String dateTimeStr = (String) json.keySet().iterator().next();
+ JSONArray array = json.get(dateTimeStr).isArray();
+ List<String> measures = new ArrayList<String>();
+ for (int i = 0; i < JsonUtils.getArraySize(array); i++) {
+ // We can't use JsonUtils.getArray here, because it returns JSONObject instead of JSONValue
+ JSONValue elem = array.get(i);
+ measures.add(JsonUtils.getAsString(elem));
}
- return new TimeMachineData().setData(data);
- }
-
- public List<TimeMachineData> toModels(JavaScriptObject json) {
- return Arrays.asList(toModel(json));
+ return new TimeMachineData()
+ .setDate(JsonUtils.parseDateTime(dateTimeStr))
+ .setValues(measures);
}
}