private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) { List<IdUuidPair> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid); long rootId = rootAndModulesOrSubviews.stream() .filter(pair -> pair.getUuid().equals(rootUuid)) .map(IdUuidPair::getId) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Couldn't find root component with uuid " + rootUuid)); commands.deletePermissions(rootId); commands.deleteLinks(rootUuid); commands.deleteAnalyses(rootUuid); commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews); commands.deleteComponents(rootUuid); commands.deleteIssues(rootUuid); commands.deleteFileSources(rootUuid); commands.deleteCeActivity(rootUuid); commands.deleteCeQueue(rootUuid); commands.deleteWebhooks(rootUuid); commands.deleteWebhookDeliveries(rootUuid); commands.deleteProjectMappings(rootUuid); commands.deleteProjectAlmBindings(rootUuid); commands.deleteBranch(rootUuid); commands.deleteLiveMeasures(rootUuid); }
@Test public void deletePermissions_deletes_permissions_of_public_project() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPublicProject(organization); addPermissions(organization, project); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deletePermissions(project.getId()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2); assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); }
@Test public void deletePermissions_deletes_permissions_of_private_project() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); addPermissions(organization, project); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deletePermissions(project.getId()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); }
@Test public void deletePermissions_deletes_permissions_of_view() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPublicPortfolio(organization); addPermissions(organization, project); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deletePermissions(project.getId()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2); assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); }