public void delete(DbSession dbSession, ComponentDto project) { checkArgument(!hasNotProjectScope(project) && !isNotDeletable(project) && project.getMainBranchProjectUuid() == null, "Only projects can be deleted"); dbClient.purgeDao().deleteProject(dbSession, project.uuid()); dbClient.userDao().cleanHomepage(dbSession, project); projectIndexers.commitAndIndex(dbSession, singletonList(project), PROJECT_DELETION); }
@Test public void call_period_cleaner_index_client_and_purge_dao() { settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5); underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList()); verify(periodCleaner).clean(any(), any(), any()); verify(dao).purge(any(), any(), any(), any()); } }
@Test public void doClean() { PurgeDao dao = mock(PurgeDao.class); DbSession session = mock(DbSession.class); when(dao.selectPurgeableAnalyses("uuid_123", session)).thenReturn(Arrays.asList( new PurgeableAnalysisDto().setAnalysisId(999).setAnalysisUuid("u999").setDate(System2.INSTANCE.now()), new PurgeableAnalysisDto().setAnalysisId(456).setAnalysisUuid("u456").setDate(System2.INSTANCE.now()) )); Filter filter1 = newFirstSnapshotInListFilter(); Filter filter2 = newFirstSnapshotInListFilter(); PurgeProfiler profiler = new PurgeProfiler(); DefaultPeriodCleaner cleaner = new DefaultPeriodCleaner(dao, profiler); cleaner.doClean("uuid_123", Arrays.asList(filter1, filter2), session); InOrder inOrder = Mockito.inOrder(dao, filter1, filter2); inOrder.verify(filter1).log(); inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of(new IdUuidPair(999, "u999")))); inOrder.verify(filter2).log(); inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of(new IdUuidPair(456, "u456")))); inOrder.verifyNoMoreInteractions(); }
public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) { PurgeMapper mapper = session.getMapper(PurgeMapper.class); PurgeCommands commands = new PurgeCommands(session, mapper, profiler); String rootUuid = conf.rootProjectIdUuid().getUuid(); deleteAbortedAnalyses(rootUuid, commands); deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.getScopesWithoutHistoricalData(), commands); purgeAnalyses(commands, rootUuid); purgeDisabledComponents(session, conf, listener); deleteOldClosedIssues(conf, mapper, listener); purgeStaleBranches(commands, conf, mapper, rootUuid); }
public void deleteBranch(DbSession session, String uuid) { PurgeProfiler profiler = new PurgeProfiler(); PurgeMapper purgeMapper = mapper(session); PurgeCommands purgeCommands = new PurgeCommands(session, profiler); deleteRootComponent(uuid, purgeMapper, purgeCommands); }
/** * Delete the non root components (ie. sub-view, application or project copy) from the specified collection of {@link ComponentDto} * and data from their child tables. * <p> * This method has no effect when passed an empty collection or only root components. * </p> */ public void deleteNonRootComponentsInView(DbSession dbSession, Collection<ComponentDto> components) { Set<ComponentDto> nonRootComponents = components.stream().filter(PurgeDao::isNotRoot).collect(MoreCollectors.toSet()); if (nonRootComponents.isEmpty()) { return; } PurgeProfiler profiler = new PurgeProfiler(); PurgeCommands purgeCommands = new PurgeCommands(dbSession, profiler); deleteNonRootComponentsInView(nonRootComponents, purgeCommands); }
public PurgeDao deleteProject(DbSession session, String uuid) { PurgeProfiler profiler = new PurgeProfiler(); PurgeCommands purgeCommands = new PurgeCommands(session, profiler); deleteProject(uuid, mapper(session), purgeCommands); return this; }
private List<PurgeableAnalysisDto> delete(String rootUuid, List<PurgeableAnalysisDto> snapshots, DbSession session) { if (LOG.isDebugEnabled()) { LOG.debug("<- Delete analyses of component {}: {}", rootUuid, Joiner.on(", ").join( snapshots.stream() .map(snapshot -> snapshot.getAnalysisUuid() + "@" + DateUtils.formatDateTime(snapshot.getDate())) .collect(MoreCollectors.toArrayList(snapshots.size())))); } purgeDao.deleteAnalyses( session, profiler, snapshots.stream().map(DefaultPeriodCleaner::toIdUuidPair).collect(MoreCollectors.toList(snapshots.size()))); return snapshots; }
private List<PurgeableAnalysisDto> selectAnalysesOfComponent(String componentUuid, DbSession session) { return purgeDao.selectPurgeableAnalyses(componentUuid, session); } }
public List<PurgeableAnalysisDto> selectPurgeableAnalyses(String componentUuid, DbSession session) { List<PurgeableAnalysisDto> result = Lists.newArrayList(); result.addAll(mapper(session).selectPurgeableAnalysesWithEvents(componentUuid)); result.addAll(mapper(session).selectPurgeableAnalysesWithoutEvents(componentUuid)); // sort by date Collections.sort(result); return result; }
public void deleteBranch(DbSession dbSession, ComponentDto branch) { // TODO: detect if other branches depend on it? dbClient.purgeDao().deleteBranch(dbSession, branch.uuid()); projectIndexers.commitAndIndex(dbSession, singletonList(branch), PROJECT_DELETION); }
public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) { PurgeMapper mapper = session.getMapper(PurgeMapper.class); PurgeCommands commands = new PurgeCommands(session, mapper, profiler); String rootUuid = conf.rootProjectIdUuid().getUuid(); deleteAbortedAnalyses(rootUuid, commands); deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.scopesWithoutHistoricalData(), commands); purgeAnalyses(commands, rootUuid); purgeDisabledComponents(session, conf.getDisabledComponentUuids(), listener); deleteOldClosedIssues(conf, mapper, listener); }
private void verifyNoEffect(ComponentDto firstRoot, ComponentDto... otherRoots) { DbSession dbSession = mock(DbSession.class); List<ComponentDto> componentDtos = Stream.concat(Stream.of(firstRoot), Arrays.stream(otherRoots)).collect(Collectors.toList()); Collections.shuffle(componentDtos); // order of collection must not matter underTest.deleteNonRootComponentsInView(dbSession, componentDtos); verifyZeroInteractions(dbSession); }
@Test public void shouldDeleteAnalyses() { db.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml"); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "u3"))); db.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots"); }
@Test public void selectPurgeableAnalyses() { db.prepareDbUnit(getClass(), "shouldSelectPurgeableAnalysis.xml"); List<PurgeableAnalysisDto> analyses = underTest.selectPurgeableAnalyses(THE_PROJECT_UUID, dbSession); assertThat(analyses).hasSize(3); assertThat(getById(analyses, "u1").isLast()).isTrue(); assertThat(getById(analyses, "u1").hasEvents()).isFalse(); assertThat(getById(analyses, "u1").getVersion()).isNull(); assertThat(getById(analyses, "u4").isLast()).isFalse(); assertThat(getById(analyses, "u4").hasEvents()).isFalse(); assertThat(getById(analyses, "u4").getVersion()).isNull(); assertThat(getById(analyses, "u5").isLast()).isFalse(); assertThat(getById(analyses, "u5").hasEvents()).isTrue(); assertThat(getById(analyses, "u5").getVersion()).isEqualTo("V5"); }
public void deleteProject(DbSession session, String uuid) { PurgeProfiler profiler = new PurgeProfiler(); PurgeMapper purgeMapper = mapper(session); PurgeCommands purgeCommands = new PurgeCommands(session, profiler); session.getMapper(BranchMapper.class).selectByProjectUuid(uuid) .stream() .filter(branch -> !uuid.equals(branch.getUuid())) .forEach(branch -> deleteRootComponent(branch.getUuid(), purgeMapper, purgeCommands)); deleteRootComponent(uuid, purgeMapper, purgeCommands); }
private void purgeDisabledComponents(DbSession session, PurgeConfiguration conf, PurgeListener listener) { PurgeMapper mapper = mapper(session); executeLargeInputs(conf.getDisabledComponentUuids(), input -> { mapper.deleteFileSourcesByFileUuid(input); mapper.resolveComponentIssuesNotAlreadyResolved(input, system2.now()); mapper.deleteLiveMeasuresByComponentUuids(input); return emptyList(); }); listener.onComponentsDisabling(conf.rootProjectIdUuid().getUuid(), conf.getDisabledComponentUuids()); session.commit(); }
public void deleteBranch(DbSession dbSession, ComponentDto branch) { // TODO: detect if other branches depend on it? dbClient.purgeDao().deleteBranch(dbSession, branch.uuid()); projectIndexers.commitAndIndex(dbSession, singletonList(branch), ProjectIndexer.Cause.PROJECT_DELETION); }
@Test public void delete_view_sub_view_and_tech_project() { db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); // view underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero(); }
public ProjectCleaner purge(DbSession session, IdUuidPair rootId, Configuration projectConfig, Collection<String> disabledComponentUuids) { long start = System.currentTimeMillis(); profiler.reset(); PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectConfig, rootId, disabledComponentUuids); periodCleaner.clean(session, configuration.rootProjectIdUuid().getUuid(), projectConfig); purgeDao.purge(session, configuration, purgeListener, profiler); session.commit(); logProfiling(start, projectConfig); return this; }