*/
package org.sonar.server.db.migrations.v51;
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.Database;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
-import java.util.SortedSet;
public class RenameComponentRelatedParamsInIssueFilters extends BaseDataChange {
private static final char FIELD_SEPARATOR = '|';
private static final String LIKE_PREFIX = "data like '%";
private static final String LIKE_SUFFIX = "%' or ";
- private static final String COMPONENTS = "components=";
private static final String COMPONENT_UUIDS = "componentUuids=";
- private static final String PROJECTS = "projects=";
- private static final String COMPONENT_ROOTS = "componentRoots=";
private static final String COMPONENT_ROOT_UUIDS = "componentRootUuids=";
private final System2 system;
final Date now = new Date(system.now());
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select id,data from issue_filters where " +
- LIKE_PREFIX + COMPONENTS + LIKE_SUFFIX +
- LIKE_PREFIX + PROJECTS + LIKE_SUFFIX +
- LIKE_PREFIX + COMPONENT_ROOTS + LIKE_SUFFIX +
+ LIKE_PREFIX + COMPONENT_UUIDS + LIKE_SUFFIX +
LIKE_PREFIX + COMPONENT_ROOT_UUIDS + "%'");
massUpdate.update("update issue_filters set data=?, updated_at=? where id=?");
massUpdate.rowPluralName("issue filters");
String[] fields = StringUtils.split(data, FIELD_SEPARATOR);
List<String> fieldsToKeep = Lists.newArrayList();
- SortedSet<String> components = Sets.newTreeSet();
- SortedSet<String> componentUuids = Sets.newTreeSet();
- Splitter componentSplitter = Splitter.on(",");
- Joiner componentJoiner = Joiner.on(",");
for (String field : fields) {
- if (field.startsWith(COMPONENTS) || field.startsWith(COMPONENT_ROOTS)) {
- components.addAll(Lists.newArrayList(componentSplitter.split(field.substring(field.indexOf("=") + 1))));
- } else if (field.startsWith(COMPONENT_UUIDS) || field.startsWith(COMPONENT_ROOT_UUIDS)) {
- componentUuids.addAll(Lists.newArrayList(componentSplitter.split(field.substring(field.indexOf("=") + 1))));
- } else if (field.startsWith(PROJECTS)) {
- fieldsToKeep.add(field.replace(PROJECTS, "projectKeys="));
+ if (field.startsWith(COMPONENT_UUIDS) || field.startsWith(COMPONENT_ROOT_UUIDS)) {
+ fieldsToKeep.add(
+ field.replace(COMPONENT_UUIDS, "fileUuids=")
+ .replace(COMPONENT_ROOT_UUIDS, "moduleUuids="));
} else {
fieldsToKeep.add(field);
}
}
- if (!components.isEmpty()) {
- fieldsToKeep.add("componentKeys=" + componentJoiner.join(components));
- }
- if (!componentUuids.isEmpty()) {
- fieldsToKeep.add("componentUuids=" + componentJoiner.join(componentUuids));
- }
-
update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR));
update.setDate(2, now);
update.setLong(3, row.getLong(1));
<dataset>
- <issue_filters
+ <!-- Not updated, no concerned field -->
+ <issue_filters
id="1"
name="No concerned field"
user_login="stephane"
created_at="2013-06-10"
updated_at="2013-06-10" />
+ <!-- Not updated, projectUuids is left as is -->
<issue_filters
id="2"
name="Has projects"
user_login="michael"
shared="[false]"
description="to be updated"
- data="statuses=OPEN|sort=SEVERITY|asc=true|projectKeys=ABC"
+ data="statuses=OPEN|sort=SEVERITY|asc=true|projectUuids=ABC"
created_at="2013-06-10"
- updated_at="2014-10-29 00:00:00.0" />
+ updated_at="2013-06-10 00:00:00.0" />
+ <!-- componentUuids replaced by fileUuids -->
<issue_filters
id="3"
name="Has components"
user_login="michael"
shared="[false]"
description="to be updated"
- data="statuses=OPEN|sort=SEVERITY|asc=true|componentKeys=ABC"
+ data="fileUuids=ABC|statuses=OPEN|sort=SEVERITY|asc=true"
created_at="2013-06-10"
updated_at="2014-10-29 00:00:00.0" />
+ <!-- componentRootUuids replaced by moduleUuids -->
<issue_filters
id="4"
name="Has componentRoots"
user_login="michael"
shared="[false]"
description="to be updated"
- data="statuses=OPEN|sort=SEVERITY|asc=true|componentKeys=ABC"
+ data="statuses=OPEN|sort=SEVERITY|asc=true|moduleUuids=ABC"
created_at="2013-06-10"
updated_at="2014-10-29 00:00:00.0" />
+ <!-- componentRootUuids replaced by moduleUuids (in the middle of the string) -->
<issue_filters
id="5"
name="Has projects"
user_login="michael"
shared="[false]"
description="to be updated"
- data="statuses=OPEN|sort=SEVERITY|asc=true|componentUuids=ABC"
+ data="statuses=OPEN|sort=SEVERITY|moduleUuids=ABC|asc=true"
created_at="2013-06-10"
updated_at="2014-10-29 00:00:00.0" />
+ <!-- componentUuidss replaced by fileUuids, componentRootUuids replaced by moduleUuids -->
<issue_filters
id="6"
name="Has all parameters"
user_login="michael"
shared="[false]"
description="to be updated"
- data="statuses=OPEN|sort=SEVERITY|projectUuids=CDE|asc=true|componentUuids=ABC,BCD"
+ data="statuses=OPEN|sort=SEVERITY|fileUuids=BCD|moduleUuids=ABC|projectUuids=CDE|asc=true"
created_at="2013-06-10"
updated_at="2014-10-29 00:00:00.0" />
</dataset>
<dataset>
+ <!-- Not updated, no concerned field -->
<issue_filters
id="1"
name="No concerned field"
created_at="2013-06-10"
updated_at="2013-06-10" />
+ <!-- Not updated, projectUuids is left as is -->
<issue_filters
id="2"
name="Has projects"
user_login="michael"
shared="[false]"
description="to be updated"
- data="statuses=OPEN|sort=SEVERITY|asc=true|projects=ABC"
+ data="statuses=OPEN|sort=SEVERITY|asc=true|projectUuids=ABC"
created_at="2013-06-10"
updated_at="2013-06-10" />
+ <!-- componentUuids replaced by fileUuids -->
<issue_filters
id="3"
name="Has components"
user_login="michael"
shared="[false]"
description="to be updated"
- data="components=ABC|statuses=OPEN|sort=SEVERITY|asc=true"
+ data="componentUuids=ABC|statuses=OPEN|sort=SEVERITY|asc=true"
created_at="2013-06-10"
updated_at="2013-06-10" />
+ <!-- componentRootUuids replaced by moduleUuids -->
<issue_filters
id="4"
name="Has componentRoots"
user_login="michael"
shared="[false]"
description="to be updated"
- data="statuses=OPEN|sort=SEVERITY|asc=true|componentRoots=ABC"
+ data="statuses=OPEN|sort=SEVERITY|asc=true|componentRootUuids=ABC"
created_at="2013-06-10"
updated_at="2013-06-10" />
+ <!-- componentRootUuids replaced by moduleUuids (in the middle of the string) -->
<issue_filters
id="5"
name="Has projects"
created_at="2013-06-10"
updated_at="2013-06-10" />
+ <!-- componentUuidss replaced by fileUuids, componentRootUuids replaced by moduleUuids -->
<issue_filters
id="6"
name="Has all parameters"