import org.sonar.core.duplication.DuplicationMapper;
import org.sonar.core.duplication.DuplicationUnitDto;
import org.sonar.core.properties.PropertiesMapper;
+import org.sonar.core.properties.PropertyDto;
import org.sonar.core.purge.PurgeMapper;
import org.sonar.core.purge.PurgeVendorMapper;
import org.sonar.core.purge.PurgeableSnapshotDto;
loadAlias(conf, "Dashboard", DashboardDto.class);
loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
loadAlias(conf, "LoadedTemplate", LoadedTemplateDto.class);
+ loadAlias(conf, "Property", PropertyDto.class);
loadAlias(conf, "PurgeableSnapshot", PurgeableSnapshotDto.class);
loadAlias(conf, "Review", ReviewDto.class);
loadAlias(conf, "Resource", ResourceDto.class);
*/
package org.sonar.core.properties;
-import java.util.List;
-
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.MyBatis;
+import java.util.List;
+
public class PropertiesDao implements BatchComponent, ServerComponent {
private MyBatis mybatis;
/**
* Returns the logins of users who have flagged as favourite the resource identified by the given id.
- *
+ *
* @param resourceId the resource id
* @return the list of logins (maybe be empty - obviously)
*/
}
}
+ public List<PropertyDto> selectGlobalProperties() {
+ SqlSession session = mybatis.openSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ return mapper.selectGlobalProperties();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public List<PropertyDto> selectProjectProperties(String resourceKey) {
+ SqlSession session = mybatis.openSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ return mapper.selectProjectProperties(resourceKey);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
}
public interface PropertiesMapper {
List<String> findUserIdsForFavouriteResource(@Param("resource_id") Integer resourceId);
+ List<PropertyDto> selectGlobalProperties();
+ List<PropertyDto> selectProjectProperties(String resourceKey);
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * 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.core.properties;
+
+public final class PropertyDto {
+ private Integer id;
+ private String key;
+ private String value;
+ private Integer resourceId;
+ private Integer userId;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public PropertyDto setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyDto setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public PropertyDto setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ public Integer getResourceId() {
+ return resourceId;
+ }
+
+ public PropertyDto setResourceId(Integer resourceId) {
+ this.resourceId = resourceId;
+ return this;
+ }
+
+ public Integer getUserId() {
+ return userId;
+ }
+
+ public PropertyDto setUserId(Integer userId) {
+ this.userId = userId;
+ return this;
+ }
+}
WHERE P.prop_key = 'favourite' AND P.resource_id = #{resource_id} AND P.user_id = U.id
</select>
+ <select id="selectGlobalProperties" resultType="Property">
+ select p.id as id, p.prop_key as "key", p.text_value as value, p.resource_id as resourceId, p.user_id as userId
+ from properties p
+ where p.resource_id is null and p.user_id is null
+ </select>
+
+ <select id="selectProjectProperties" parameterType="String" resultType="Property">
+ select p.id as id, p.prop_key as "key", p.text_value as value, p.resource_id as resourceId, p.user_id as userId
+ from properties p, projects r
+ where p.resource_id=r.id and p.user_id is null and r.kee=#{id}
+ </select>
+
</mapper>
*/
package org.sonar.core.properties;
-import static org.hamcrest.Matchers.hasItems;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.core.persistence.DaoTestCase;
+import java.util.List;
+
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
public class PropertiesDaoTest extends DaoTestCase {
private PropertiesDao dao;
assertThat(userIds.size(), is(2));
assertThat(userIds, hasItems("user3", "user4"));
}
+
+ @Test
+ public void selectGlobalProperties() throws Exception {
+ setupData("selectGlobalProperties");
+ List<PropertyDto> properties = dao.selectGlobalProperties();
+ assertThat(properties.size(), is(2));
+
+ PropertyDto first = findById(properties, 1);
+ assertThat(first.getKey(), is("global.one"));
+ assertThat(first.getValue(), is("one"));
+
+ PropertyDto second = findById(properties, 2);
+ assertThat(second.getKey(), is("global.two"));
+ assertThat(second.getValue(), is("two"));
+ }
+
+ @Test
+ public void selectProjectProperties() throws Exception {
+ setupData("selectProjectProperties");
+ List<PropertyDto> properties = dao.selectProjectProperties("org.struts:struts");
+ assertThat(properties.size(), is(1));
+
+ PropertyDto first = properties.get(0);
+ assertThat(first.getKey(), is("struts.one"));
+ assertThat(first.getValue(), is("one"));
+ }
+
+ private PropertyDto findById(List<PropertyDto> properties, int id) {
+ for (PropertyDto property : properties) {
+ if (property.getId() == id) {
+ return property;
+ }
+ }
+ return null;
+ }
}
--- /dev/null
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.one" text_value="one" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="global.two" text_value="two" resource_id="[null]" user_id="[null]"/>
+
+ <!-- project -->
+ <properties id="3" prop_key="project.one" text_value="one" resource_id="10" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="4" prop_key="user.one" text_value="one" resource_id="[null]" user_id="100"/>
+ <properties id="5" prop_key="user.two" text_value="two" resource_id="10" user_id="100"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.one" text_value="one" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="global.two" text_value="two" resource_id="[null]" user_id="[null]"/>
+
+ <!-- struts -->
+ <properties id="3" prop_key="struts.one" text_value="one" resource_id="10" user_id="[null]"/>
+
+ <!-- struts -->
+ <properties id="4" prop_key="commonslang.one" text_value="one" resource_id="11" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="5" prop_key="user.one" text_value="one" resource_id="[null]" user_id="100"/>
+ <properties id="6" prop_key="user.two" text_value="two" resource_id="10" user_id="100"/>
+
+ <projects id="10" kee="org.struts:struts"/>
+ <projects id="11" kee="org.apache:commons-lang"/>
+</dataset>