aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb53
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java101
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java70
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java22
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java100
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java42
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java40
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java6
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java2
9 files changed, 426 insertions, 10 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb
index b79538925c1..89b78929d1b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb
@@ -33,7 +33,18 @@ class Api::PropertiesController < Api::RestController
def show
key = params[:id]
- prop = Property.by_key(key)
+ resource_id_or_key = params[:resource]
+ if resource_id_or_key
+ resource = Project.by_key(resource_id_or_key)
+ if resource
+ prop = Property.by_key(key, resource.id)
+ else
+ rest_status_ko('Resource [' + resource_id_or_key + '] does not exist', 404)
+ return
+ end
+ else
+ prop = Property.by_key(key)
+ end
if prop
if viewable?(key)
rest_render([prop])
@@ -48,9 +59,19 @@ class Api::PropertiesController < Api::RestController
def create
key = params[:id]
value = params[:value] || request.raw_post
+ resource_id_or_key = params[:resource]
+ if resource_id_or_key
+ resource = Project.by_key(resource_id_or_key)
+ if resource
+ resource_id_or_key = resource.id
+ else
+ rest_status_ko('Resource [' + resource_id_or_key + '] does not exist', 404)
+ return
+ end
+ end
if key
begin
- Property.set(key, value)
+ Property.set(key, value, resource_id_or_key)
rest_status_ok
rescue Exception => ex
rest_status_ko(ex.message, 400)
@@ -63,9 +84,19 @@ class Api::PropertiesController < Api::RestController
def update
key = params[:id]
value = params[:value] || request.raw_post
+ resource_id_or_key = params[:resource]
+ if resource_id_or_key
+ resource = Project.by_key(resource_id_or_key)
+ if resource
+ resource_id_or_key = resource.id
+ else
+ rest_status_ko('Resource [' + resource_id_or_key + '] does not exist', 404)
+ return
+ end
+ end
if key
begin
- Property.set(key, value)
+ Property.set(key, value, resource_id_or_key)
rest_status_ok
rescue Exception => ex
rest_status_ko(ex.message, 400)
@@ -77,9 +108,19 @@ class Api::PropertiesController < Api::RestController
def destroy
key = params[:id]
- if key
+ resource_id_or_key = params[:resource]
+ if resource_id_or_key
+ resource = Project.by_key(resource_id_or_key)
+ if resource
+ resource_id_or_key = resource.id
+ else
+ rest_status_ko('Resource [' + resource_id_or_key + '] does not exist', 404)
+ return
+ end
+ end
+ if key
begin
- Property.clear(key)
+ Property.clear(key, resource_id_or_key)
rest_status_ok
rescue Exception => ex
rest_status_ko(ex.message, 400)
@@ -111,4 +152,4 @@ class Api::PropertiesController < Api::RestController
!property_key.to_s.index('.secured') || is_admin?
end
-end \ No newline at end of file
+end
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java
new file mode 100644
index 00000000000..d1d2921d10c
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java
@@ -0,0 +1,101 @@
+/*
+ * 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.6
+ */
+public class PropertyCreateQuery extends CreateQuery<Property> {
+
+ private String key;
+ private String value;
+ private String resourceKeyOrId;
+
+ public PropertyCreateQuery() {
+ }
+
+ public PropertyCreateQuery(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public PropertyCreateQuery(String key, String value, String resourceKeyOrId) {
+ this.key = key;
+ this.value = value;
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public PropertyCreateQuery(Property property) {
+ this.key = property.getKey();
+ this.value = property.getValue();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyCreateQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public PropertyCreateQuery setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyCreateQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder();
+ url.append(PropertyQuery.BASE_URL);
+ url.append("/").append(key);
+ url.append('?');
+ appendUrlParameter(url, "value", value);
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.toString();
+ }
+
+ /**
+ * Property value is transmitted through request body as content may
+ * exceed URL size allowed by the server.
+ */
+ @Override
+ public String getBody() {
+ return value;
+ }
+
+ @Override
+ public Class<Property> getModelClass() {
+ return Property.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java
new file mode 100644
index 00000000000..07c6a193f10
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java
@@ -0,0 +1,70 @@
+/*
+ * 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.6
+ */
+public class PropertyDeleteQuery extends DeleteQuery<Property> {
+
+ private String key;
+ private String resourceKeyOrId;
+
+ public PropertyDeleteQuery(String key) {
+ this.key = key;
+ }
+
+ public PropertyDeleteQuery(String key, String resourceKeyOrId) {
+ this.key = key;
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public PropertyDeleteQuery(Property property) {
+ this.key = property.getKey();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyDeleteQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyDeleteQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder();
+ url.append(PropertyQuery.BASE_URL);
+ url.append("/").append(key);
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
index 1e005cac291..8fa3a95ea9d 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
@@ -23,6 +23,7 @@ public class PropertyQuery extends Query<Property> {
public static final String BASE_URL = "/api/properties";
private String key = null;
+ private String resourceKeyOrId = null;
public String getKey() {
return key;
@@ -33,13 +34,24 @@ public class PropertyQuery extends Query<Property> {
return this;
}
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
@Override
public String getUrl() {
- String url = BASE_URL;
+ StringBuilder url = new StringBuilder(BASE_URL);
if (key != null) {
- url += "/" + key;
+ url.append("/").append(key);
}
- return url + "?";
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.toString();
}
@Override
@@ -54,4 +66,8 @@ public class PropertyQuery extends Query<Property> {
public static PropertyQuery createForKey(String key) {
return new PropertyQuery().setKey(key);
}
+
+ public static PropertyQuery createForResource(String key, String resourceKeyOrId) {
+ return new PropertyQuery().setKey(key).setResourceKeyOrId(resourceKeyOrId);
+ }
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java
new file mode 100644
index 00000000000..f66583fbe9f
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java
@@ -0,0 +1,100 @@
+/*
+ * 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.6
+ */
+public class PropertyUpdateQuery extends UpdateQuery<Property> {
+
+ private String key;
+ private String value;
+ private String resourceKeyOrId;
+
+ public PropertyUpdateQuery() {
+ }
+
+ public PropertyUpdateQuery(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public PropertyUpdateQuery(String key, String value, String resourceKeyOrId) {
+ this.key = key;
+ this.value = value;
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public PropertyUpdateQuery(Property property) {
+ this.key = property.getKey();
+ this.value = property.getValue();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyUpdateQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public PropertyUpdateQuery setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyUpdateQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder();
+ url.append(PropertyQuery.BASE_URL);
+ url.append("/").append(key);
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.toString();
+ }
+
+ /**
+ * Property value is transmitted through request body as content may
+ * exceed URL size allowed by the server.
+ */
+ @Override
+ public String getBody() {
+ return value;
+ }
+
+ @Override
+ public Class<Property> getModelClass() {
+ return Property.class;
+ }
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java
new file mode 100644
index 00000000000..c465af21b5e
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class PropertyCreateQueryTest {
+
+ @Test
+ public void create() {
+ PropertyCreateQuery query = new PropertyCreateQuery("foo", "bar");
+ assertThat(query.getUrl(), is("/api/properties/foo?value=bar&"));
+ assertThat(query.getModelClass().getName(), is(Property.class.getName()));
+ }
+
+ @Test
+ public void createForResource() {
+ PropertyCreateQuery query = new PropertyCreateQuery("foo", "bar", "my:resource");
+ assertThat(query.getUrl(), is("/api/properties/foo?value=bar&resource=my:resource&"));
+ assertThat(query.getModelClass().getName(), is(Property.class.getName()));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java
new file mode 100644
index 00000000000..d55babe0831
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class PropertyDeleteQueryTest {
+
+ @Test
+ public void delete() {
+ PropertyDeleteQuery query = new PropertyDeleteQuery("foo");
+ assertThat(query.getUrl(), is("/api/properties/foo?"));
+ }
+
+ @Test
+ public void deleteResourceProp() {
+ PropertyDeleteQuery query = new PropertyDeleteQuery("foo", "my:resource");
+ assertThat(query.getUrl(), is("/api/properties/foo?resource=my:resource&"));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
index 8becf06df5a..66e6f6e3b29 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
@@ -37,4 +37,10 @@ public class PropertyQueryTest {
assertThat(PropertyQuery.createForKey("myprop").getUrl(), is("/api/properties/myprop?"));
assertThat(PropertyQuery.createForKey("myprop").getModelClass().getName(), is(Property.class.getName()));
}
+
+ @Test
+ public void byKeyAndResource() {
+ assertThat(PropertyQuery.createForResource("myprop", "my:resource").getUrl(), is("/api/properties/myprop?resource=my:resource&"));
+ assertThat(PropertyQuery.createForResource("myprop", "my:resource").getModelClass().getName(), is(Property.class.getName()));
+ }
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
index 3d4b5df474b..f29462123d6 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertThat;
public class UserPropertyDeleteQueryTest {
@Test
- public void create() {
+ public void delete() {
UserPropertyDeleteQuery query = new UserPropertyDeleteQuery("foo");
assertThat(query.getUrl(), is("/api/user_properties/foo"));
}