diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-20 21:46:50 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-20 21:46:50 +0000 |
commit | ea3eb66a50e49b349174b1c03e9567e79f8c6596 (patch) | |
tree | 2a3391e47d5b39140f23e6be60561cdd0d0c854b /sonar-gwt-api | |
parent | d3bac1b2a70bd187247e6c44ba35f09e1a5a44c6 (diff) | |
download | sonarqube-ea3eb66a50e49b349174b1c03e9567e79f8c6596.tar.gz sonarqube-ea3eb66a50e49b349174b1c03e9567e79f8c6596.zip |
SONAR-833 time machine WS : improve SQL requests + better support of Q model characteristics
Diffstat (limited to 'sonar-gwt-api')
2 files changed, 33 insertions, 17 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 f4c1cea3f3e..1fddae26e76 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 @@ -2,27 +2,43 @@ package org.sonar.wsclient.gwt.unmarshallers; 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 org.sonar.wsclient.services.TimeMachine; +import org.sonar.wsclient.services.TimeMachineCell; +import org.sonar.wsclient.services.TimeMachineColumn; -import java.util.ArrayList; -import java.util.List; +public class TimeMachineUnmarshaller extends AbstractUnmarshaller<TimeMachine> { -public class TimeMachineUnmarshaller extends AbstractUnmarshaller<TimeMachineData> { + protected TimeMachine parse(JSONObject json) { + JSONArray cols = json.get("cols").isArray(); + JSONArray cells = json.get("cells").isArray(); + return new TimeMachine(toColumns(cols), toCells(cells)); + } + + private TimeMachineColumn[] toColumns(JSONArray cols) { + int size = cols.size(); + TimeMachineColumn[] result = new TimeMachineColumn[size]; + for (int index = 0; index < JsonUtils.getArraySize(cols); index++) { + JSONObject elem = JsonUtils.getArray(cols, index); + result[index] = new TimeMachineColumn(index, JsonUtils.getString(elem, "metric"), null, null); + } + return result; + } - 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)); + private TimeMachineCell[] toCells(JSONArray cells) { + int size = JsonUtils.getArraySize(cells); + TimeMachineCell[] result = new TimeMachineCell[size]; + for (int i = 0; i < size; i++) { + JSONObject cellJson = JsonUtils.getArray(cells, i); + JSONArray valuesJson = cellJson.get("v").isArray(); + Object[] resultValues = new Object[valuesJson.size()]; + for (int indexValue = 0; indexValue < JsonUtils.getArraySize(valuesJson); indexValue++) { + Object value = valuesJson.get(indexValue); + resultValues[indexValue] = value; + } + result[i] = new TimeMachineCell(JsonUtils.getDate(cellJson, "d"), resultValues); } - return new TimeMachineData() - .setDate(JsonUtils.parseDateTime(dateTimeStr)) - .setValues(measures); + return result; } } 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 637af109357..d28a90ccee8 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 @@ -46,7 +46,7 @@ public final class Unmarshallers { // FavouriteUnmarshaller // PluginUnmarshaller // RuleUnmarshaller - unmarshallers.put(TimeMachineData.class, new TimeMachineUnmarshaller()); + unmarshallers.put(TimeMachine.class, new TimeMachineUnmarshaller()); } public static Unmarshaller forModel(Class modelClass) { |