mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate);
}
- public void delete(DbSession session, String componentUuid, String qualifier) {
- if (auditPersister != null) {
- auditPersister.deleteComponent(session, new ComponentNewValue(componentUuid, qualifier), qualifier);
- }
- mapper(session).delete(componentUuid);
- }
-
private static void checkThatNotTooManyComponents(ComponentQuery query) {
checkThatNotTooManyConditions(query.getComponentKeys(), "Too many component keys in query");
checkThatNotTooManyConditions(query.getComponentUuids(), "Too many component UUIDs in query");
"from components where uuid='" + uuid + "'");
}
- @Test
- public void delete() {
- ComponentDto project1 = db.components().insertPrivateProject(t -> t.setDbKey("PROJECT_1"));
- db.components().insertPrivateProject(t -> t.setDbKey("PROJECT_2"));
-
- underTest.delete(dbSession, project1.uuid(), null);
- dbSession.commit();
-
- assertThat(underTest.selectByKey(dbSession, "PROJECT_1")).isEmpty();
- assertThat(underTest.selectByKey(dbSession, "PROJECT_2")).isPresent();
- }
-
@Test
public void selectByQuery_throws_IAE_if_too_many_component_keys() {
Set<String> keys = IntStream.range(0, 1_010).mapToObj(String::valueOf).collect(toSet());
assertThat(result).isEmpty();
}
- @Test
- public void delete_auditPersisterIsCalled() {
- underTestWithAuditPersister.delete(dbSession, "anyUuid", APP);
-
- verify(auditPersister, Mockito.times(1))
- .deleteComponent(any(DbSession.class), any(ComponentNewValue.class), anyString());
- }
-
@Test
public void setPrivateForRootComponentUuid_auditPersisterIsCalled() {
underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, APP);
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
+import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME;
import static org.sonar.server.component.index.ComponentIndexDefinition.TYPE_COMPONENT;
import static org.sonar.server.es.ProjectIndexer.Cause.PROJECT_CREATION;
indexProject(project, PROJECT_CREATION);
assertThatIndexHasSize(1);
- db.getDbClient().componentDao().delete(db.getSession(), project.uuid(), Qualifiers.PROJECT);
+ db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), PROJECT);
indexProject(project, PROJECT_DELETION);
assertThatIndexHasSize(0);
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.server.es.ProjectIndexer.Cause.PERMISSION_CHANGE;
verifyAuthorized(project, user2);
}
- @Test
- public void deletion_resilience_will_deindex_projects() {
- ComponentDto project1 = createUnindexedPublicProject();
- ComponentDto project2 = createUnindexedPublicProject();
- // UserDto user1 = db.users().insertUser();
- indexOnStartup();
- assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isEqualTo(2);
-
- // Simulate a indexation issue
- db.getDbClient().componentDao().delete(db.getSession(), project1.uuid(), Qualifiers.PROJECT);
- underTest.prepareForRecovery(db.getSession(), asList(project1.uuid()), ProjectIndexer.Cause.PROJECT_DELETION);
- assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isEqualTo(1);
- Collection<EsQueueDto> esQueueDtos = db.getDbClient().esQueueDao().selectForRecovery(db.getSession(), Long.MAX_VALUE, 2);
-
- underTest.index(db.getSession(), esQueueDtos);
-
- assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isZero();
- assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isEqualTo(1);
- }
-
@Test
public void indexOnStartup_grants_access_to_user() {
ComponentDto project = createAndIndexPrivateProject();
indexPermissions(project, ProjectIndexer.Cause.PROJECT_CREATION);
verifyAuthorized(project, user);
- db.getDbClient().componentDao().delete(db.getSession(), project.uuid(), Qualifiers.PROJECT);
+ db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), PROJECT);
indexPermissions(project, ProjectIndexer.Cause.PROJECT_DELETION);
verifyNotAuthorized(project, user);
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
- db.getDbClient().componentDao().delete(db.getSession(), project.uuid(), PROJECT);
+ db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), PROJECT);
db.commit();
SuggestionsWsResponse response = ws.newRequest()