diff options
author | Godin <mandrikov@gmail.com> | 2010-12-12 04:35:09 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-12 04:35:09 +0000 |
commit | 30041ec9b27951cd09b7d6b64694f2d179f7ec19 (patch) | |
tree | 5adb31484c5a6609ddaee02e6692176120ba6b0c /sonar-gwt-api | |
parent | dad95d1c68b191e04783306943c548e0908658e2 (diff) | |
download | sonarqube-30041ec9b27951cd09b7d6b64694f2d179f7ec19.tar.gz sonarqube-30041ec9b27951cd09b7d6b64694f2d179f7ec19.zip |
SONAR-833: Add time machine to sonar-ws-client and sonar-gwt-api
Diffstat (limited to 'sonar-gwt-api')
4 files changed, 50 insertions, 10 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 9682d29749c..57de5419ed5 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 @@ -50,13 +50,14 @@ public final class JsonUtils { url += "format=json&"; } if (!url.contains("callback=")) { - //IMPORTANT : the url should ended with ?callback= or &callback= for JSONP calls + // IMPORTANT : the url should ended with ?callback= or &callback= for JSONP calls url += "callback="; } makeJSONRequest(requestId++, URL.encode(url), handler); } - public static native void makeJSONRequest(int requestId, String url, JSONHandler handler) /*-{ + public static native void makeJSONRequest(int requestId, String url, JSONHandler handler) + /*-{ var callback = "callback" + requestId; // create SCRIPT tag, and set SRC attribute equal to JSON feed URL + callback function name @@ -115,12 +116,7 @@ public final class JsonUtils { public static Date getDate(JSONObject json, String field) { String date = getString(json, field); if (date != null) { - DateTimeFormat frmt = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ssZ"); - if (date.endsWith("Z") && date.length() > 2) { - // see SONAR-1182 - date = date.substring(0, date.length() - 2) + "+0000"; - } - return frmt.parse(date); + return parseDateTime(date); } return null; } @@ -177,5 +173,16 @@ public final class JsonUtils { throw new JavaScriptException("Not implemented"); } -} + /** + * @since 2.5 + */ + public static Date parseDateTime(String dateTime) { + DateTimeFormat frmt = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + if (dateTime.endsWith("Z") && dateTime.length() > 2) { + // see SONAR-1182 + dateTime = dateTime.substring(0, dateTime.length() - 2) + "+0000"; + } + return frmt.parse(dateTime); + } +} diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java index f6ad914bffc..3451bf16ed5 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java +++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java @@ -92,7 +92,7 @@ public class ResourceUnmarshaller extends AbstractUnmarshaller<Resource> { .setRuleKey(JsonUtils.getString(json, "rule_key")) .setRuleName(JsonUtils.getString(json, "rule_name")) .setRuleCategory(JsonUtils.getString(json, "rule_category")) - .setRulePriority(JsonUtils.getString(json, "rule_priority")) + .setRuleSeverity(JsonUtils.getString(json, "rule_priority")) .setCharacteristicKey(JsonUtils.getString(json, "ctic_key")) .setCharacteristicName(JsonUtils.getString(json, "ctic_name")); return measure; 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 new file mode 100644 index 00000000000..53f56ba35dc --- /dev/null +++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java @@ -0,0 +1,32 @@ +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 org.sonar.gwt.JsonUtils; +import org.sonar.wsclient.services.TimeMachineData; + +import java.util.*; + +public class TimeMachineUnmarshaller implements Unmarshaller<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> values = new ArrayList<String>(); + for (int i = 0; i < JsonUtils.getArraySize(array); i++) { + String value = array.get(i).isString().stringValue(); + values.add(value); + } + data.put(JsonUtils.parseDateTime(dateTimeStr), values); + } + return new TimeMachineData().setData(data); + } + + public List<TimeMachineData> toModels(JavaScriptObject json) { + return Arrays.asList(toModel(json)); + } + +} diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java index deb77356232..93a5dbf8110 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java +++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java @@ -41,6 +41,7 @@ public final class Unmarshallers { unmarshallers.put(Violation.class, new ViolationUnmarshaller()); unmarshallers.put(Server.class, new ServerUnmarshaller()); unmarshallers.put(DependencyTree.class, new DependencyTreeUnmarshaller()); + unmarshallers.put(TimeMachineData.class, new TimeMachineUnmarshaller()); } public static Unmarshaller forModel(Class modelClass) { |