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.*;
import org.sonar.gwt.JsonUtils;
import org.sonar.wsclient.services.TimeMachineData;
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);
+ JSONValue elem = array.get(i);
+ values.add(getAsString(elem));
}
data.put(JsonUtils.parseDateTime(dateTimeStr), values);
}
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));
}
resource_id = params[:resource]
metric_keys = params[:metrics].split(',')
metrics = Metric.by_keys(metric_keys)
- first_date = parse_datetime(params[:first_date])
- last_date = parse_datetime(params[:last_date])
+ first_date = parse_datetime(params[:fromDateTime])
+ last_date = parse_datetime(params[:toDateTime])
@resource=Project.by_key(resource_id)
if @resource.nil?
measures = find_measures(metrics, snapshots)
- result = []
+ result = {}
if !measures.empty?
measures_by_sid = {}
measures.each do |measure|
metric_keys.each do |metric|
values<<values_by_key[metric]
end
- result<<{format_datetime(snapshot.created_at) => values}
+ result[format_datetime(snapshot.created_at)] = values
end
end
import java.util.Date;
+/**
+ * @since 2.5
+ */
public class TimeMachineQuery extends Query<TimeMachineData> {
public static final String BASE_URL = "/api/timemachine";
url.append('?');
appendUrlParameter(url, "resource", resourceKeyOrId);
appendUrlParameter(url, "metrics", metrics);
- appendUrlParameter(url, "first_date", from);
- appendUrlParameter(url, "last_date", to);
+ appendUrlParameter(url, "fromDateTime", from, true);
+ appendUrlParameter(url, "toDateTime", to, true);
return url.toString();
}