aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-gwt-api
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-13 12:40:25 +0000
committerGodin <mandrikov@gmail.com>2010-12-13 12:40:25 +0000
commit12b66215dca176a1ed3136abbbe24fb49f8b5cc9 (patch)
treeb509b118856b885d2c72a3be84c6c90124044723 /sonar-gwt-api
parent44a8c358c81415c9ed69ca676619bc04f56c853b (diff)
downloadsonarqube-12b66215dca176a1ed3136abbbe24fb49f8b5cc9.tar.gz
sonarqube-12b66215dca176a1ed3136abbbe24fb49f8b5cc9.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/gwt/JsonUtils.java23
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java24
2 files changed, 20 insertions, 27 deletions
diff --git a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java
index 57de5419ed5..b473cc37028 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java
@@ -101,16 +101,7 @@ public final class JsonUtils {
}
public static String getString(JSONObject json, String field) {
- JSONValue jsonValue;
- JSONString jsonString;
- if ((jsonValue = json.get(field)) == null) {
- return null;
- }
- if ((jsonString = jsonValue.isString()) == null) {
- JSONNumber jsonNumber = jsonValue.isNumber();
- return jsonNumber != null ? jsonNumber.toString() : null;
- }
- return jsonString.stringValue();
+ return getAsString(json.get(field));
}
public static Date getDate(JSONObject json, String field) {
@@ -173,6 +164,18 @@ public final class JsonUtils {
throw new JavaScriptException("Not implemented");
}
+ public static String getAsString(JSONValue jsonValue) {
+ if (jsonValue == null) {
+ return null;
+ }
+ JSONString jsonString;
+ if ((jsonString = jsonValue.isString()) == null) {
+ JSONNumber jsonNumber = jsonValue.isNumber();
+ return jsonNumber != null ? jsonNumber.toString() : null;
+ }
+ return jsonString.stringValue();
+ }
+
/**
* @since 2.5
*/
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 d28438fb160..008e53b98f0 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,7 +1,9 @@
package org.sonar.wsclient.gwt.unmarshallers;
import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.*;
+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;
@@ -14,28 +16,16 @@ public class TimeMachineUnmarshaller implements Unmarshaller<TimeMachineData> {
Map<Date, List<String>> data = new HashMap<Date, List<String>>();
for (String dateTimeStr : map.keySet()) {
JSONArray array = map.get(dateTimeStr).isArray();
- List<String> values = new ArrayList<String>();
+ List<String> measures = new ArrayList<String>();
for (int i = 0; i < JsonUtils.getArraySize(array); i++) {
- JSONValue elem = array.get(i);
- values.add(getAsString(elem));
+ JSONValue elem = JsonUtils.getArray(array, i);
+ measures.add(JsonUtils.getAsString(elem));
}
- data.put(JsonUtils.parseDateTime(dateTimeStr), values);
+ data.put(JsonUtils.parseDateTime(dateTimeStr), measures);
}
return new TimeMachineData().setData(data);
}
- public String getAsString(JSONValue jsonValue) {
- if (jsonValue == null) {
- return null;
- }
- JSONString jsonString;
- if ((jsonString = jsonValue.isString()) == null) {
- JSONNumber jsonNumber = jsonValue.isNumber();
- return jsonNumber != null ? jsonNumber.toString() : null;
- }
- return jsonString.stringValue();
- }
-
public List<TimeMachineData> toModels(JavaScriptObject json) {
return Arrays.asList(toModel(json));
}