aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-20 21:46:50 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-20 21:46:50 +0000
commitea3eb66a50e49b349174b1c03e9567e79f8c6596 (patch)
tree2a3391e47d5b39140f23e6be60561cdd0d0c854b /sonar-ws-client/src/main/java/org/sonar
parentd3bac1b2a70bd187247e6c44ba35f09e1a5a44c6 (diff)
downloadsonarqube-ea3eb66a50e49b349174b1c03e9567e79f8c6596.tar.gz
sonarqube-ea3eb66a50e49b349174b1c03e9567e79f8c6596.zip
SONAR-833 time machine WS : improve SQL requests + better support of Q model characteristics
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachine.java58
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineCell.java (renamed from sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java)36
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineColumn.java54
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineQuery.java14
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java19
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java67
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java2
7 files changed, 198 insertions, 52 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachine.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachine.java
new file mode 100644
index 00000000000..fc859009ea0
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachine.java
@@ -0,0 +1,58 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * Past values of a given resource
+ *
+ * @since 2.5
+ */
+public class TimeMachine extends Model {
+
+ private TimeMachineColumn[] columns;
+ private TimeMachineCell[] cells;
+
+ public TimeMachine(TimeMachineColumn[] columns, TimeMachineCell[] cells) {
+ this.columns = columns;
+ this.cells = cells;
+ }
+
+ public TimeMachineColumn[] getColumns() {
+ return columns;
+ }
+
+ public TimeMachineCell[] getCells() {
+ return cells;
+ }
+
+ public TimeMachineColumn getColumn(String metricKey) {
+ for (TimeMachineColumn column : columns) {
+ if (metricKey.equals(column.getMetricKey()) && column.getCharacteristicKey()==null) {
+ return column;
+ }
+ }
+ return null;
+ }
+
+ public int getColumnIndex(String metricKey) {
+ TimeMachineColumn col = getColumn(metricKey);
+ return col!=null ? col.getIndex() : -1;
+ }
+}
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/TimeMachineCell.java
index 23d3bfc48c9..3f3beb188cf 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/TimeMachineCell.java
@@ -19,46 +19,26 @@
*/
package org.sonar.wsclient.services;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.List;
/**
* @since 2.5
*/
-public class TimeMachineData extends Model {
+public class TimeMachineCell {
+
private Date date;
+ public Object[] values;
- /**
- * We use strings here in order to support measures with string value.
- */
- private List<String> values = new ArrayList<String>();
+ public TimeMachineCell(Date date, Object[] values) {
+ this.date = date;
+ this.values = values;
+ }
public Date getDate() {
return date;
}
- public TimeMachineData setDate(Date date) {
- this.date = date;
- return this;
- }
-
- public List<String> getValues() {
+ public Object[] 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;
- }
- }
-
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineColumn.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineColumn.java
new file mode 100644
index 00000000000..1d9bd009e36
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineColumn.java
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.5
+ */
+public class TimeMachineColumn {
+
+ private int index;
+ private String metricKey;
+ private String modelName;
+ private String characteristicKey;
+
+ public TimeMachineColumn(int index, String metricKey, String modelName, String characteristicKey) {
+ this.index = index;
+ this.metricKey = metricKey;
+ this.modelName = modelName;
+ this.characteristicKey = characteristicKey;
+ }
+
+ public String getMetricKey() {
+ return metricKey;
+ }
+
+ public String getModelName() {
+ return modelName;
+ }
+
+ public String getCharacteristicKey() {
+ return characteristicKey;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+}
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 285f977715a..04fa7c4ea8f 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
@@ -24,7 +24,7 @@ import java.util.Date;
/**
* @since 2.5
*/
-public class TimeMachineQuery extends Query<TimeMachineData> {
+public class TimeMachineQuery extends Query<TimeMachine> {
public static final String BASE_URL = "/api/timemachine";
@@ -87,18 +87,16 @@ public class TimeMachineQuery extends Query<TimeMachineData> {
}
@Override
- public Class<TimeMachineData> getModelClass() {
- return TimeMachineData.class;
+ public Class<TimeMachine> getModelClass() {
+ return TimeMachine.class;
}
public static TimeMachineQuery createForMetrics(String resourceKeyOrId, String... metricKeys) {
- return new TimeMachineQuery(resourceKeyOrId)
- .setMetrics(metricKeys);
+ return new TimeMachineQuery(resourceKeyOrId).setMetrics(metricKeys);
}
- public static TimeMachineQuery createForResource(Resource resource, String... metricKeys) {
- return new TimeMachineQuery(resource.getId().toString())
- .setMetrics(metricKeys);
+ public static TimeMachineQuery createForMetrics(Resource resource, String... metricKeys) {
+ return new TimeMachineQuery(resource.getId().toString()).setMetrics(metricKeys);
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java
index 61e5940cb0f..ab4cd8d1028 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java
@@ -1,3 +1,22 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
package org.sonar.wsclient.services;
import java.util.Date;
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 1289e63a5ae..72203450dfc 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
@@ -1,26 +1,63 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
package org.sonar.wsclient.unmarshallers;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
-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 = JsonUtils.getArray(json, "cols");
+ JSONArray cells = JsonUtils.getArray(json, "cells");
+ 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 < size; index++) {
+ JSONObject colJson = (JSONObject)cols.get(index);
+ result[index]=new TimeMachineColumn(index, JsonUtils.getString(colJson, "metric"), null, null);
+ }
+ return result;
+ }
+
+ private TimeMachineCell[] toCells(JSONArray cells) {
+ int size = cells.size();
+ TimeMachineCell[] result = new TimeMachineCell[size];
+ for (int i = 0; i < size; i++) {
+ JSONObject cellJson = (JSONObject)cells.get(i);
+ JSONArray valuesJson = JsonUtils.getArray(cellJson, "v");
- 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);
+ Object[] resultValues = new Object[valuesJson.size()];
+ for (int indexValue = 0; indexValue < valuesJson.size(); indexValue++) {
+ Object value = valuesJson.get(indexValue);
+ resultValues[indexValue]=value;
+ }
+ result[i]=new TimeMachineCell(JsonUtils.getDateTime(cellJson, "d"), resultValues);
}
- return new TimeMachineData()
- .setDate(JsonUtils.parseDateTime(dateTimeStr))
- .setValues(measures);
+ return result;
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
index 9f16130116b..ece84d4e2b3 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
@@ -44,7 +44,7 @@ public final class Unmarshallers {
unmarshallers.put(Favourite.class, new FavouriteUnmarshaller());
unmarshallers.put(Plugin.class, new PluginUnmarshaller());
unmarshallers.put(Rule.class, new RuleUnmarshaller());
- unmarshallers.put(TimeMachineData.class, new TimeMachineUnmarshaller());
+ unmarshallers.put(TimeMachine.class, new TimeMachineUnmarshaller());
}
public static <MODEL extends Model> Unmarshaller<MODEL> forModel(Class<MODEL> modelClass) {