diff options
author | Godin <mandrikov@gmail.com> | 2010-12-13 21:55:49 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-13 21:55:49 +0000 |
commit | d104ca20751117924dc7e74a9cf13445926b0acc (patch) | |
tree | 4ddaaf560ff2c6d8adeb03d643d5e5b015846604 /sonar-ws-client/src/main/java/org/sonar/wsclient | |
parent | d52d82788c75ca8f67270b247105d3350b22f4e8 (diff) | |
download | sonarqube-d104ca20751117924dc7e74a9cf13445926b0acc.tar.gz sonarqube-d104ca20751117924dc7e74a9cf13445926b0acc.zip |
SONAR-833: New Web Service to get history of measures (time machine)
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar/wsclient')
3 files changed, 47 insertions, 36 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java index 4c68d2c3ca1..e0d669d7c2e 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java @@ -1,36 +1,42 @@ package org.sonar.wsclient.services; +import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class TimeMachineData extends Model { + private Date date; /** * We use strings here in order to support measures with string value. */ - private Map<Date, List<String>> data = new HashMap<Date, List<String>>(); + private List<String> values = new ArrayList<String>(); - public Map<Date, List<String>> getData() { - return data; + public Date getDate() { + return date; } - public TimeMachineData setData(Map<Date, List<String>> data) { - this.data = data; + public TimeMachineData setDate(Date date) { + this.date = date; return this; } - public Double getValueAsDouble(Date date, int index) { - if (data.containsKey(date)) { - String valueStr = data.get(date).get(index); - try { - return valueStr == null ? null : Double.valueOf(valueStr); - } catch (NumberFormatException e) { - return null; - } + public List<String> getValues() { + return values; + } + + public TimeMachineData setValues(List<String> values) { + this.values = values; + return this; + } + + public Double getValueAsDouble(int index) { + String valueStr = values.get(index); + try { + return valueStr == null ? null : Double.valueOf(valueStr); + } catch (NumberFormatException e) { + return null; } - return null; } } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineQuery.java index 6d4fee7fa96..04f2019d490 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineQuery.java @@ -14,6 +14,9 @@ public class TimeMachineQuery extends Query<TimeMachineData> { private Date from; private Date to; + private String model; + private String[] characteristicKeys; + public TimeMachineQuery(String resourceKeyOrId) { this.resourceKeyOrId = resourceKeyOrId; } @@ -45,6 +48,12 @@ public class TimeMachineQuery extends Query<TimeMachineData> { return this; } + public TimeMachineQuery setCharacteristicKeys(String model, String... keys) { + this.model = model; + this.characteristicKeys = keys; + return this; + } + @Override public String getUrl() { StringBuilder url = new StringBuilder(BASE_URL); @@ -53,6 +62,8 @@ public class TimeMachineQuery extends Query<TimeMachineData> { appendUrlParameter(url, "metrics", metrics); appendUrlParameter(url, "fromDateTime", from, true); appendUrlParameter(url, "toDateTime", to, true); + appendUrlParameter(url, "model", model); + appendUrlParameter(url, "characteristics", characteristicKeys); return url.toString(); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java index dab000f069c..1289e63a5ae 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java @@ -2,31 +2,25 @@ package org.sonar.wsclient.unmarshallers; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import org.json.simple.JSONValue; 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(String json) { - JSONObject map = (JSONObject) JSONValue.parse(json); - Map<Date, List<String>> data = new HashMap<Date, List<String>>(); - for (Object key : map.keySet()) { - JSONArray array = (JSONArray) map.get(key); - List<String> measures = new ArrayList<String>(); - for (int i = 0; i < array.size(); i++) { - Object elem = array.get(i); - String value = elem == null ? null : elem.toString(); - measures.add(value); - } - data.put(JsonUtils.parseDateTime((String) key), measures); + protected TimeMachineData parse(JSONObject json) { + String dateTimeStr = (String) json.keySet().iterator().next(); + JSONArray array = (JSONArray) json.get(dateTimeStr); + List<String> measures = new ArrayList<String>(); + for (int i = 0; i < array.size(); i++) { + Object elem = array.get(i); + String value = elem == null ? null : elem.toString(); + measures.add(value); } - return new TimeMachineData().setData(data); - } - - public List<TimeMachineData> toModels(String json) { - throw new UnsupportedOperationException(); + return new TimeMachineData() + .setDate(JsonUtils.parseDateTime(dateTimeStr)) + .setValues(measures); } } |