@@ -77,9 +77,9 @@ public class ProjectPersisterIT { | |||
ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID", | |||
p -> p.setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto(); | |||
assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt()); | |||
assertProject(p1.getUuid(), "OLD_DESC", ROOT.getName(), p1.getUpdatedAt()); | |||
underTest.persist(dbTester.getSession()); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), 1000L); | |||
assertProject(ROOT.getUuid(), ROOT.getDescription(), ROOT.getName(), 1000L); | |||
} | |||
@Test | |||
@@ -87,9 +87,9 @@ public class ProjectPersisterIT { | |||
ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID", | |||
p -> p.setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto(); | |||
assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt()); | |||
assertProject(p1.getUuid(), ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt()); | |||
underTest.persist(dbTester.getSession()); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), 1000L); | |||
assertProject(ROOT.getUuid(), ROOT.getDescription(), ROOT.getName(), 1000L); | |||
} | |||
@Test | |||
@@ -97,15 +97,15 @@ public class ProjectPersisterIT { | |||
ProjectDto p1 = dbTester.components().insertPublicProject( | |||
c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription(ROOT.getDescription())).getProjectDto(); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); | |||
assertProject(p1.getUuid(), ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); | |||
underTest.persist(dbTester.getSession()); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); | |||
assertProject(p1.getUuid(), ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); | |||
} | |||
private void assertProject(String description, String name, long updated) { | |||
private void assertProject(String uuid, String description, String name, long updated) { | |||
assertThat(dbTester.getDbClient().projectDao().selectProjectByKey(dbTester.getSession(), ROOT.getKey()).get()) | |||
.extracting(ProjectDto::getName, ProjectDto::getDescription, ProjectDto::getUpdatedAt) | |||
.containsExactly(name, description, updated); | |||
.extracting(ProjectDto::getUuid, ProjectDto::getName, ProjectDto::getDescription, ProjectDto::getUpdatedAt) | |||
.containsExactly(uuid, name, description, updated); | |||
} | |||
} |
@@ -52,7 +52,9 @@ public class ProjectExportTaskProcessor implements CeTaskProcessor { | |||
private void processProjectExport(CeTask task) { | |||
CeTask.Component exportComponent = mandatoryComponent(task, PROJECT_EXPORT); | |||
ProjectDescriptor projectExportDescriptor = new ProjectDescriptor(task.getEntity().get().getUuid(), | |||
CeTask.Component entity = task.getEntity() | |||
.orElseThrow(() -> new IllegalStateException("Compute engine task for project export doesn't contain entity")); | |||
ProjectDescriptor projectExportDescriptor = new ProjectDescriptor(entity.getUuid(), | |||
mandatoryKey(exportComponent), mandatoryName(exportComponent)); | |||
try (TaskContainer taskContainer = new TaskContainerImpl(componentContainer, |
@@ -100,7 +100,10 @@ import static java.util.Collections.singletonList; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.groups.Tuple.tuple; | |||
import static org.mockito.ArgumentMatchers.anyList; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.only; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.verifyNoInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.db.ce.CeTaskTypes.REPORT; | |||
@@ -1219,6 +1222,7 @@ public class PurgeDaoIT { | |||
@Test | |||
public void should_delete_old_closed_issues() { | |||
PurgeListener listener = mock(PurgeListener.class); | |||
RuleDto rule = db.rules().insert(); | |||
ProjectData projectData = db.components().insertPublicProject(); | |||
ComponentDto mainBranch = projectData.getMainBranchComponent(); | |||
@@ -1241,7 +1245,7 @@ public class PurgeDaoIT { | |||
db.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(notClosed)); | |||
when(system2.now()).thenReturn(new Date().getTime()); | |||
underTest.purge(dbSession, newConfigurationWith30Days(system2, mainBranch.uuid(), projectData.projectUuid()), PurgeListener.EMPTY, new PurgeProfiler()); | |||
underTest.purge(dbSession, newConfigurationWith30Days(system2, mainBranch.uuid(), projectData.projectUuid()), listener, new PurgeProfiler()); | |||
dbSession.commit(); | |||
// old closed got deleted | |||
@@ -1260,6 +1264,8 @@ public class PurgeDaoIT { | |||
Optional<IssueDto> oldClosedFromQuery = db.getDbClient().issueDao().selectByKey(dbSession, oldClosed.getKey()); | |||
assertThat(oldClosedFromQuery).isEmpty(); | |||
verify(listener, only()).onIssuesRemoval(projectData.projectUuid(), List.of(oldClosed.getKee())); | |||
} | |||
@Test |
@@ -93,7 +93,7 @@ public class ImportAzureProjectActionIT { | |||
private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), i18n, System2.INSTANCE, | |||
mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(), | |||
defaultBranchNameResolver, true); | |||
defaultBranchNameResolver); | |||
private final Encryption encryption = mock(Encryption.class); | |||
private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession); |
@@ -93,7 +93,7 @@ public class ImportBitbucketCloudRepoActionIT { | |||
DefaultBranchNameResolver defaultBranchNameResolver = mock(DefaultBranchNameResolver.class); | |||
private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), i18n, System2.INSTANCE, | |||
mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(), | |||
defaultBranchNameResolver, true); | |||
defaultBranchNameResolver); | |||
private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession); | |||
private final ProjectKeyGenerator projectKeyGenerator = mock(ProjectKeyGenerator.class); |
@@ -100,7 +100,7 @@ public class ImportBitbucketServerProjectActionIT { | |||
private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), i18n, System2.INSTANCE, | |||
mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(), | |||
defaultBranchNameResolver, true); | |||
defaultBranchNameResolver); | |||
private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession); | |||
private final ProjectKeyGenerator projectKeyGenerator = mock(ProjectKeyGenerator.class); |
@@ -94,7 +94,7 @@ public class ImportGithubProjectActionIT { | |||
private final PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class); | |||
private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), mock(I18n.class), System2.INSTANCE, | |||
permissionTemplateService, new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(), | |||
defaultBranchNameResolver, true); | |||
defaultBranchNameResolver); | |||
private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession); | |||
private final ProjectKeyGenerator projectKeyGenerator = mock(ProjectKeyGenerator.class); |
@@ -84,7 +84,7 @@ public class ImportGitLabProjectActionIT { | |||
private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), mock(I18n.class), System2.INSTANCE, | |||
mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(), | |||
defaultBranchNameResolver, true); | |||
defaultBranchNameResolver); | |||
private final GitlabHttpClient gitlabHttpClient = mock(GitlabHttpClient.class); | |||
private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession); |
@@ -93,7 +93,7 @@ public class ReportSubmitterIT { | |||
private final PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class); | |||
private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), mock(I18n.class), mock(System2.class), permissionTemplateService, | |||
new FavoriteUpdater(db.getDbClient()), projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver, true); | |||
new FavoriteUpdater(db.getDbClient()), projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver); | |||
private final BranchSupport ossEditionBranchSupport = new BranchSupport(null); | |||
private final ReportSubmitter underTest = new ReportSubmitter(queue, userSession, componentUpdater, permissionTemplateService, db.getDbClient(), ossEditionBranchSupport, |
@@ -80,7 +80,7 @@ public class ComponentUpdaterIT { | |||
private final ComponentUpdater underTest = new ComponentUpdater(db.getDbClient(), i18n, system2, | |||
permissionTemplateService, | |||
new FavoriteUpdater(db.getDbClient()), | |||
projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver, true); | |||
projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver); | |||
@Before | |||
public void before() { |
@@ -107,7 +107,7 @@ public class CreateActionIT { | |||
new CreateAction( | |||
db.getDbClient(), userSession, | |||
new ComponentUpdater(db.getDbClient(), i18n, system2, permissionTemplateService, new FavoriteUpdater(db.getDbClient()), | |||
projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver, true), | |||
projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver), | |||
projectDefaultVisibility, defaultBranchNameResolver, newCodeDefinitionResolver)); | |||
@Before |
@@ -65,20 +65,11 @@ public class ComponentUpdater { | |||
private final Indexers indexers; | |||
private final UuidFactory uuidFactory; | |||
private final DefaultBranchNameResolver defaultBranchNameResolver; | |||
private final boolean useDifferentUuids; | |||
@Autowired | |||
public ComponentUpdater(DbClient dbClient, I18n i18n, System2 system2, | |||
PermissionTemplateService permissionTemplateService, FavoriteUpdater favoriteUpdater, | |||
Indexers indexers, UuidFactory uuidFactory, DefaultBranchNameResolver defaultBranchNameResolver) { | |||
this(dbClient, i18n, system2, permissionTemplateService, favoriteUpdater, indexers, uuidFactory, defaultBranchNameResolver, false); | |||
} | |||
@VisibleForTesting | |||
public ComponentUpdater(DbClient dbClient, I18n i18n, System2 system2, | |||
PermissionTemplateService permissionTemplateService, FavoriteUpdater favoriteUpdater, | |||
Indexers indexers, UuidFactory uuidFactory, DefaultBranchNameResolver defaultBranchNameResolver, | |||
boolean useDifferentUuids) { | |||
this.dbClient = dbClient; | |||
this.i18n = i18n; | |||
this.system2 = system2; | |||
@@ -87,7 +78,6 @@ public class ComponentUpdater { | |||
this.indexers = indexers; | |||
this.uuidFactory = uuidFactory; | |||
this.defaultBranchNameResolver = defaultBranchNameResolver; | |||
this.useDifferentUuids = useDifferentUuids; | |||
} | |||
/** |
@@ -154,23 +154,22 @@ public class BulkDeleteAction implements ProjectsWsAction { | |||
ComponentQuery query = buildDbQuery(searchRequest); | |||
Set<ComponentDto> componentDtos = new HashSet<>(dbClient.componentDao().selectByQuery(dbSession, query, 0, Integer.MAX_VALUE)); | |||
List<EntityDto> entities = dbClient.entityDao().selectByKeys(dbSession, componentDtos.stream().map(ComponentDto::getKey).collect(toSet())); | |||
Set<String> entityUuids = entities.stream().map(EntityDto::getUuid).collect(toSet()); | |||
Map<String, String> mainBranchUuidByEntityUuid = dbClient.branchDao().selectMainBranchesByProjectUuids(dbSession, entityUuids).stream() | |||
.collect(Collectors.toMap(BranchDto::getProjectUuid, BranchDto::getUuid)); | |||
try { | |||
entities.forEach(p -> componentCleanerService.deleteEntity(dbSession, p)); | |||
} finally { | |||
callDeleteListeners(dbSession, entities); | |||
callDeleteListeners(dbSession, mainBranchUuidByEntityUuid, entities); | |||
} | |||
} | |||
response.noContent(); | |||
} | |||
private void callDeleteListeners(DbSession dbSession, List<EntityDto> entities) { | |||
Set<String> entityUuids = entities.stream().map(EntityDto::getUuid).collect(toSet()); | |||
Map<String, String> mainBranchUuidByEntityUuid = dbClient.branchDao().selectMainBranchesByProjectUuids(dbSession, entityUuids).stream() | |||
.collect(Collectors.toMap(BranchDto::getProjectUuid, BranchDto::getUuid)); | |||
ImmutableSet<DeletedProject> deletedProjects = entities.stream().map(entity -> new DeletedProject(Project.from(entity), mainBranchUuidByEntityUuid.get(entity.getUuid()))) | |||
.collect(toImmutableSet()); | |||
private void callDeleteListeners(DbSession dbSession, Map<String, String> mainBranchUuidByEntityUuid , List<EntityDto> entities) { | |||
Set<DeletedProject> deletedProjects = entities.stream().map(entity -> new DeletedProject(Project.from(entity), | |||
mainBranchUuidByEntityUuid.get(entity.getUuid()))).collect(toSet()); | |||
projectLifeCycleListeners.onProjectsDeleted(deletedProjects); | |||
} | |||