package org.sonar.core.issue;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.StringUtils;
+
import javax.annotation.CheckForNull;
import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
public class DefaultIssueFilter {
return this;
}
+ public Map<String, Object> dataAsMap(){
+ return dataAsMap(data);
+ }
+
+ @VisibleForTesting
+ Map<String, Object> dataAsMap(String data) {
+ Map<String, Object> map = newHashMap();
+
+ Iterable<String> keyValues = Splitter.on(DefaultIssueFilter.SEPARATOR).split(data);
+ for (String keyValue : keyValues) {
+ String[] keyValueSplit = StringUtils.split(keyValue, DefaultIssueFilter.KEY_VALUE_SEPARATOR);
+ if (keyValueSplit.length != 2) {
+ throw new IllegalArgumentException("Key value should be separate by a '"+ DefaultIssueFilter.KEY_VALUE_SEPARATOR + "'");
+ }
+ String key = keyValueSplit[0];
+ String value = keyValueSplit[1];
+ String[] listValues = StringUtils.split(value, DefaultIssueFilter.LIST_SEPARATOR);
+ if (listValues.length > 1) {
+ map.put(key, newArrayList(listValues));
+ } else {
+ map.put(key, value);
+ }
+ }
+ return map;
+ }
+
+ @VisibleForTesting
+ String mapAsdata(Map<String, Object> map) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ for (Map.Entry<String, Object> entries : map.entrySet()){
+ String key = entries.getKey();
+ Object value = entries.getValue();
+
+ stringBuilder.append(key);
+ stringBuilder.append(DefaultIssueFilter.KEY_VALUE_SEPARATOR);
+
+ List valuesList = newArrayList();
+ if (value instanceof List) {
+ // assume that it contains only strings
+ valuesList = (List) value;
+ } else if (value instanceof CharSequence) {
+ valuesList = Lists.newArrayList(Splitter.on(',').omitEmptyStrings().split((CharSequence) value));
+ } else {
+ stringBuilder.append(value);
+ }
+ for (Iterator<Object> valueListIter = valuesList.iterator(); valueListIter.hasNext();) {
+ Object valueList = valueListIter.next();
+ stringBuilder.append(valueList);
+ if (valueListIter.hasNext()) {
+ stringBuilder.append(DefaultIssueFilter.LIST_SEPARATOR);
+ }
+ }
+ stringBuilder.append(DefaultIssueFilter.SEPARATOR);
+ }
+
+ if (stringBuilder.length() > 0) {
+ // Delete useless last separator character
+ stringBuilder.deleteCharAt(stringBuilder.length() - 1);
+ }
+
+ return stringBuilder.toString();
+ }
+
}
private Long id;
private String name;
- private String user;
+ private String userLogin;
private Boolean shared;
private String description;
private String data;
return this;
}
- public String getUser() {
- return user;
+ public String getUserLogin() {
+ return userLogin;
}
- public IssueFilterDto setUser(@Nullable String user) {
- this.user = user;
+ public IssueFilterDto setUserLogin(@Nullable String userLogin) {
+ this.userLogin = userLogin;
return this;
}
return new DefaultIssueFilter()
.setId(id)
.setName(name)
- .setUser(user)
+ .setUser(userLogin)
.setDescription(description)
.setShared(shared)
.setData(data)
return new IssueFilterDto()
.setId(issueFilter.id())
.setName(issueFilter.name())
- .setUser(issueFilter.user())
+ .setUserLogin(issueFilter.user())
.setDescription(issueFilter.description())
.setShared(issueFilter.shared())
.setData(issueFilter.data())
<sql id="issueFilterColumns">
if.id,
if.name as name,
- if.user as user,
+ if.user_login as userLogin,
if.shared as shared,
if.description as description,
if.data as data,
<select id="selectByUser" parameterType="String" resultType="IssueFilter">
select <include refid="issueFilterColumns"/>
- from issue_filters if WHERE user=#{user}
+ from issue_filters if WHERE user_login=#{user}
</select>
<insert id="insert" parameterType="IssueFilter" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO issue_filters (name, user, shared, description, data, created_at, updated_at)
- VALUES (#{name}, #{user}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
+ INSERT INTO issue_filters (name, user_login, shared, description, data, created_at, updated_at)
+ VALUES (#{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
</insert>
<!-- Oracle -->
<selectKey order="BEFORE" resultType="Long" keyProperty="id">
select issue_filters_seq.NEXTVAL from DUAL
</selectKey>
- INSERT INTO issue_filters (id, name, user, shared, description, data, created_at, updated_at)
- VALUES (#{id}, #{name}, #{user}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
+ INSERT INTO issue_filters (id, name, user_login, shared, description, data, created_at, updated_at)
+ VALUES (#{id}, #{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
</insert>
<update id="update" parameterType="IssueFilter">
update issue_filters set
name=#{name},
- user=#{user},
+ user_login=#{userLogin},
shared=#{shared},
description=#{description},
data=#{data},
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"NAME" VARCHAR(100) NOT NULL,
"SHARED" BOOLEAN NOT NULL DEFAULT FALSE,
- "USER" VARCHAR(40),
+ "USER_LOGIN" VARCHAR(40),
"DESCRIPTION" VARCHAR(4000),
"DATA" CLOB(2147483647),
"CREATED_AT" TIMESTAMP,
CREATE TABLE "ISSUE_FILTER_FAVOURITES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
- "USER" VARCHAR(40) NOT NULL,
+ "USER_LOGIN" VARCHAR(40) NOT NULL,
"ISSUE_FILTER_ID" INTEGER NOT NULL,
"CREATED_AT" TIMESTAMP
);
CREATE INDEX "ISSUE_FILTERS_NAME" ON "ISSUE_FILTERS" ("NAME");
-CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER");
+CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER_LOGIN");
CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN");
IssueFilterDto filterDto = new IssueFilterDto();
filterDto.setName("Sonar Open issues");
- filterDto.setUser("michael");
+ filterDto.setUserLogin("michael");
filterDto.setShared(true);
filterDto.setDescription("All open issues on Sonar");
filterDto.setData("statuses=OPEN|componentRoots=org.codehaus.sonar");
IssueFilterDto filterDto = new IssueFilterDto();
filterDto.setId(2L);
filterDto.setName("Closed issues");
- filterDto.setUser("henry");
+ filterDto.setUserLogin("henry");
filterDto.setShared(false);
filterDto.setDescription("All closed issues");
filterDto.setData("statuses=CLOSED");
<issue_filters
id="1"
name="Sonar Issues"
- user="stephane"
+ user_login="stephane"
shared="[true]"
description="All issues of Sonar"
data="componentRoots=org.codehaus.sonar"
<issue_filters
id="2"
name="Open issues"
- user="michael"
+ user_login="michael"
shared="[false]"
description="All open issues"
data="statuses=OPEN"
<issue_filters
id="2"
name="Open issues"
- user="michael"
+ user_login="michael"
shared="[false]"
description="All open issues"
data="statuses=OPEN"
<issue_filters
id="1"
name="Sonar Issues"
- user="stephane"
+ user_login="stephane"
shared="[true]"
description="All issues of Sonar"
data="componentRoots=org.codehaus.sonar"
<issue_filters
id="2"
name="Open issues"
- user="michael"
+ user_login="michael"
shared="[false]"
description="All open issues"
data="statuses=OPEN"
<issue_filters
id="3"
name="Sonar Open issues"
- user="michael"
+ user_login="michael"
shared="[true]"
description="All open issues on Sonar"
data="statuses=OPEN|componentRoots=org.codehaus.sonar"
<issue_filters
id="1"
name="Sonar Issues"
- user="stephane"
+ user_login="stephane"
shared="[true]"
description="All issues of Sonar"
data="componentRoots=org.codehaus.sonar"
<issue_filters
id="2"
name="Open issues"
- user="michael"
+ user_login="michael"
shared="[false]"
description="All open issues"
data="statuses=OPEN"
<issue_filters
id="3"
name="Sonar Open issues"
- user="michael"
+ user_login="michael"
shared="[true]"
description="All open issues on Sonar"
data="statuses=OPEN|componentRoots=org.codehaus.sonar"
<issue_filters
id="1"
name="Sonar Issues"
- user="stephane"
+ user_login="stephane"
shared="[true]"
description="All issues of Sonar"
data="componentRoots=org.codehaus.sonar"
<issue_filters
id="2"
name="Closed issues"
- user="henry"
+ user_login="henry"
shared="[false]"
description="All closed issues"
data="statuses=CLOSED"
class CreateIssueFilters < ActiveRecord::Migration
def self.up
- create_table 'issue_filters' do |t|
- t.column 'name', :string, :null => false, :limit => 100
- t.column 'user', :string, :null => true, :limit => 40
- t.column 'shared', :boolean, :null => false, :default => false
- t.column 'description', :string, :null => true, :limit => 4000
- t.column 'data', :text, :null => true
- t.timestamps
+ create_table :issue_filters do |t|
+ t.column :name, :string, :null => false, :limit => 100
+ t.column :user_login, :string, :null => true, :limit => 40
+ t.column :shared, :boolean, :null => false, :default => false
+ t.column :description, :string, :null => true, :limit => 4000
+ t.column :data, :text, :null => true
+ t.column :created_at, :datetime, :null => true
+ t.column :updated_at, :datetime, :null => true
end
- add_index 'issue_filters', 'name', :name => 'issue_filters_name'
+ add_index :issue_filters, :name, :name => 'issue_filters_name'
end
end
\ No newline at end of file
class CreateIssueFilterFavourites < ActiveRecord::Migration
def self.up
- create_table 'issue_filter_favourites' do |t|
- t.column 'user', :string, :null => false, :limit => 40
- t.column 'issue_filter_id', :integer, :null => false
- t.column 'created_at', :datetime
+ create_table :issue_filter_favourites do |t|
+ t.column :user_login, :string, :null => false, :limit => 40
+ t.column :issue_filter_id, :integer, :null => false
+ t.column :created_at, :datetime
end
- add_index 'issue_filter_favourites', 'user', :name => 'issue_filter_favs_user'
+ add_index :issue_filter_favourites, :user_login, :name => 'issue_filter_favs_user'
end
end