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
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
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);
}
}
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,
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;
@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();
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
Optional<IssueDto> oldClosedFromQuery = db.getDbClient().issueDao().selectByKey(dbSession, oldClosed.getKey());
assertThat(oldClosedFromQuery).isEmpty();
+
+ verify(listener, only()).onIssuesRemoval(projectData.projectUuid(), List.of(oldClosed.getKee()));
}
@Test
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);
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);
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);
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);
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);
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,
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() {
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
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;
this.indexers = indexers;
this.uuidFactory = uuidFactory;
this.defaultBranchNameResolver = defaultBranchNameResolver;
- this.useDifferentUuids = useDifferentUuids;
}
/**
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);
}