* @return a map with currentKey/newKey is a bulk update was executed
*/
public Map<String, String> simulateBulkUpdateKey(DbSession dbSession, String projectUuid, String stringToReplace, String replacementString) {
- return collectAllModules(projectUuid, stringToReplace, mapper(dbSession))
+ return collectAllModules(projectUuid, stringToReplace, mapper(dbSession), false)
.stream()
.collect(Collectors.toMap(
ResourceDto::getKey,
public void bulkUpdateKey(DbSession session, String projectUuid, String stringToReplace, String replacementString) {
ComponentKeyUpdaterMapper mapper = session.getMapper(ComponentKeyUpdaterMapper.class);
// must SELECT first everything
- Set<ResourceDto> modules = collectAllModules(projectUuid, stringToReplace, mapper);
+ Set<ResourceDto> modules = collectAllModules(projectUuid, stringToReplace, mapper, true);
// add branches
Map<String, String> branchBaseKeys = new HashMap<>();
.stream()
.filter(branch -> !projectUuid.equals(branch.getUuid()))
.forEach(branch -> {
- Set<ResourceDto> branchModules = collectAllModules(branch.getUuid(), stringToReplace, mapper);
+ Set<ResourceDto> branchModules = collectAllModules(branch.getUuid(), stringToReplace, mapper, true);
modules.addAll(branchModules);
branchModules.forEach(module -> branchBaseKeys.put(module.getKey(), branchBaseKey(module.getKey())));
});
}
}
- private static Set<ResourceDto> collectAllModules(String projectUuid, String stringToReplace, ComponentKeyUpdaterMapper mapper) {
+ private static Set<ResourceDto> collectAllModules(String projectUuid, String stringToReplace, ComponentKeyUpdaterMapper mapper, boolean includeDisabled) {
ResourceDto project = mapper.selectProject(projectUuid);
Set<ResourceDto> modules = new HashSet<>();
- if (project.getKey().contains(stringToReplace)) {
+ if (project.getKey().contains(stringToReplace) && (project.isEnabled() || includeDisabled)) {
modules.add(project);
}
for (ResourceDto submodule : mapper.selectDescendantProjects(projectUuid)) {
- modules.addAll(collectAllModules(submodule.getUuid(), stringToReplace, mapper));
+ modules.addAll(collectAllModules(submodule.getUuid(), stringToReplace, mapper, includeDisabled));
}
return modules;
}
where
root_uuid = #{rootUuid,jdbcType=VARCHAR}
and scope != 'PRJ'
- and enabled = ${_true}
</select>
<select id="selectDescendantProjects" parameterType="String" resultMap="resourceResultMap">
scope='PRJ'
and root_uuid = #{rootUuid,jdbcType=VARCHAR}
and uuid != #{rootUuid,jdbcType=VARCHAR}
- and enabled = ${_true}
</select>
<update id="update" parameterType="Resource">
}
@Test
- public void updateKey_does_not_update_inactive_components() {
+ public void updateKey_updates_disabled_components() {
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "A").setDbKey("my_project"));
ComponentDto directory = db.components().insertComponent(newDirectory(project, "/directory").setDbKey("my_project:directory"));
dbSession.commit();
List<ComponentDto> result = dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, "your_project");
- assertThat(result).hasSize(5).extracting(ComponentDto::getDbKey)
- .containsOnlyOnce("your_project", "your_project:directory", "your_project:directory/file", "my_project:inactive_directory", "my_project:inactive_directory/file");
+ assertThat(result)
+ .hasSize(5)
+ .extracting(ComponentDto::getDbKey)
+ .containsOnlyOnce("your_project", "your_project:directory", "your_project:directory/file", "your_project:inactive_directory", "your_project:inactive_directory/file");
}
@Test
}
@Test
- public void bulk_update_key_does_not_update_inactive_components() {
+ public void bulk_update_key_updates_disabled_components() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setDbKey("my_project"));
db.components().insertComponent(newModuleDto(project).setDbKey("my_project:module"));
db.components().insertComponent(newModuleDto(project).setDbKey("my_project:inactive_module").setEnabled(false));
underTest.bulkUpdateKey(dbSession, "A", "my_", "your_");
List<ComponentDto> result = dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, "your_project");
- assertThat(result).hasSize(3).extracting(ComponentDto::getDbKey)
- .containsOnlyOnce("your_project", "your_project:module", "my_project:inactive_module");
+ assertThat(result)
+ .hasSize(3)
+ .extracting(ComponentDto::getDbKey)
+ .containsOnlyOnce("your_project", "your_project:module", "your_project:inactive_module");
}
@Test
}
@Test
- public void simulate_bulk_update_key_do_not_return_disable_components() {
+ public void simulate_bulk_update_key_does_not_return_disable_components() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setDbKey("project"));
db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module"));
db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false));
+ db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "D").setDbKey("other-project"));
Map<String, String> result = underTest.simulateBulkUpdateKey(dbSession, "A", "project", "new-project");
- assertThat(result)
- .hasSize(2)
- .containsOnly(entry("project", "new-project"), entry("project:enabled-module", "new-project:enabled-module"));
+ assertThat(result).containsOnly(
+ entry("project", "new-project"),
+ entry("project:enabled-module", "new-project:enabled-module"));
}
@Test
assertComponentKeyUpdated(project.getDbKey(), "your_project");
assertComponentKeyUpdated(module.getDbKey(), "your_project:root:module");
assertComponentKeyUpdated(file.getDbKey(), "your_project:root:module:src/File.xoo");
- assertComponentKeyNotUpdated(inactiveModule.getDbKey());
- assertComponentKeyNotUpdated(inactiveFile.getDbKey());
+ assertComponentKeyUpdated(inactiveModule.getDbKey(), "your_project:root:inactive_module");
+ assertComponentKeyUpdated(inactiveFile.getDbKey(), "your_project:root:module:src/InactiveFile.xoo");
}
private void assertComponentKeyUpdated(String oldKey, String newKey) {
assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
}
- private void assertComponentKeyNotUpdated(String key) {
- assertThat(dbClient.componentDao().selectByKey(dbSession, key)).isPresent();
- }
-
}
// Check file key has been updated
assertThat(db.getDbClient().componentDao().selectByKey(dbSession, file.getDbKey())).isAbsent();
assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/File.xoo")).isNotNull();
+ assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/InactiveFile.xoo")).isNotNull();
- assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getDbKey())).isPresent();
+ assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getDbKey())).isAbsent();
org.assertj.core.api.Assertions.assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
}
assertComponentKeyUpdated(project.getDbKey(), "your_project");
assertComponentKeyUpdated(module.getDbKey(), "your_project:root:module");
assertComponentKeyUpdated(file.getDbKey(), "your_project:root:module:src/File.xoo");
- assertComponentKeyNotUpdated(inactiveModule.getDbKey());
- assertComponentKeyNotUpdated(inactiveFile.getDbKey());
+ assertComponentKeyUpdated(inactiveModule.getDbKey(), "your_project:root:inactive_module");
+ assertComponentKeyUpdated(inactiveFile.getDbKey(), "your_project:root:module:src/InactiveFile.xoo");
}
private void assertComponentKeyUpdated(String oldKey, String newKey) {
assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
}
- private void assertComponentKeyNotUpdated(String key) {
- assertThat(dbClient.componentDao().selectByKey(dbSession, key)).isPresent();
- }
-
private ComponentDto insertSampleRootProject() {
return insertProject("sample:root");
}