#!/usr/bin/env bash | |||||
# the user "admin" becomes root and can create organizations | |||||
curl -XPOST -u admin:admin "http://localhost:9000/api/organizations/enable_support" |
this.scmRevisionId = scmRevisionId; | this.scmRevisionId = scmRevisionId; | ||||
} | } | ||||
/** | |||||
* | |||||
* @deprecated since 8.7. No longer used - it's always empty. | |||||
*/ | |||||
@Override | @Override | ||||
@Deprecated | |||||
public Optional<Organization> getOrganization() { | public Optional<Organization> getOrganization() { | ||||
return empty(); | return empty(); | ||||
} | } |
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
import org.sonar.db.component.ComponentDto; | import org.sonar.db.component.ComponentDto; | ||||
import org.sonar.db.component.ComponentUpdateDto; | import org.sonar.db.component.ComponentUpdateDto; | ||||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||||
import static java.util.Optional.ofNullable; | import static java.util.Optional.ofNullable; | ||||
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; | import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; | ||||
private final AnalysisMetadataHolder analysisMetadataHolder; | private final AnalysisMetadataHolder analysisMetadataHolder; | ||||
private final BranchPersister branchPersister; | private final BranchPersister branchPersister; | ||||
private final ProjectPersister projectPersister; | private final ProjectPersister projectPersister; | ||||
private final DefaultOrganizationProvider defaultOrganizationProvider; | |||||
public PersistComponentsStep(DbClient dbClient, TreeRootHolder treeRootHolder, System2 system2, | public PersistComponentsStep(DbClient dbClient, TreeRootHolder treeRootHolder, System2 system2, | ||||
MutableDisabledComponentsHolder disabledComponentsHolder, AnalysisMetadataHolder analysisMetadataHolder, | MutableDisabledComponentsHolder disabledComponentsHolder, AnalysisMetadataHolder analysisMetadataHolder, | ||||
BranchPersister branchPersister, ProjectPersister projectPersister, DefaultOrganizationProvider defaultOrganizationProvider) { | |||||
BranchPersister branchPersister, ProjectPersister projectPersister) { | |||||
this.dbClient = dbClient; | this.dbClient = dbClient; | ||||
this.treeRootHolder = treeRootHolder; | this.treeRootHolder = treeRootHolder; | ||||
this.system2 = system2; | this.system2 = system2; | ||||
this.analysisMetadataHolder = analysisMetadataHolder; | this.analysisMetadataHolder = analysisMetadataHolder; | ||||
this.branchPersister = branchPersister; | this.branchPersister = branchPersister; | ||||
this.projectPersister = projectPersister; | this.projectPersister = projectPersister; | ||||
this.defaultOrganizationProvider = defaultOrganizationProvider; | |||||
} | } | ||||
@Override | @Override | ||||
String componentUuid = component.getUuid(); | String componentUuid = component.getUuid(); | ||||
ComponentDto componentDto = new ComponentDto(); | ComponentDto componentDto = new ComponentDto(); | ||||
componentDto.setOrganizationUuid(defaultOrganizationProvider.get().getUuid()); | |||||
componentDto.setUuid(componentUuid); | componentDto.setUuid(componentUuid); | ||||
componentDto.setDbKey(componentKey); | componentDto.setDbKey(componentKey); | ||||
componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); | componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); |
@Test | @Test | ||||
@UseDataProvider("booleanValues") | @UseDataProvider("booleanValues") | ||||
public void organization_is_null_when_organization_are_disabled(boolean allStepsExecuted) { | |||||
public void organization_is_null(boolean allStepsExecuted) { | |||||
underTest.finished(allStepsExecuted); | underTest.finished(allStepsExecuted); | ||||
verify(postProjectAnalysisTask).finished(taskContextCaptor.capture()); | verify(postProjectAnalysisTask).finished(taskContextCaptor.capture()); |
import org.sonar.db.DbClient; | import org.sonar.db.DbClient; | ||||
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
import org.sonar.db.component.ComponentDao; | import org.sonar.db.component.ComponentDao; | ||||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||||
import static java.util.Collections.emptyList; | import static java.util.Collections.emptyList; | ||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | ||||
mock(MutableDisabledComponentsHolder.class), | mock(MutableDisabledComponentsHolder.class), | ||||
mock(AnalysisMetadataHolder.class), | mock(AnalysisMetadataHolder.class), | ||||
mock(BranchPersister.class), | mock(BranchPersister.class), | ||||
mock(ProjectPersister.class), | |||||
mock(DefaultOrganizationProvider.class)).execute(new TestComputationStepContext()); | |||||
mock(ProjectPersister.class)).execute(new TestComputationStepContext()); | |||||
} | } | ||||
} | } |
import org.sonar.db.component.BranchType; | import org.sonar.db.component.BranchType; | ||||
import org.sonar.db.component.ComponentDto; | import org.sonar.db.component.ComponentDto; | ||||
import org.sonar.db.component.ComponentTesting; | import org.sonar.db.component.ComponentTesting; | ||||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||||
import org.sonar.server.project.Project; | import org.sonar.server.project.Project; | ||||
import static org.apache.commons.lang.StringUtils.isEmpty; | import static org.apache.commons.lang.StringUtils.isEmpty; | ||||
@Rule | @Rule | ||||
public DbTester db = DbTester.create(System2.INSTANCE); | public DbTester db = DbTester.create(System2.INSTANCE); | ||||
public DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||||
@Rule | @Rule | ||||
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | ||||
@Rule | @Rule | ||||
BranchPersister branchPersister = mock(BranchPersister.class); | BranchPersister branchPersister = mock(BranchPersister.class); | ||||
ProjectPersister projectPersister = mock(ProjectPersister.class); | ProjectPersister projectPersister = mock(ProjectPersister.class); | ||||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister, | |||||
defaultOrganizationProvider); | |||||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister); | |||||
} | } | ||||
@Override | @Override | ||||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | assertThat(db.countRowsOfTable("components")).isEqualTo(3); | ||||
ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); | ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); | ||||
assertThat(directoryDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(directoryDto.name()).isEqualTo("dir"); | assertThat(directoryDto.name()).isEqualTo("dir"); | ||||
assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir"); | assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir"); | ||||
assertThat(directoryDto.description()).isNull(); | assertThat(directoryDto.description()).isNull(); | ||||
assertThat(directoryDto.getCreatedAt()).isEqualTo(now); | assertThat(directoryDto.getCreatedAt()).isEqualTo(now); | ||||
ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); | ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); | ||||
assertThat(fileDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(fileDto.name()).isEqualTo("Foo.java"); | assertThat(fileDto.name()).isEqualTo("Foo.java"); | ||||
assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java"); | assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java"); | ||||
assertThat(fileDto.description()).isNull(); | assertThat(fileDto.description()).isNull(); | ||||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | assertThat(db.countRowsOfTable("components")).isEqualTo(3); | ||||
ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); | ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); | ||||
assertThat(directoryDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(directoryDto.name()).isEqualTo("dir"); | assertThat(directoryDto.name()).isEqualTo("dir"); | ||||
assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir"); | assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir"); | ||||
assertThat(directoryDto.description()).isNull(); | assertThat(directoryDto.description()).isNull(); | ||||
assertThat(directoryDto.getCreatedAt()).isEqualTo(now); | assertThat(directoryDto.getCreatedAt()).isEqualTo(now); | ||||
ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); | ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); | ||||
assertThat(fileDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(fileDto.name()).isEqualTo("Foo.java"); | assertThat(fileDto.name()).isEqualTo("Foo.java"); | ||||
assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java"); | assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java"); | ||||
assertThat(fileDto.description()).isNull(); | assertThat(fileDto.description()).isNull(); |
import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto; | import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto; | ||||
public class UpdateQualityProfilesLastUsedDateStepTest { | public class UpdateQualityProfilesLastUsedDateStepTest { | ||||
static final long ANALYSIS_DATE = 1_123_456_789L; | |||||
private static final long ANALYSIS_DATE = 1_123_456_789L; | |||||
private static final Component PROJECT = ReportComponent.DUMB_PROJECT; | private static final Component PROJECT = ReportComponent.DUMB_PROJECT; | ||||
private QProfileDto sonarWayJava = newProfile("sonar-way-java"); | private QProfileDto sonarWayJava = newProfile("sonar-way-java"); | ||||
private QProfileDto sonarWayPhp = newProfile("sonar-way-php"); | private QProfileDto sonarWayPhp = newProfile("sonar-way-php"); |
import org.sonar.db.component.ComponentDbTester; | import org.sonar.db.component.ComponentDbTester; | ||||
import org.sonar.db.component.ComponentDto; | import org.sonar.db.component.ComponentDto; | ||||
import org.sonar.db.component.ComponentTesting; | import org.sonar.db.component.ComponentTesting; | ||||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||||
@Rule | @Rule | ||||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | public DbTester dbTester = DbTester.create(System2.INSTANCE); | ||||
public DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester); | |||||
@Rule | @Rule | ||||
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | ||||
@Rule | @Rule | ||||
analysisMetadataHolder.setBranch(new DefaultBranchImpl()); | analysisMetadataHolder.setBranch(new DefaultBranchImpl()); | ||||
BranchPersister branchPersister = mock(BranchPersister.class); | BranchPersister branchPersister = mock(BranchPersister.class); | ||||
ProjectPersister projectPersister = mock(ProjectPersister.class); | ProjectPersister projectPersister = mock(ProjectPersister.class); | ||||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister, | |||||
defaultOrganizationProvider); | |||||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister); | |||||
} | } | ||||
@Override | @Override | ||||
private ComponentDto newViewDto() { | private ComponentDto newViewDto() { | ||||
return ComponentTesting.newView(VIEW_UUID) | return ComponentTesting.newView(VIEW_UUID) | ||||
.setOrganizationUuid(defaultOrganizationProvider.get().getUuid()) | |||||
.setDbKey(VIEW_KEY) | .setDbKey(VIEW_KEY) | ||||
.setName(VIEW_NAME); | .setName(VIEW_NAME); | ||||
} | } | ||||
* Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} | * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} | ||||
*/ | */ | ||||
private void assertDtoIsView(ComponentDto dto) { | private void assertDtoIsView(ComponentDto dto) { | ||||
assertThat(dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(dto.name()).isEqualTo(VIEW_NAME); | assertThat(dto.name()).isEqualTo(VIEW_NAME); | ||||
assertThat(dto.longName()).isEqualTo(VIEW_NAME); | assertThat(dto.longName()).isEqualTo(VIEW_NAME); | ||||
assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); | assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); | ||||
* Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} | * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} | ||||
*/ | */ | ||||
private void assertDtoIsApplication(ComponentDto dto) { | private void assertDtoIsApplication(ComponentDto dto) { | ||||
assertThat(dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(dto.name()).isEqualTo(VIEW_NAME); | assertThat(dto.name()).isEqualTo(VIEW_NAME); | ||||
assertThat(dto.longName()).isEqualTo(VIEW_NAME); | assertThat(dto.longName()).isEqualTo(VIEW_NAME); | ||||
assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); | assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); | ||||
* Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)} | * Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)} | ||||
*/ | */ | ||||
private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) { | private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) { | ||||
assertThat(sv1Dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME); | assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME); | ||||
assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME); | assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME); | ||||
assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION); | assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION); | ||||
} | } | ||||
private void assertDtoIsProjectView1(ComponentDto pv1Dto, ComponentDto viewDto, ComponentDto parentViewDto, ComponentDto project) { | private void assertDtoIsProjectView1(ComponentDto pv1Dto, ComponentDto viewDto, ComponentDto parentViewDto, ComponentDto project) { | ||||
assertThat(pv1Dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||||
assertThat(pv1Dto.name()).isEqualTo(PROJECT_VIEW_1_NAME); | assertThat(pv1Dto.name()).isEqualTo(PROJECT_VIEW_1_NAME); | ||||
assertThat(pv1Dto.longName()).isEqualTo(PROJECT_VIEW_1_NAME); | assertThat(pv1Dto.longName()).isEqualTo(PROJECT_VIEW_1_NAME); | ||||
assertThat(pv1Dto.description()).isNull(); | assertThat(pv1Dto.description()).isNull(); |
import org.sonar.server.notification.DefaultNotificationManager; | import org.sonar.server.notification.DefaultNotificationManager; | ||||
import org.sonar.server.notification.NotificationService; | import org.sonar.server.notification.NotificationService; | ||||
import org.sonar.server.notification.email.EmailNotificationChannel; | import org.sonar.server.notification.email.EmailNotificationChannel; | ||||
import org.sonar.server.organization.DefaultOrganizationProviderImpl; | |||||
import org.sonar.server.platform.OfficialDistribution; | import org.sonar.server.platform.OfficialDistribution; | ||||
import org.sonar.server.platform.ServerFileSystemImpl; | import org.sonar.server.platform.ServerFileSystemImpl; | ||||
import org.sonar.server.platform.ServerImpl; | import org.sonar.server.platform.ServerImpl; | ||||
ServerIdChecksum.class, | ServerIdChecksum.class, | ||||
UriReader.class, | UriReader.class, | ||||
ServerImpl.class, | ServerImpl.class, | ||||
DefaultOrganizationProviderImpl.class, | |||||
SynchronousAsyncExecution.class); | SynchronousAsyncExecution.class); | ||||
} | } | ||||
public static final Set<String> TABLES = unmodifiableSet(new HashSet<>(asList( | public static final Set<String> TABLES = unmodifiableSet(new HashSet<>(asList( | ||||
"active_rules", | "active_rules", | ||||
"active_rule_parameters", | "active_rule_parameters", | ||||
"alm_app_installs", | |||||
"alm_settings", | "alm_settings", | ||||
"alm_pats", | "alm_pats", | ||||
"analysis_properties", | "analysis_properties", | ||||
"metrics", | "metrics", | ||||
"new_code_periods", | "new_code_periods", | ||||
"notifications", | "notifications", | ||||
"organizations", | |||||
"organization_alm_bindings", | |||||
"organization_members", | |||||
"org_qprofiles", | "org_qprofiles", | ||||
"org_quality_gates", | |||||
"permission_templates", | "permission_templates", | ||||
"perm_templates_users", | "perm_templates_users", | ||||
"perm_templates_groups", | "perm_templates_groups", |
* Data is truncated between each tests. The schema is created between each test. | * Data is truncated between each tests. The schema is created between each test. | ||||
*/ | */ | ||||
public class CoreDbTester extends AbstractDbTester<CoreTestDb> { | public class CoreDbTester extends AbstractDbTester<CoreTestDb> { | ||||
private final DefaultOrganizationTesting defaultOrganizationTesting; | |||||
private CoreDbTester(CoreTestDb testDb) { | private CoreDbTester(CoreTestDb testDb) { | ||||
super(testDb); | super(testDb); | ||||
this.defaultOrganizationTesting = new DefaultOrganizationTesting(this); | |||||
} | } | ||||
public static CoreDbTester createForSchema(Class testClass, String filename) { | public static CoreDbTester createForSchema(Class testClass, String filename) { | ||||
protected void after() { | protected void after() { | ||||
db.stop(); | db.stop(); | ||||
} | } | ||||
public DefaultOrganizationTesting defaultOrganization() { | |||||
return defaultOrganizationTesting; | |||||
} | |||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.db; | |||||
public class DefaultOrganizationTesting { | |||||
private static final String TABLE_ORGANIZATIONS = "organizations"; | |||||
private static final String DEFAULT_ORGANIZATION_UUID = "def-org"; | |||||
private final CoreDbTester db; | |||||
public DefaultOrganizationTesting(CoreDbTester db) { | |||||
this.db = db; | |||||
} | |||||
public String setupDefaultOrganization() { | |||||
insertInternalProperty(DEFAULT_ORGANIZATION_UUID); | |||||
insertOrganization(DEFAULT_ORGANIZATION_UUID); | |||||
return DEFAULT_ORGANIZATION_UUID; | |||||
} | |||||
public String insertOrganization() { | |||||
insertOrganization(DEFAULT_ORGANIZATION_UUID); | |||||
return DEFAULT_ORGANIZATION_UUID; | |||||
} | |||||
public void insertOrganization(String uuid) { | |||||
db.executeInsert( | |||||
TABLE_ORGANIZATIONS, | |||||
"UUID", uuid, | |||||
"KEE", uuid, | |||||
"NAME", uuid, | |||||
"CREATED_AT", "1000", | |||||
"UPDATED_AT", "1000"); | |||||
} | |||||
public String insertInternalProperty() { | |||||
insertInternalProperty(DEFAULT_ORGANIZATION_UUID); | |||||
return DEFAULT_ORGANIZATION_UUID; | |||||
} | |||||
public void insertInternalProperty(String defaultOrganizationUuid) { | |||||
db.executeInsert( | |||||
"INTERNAL_PROPERTIES", | |||||
"KEE", "organization.default", | |||||
"IS_EMPTY", "false", | |||||
"TEXT_VALUE", defaultOrganizationUuid); | |||||
} | |||||
} |
import org.sonar.db.metric.MetricDao; | import org.sonar.db.metric.MetricDao; | ||||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | import org.sonar.db.newcodeperiod.NewCodePeriodDao; | ||||
import org.sonar.db.notification.NotificationQueueDao; | import org.sonar.db.notification.NotificationQueueDao; | ||||
import org.sonar.db.organization.OrganizationDao; | |||||
import org.sonar.db.permission.AuthorizationDao; | import org.sonar.db.permission.AuthorizationDao; | ||||
import org.sonar.db.permission.GroupPermissionDao; | import org.sonar.db.permission.GroupPermissionDao; | ||||
import org.sonar.db.permission.UserPermissionDao; | import org.sonar.db.permission.UserPermissionDao; | ||||
MetricDao.class, | MetricDao.class, | ||||
NewCodePeriodDao.class, | NewCodePeriodDao.class, | ||||
NotificationQueueDao.class, | NotificationQueueDao.class, | ||||
OrganizationDao.class, | |||||
PermissionTemplateCharacteristicDao.class, | PermissionTemplateCharacteristicDao.class, | ||||
PermissionTemplateDao.class, | PermissionTemplateDao.class, | ||||
PluginDao.class, | PluginDao.class, |
import org.sonar.db.metric.MetricDao; | import org.sonar.db.metric.MetricDao; | ||||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | import org.sonar.db.newcodeperiod.NewCodePeriodDao; | ||||
import org.sonar.db.notification.NotificationQueueDao; | import org.sonar.db.notification.NotificationQueueDao; | ||||
import org.sonar.db.organization.OrganizationDao; | |||||
import org.sonar.db.permission.AuthorizationDao; | import org.sonar.db.permission.AuthorizationDao; | ||||
import org.sonar.db.permission.GroupPermissionDao; | import org.sonar.db.permission.GroupPermissionDao; | ||||
import org.sonar.db.permission.UserPermissionDao; | import org.sonar.db.permission.UserPermissionDao; | ||||
private final SchemaMigrationDao schemaMigrationDao; | private final SchemaMigrationDao schemaMigrationDao; | ||||
private final AuthorizationDao authorizationDao; | private final AuthorizationDao authorizationDao; | ||||
private final OrganizationDao organizationDao; | |||||
private final QualityProfileDao qualityProfileDao; | private final QualityProfileDao qualityProfileDao; | ||||
private final QualityProfileExportDao qualityProfileExportDao; | private final QualityProfileExportDao qualityProfileExportDao; | ||||
private final PropertiesDao propertiesDao; | private final PropertiesDao propertiesDao; | ||||
projectAlmSettingDao = getDao(map, ProjectAlmSettingDao.class); | projectAlmSettingDao = getDao(map, ProjectAlmSettingDao.class); | ||||
schemaMigrationDao = getDao(map, SchemaMigrationDao.class); | schemaMigrationDao = getDao(map, SchemaMigrationDao.class); | ||||
authorizationDao = getDao(map, AuthorizationDao.class); | authorizationDao = getDao(map, AuthorizationDao.class); | ||||
organizationDao = getDao(map, OrganizationDao.class); | |||||
qualityProfileDao = getDao(map, QualityProfileDao.class); | qualityProfileDao = getDao(map, QualityProfileDao.class); | ||||
qualityProfileExportDao = getDao(map, QualityProfileExportDao.class); | qualityProfileExportDao = getDao(map, QualityProfileExportDao.class); | ||||
propertiesDao = getDao(map, PropertiesDao.class); | propertiesDao = getDao(map, PropertiesDao.class); | ||||
return authorizationDao; | return authorizationDao; | ||||
} | } | ||||
public OrganizationDao organizationDao() { | |||||
return organizationDao; | |||||
} | |||||
public IssueDao issueDao() { | public IssueDao issueDao() { | ||||
return issueDao; | return issueDao; | ||||
} | } |
import org.sonar.db.newcodeperiod.NewCodePeriodMapper; | import org.sonar.db.newcodeperiod.NewCodePeriodMapper; | ||||
import org.sonar.db.notification.NotificationQueueDto; | import org.sonar.db.notification.NotificationQueueDto; | ||||
import org.sonar.db.notification.NotificationQueueMapper; | import org.sonar.db.notification.NotificationQueueMapper; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.organization.OrganizationMapper; | |||||
import org.sonar.db.permission.AuthorizationMapper; | import org.sonar.db.permission.AuthorizationMapper; | ||||
import org.sonar.db.permission.GroupPermissionDto; | import org.sonar.db.permission.GroupPermissionDto; | ||||
import org.sonar.db.permission.GroupPermissionMapper; | import org.sonar.db.permission.GroupPermissionMapper; | ||||
confBuilder.loadAlias("Issue", IssueDto.class); | confBuilder.loadAlias("Issue", IssueDto.class); | ||||
confBuilder.loadAlias("Measure", MeasureDto.class); | confBuilder.loadAlias("Measure", MeasureDto.class); | ||||
confBuilder.loadAlias("NotificationQueue", NotificationQueueDto.class); | confBuilder.loadAlias("NotificationQueue", NotificationQueueDto.class); | ||||
confBuilder.loadAlias("Organization", OrganizationDto.class); | |||||
confBuilder.loadAlias("PermissionTemplateCharacteristic", PermissionTemplateCharacteristicDto.class); | confBuilder.loadAlias("PermissionTemplateCharacteristic", PermissionTemplateCharacteristicDto.class); | ||||
confBuilder.loadAlias("PermissionTemplateGroup", PermissionTemplateGroupDto.class); | confBuilder.loadAlias("PermissionTemplateGroup", PermissionTemplateGroupDto.class); | ||||
confBuilder.loadAlias("PermissionTemplate", PermissionTemplateDto.class); | confBuilder.loadAlias("PermissionTemplate", PermissionTemplateDto.class); | ||||
MetricMapper.class, | MetricMapper.class, | ||||
NewCodePeriodMapper.class, | NewCodePeriodMapper.class, | ||||
NotificationQueueMapper.class, | NotificationQueueMapper.class, | ||||
OrganizationMapper.class, | |||||
PermissionTemplateCharacteristicMapper.class, | PermissionTemplateCharacteristicMapper.class, | ||||
PermissionTemplateMapper.class, | PermissionTemplateMapper.class, | ||||
PluginMapper.class, | PluginMapper.class, |
checkThatNotTooManyConditions(query.getComponentUuids(), "Too many component UUIDs in query"); | checkThatNotTooManyConditions(query.getComponentUuids(), "Too many component UUIDs in query"); | ||||
} | } | ||||
public List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(DbSession dbSession, String organizationUuid) { | |||||
return mapper(dbSession).selectPrivateProjectsWithNcloc(organizationUuid); | |||||
public List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(DbSession dbSession) { | |||||
return mapper(dbSession).selectPrivateProjectsWithNcloc(); | |||||
} | } | ||||
public boolean existAnyOfComponentsWithQualifiers(DbSession session, Collection<String> componentKeys, Set<String> qualifiers) { | public boolean existAnyOfComponentsWithQualifiers(DbSession session, Collection<String> componentKeys, Set<String> qualifiers) { |
import com.google.common.base.Strings; | import com.google.common.base.Strings; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Objects; | |||||
import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||
import javax.annotation.CheckForNull; | import javax.annotation.CheckForNull; | ||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
public static final String UUID_PATH_OF_ROOT = UUID_PATH_SEPARATOR; | public static final String UUID_PATH_OF_ROOT = UUID_PATH_SEPARATOR; | ||||
private static final Splitter UUID_PATH_SPLITTER = Splitter.on(UUID_PATH_SEPARATOR).omitEmptyStrings(); | private static final Splitter UUID_PATH_SPLITTER = Splitter.on(UUID_PATH_SEPARATOR).omitEmptyStrings(); | ||||
/** | |||||
* The UUID of the organization the component belongs to. Can't be null in DB. | |||||
*/ | |||||
private String organizationUuid; | |||||
/** | /** | ||||
* Non-empty and unique functional key. Do not rename, used by MyBatis. | * Non-empty and unique functional key. Do not rename, used by MyBatis. | ||||
*/ | */ | ||||
return buildLikeValue(formatUuidPathFromParent(this), WildcardPosition.AFTER); | return buildLikeValue(formatUuidPathFromParent(this), WildcardPosition.AFTER); | ||||
} | } | ||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public String getOrganizationUuid() { | |||||
return organizationUuid; | |||||
} | |||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public ComponentDto setOrganizationUuid(String organizationUuid) { | |||||
this.organizationUuid = organizationUuid; | |||||
return this; | |||||
} | |||||
public String uuid() { | public String uuid() { | ||||
return uuid; | return uuid; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
ComponentDto that = (ComponentDto) o; | ComponentDto that = (ComponentDto) o; | ||||
return uuid != null ? uuid.equals(that.uuid) : (that.uuid == null); | |||||
return Objects.equals(uuid, that.uuid); | |||||
} | } | ||||
public ComponentDto copy() { | public ComponentDto copy() { | ||||
ComponentDto copy = new ComponentDto(); | ComponentDto copy = new ComponentDto(); | ||||
copy.projectUuid = projectUuid; | copy.projectUuid = projectUuid; | ||||
copy.organizationUuid = organizationUuid; | |||||
copy.kee = kee; | copy.kee = kee; | ||||
copy.uuid = uuid; | copy.uuid = uuid; | ||||
copy.uuidPath = uuidPath; | copy.uuidPath = uuidPath; |
int countEnabledModulesByProjectUuid(@Param("projectUuid") String projectUuid); | int countEnabledModulesByProjectUuid(@Param("projectUuid") String projectUuid); | ||||
/** | |||||
* Counts the number of components with the specified id belonging to the specified organization. | |||||
* | |||||
* @return 1 or 0. Either because the organization uuid is not the one of the component or because the component does | |||||
* not exist. | |||||
*/ | |||||
int countComponentByOrganizationAndUuid(@Param("organizationUuid") String organizationUuid, @Param("componentUuid") String componentUuid); | |||||
List<ComponentDto> selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds); | List<ComponentDto> selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds); | ||||
int countByQuery(@Param("query") ComponentQuery query); | int countByQuery(@Param("query") ComponentQuery query); | ||||
List<KeyWithUuidDto> selectAllSiblingComponentKeysHavingOpenIssues(@Param("referenceBranchUuid") String referenceBranchUuid, | List<KeyWithUuidDto> selectAllSiblingComponentKeysHavingOpenIssues(@Param("referenceBranchUuid") String referenceBranchUuid, | ||||
@Param("currentBranchUuid") String currentBranchUuid); | @Param("currentBranchUuid") String currentBranchUuid); | ||||
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(@Param("organizationUuid") String organizationUuid); | |||||
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(); | |||||
List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(String projectKey); | List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(String projectKey); | ||||
CoreMetrics.NEW_LINES_KEY, | CoreMetrics.NEW_LINES_KEY, | ||||
CoreMetrics.NEW_RELIABILITY_RATING_KEY); | CoreMetrics.NEW_RELIABILITY_RATING_KEY); | ||||
private static final String SQL_PROJECTS = "SELECT p.organization_uuid, p.uuid, p.kee, p.name, s.created_at, p.tags, p.qualifier " + | |||||
private static final String SQL_PROJECTS = "SELECT p.uuid, p.kee, p.name, s.created_at, p.tags, p.qualifier " + | |||||
"FROM projects p " + | "FROM projects p " + | ||||
"LEFT OUTER JOIN snapshots s ON s.component_uuid=p.uuid AND s.islast=? " + | "LEFT OUTER JOIN snapshots s ON s.component_uuid=p.uuid AND s.islast=? " + | ||||
"WHERE p.qualifier in (?, ?)"; | "WHERE p.qualifier in (?, ?)"; | ||||
try (PreparedStatement stmt = createProjectsStatement(session, projectUuid); | try (PreparedStatement stmt = createProjectsStatement(session, projectUuid); | ||||
ResultSet rs = stmt.executeQuery()) { | ResultSet rs = stmt.executeQuery()) { | ||||
while (rs.next()) { | while (rs.next()) { | ||||
String orgUuid = rs.getString(1); | |||||
String uuid = rs.getString(2); | |||||
String key = rs.getString(3); | |||||
String name = rs.getString(4); | |||||
Long analysisDate = DatabaseUtils.getLong(rs, 5); | |||||
List<String> tags = readDbTags(DatabaseUtils.getString(rs, 6)); | |||||
String qualifier = rs.getString(7); | |||||
Project project = new Project(orgUuid, uuid, key, name, qualifier, tags, analysisDate); | |||||
String uuid = rs.getString(1); | |||||
String key = rs.getString(2); | |||||
String name = rs.getString(3); | |||||
Long analysisDate = DatabaseUtils.getLong(rs, 4); | |||||
List<String> tags = readDbTags(DatabaseUtils.getString(rs, 5)); | |||||
String qualifier = rs.getString(6); | |||||
Project project = new Project(uuid, key, name, qualifier, tags, analysisDate); | |||||
projects.add(project); | projects.add(project); | ||||
} | } | ||||
return projects; | return projects; | ||||
} | } | ||||
public static class Project { | public static class Project { | ||||
private final String organizationUuid; | |||||
private final String uuid; | private final String uuid; | ||||
private final String key; | private final String key; | ||||
private final String name; | private final String name; | ||||
private final Long analysisDate; | private final Long analysisDate; | ||||
private final List<String> tags; | private final List<String> tags; | ||||
public Project(String organizationUuid, String uuid, String key, String name, String qualifier, List<String> tags, @Nullable Long analysisDate) { | |||||
this.organizationUuid = organizationUuid; | |||||
public Project(String uuid, String key, String name, String qualifier, List<String> tags, @Nullable Long analysisDate) { | |||||
this.uuid = uuid; | this.uuid = uuid; | ||||
this.key = key; | this.key = key; | ||||
this.name = name; | this.name = name; | ||||
this.analysisDate = analysisDate; | this.analysisDate = analysisDate; | ||||
} | } | ||||
public String getOrganizationUuid() { | |||||
return organizationUuid; | |||||
} | |||||
public String getUuid() { | public String getUuid() { | ||||
return uuid; | return uuid; | ||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.db.organization; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import java.util.Optional; | |||||
import java.util.Set; | |||||
import org.sonar.api.utils.System2; | |||||
import org.sonar.db.Dao; | |||||
import org.sonar.db.DbSession; | |||||
import org.sonar.db.Pagination; | |||||
import org.sonar.db.component.BranchType; | |||||
import org.sonar.db.permission.template.DefaultTemplates; | |||||
import org.sonar.db.property.InternalPropertiesDao; | |||||
import org.sonar.db.user.GroupDto; | |||||
import static com.google.common.base.Preconditions.checkState; | |||||
import static java.util.Objects.requireNonNull; | |||||
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY; | |||||
import static org.sonar.db.DatabaseUtils.executeLargeInputs; | |||||
import static org.sonar.db.DatabaseUtils.executeLargeUpdates; | |||||
public class OrganizationDao implements Dao { | |||||
/** | |||||
* The UUID of the default organization. | |||||
* Can't be null unless SQ is strongly corrupted. | |||||
*/ | |||||
public static final String DEFAULT_ORGANIZATION = "organization.default"; | |||||
private final System2 system2; | |||||
private final InternalPropertiesDao internalPropertiesDao; | |||||
public OrganizationDao(System2 system2, InternalPropertiesDao internalPropertiesDao) { | |||||
this.system2 = system2; | |||||
this.internalPropertiesDao = internalPropertiesDao; | |||||
} | |||||
public void insert(DbSession dbSession, OrganizationDto organization, boolean newProjectPrivate) { | |||||
checkDto(organization); | |||||
long now = system2.now(); | |||||
organization.setCreatedAt(now); | |||||
organization.setUpdatedAt(now); | |||||
getMapper(dbSession).insert(organization, newProjectPrivate); | |||||
} | |||||
// TODO remove after getting rid of organization code | |||||
public OrganizationDto getDefaultOrganization(DbSession dbSession) { | |||||
Optional<String> uuid = internalPropertiesDao.selectByKey(dbSession, DEFAULT_ORGANIZATION); | |||||
checkState(uuid.isPresent() && !uuid.get().isEmpty(), "No Default organization uuid configured"); | |||||
return getMapper(dbSession).selectByUuid(uuid.get()); | |||||
} | |||||
public int countByQuery(DbSession dbSession, OrganizationQuery organizationQuery) { | |||||
requireNonNull(organizationQuery, "organizationQuery can't be null"); | |||||
return getMapper(dbSession).countByQuery(organizationQuery); | |||||
} | |||||
public List<OrganizationDto> selectByQuery(DbSession dbSession, OrganizationQuery organizationQuery, Pagination pagination) { | |||||
requireNonNull(organizationQuery, "organizationQuery can't be null"); | |||||
return getMapper(dbSession).selectByQuery(organizationQuery, pagination); | |||||
} | |||||
public Optional<OrganizationDto> selectByUuid(DbSession dbSession, String uuid) { | |||||
checkUuid(uuid); | |||||
return Optional.ofNullable(getMapper(dbSession).selectByUuid(uuid)); | |||||
} | |||||
public Optional<OrganizationDto> selectByKey(DbSession dbSession, String key) { | |||||
requireNonNull(key, "key can't be null"); | |||||
return Optional.ofNullable(getMapper(dbSession).selectByKey(key)); | |||||
} | |||||
public List<OrganizationDto> selectByUuids(DbSession dbSession, Set<String> organizationUuids) { | |||||
return executeLargeInputs(organizationUuids, getMapper(dbSession)::selectByUuids); | |||||
} | |||||
public List<OrganizationDto> selectByPermission(DbSession dbSession, String userUuid, String permission) { | |||||
return getMapper(dbSession).selectByPermission(userUuid, permission); | |||||
} | |||||
public List<String> selectAllUuids(DbSession dbSession) { | |||||
return getMapper(dbSession).selectAllUuids(); | |||||
} | |||||
/** | |||||
* Retrieve the default template of the specified organization if: | |||||
* <ol> | |||||
* <li>the specified organization exists</li> | |||||
* <li>the project default permission template is defined</li> | |||||
* </ol> | |||||
*/ | |||||
public Optional<DefaultTemplates> getDefaultTemplates(DbSession dbSession, String organizationUuid) { | |||||
checkUuid(organizationUuid); | |||||
return Optional.ofNullable(getMapper(dbSession).selectDefaultTemplatesByUuid(organizationUuid)); | |||||
} | |||||
public void setDefaultTemplates(DbSession dbSession, String uuid, DefaultTemplates defaultTemplates) { | |||||
checkUuid(uuid); | |||||
checkDefaultTemplates(defaultTemplates); | |||||
long now = system2.now(); | |||||
getMapper(dbSession).updateDefaultTemplates(uuid, defaultTemplates, now); | |||||
} | |||||
public Optional<String> getDefaultGroupUuid(DbSession dbSession, String organizationUuid) { | |||||
checkUuid(organizationUuid); | |||||
return Optional.ofNullable(getMapper(dbSession).selectDefaultGroupUuidByUuid(organizationUuid)); | |||||
} | |||||
public void setDefaultGroupUuid(DbSession dbSession, String uuid, GroupDto defaultGroup) { | |||||
checkUuid(uuid); | |||||
String defaultGroupUuid = requireNonNull(defaultGroup, "Default group cannot be null").getUuid(); | |||||
getMapper(dbSession).updateDefaultGroupUuid(uuid, requireNonNull(defaultGroupUuid, "Default group uuid cannot be null"), system2.now()); | |||||
} | |||||
public int update(DbSession dbSession, OrganizationDto organization) { | |||||
checkDto(organization); | |||||
organization.setUpdatedAt(system2.now()); | |||||
return getMapper(dbSession).update(organization); | |||||
} | |||||
public int deleteByUuid(DbSession dbSession, String uuid) { | |||||
return getMapper(dbSession).deleteByUuid(uuid); | |||||
} | |||||
public List<OrganizationWithNclocDto> selectOrganizationsWithNcloc(DbSession dbSession, List<String> organizationUuids) { | |||||
List<OrganizationWithNclocDto> result = new ArrayList<>(); | |||||
executeLargeUpdates(organizationUuids, chunk -> result.addAll(getMapper(dbSession).selectOrganizationsWithNcloc(NCLOC_KEY, chunk, BranchType.BRANCH))); | |||||
return result; | |||||
} | |||||
private static void checkDto(OrganizationDto organization) { | |||||
requireNonNull(organization, "OrganizationDto can't be null"); | |||||
} | |||||
private static OrganizationMapper getMapper(DbSession dbSession) { | |||||
return dbSession.getMapper(OrganizationMapper.class); | |||||
} | |||||
private static void checkUuid(String uuid) { | |||||
requireNonNull(uuid, "uuid can't be null"); | |||||
} | |||||
private static void checkDefaultTemplates(DefaultTemplates defaultTemplates) { | |||||
requireNonNull(defaultTemplates, "defaultTemplates can't be null"); | |||||
requireNonNull(defaultTemplates.getProjectUuid()); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.db.organization; | |||||
import java.util.Objects; | |||||
import javax.annotation.CheckForNull; | |||||
import javax.annotation.Nullable; | |||||
import org.sonar.api.server.authentication.UserIdentity; | |||||
public class OrganizationDto { | |||||
public enum Subscription { | |||||
/** | |||||
* Subscription of the default organization, only for SonarQube | |||||
*/ | |||||
SONARQUBE, | |||||
/** | |||||
* Organization that has not subscribed to a paid subscription, only for SonarCloud | |||||
*/ | |||||
FREE, | |||||
/** | |||||
* Organization that subscribed to paid plan subscription, only for SonarCloud | |||||
*/ | |||||
PAID | |||||
} | |||||
/** Technical unique identifier, can't be null */ | |||||
private String uuid; | |||||
/** | |||||
* Functional unique identifier, can't be null. | |||||
* | |||||
* On personal organization (created the first time the user authenticates), the key can have the following format : | |||||
* - When {@link UserIdentity#getLogin()} is not null, it's a slug of the login | |||||
* - When {@link UserIdentity#getLogin()} is null, it's a slug of the name appended to a random number | |||||
* | |||||
* Length is set to 255 (As login length is 255, the size must be at least 255). | |||||
*/ | |||||
private String key; | |||||
/** | |||||
* Name, can't be null. | |||||
* | |||||
* Length is set to 300, as it's generated from the key when no name is provided. | |||||
*/ | |||||
private String name; | |||||
/** description can't be null */ | |||||
private String description; | |||||
/** url can be null */ | |||||
private String url; | |||||
/** avatar url can be null */ | |||||
private String avatarUrl; | |||||
private Subscription subscription; | |||||
private String defaultGroupUuid; | |||||
private String defaultQualityGateUuid; | |||||
private long createdAt; | |||||
private long updatedAt; | |||||
public String getUuid() { | |||||
return uuid; | |||||
} | |||||
public OrganizationDto setUuid(String uuid) { | |||||
this.uuid = uuid; | |||||
return this; | |||||
} | |||||
public String getKey() { | |||||
return key; | |||||
} | |||||
public OrganizationDto setKey(String key) { | |||||
this.key = key; | |||||
return this; | |||||
} | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public OrganizationDto setName(String name) { | |||||
this.name = name; | |||||
return this; | |||||
} | |||||
@CheckForNull | |||||
public String getDescription() { | |||||
return description; | |||||
} | |||||
public OrganizationDto setDescription(@Nullable String description) { | |||||
this.description = description; | |||||
return this; | |||||
} | |||||
@CheckForNull | |||||
public String getUrl() { | |||||
return url; | |||||
} | |||||
public OrganizationDto setUrl(@Nullable String url) { | |||||
this.url = url; | |||||
return this; | |||||
} | |||||
@CheckForNull | |||||
public String getAvatarUrl() { | |||||
return avatarUrl; | |||||
} | |||||
public OrganizationDto setAvatarUrl(@Nullable String avatarUrl) { | |||||
this.avatarUrl = avatarUrl; | |||||
return this; | |||||
} | |||||
@CheckForNull | |||||
public String getDefaultGroupUuid() { | |||||
return defaultGroupUuid; | |||||
} | |||||
public OrganizationDto setDefaultGroupUuid(@Nullable String defaultGroupUuid) { | |||||
this.defaultGroupUuid = defaultGroupUuid; | |||||
return this; | |||||
} | |||||
public Subscription getSubscription() { | |||||
return subscription; | |||||
} | |||||
public OrganizationDto setSubscription(Subscription subscription) { | |||||
this.subscription = subscription; | |||||
return this; | |||||
} | |||||
public long getCreatedAt() { | |||||
return createdAt; | |||||
} | |||||
public OrganizationDto setCreatedAt(long createdAt) { | |||||
this.createdAt = createdAt; | |||||
return this; | |||||
} | |||||
public long getUpdatedAt() { | |||||
return updatedAt; | |||||
} | |||||
public OrganizationDto setUpdatedAt(long updatedAt) { | |||||
this.updatedAt = updatedAt; | |||||
return this; | |||||
} | |||||
public String getDefaultQualityGateUuid() { | |||||
return defaultQualityGateUuid; | |||||
} | |||||
public OrganizationDto setDefaultQualityGateUuid(String defaultQualityGateUuid) { | |||||
this.defaultQualityGateUuid = defaultQualityGateUuid; | |||||
return this; | |||||
} | |||||
@Override | |||||
public boolean equals(Object o) { | |||||
if (this == o) { | |||||
return true; | |||||
} | |||||
if (o == null || getClass() != o.getClass()) { | |||||
return false; | |||||
} | |||||
OrganizationDto that = (OrganizationDto) o; | |||||
return Objects.equals(uuid, that.uuid); | |||||
} | |||||
@Override | |||||
public int hashCode() { | |||||
return Objects.hash(uuid); | |||||
} | |||||
@Override | |||||
public String toString() { | |||||
return "OrganizationDto{" + | |||||
"uuid='" + uuid + '\'' + | |||||
", key='" + key + '\'' + | |||||
", name='" + name + '\'' + | |||||
", description='" + description + '\'' + | |||||
", url='" + url + '\'' + | |||||
", avatarUrl='" + avatarUrl + '\'' + | |||||
", defaultQualityGateUuid=" + defaultQualityGateUuid + | |||||
", subscription=" + subscription + | |||||
", createdAt=" + createdAt + | |||||
", updatedAt=" + updatedAt + | |||||
'}'; | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.db.organization; | |||||
import java.util.List; | |||||
import java.util.stream.Collectors; | |||||
import org.sonar.db.DbClient; | |||||
import org.sonar.db.DbSession; | |||||
import org.sonar.db.permission.GlobalPermission; | |||||
public class OrganizationHelper { | |||||
private static final String ADMIN_PERMISSION = GlobalPermission.ADMINISTER.getKey(); | |||||
private final DbClient dbClient; | |||||
public OrganizationHelper(DbClient dbClient) { | |||||
this.dbClient = dbClient; | |||||
} | |||||
public List<OrganizationDto> selectOrganizationsWithLastAdmin(DbSession dbSession, String userUuid) { | |||||
return dbClient.organizationDao().selectByPermission(dbSession, userUuid, ADMIN_PERMISSION).stream() | |||||
.filter(org -> isLastAdmin(dbSession, userUuid)) | |||||
.collect(Collectors.toList()); | |||||
} | |||||
private boolean isLastAdmin(DbSession dbSession, String userUuid) { | |||||
return dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingUser(dbSession, ADMIN_PERMISSION, userUuid) == 0; | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.db.organization; | |||||
import java.util.List; | |||||
import javax.annotation.CheckForNull; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import org.sonar.db.Pagination; | |||||
import org.sonar.db.component.BranchType; | |||||
import org.sonar.db.permission.template.DefaultTemplates; | |||||
public interface OrganizationMapper { | |||||
void insert(@Param("organization") OrganizationDto organization, @Param("newProjectPrivate") boolean newProjectPrivate); | |||||
int countByQuery(@Param("query") OrganizationQuery organizationQuery); | |||||
List<OrganizationDto> selectByQuery(@Param("query") OrganizationQuery organizationQuery, | |||||
@Param("pagination") Pagination pagination); | |||||
@CheckForNull | |||||
OrganizationDto selectByKey(@Param("key") String key); | |||||
@CheckForNull | |||||
OrganizationDto selectByUuid(@Param("uuid") String uuid); | |||||
List<OrganizationDto> selectByUuids(@Param("uuids") List<String> uuids); | |||||
List<OrganizationDto> selectByPermission(@Param("userUuid") String userUuid, @Param("permission") String permission); | |||||
List<String> selectAllUuids(); | |||||
DefaultTemplates selectDefaultTemplatesByUuid(@Param("uuid") String uuid); | |||||
String selectDefaultGroupUuidByUuid(@Param("uuid") String uuid); | |||||
boolean selectNewProjectPrivateByUuid(@Param("uuid") String uuid); | |||||
/** | |||||
* Update the organization with UUID specified by {@link OrganizationDto#getUuid()}. | |||||
* <p> | |||||
* This method ignores {@link OrganizationDto#getCreatedAt()} and {@link OrganizationDto#getKey()} | |||||
* (they are not updated). | |||||
* </p> | |||||
*/ | |||||
int update(@Param("organization") OrganizationDto organization); | |||||
void updateDefaultTemplates(@Param("organizationUuid") String organizationUuid, | |||||
@Param("defaultTemplates") DefaultTemplates defaultTemplates, @Param("now") long now); | |||||
void updateDefaultGroupUuid(@Param("organizationUuid") String organizationUuid, | |||||
@Param("defaultGroupUuid") String defaultGroupUuid, @Param("now") long now); | |||||
void updateDefaultQualityGate(@Param("organizationUuid") String organizationUuid, | |||||
@Param("defaultQualityGateUuid") String defaultQualityGateUuid, @Param("now") long now); | |||||
void updateNewProjectPrivate(@Param("organizationUuid") String organizationUuid, @Param("newProjectPrivate") boolean newProjectPrivate, @Param("now") long now); | |||||
int deleteByUuid(@Param("uuid") String uuid); | |||||
List<OrganizationWithNclocDto> selectOrganizationsWithNcloc( | |||||
@Param("ncloc") String ncloc, | |||||
@Param("organizationUuids") List<String> organizationUuids, | |||||
@Param("branchType") BranchType branchType); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.db.organization; | |||||
import java.util.Collection; | |||||
import java.util.Objects; | |||||
import java.util.Set; | |||||
import javax.annotation.CheckForNull; | |||||
import javax.annotation.Nullable; | |||||
import static org.sonar.core.util.stream.MoreCollectors.toSet; | |||||
public class OrganizationQuery { | |||||
private static final OrganizationQuery NO_FILTER = newOrganizationQueryBuilder().build(); | |||||
private final Set<String> keys; | |||||
private final boolean withAnalyses; | |||||
@Nullable | |||||
private final Long analyzedAfter; | |||||
private OrganizationQuery(Builder builder) { | |||||
this.keys = builder.keys; | |||||
this.withAnalyses = builder.withAnalyses; | |||||
this.analyzedAfter = builder.analyzedAfter; | |||||
} | |||||
@CheckForNull | |||||
public Set<String> getKeys() { | |||||
return keys; | |||||
} | |||||
public boolean isWithAnalyses() { | |||||
return withAnalyses; | |||||
} | |||||
@CheckForNull | |||||
public Long getAnalyzedAfter() { | |||||
return analyzedAfter; | |||||
} | |||||
public static OrganizationQuery returnAll() { | |||||
return NO_FILTER; | |||||
} | |||||
public static Builder newOrganizationQueryBuilder() { | |||||
return new Builder(); | |||||
} | |||||
public static class Builder { | |||||
private Set<String> keys; | |||||
private boolean withAnalyses = false; | |||||
@Nullable | |||||
private Long analyzedAfter; | |||||
private Builder() { | |||||
// use static factory method | |||||
} | |||||
public Builder setKeys(@Nullable Collection<String> keys) { | |||||
if (keys != null && !keys.isEmpty()) { | |||||
this.keys = keys.stream() | |||||
.filter(Objects::nonNull) | |||||
.collect(toSet(keys.size())); | |||||
} | |||||
return this; | |||||
} | |||||
public Builder setWithAnalyses() { | |||||
this.withAnalyses = true; | |||||
return this; | |||||
} | |||||
public Builder setAnalyzedAfter(long l) { | |||||
this.analyzedAfter = l; | |||||
return this; | |||||
} | |||||
public OrganizationQuery build() { | |||||
return new OrganizationQuery(this); | |||||
} | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
@ParametersAreNonnullByDefault | |||||
package org.sonar.db.organization; | |||||
import javax.annotation.ParametersAreNonnullByDefault; | |||||
} | } | ||||
/** | /** | ||||
* Loads all the permissions granted to anonymous user for the specified organization | |||||
* Loads all the permissions granted to anonymous user | |||||
*/ | */ | ||||
public Set<String> selectGlobalPermissionsOfAnonymous(DbSession dbSession) { | public Set<String> selectGlobalPermissionsOfAnonymous(DbSession dbSession) { | ||||
return mapper(dbSession).selectGlobalPermissionsOfAnonymous(); | return mapper(dbSession).selectGlobalPermissionsOfAnonymous(); |
private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup"; | private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup"; | ||||
/** | /** | ||||
* Returns the names of the groups that match the given query, for the given organization. | |||||
* Returns the names of the groups that match the given query. | |||||
* The virtual group "Anyone" may be returned as the value {@link DefaultGroups#ANYONE}. | * The virtual group "Anyone" may be returned as the value {@link DefaultGroups#ANYONE}. | ||||
* @return group names, sorted in alphabetical order | * @return group names, sorted in alphabetical order | ||||
*/ | */ | ||||
} | } | ||||
/** | /** | ||||
* Select global or project permission of given groups and organization. Anyone virtual group is supported | |||||
* Select global or project permission of given groups. Anyone virtual group is supported | |||||
* through the value "zero" (0L) in {@code groupUuids}. | * through the value "zero" (0L) in {@code groupUuids}. | ||||
*/ | */ | ||||
public List<GroupPermissionDto> selectByGroupUuids(DbSession dbSession, List<String> groupUuids, @Nullable String projectUuid) { | public List<GroupPermissionDto> selectByGroupUuids(DbSession dbSession, List<String> groupUuids, @Nullable String projectUuid) { |
private String tags; | private String tags; | ||||
private long createdAt; | private long createdAt; | ||||
private long updatedAt; | private long updatedAt; | ||||
private String organizationUuid; | |||||
public ProjectDto() { | public ProjectDto() { | ||||
// nothing to do here | // nothing to do here | ||||
return this; | return this; | ||||
} | } | ||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public String getOrganizationUuid() { | |||||
return organizationUuid; | |||||
} | |||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public ProjectDto setOrganizationUuid(String organizationUuid) { | |||||
this.organizationUuid = organizationUuid; | |||||
return this; | |||||
} | |||||
public String getName() { | public String getName() { | ||||
return name; | return name; | ||||
} | } |
save(getMapper(session), property.getKey(), property.getUserUuid(), property.getComponentUuid(), property.getValue()); | save(getMapper(session), property.getKey(), property.getUserUuid(), property.getComponentUuid(), property.getValue()); | ||||
} | } | ||||
private void save(PropertiesMapper mapper, String key, | |||||
@Nullable String userUuid, @Nullable String componentUuid, @Nullable String value) { | |||||
private void save(PropertiesMapper mapper, String key, @Nullable String userUuid, @Nullable String componentUuid, @Nullable String value) { | |||||
checkKey(key); | checkKey(key); | ||||
long now = system2.now(); | long now = system2.now(); |
int delete(@Param("key") String key, @Nullable @Param("userUuid") String userUuid, @Nullable @Param("componentUuid") String componentUuid); | int delete(@Param("key") String key, @Nullable @Param("userUuid") String userUuid, @Nullable @Param("componentUuid") String componentUuid); | ||||
int deleteById(long id); | |||||
int deleteProjectProperty(@Param("key") String key, @Param("componentUuid") String componentUuid); | int deleteProjectProperty(@Param("key") String key, @Param("componentUuid") String componentUuid); | ||||
int deleteProjectProperties(@Param("key") String key, @Param("value") String value); | int deleteProjectProperties(@Param("key") String key, @Param("value") String value); |
/** | /** | ||||
* @param dbSession | * @param dbSession | ||||
* @param name non-null group name | * @param name non-null group name | ||||
* @return the group with the given organization key and name | |||||
* @return the group with the given name | |||||
*/ | */ | ||||
public Optional<GroupDto> selectByName(DbSession dbSession, String name) { | public Optional<GroupDto> selectByName(DbSession dbSession, String name) { | ||||
return Optional.ofNullable(mapper(dbSession).selectByName(name)); | return Optional.ofNullable(mapper(dbSession).selectByName(name)); |
import org.sonar.db.Dao; | import org.sonar.db.Dao; | ||||
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
import org.sonar.db.component.ComponentDto; | import org.sonar.db.component.ComponentDto; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.project.ProjectDto; | import org.sonar.db.project.ProjectDto; | ||||
import static java.util.Locale.ENGLISH; | import static java.util.Locale.ENGLISH; | ||||
mapper(dbSession).deactivateUser(user.getLogin(), system2.now()); | mapper(dbSession).deactivateUser(user.getLogin(), system2.now()); | ||||
} | } | ||||
public void cleanHomepage(DbSession dbSession, OrganizationDto organization) { | |||||
mapper(dbSession).clearHomepages("ORGANIZATION", organization.getUuid(), system2.now()); | |||||
} | |||||
public void cleanHomepage(DbSession dbSession, ProjectDto project) { | public void cleanHomepage(DbSession dbSession, ProjectDto project) { | ||||
mapper(dbSession).clearHomepages("PROJECT", project.getUuid(), system2.now()); | mapper(dbSession).clearHomepages("PROJECT", project.getUuid(), system2.now()); | ||||
} | } |
import org.sonar.api.utils.System2; | import org.sonar.api.utils.System2; | ||||
import org.sonar.db.Dao; | import org.sonar.db.Dao; | ||||
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.project.ProjectDto; | import org.sonar.db.project.ProjectDto; | ||||
import org.sonar.db.property.InternalPropertiesDao; | |||||
import static com.google.common.base.Preconditions.checkState; | |||||
public class WebhookDao implements Dao { | public class WebhookDao implements Dao { | ||||
private final System2 system2; | private final System2 system2; | ||||
private final InternalPropertiesDao internalPropertiesDao; | |||||
public WebhookDao(System2 system2, InternalPropertiesDao internalPropertiesDao) { | |||||
public WebhookDao(System2 system2) { | |||||
this.system2 = system2; | this.system2 = system2; | ||||
this.internalPropertiesDao = internalPropertiesDao; | |||||
} | } | ||||
public List<WebhookDto> selectAll(DbSession dbSession) { | public List<WebhookDto> selectAll(DbSession dbSession) { | ||||
return Optional.ofNullable(mapper(dbSession).selectByUuid(uuid)); | return Optional.ofNullable(mapper(dbSession).selectByUuid(uuid)); | ||||
} | } | ||||
// TODO remove | |||||
@Deprecated | |||||
public List<WebhookDto> selectByOrganization(DbSession dbSession, OrganizationDto organizationDto) { | |||||
return mapper(dbSession).selectForOrganizationUuidOrderedByName(organizationDto.getUuid()); | |||||
} | |||||
// TODO remove | |||||
@Deprecated | |||||
public List<WebhookDto> selectByOrganizationUuid(DbSession dbSession, String organizationUuid) { | |||||
return mapper(dbSession).selectForOrganizationUuidOrderedByName(organizationUuid); | |||||
} | |||||
public List<WebhookDto> selectByProject(DbSession dbSession, ProjectDto projectDto) { | public List<WebhookDto> selectByProject(DbSession dbSession, ProjectDto projectDto) { | ||||
return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid()); | return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid()); | ||||
} | } | ||||
public void insert(DbSession dbSession, WebhookDto dto) { | public void insert(DbSession dbSession, WebhookDto dto) { | ||||
checkState(dto.getOrganizationUuid() == null || dto.getProjectUuid() == null, | |||||
"A webhook can not be linked to both an organization and a project."); | |||||
if (dto.getProjectUuid() == null && dto.getOrganizationUuid() == null) { | |||||
Optional<String> uuid = internalPropertiesDao.selectByKey(dbSession, "organization.default"); | |||||
checkState(uuid.isPresent() && !uuid.get().isEmpty(), "No Default organization uuid configured"); | |||||
dto.setOrganizationUuid(uuid.get()); | |||||
} | |||||
mapper(dbSession).insert(dto.setCreatedAt(system2.now()).setUpdatedAt(system2.now())); | mapper(dbSession).insert(dto.setCreatedAt(system2.now()).setUpdatedAt(system2.now())); | ||||
} | } | ||||
/** URL, can't be null */ | /** URL, can't be null */ | ||||
private String url; | private String url; | ||||
@Nullable | |||||
private String organizationUuid; | |||||
@Nullable | @Nullable | ||||
private String projectUuid; | private String projectUuid; | ||||
return this; | return this; | ||||
} | } | ||||
public WebhookDto setOrganizationUuid(@Nullable String organizationUuid) { | |||||
this.organizationUuid = organizationUuid; | |||||
return this; | |||||
} | |||||
public WebhookDto setProjectUuid(@Nullable String projectUuid) { | public WebhookDto setProjectUuid(@Nullable String projectUuid) { | ||||
this.projectUuid = projectUuid; | this.projectUuid = projectUuid; | ||||
return this; | return this; | ||||
return url; | return url; | ||||
} | } | ||||
@Nullable | |||||
public String getOrganizationUuid() { | |||||
return organizationUuid; | |||||
} | |||||
@Nullable | @Nullable | ||||
public String getProjectUuid() { | public String getProjectUuid() { | ||||
return projectUuid; | return projectUuid; |
List<WebhookDto> selectGlobalWebhooksOrderedByName(); | List<WebhookDto> selectGlobalWebhooksOrderedByName(); | ||||
// TODO remove | |||||
@Deprecated | |||||
List<WebhookDto> selectForProjectUuidOrderedByName(@Param("projectUuid") String projectUuid); | List<WebhookDto> selectForProjectUuidOrderedByName(@Param("projectUuid") String projectUuid); | ||||
// TODO remove | |||||
@Deprecated | |||||
List<WebhookDto> selectForOrganizationUuidOrderedByName(@Param("organizationUuid") String organizationUuid); | |||||
void insert(WebhookDto dto); | void insert(WebhookDto dto); | ||||
void update(WebhookDto dto); | void update(WebhookDto dto); | ||||
void delete(@Param("uuid") String uuid); | void delete(@Param("uuid") String uuid); | ||||
void deleteForProjectUuid(@Param("projectUuid") String organizationUuid); | |||||
void deleteForProjectUuid(@Param("projectUuid") String projectUuid); | |||||
} | } |
<sql id="projectColumns"> | <sql id="projectColumns"> | ||||
p.uuid as uuid, | p.uuid as uuid, | ||||
p.organization_uuid as organizationUuid, | |||||
p.kee as kee, | p.kee as kee, | ||||
p.qualifier as qualifier, | p.qualifier as qualifier, | ||||
p.name as name, | p.name as name, |
<mapper namespace="org.sonar.db.component.ComponentMapper"> | <mapper namespace="org.sonar.db.component.ComponentMapper"> | ||||
<sql id="componentColumns"> | <sql id="componentColumns"> | ||||
p.organization_uuid as organizationUuid, | |||||
p.uuid as uuid, | p.uuid as uuid, | ||||
p.uuid_path as uuidPath, | p.uuid_path as uuidPath, | ||||
p.project_uuid as projectUuid, | p.project_uuid as projectUuid, | ||||
select | select | ||||
<include refid="componentColumns"/> | <include refid="componentColumns"/> | ||||
from components root | from components root | ||||
inner join components p on p.project_uuid=root.uuid and p.organization_uuid=root.organization_uuid | |||||
inner join components p on p.project_uuid=root.uuid | |||||
where | where | ||||
root.uuid=#{projectUuid,jdbcType=VARCHAR} | root.uuid=#{projectUuid,jdbcType=VARCHAR} | ||||
</select> | </select> | ||||
INNER JOIN components child ON | INNER JOIN components child ON | ||||
child.root_uuid=p.uuid | child.root_uuid=p.uuid | ||||
and child.enabled=${_true} | and child.enabled=${_true} | ||||
and child.organization_uuid=p.organization_uuid | |||||
where | where | ||||
p.enabled=${_true} | p.enabled=${_true} | ||||
and p.scope='PRJ' | and p.scope='PRJ' | ||||
<sql id="modulesTreeQuery"> | <sql id="modulesTreeQuery"> | ||||
INNER JOIN components module ON | INNER JOIN components module ON | ||||
module.project_uuid = p.project_uuid | module.project_uuid = p.project_uuid | ||||
and module.organization_uuid = p.organization_uuid | |||||
and module.uuid = #{moduleUuid} | and module.uuid = #{moduleUuid} | ||||
and module.scope='PRJ' AND module.enabled = ${_true} | and module.scope='PRJ' AND module.enabled = ${_true} | ||||
where | where | ||||
FROM components root | FROM components root | ||||
INNER JOIN components p on | INNER JOIN components p on | ||||
p.project_uuid=root.uuid | p.project_uuid=root.uuid | ||||
and p.organization_uuid=root.organization_uuid | |||||
and p.enabled=${_true} | and p.enabled=${_true} | ||||
and p.scope='FIL' | and p.scope='FIL' | ||||
INNER JOIN file_sources fs ON | INNER JOIN file_sources fs ON | ||||
and p.qualifier = 'BRC' | and p.qualifier = 'BRC' | ||||
</select> | </select> | ||||
<select id="countComponentByOrganizationAndUuid" resultType="int"> | |||||
select | |||||
count(1) | |||||
from components p | |||||
where | |||||
p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} | |||||
and p.uuid = #{componentUuid,jdbcType=BIGINT} | |||||
</select> | |||||
<select id="selectByQuery" resultType="Component"> | <select id="selectByQuery" resultType="Component"> | ||||
select | select | ||||
<include refid="componentColumns"/> | <include refid="componentColumns"/> | ||||
<insert id="insert" parameterType="Component"> | <insert id="insert" parameterType="Component"> | ||||
INSERT INTO components ( | INSERT INTO components ( | ||||
organization_uuid, | |||||
kee, | kee, | ||||
uuid, | uuid, | ||||
uuid_path, | uuid_path, | ||||
b_qualifier | b_qualifier | ||||
) | ) | ||||
VALUES ( | VALUES ( | ||||
#{organizationUuid,jdbcType=VARCHAR}, | |||||
#{kee,jdbcType=VARCHAR}, | #{kee,jdbcType=VARCHAR}, | ||||
#{uuid,jdbcType=VARCHAR}, | #{uuid,jdbcType=VARCHAR}, | ||||
#{uuidPath,jdbcType=VARCHAR}, | #{uuidPath,jdbcType=VARCHAR}, | ||||
and p.scope = 'PRJ' | and p.scope = 'PRJ' | ||||
and p.qualifier = 'TRK' | and p.qualifier = 'TRK' | ||||
and p.copy_component_uuid is null | and p.copy_component_uuid is null | ||||
and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} | |||||
group by p.kee, p.name | group by p.kee, p.name | ||||
order by ncloc desc | order by ncloc desc | ||||
</select> | </select> |
</if> | </if> | ||||
</sql> | </sql> | ||||
<sql id="issueForIndexingColumns"> | |||||
i.kee as "key", | |||||
root.uuid as "projectUuid", | |||||
i.updated_at as "updatedAt", | |||||
i.assignee, | |||||
i.gap, | |||||
i.issue_attributes as "attributes", | |||||
i.line, | |||||
i.message, | |||||
i.resolution, | |||||
i.severity, | |||||
i.manual_severity as "manualSeverity", | |||||
i.checksum, | |||||
i.status, | |||||
i.effort, | |||||
i.author_login as "authorLogin", | |||||
i.issue_close_date as "issueCloseDate", | |||||
i.issue_creation_date as "issueCreationDate", | |||||
i.issue_update_date as "issueUpdateDate", | |||||
r.is_external as "isExternal", | |||||
r.plugin_name as "pluginName", | |||||
r.plugin_rule_key as "pluginRuleKey", | |||||
r.language, | |||||
p.uuid as "projectUuid", | |||||
p.module_uuid_path as "moduleUuidPath", | |||||
p.path, | |||||
p.scope, | |||||
p.organization_uuid as "organizationUuid", | |||||
i.tags, | |||||
i.issue_type as "issueType" | |||||
</sql> | |||||
<insert id="insert" parameterType="Issue" useGeneratedKeys="false"> | <insert id="insert" parameterType="Issue" useGeneratedKeys="false"> | ||||
INSERT INTO issues (kee, rule_uuid, severity, manual_severity, | INSERT INTO issues (kee, rule_uuid, severity, manual_severity, | ||||
message, line, locations, gap, effort, status, tags, | message, line, locations, gap, effort, status, tags, |
<?xml version="1.0" encoding="UTF-8" ?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd"> | |||||
<mapper namespace="org.sonar.db.organization.OrganizationMapper"> | |||||
<sql id="selectColumns"> | |||||
org.uuid as "uuid", | |||||
org.kee as "key", | |||||
org.name as "name", | |||||
org.description as "description", | |||||
org.default_quality_gate_uuid as "defaultQualityGateUuid", | |||||
org.url as "url", | |||||
org.avatar_url as "avatarUrl", | |||||
org.subscription as "subscription", | |||||
org.created_at as "createdAt", | |||||
org.updated_at as "updatedAt" | |||||
</sql> | |||||
<sql id="defaultTemplatesColumns"> | |||||
org.default_perm_template_project as "projectUuid", | |||||
org.default_perm_template_app as "applicationsUuid", | |||||
org.default_perm_template_port as "portfoliosUuid" | |||||
</sql> | |||||
<select id="selectByUuid" resultType="Organization"> | |||||
select | |||||
<include refid="selectColumns"/> | |||||
from organizations org | |||||
where | |||||
org.uuid = #{uuid, jdbcType=VARCHAR} | |||||
</select> | |||||
<select id="selectDefaultTemplatesByUuid" resultType="org.sonar.db.permission.template.DefaultTemplates"> | |||||
select | |||||
<include refid="defaultTemplatesColumns"/> | |||||
from organizations org | |||||
where | |||||
org.uuid = #{uuid, jdbcType=VARCHAR} | |||||
and org.default_perm_template_project is not null | |||||
</select> | |||||
<select id="selectByKey" resultType="Organization"> | |||||
select | |||||
<include refid="selectColumns"/> | |||||
from organizations org | |||||
where | |||||
org.kee = #{key, jdbcType=VARCHAR} | |||||
</select> | |||||
<select id="selectByUuids" resultType="Organization"> | |||||
select | |||||
<include refid="selectColumns"/> | |||||
from organizations org | |||||
where | |||||
org.uuid in | |||||
<foreach collection="uuids" open="(" close=")" item="uuid" separator=","> | |||||
#{uuid, jdbcType=VARCHAR} | |||||
</foreach> | |||||
</select> | |||||
<select id="countByQuery" resultType="int"> | |||||
select count(org.uuid) | |||||
<include refid="sqlSelectByQuery" /> | |||||
</select> | |||||
<select id="selectByQuery" parameterType="map" resultType="Organization"> | |||||
select | |||||
<include refid="selectColumns"/> | |||||
<include refid="sqlSelectByQuery" /> | |||||
order by | |||||
org.created_at desc | |||||
limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER} | |||||
</select> | |||||
<select id="selectByQuery" parameterType="map" resultType="Organization" databaseId="mssql"> | |||||
select * from ( | |||||
select row_number() over(order by org.created_at desc) as number, | |||||
<include refid="selectColumns"/> | |||||
<include refid="sqlSelectByQuery" /> | |||||
) as query | |||||
where | |||||
query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER} | |||||
order by | |||||
query.createdAt desc | |||||
</select> | |||||
<select id="selectByQuery" parameterType="map" resultType="Organization" databaseId="oracle"> | |||||
select * from ( | |||||
select rownum as rn, t.* from ( | |||||
select | |||||
<include refid="selectColumns"/> | |||||
<include refid="sqlSelectByQuery" /> | |||||
ORDER BY org.created_at desc | |||||
) t | |||||
) t | |||||
where | |||||
t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER} | |||||
</select> | |||||
<sql id="sqlSelectByQuery"> | |||||
from organizations org | |||||
<where> | |||||
<if test="query.keys != null"> | |||||
org.kee in | |||||
<foreach collection="query.keys" open="(" close=")" item="key" separator=","> | |||||
#{key, jdbcType=VARCHAR} | |||||
</foreach> | |||||
</if> | |||||
<if test="query.withAnalyses"> | |||||
and exists( | |||||
select 1 | |||||
from snapshots s | |||||
inner join components p on p.uuid = s.component_uuid | |||||
where p.organization_uuid = org.uuid | |||||
and p.enabled = ${_true} | |||||
and s.islast = ${_true} | |||||
) | |||||
</if> | |||||
<if test="query.analyzedAfter != null"> | |||||
and exists( | |||||
select 1 | |||||
from snapshots s | |||||
inner join components p on p.uuid = s.component_uuid | |||||
where p.organization_uuid = org.uuid | |||||
and p.enabled = ${_true} | |||||
and s.islast = ${_true} | |||||
and s.created_at >= #{query.analyzedAfter,jdbcType=BIGINT} | |||||
) | |||||
</if> | |||||
</where> | |||||
</sql> | |||||
<select id="selectByPermission" parameterType="map" resultType="Organization"> | |||||
select | |||||
<include refid="selectColumns"/> | |||||
from organizations org | |||||
inner join user_roles ur on ur.user_uuid = #{userUuid,jdbcType=VARCHAR} | |||||
and ur.component_uuid is null | |||||
and ur.role = #{permission,jdbcType=VARCHAR} | |||||
union | |||||
select | |||||
<include refid="selectColumns"/> | |||||
from organizations org | |||||
inner join group_roles g on g.component_uuid is null | |||||
and g.role = #{permission,jdbcType=VARCHAR} | |||||
inner join groups_users gu on | |||||
gu.group_uuid = g.group_uuid | |||||
and gu.user_uuid= #{userUuid,jdbcType=VARCHAR} | |||||
</select> | |||||
<select id="selectAllUuids" resultType="String"> | |||||
select uuid from organizations | |||||
</select> | |||||
<select id="selectDefaultGroupUuidByUuid" resultType="string"> | |||||
select org.default_group_uuid | |||||
from organizations org | |||||
where | |||||
org.uuid = #{uuid, jdbcType=VARCHAR} | |||||
</select> | |||||
<select id="selectNewProjectPrivateByUuid" resultType="Boolean"> | |||||
select org.new_project_private | |||||
from organizations org | |||||
where | |||||
org.uuid = #{uuid, jdbcType=VARCHAR} | |||||
</select> | |||||
<select id="selectOrganizationsWithNcloc" resultType="org.sonar.db.organization.OrganizationWithNclocDto"> | |||||
select o.uuid as id, o.kee as kee, o.name as name, t.ncloc as ncloc | |||||
from organizations o | |||||
left outer join ( | |||||
select orgUuid, sum(sumncloc.maxncloc) as ncloc from ( | |||||
select b.project_uuid, p.organization_uuid as orgUuid, max(lm.value) as maxncloc | |||||
from live_measures lm | |||||
inner join metrics m on m.uuid = lm.metric_uuid | |||||
inner join components p on p.uuid = lm.component_uuid | |||||
inner join project_branches b on b.uuid = p.uuid | |||||
where | |||||
m.name = #{ncloc, jdbcType=VARCHAR} | |||||
and p.enabled = ${_true} | |||||
and p.private = ${_true} | |||||
and p.scope = 'PRJ' | |||||
and p.qualifier = 'TRK' | |||||
and p.copy_component_uuid is null | |||||
and p.organization_uuid in <foreach collection="organizationUuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach> | |||||
and b.branch_type = #{branchType, jdbcType=VARCHAR} | |||||
group by b.project_uuid, p.organization_uuid | |||||
) sumncloc | |||||
group by orgUuid | |||||
) t on t.orgUuid = o.uuid | |||||
where | |||||
o.uuid in <foreach collection="organizationUuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach> | |||||
</select> | |||||
<insert id="insert" parameterType="map" useGeneratedKeys="false"> | |||||
insert into organizations | |||||
( | |||||
uuid, | |||||
kee, | |||||
name, | |||||
description, | |||||
url, | |||||
avatar_url, | |||||
new_project_private, | |||||
default_quality_gate_uuid, | |||||
subscription, | |||||
created_at, | |||||
updated_at | |||||
) | |||||
values | |||||
( | |||||
#{organization.uuid, jdbcType=VARCHAR}, | |||||
#{organization.key, jdbcType=VARCHAR}, | |||||
#{organization.name, jdbcType=VARCHAR}, | |||||
#{organization.description, jdbcType=VARCHAR}, | |||||
#{organization.url, jdbcType=VARCHAR}, | |||||
#{organization.avatarUrl, jdbcType=VARCHAR}, | |||||
#{newProjectPrivate, jdbcType=BOOLEAN}, | |||||
#{organization.defaultQualityGateUuid, jdbcType=VARCHAR}, | |||||
#{organization.subscription, jdbcType=VARCHAR}, | |||||
#{organization.createdAt, jdbcType=BIGINT}, | |||||
#{organization.updatedAt, jdbcType=BIGINT} | |||||
) | |||||
</insert> | |||||
<update id="update" parameterType="Organization"> | |||||
update organizations | |||||
set | |||||
kee = #{organization.key, jdbcType=VARCHAR}, | |||||
name = #{organization.name, jdbcType=VARCHAR}, | |||||
description = #{organization.description, jdbcType=VARCHAR}, | |||||
url = #{organization.url, jdbcType=VARCHAR}, | |||||
default_quality_gate_uuid = #{organization.defaultQualityGateUuid, jdbcType=VARCHAR}, | |||||
subscription = #{organization.subscription, jdbcType=VARCHAR}, | |||||
avatar_url = #{organization.avatarUrl, jdbcType=VARCHAR}, | |||||
updated_at = #{organization.updatedAt, jdbcType=BIGINT} | |||||
where | |||||
uuid = #{organization.uuid, jdbcType=VARCHAR} | |||||
</update> | |||||
<update id="updateDefaultTemplates"> | |||||
update organizations | |||||
set | |||||
default_perm_template_project = #{defaultTemplates.projectUuid, jdbcType=VARCHAR}, | |||||
default_perm_template_app = #{defaultTemplates.applicationsUuid, jdbcType=VARCHAR}, | |||||
default_perm_template_port = #{defaultTemplates.portfoliosUuid, jdbcType=VARCHAR}, | |||||
updated_at = #{now, jdbcType=BIGINT} | |||||
where | |||||
uuid = #{organizationUuid, jdbcType=VARCHAR} | |||||
</update> | |||||
<update id="updateDefaultGroupUuid"> | |||||
update organizations | |||||
set | |||||
default_group_uuid = #{defaultGroupUuid, jdbcType=VARCHAR}, | |||||
updated_at = #{now, jdbcType=BIGINT} | |||||
where | |||||
uuid = #{organizationUuid, jdbcType=VARCHAR} | |||||
</update> | |||||
<update id="updateDefaultQualityGate"> | |||||
update organizations | |||||
set | |||||
default_quality_gate_uuid = #{defaultQualityGateUuid, jdbcType=INTEGER}, | |||||
updated_at = #{now, jdbcType=BIGINT} | |||||
where | |||||
uuid = #{organizationUuid, jdbcType=VARCHAR} | |||||
</update> | |||||
<update id="updateNewProjectPrivate"> | |||||
update organizations | |||||
set | |||||
new_project_private = #{newProjectPrivate, jdbcType=INTEGER}, | |||||
updated_at = #{now, jdbcType=BIGINT} | |||||
where | |||||
uuid = #{organizationUuid, jdbcType=VARCHAR} | |||||
</update> | |||||
<delete id="deleteByUuid"> | |||||
delete from organizations | |||||
where | |||||
uuid = #{uuid, jdbcType=VARCHAR} | |||||
</delete> | |||||
</mapper> |
<sql id="projectColumns"> | <sql id="projectColumns"> | ||||
p.uuid as uuid, | p.uuid as uuid, | ||||
p.organization_uuid as organizationUuid, | |||||
p.kee as kee, | p.kee as kee, | ||||
p.qualifier as qualifier, | p.qualifier as qualifier, | ||||
p.name as name, | p.name as name, | ||||
<insert id="insert" parameterType="Project"> | <insert id="insert" parameterType="Project"> | ||||
INSERT INTO projects ( | INSERT INTO projects ( | ||||
organization_uuid, | |||||
kee, | kee, | ||||
qualifier, | qualifier, | ||||
uuid, | uuid, | ||||
updated_at | updated_at | ||||
) | ) | ||||
VALUES ( | VALUES ( | ||||
#{organizationUuid,jdbcType=VARCHAR}, | |||||
#{kee,jdbcType=VARCHAR}, | #{kee,jdbcType=VARCHAR}, | ||||
#{qualifier,jdbcType=VARCHAR}, | #{qualifier,jdbcType=VARCHAR}, | ||||
#{uuid,jdbcType=VARCHAR}, | #{uuid,jdbcType=VARCHAR}, |
uuid, | uuid, | ||||
name, | name, | ||||
url, | url, | ||||
organization_uuid as organizationUuid, | |||||
project_uuid as projectUuid, | project_uuid as projectUuid, | ||||
secret, | secret, | ||||
created_at as createdAt, | created_at as createdAt, | ||||
order by name asc | order by name asc | ||||
</select> | </select> | ||||
<select id="selectForOrganizationUuidOrderedByName" parameterType="String" resultType="org.sonar.db.webhook.WebhookDto"> | |||||
select <include refid="sqlColumns" /> | |||||
from webhooks | |||||
where organization_uuid = #{organizationUuid,jdbcType=VARCHAR} | |||||
order by name asc | |||||
</select> | |||||
<select id="selectForProjectUuidOrderedByName" parameterType="String" resultType="org.sonar.db.webhook.WebhookDto"> | <select id="selectForProjectUuidOrderedByName" parameterType="String" resultType="org.sonar.db.webhook.WebhookDto"> | ||||
select <include refid="sqlColumns" /> | select <include refid="sqlColumns" /> | ||||
from webhooks | from webhooks | ||||
uuid, | uuid, | ||||
name, | name, | ||||
url, | url, | ||||
organization_uuid, | |||||
project_uuid, | project_uuid, | ||||
secret, | secret, | ||||
created_at, | created_at, | ||||
#{uuid,jdbcType=VARCHAR}, | #{uuid,jdbcType=VARCHAR}, | ||||
#{name,jdbcType=VARCHAR}, | #{name,jdbcType=VARCHAR}, | ||||
#{url,jdbcType=VARCHAR}, | #{url,jdbcType=VARCHAR}, | ||||
#{organizationUuid,jdbcType=VARCHAR}, | |||||
#{projectUuid,jdbcType=VARCHAR}, | #{projectUuid,jdbcType=VARCHAR}, | ||||
#{secret,jdbcType=VARCHAR}, | #{secret,jdbcType=VARCHAR}, | ||||
#{createdAt,jdbcType=BIGINT}, | #{createdAt,jdbcType=BIGINT}, | ||||
uuid = #{uuid,jdbcType=VARCHAR} | uuid = #{uuid,jdbcType=VARCHAR} | ||||
</delete> | </delete> | ||||
<delete id="deleteForOrganizationUuid" parameterType="String"> | |||||
delete from webhooks | |||||
where | |||||
organization_uuid = #{organizationUuid,jdbcType=VARCHAR} | |||||
</delete> | |||||
<delete id="deleteForProjectUuid" parameterType="String"> | <delete id="deleteForProjectUuid" parameterType="String"> | ||||
delete from webhooks | delete from webhooks | ||||
where | where |
ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID"); | ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID"); | ||||
CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_UUIDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_UUID"); | CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_UUIDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_UUID"); | ||||
CREATE TABLE "ALM_APP_INSTALLS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"ALM_ID" VARCHAR(40) NOT NULL, | |||||
"OWNER_ID" VARCHAR(4000) NOT NULL, | |||||
"INSTALL_ID" VARCHAR(4000) NOT NULL, | |||||
"IS_OWNER_USER" BOOLEAN NOT NULL, | |||||
"USER_EXTERNAL_ID" VARCHAR(255), | |||||
"CREATED_AT" BIGINT NOT NULL, | |||||
"UPDATED_AT" BIGINT NOT NULL | |||||
); | |||||
ALTER TABLE "ALM_APP_INSTALLS" ADD CONSTRAINT "PK_ALM_APP_INSTALLS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ALM_APP_INSTALLS_OWNER" ON "ALM_APP_INSTALLS"("ALM_ID", "OWNER_ID"); | |||||
CREATE UNIQUE INDEX "ALM_APP_INSTALLS_INSTALL" ON "ALM_APP_INSTALLS"("ALM_ID", "INSTALL_ID"); | |||||
CREATE INDEX "ALM_APP_INSTALLS_EXTERNAL_ID" ON "ALM_APP_INSTALLS"("USER_EXTERNAL_ID"); | |||||
CREATE TABLE "ALM_PATS"( | CREATE TABLE "ALM_PATS"( | ||||
"UUID" VARCHAR(40) NOT NULL, | "UUID" VARCHAR(40) NOT NULL, | ||||
"PAT" VARCHAR(2000) NOT NULL, | "PAT" VARCHAR(2000) NOT NULL, | ||||
CREATE TABLE "COMPONENTS"( | CREATE TABLE "COMPONENTS"( | ||||
"UUID" VARCHAR(50) NOT NULL, | "UUID" VARCHAR(50) NOT NULL, | ||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"KEE" VARCHAR(400), | "KEE" VARCHAR(400), | ||||
"DEPRECATED_KEE" VARCHAR(400), | "DEPRECATED_KEE" VARCHAR(400), | ||||
"NAME" VARCHAR(2000), | "NAME" VARCHAR(2000), | ||||
"B_MODULE_UUID_PATH" VARCHAR(1500), | "B_MODULE_UUID_PATH" VARCHAR(1500), | ||||
"CREATED_AT" TIMESTAMP | "CREATED_AT" TIMESTAMP | ||||
); | ); | ||||
CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID"); | |||||
CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE"); | CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE"); | ||||
CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID"); | CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID"); | ||||
CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID"); | CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID"); | ||||
CREATE INDEX "QPROFILES_RP_UUID" ON "ORG_QPROFILES"("RULES_PROFILE_UUID"); | CREATE INDEX "QPROFILES_RP_UUID" ON "ORG_QPROFILES"("RULES_PROFILE_UUID"); | ||||
CREATE INDEX "ORG_QPROFILES_PARENT_UUID" ON "ORG_QPROFILES"("PARENT_UUID"); | CREATE INDEX "ORG_QPROFILES_PARENT_UUID" ON "ORG_QPROFILES"("PARENT_UUID"); | ||||
CREATE TABLE "ORG_QUALITY_GATES"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"QUALITY_GATE_UUID" VARCHAR(40) NOT NULL | |||||
); | |||||
ALTER TABLE "ORG_QUALITY_GATES" ADD CONSTRAINT "PK_ORG_QUALITY_GATES" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "UNIQ_ORG_QUALITY_GATES" ON "ORG_QUALITY_GATES"("ORGANIZATION_UUID", "QUALITY_GATE_UUID"); | |||||
CREATE TABLE "ORGANIZATION_ALM_BINDINGS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"ALM_APP_INSTALL_UUID" VARCHAR(40) NOT NULL, | |||||
"ALM_ID" VARCHAR(40) NOT NULL, | |||||
"URL" VARCHAR(2000) NOT NULL, | |||||
"USER_UUID" VARCHAR(255) NOT NULL, | |||||
"MEMBERS_SYNC_ENABLED" BOOLEAN, | |||||
"CREATED_AT" BIGINT NOT NULL | |||||
); | |||||
ALTER TABLE "ORGANIZATION_ALM_BINDINGS" ADD CONSTRAINT "PK_ORGANIZATION_ALM_BINDINGS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ORG_ALM_BINDINGS_ORG" ON "ORGANIZATION_ALM_BINDINGS"("ORGANIZATION_UUID"); | |||||
CREATE UNIQUE INDEX "ORG_ALM_BINDINGS_INSTALL" ON "ORGANIZATION_ALM_BINDINGS"("ALM_APP_INSTALL_UUID"); | |||||
CREATE TABLE "ORGANIZATION_MEMBERS"( | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"USER_UUID" VARCHAR(255) NOT NULL | |||||
); | |||||
ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("USER_UUID", "ORGANIZATION_UUID"); | |||||
CREATE INDEX "ORG_MEMBERS_USER_UUID" ON "ORGANIZATION_MEMBERS"("USER_UUID"); | |||||
CREATE TABLE "ORGANIZATIONS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"KEE" VARCHAR(255) NOT NULL, | |||||
"NAME" VARCHAR(255) NOT NULL, | |||||
"DESCRIPTION" VARCHAR(256), | |||||
"URL" VARCHAR(256), | |||||
"AVATAR_URL" VARCHAR(256), | |||||
"GUARDED" BOOLEAN, | |||||
"DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL, | |||||
"DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), | |||||
"NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, | |||||
"SUBSCRIPTION" VARCHAR(40) NOT NULL, | |||||
"CREATED_AT" BIGINT NOT NULL, | |||||
"UPDATED_AT" BIGINT NOT NULL, | |||||
"DEFAULT_GROUP_UUID" VARCHAR(40) | |||||
); | |||||
ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); | |||||
CREATE TABLE "PERM_TEMPLATES_GROUPS"( | CREATE TABLE "PERM_TEMPLATES_GROUPS"( | ||||
"PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, | "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, | ||||
"CREATED_AT" TIMESTAMP, | "CREATED_AT" TIMESTAMP, | ||||
"UUID" VARCHAR(40) NOT NULL, | "UUID" VARCHAR(40) NOT NULL, | ||||
"KEE" VARCHAR(400) NOT NULL, | "KEE" VARCHAR(400) NOT NULL, | ||||
"QUALIFIER" VARCHAR(10) NOT NULL, | "QUALIFIER" VARCHAR(10) NOT NULL, | ||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"NAME" VARCHAR(2000), | "NAME" VARCHAR(2000), | ||||
"DESCRIPTION" VARCHAR(2000), | "DESCRIPTION" VARCHAR(2000), | ||||
"PRIVATE" BOOLEAN NOT NULL, | "PRIVATE" BOOLEAN NOT NULL, | ||||
CREATE TABLE "WEBHOOKS"( | CREATE TABLE "WEBHOOKS"( | ||||
"UUID" VARCHAR(40) NOT NULL, | "UUID" VARCHAR(40) NOT NULL, | ||||
"ORGANIZATION_UUID" VARCHAR(40), | |||||
"PROJECT_UUID" VARCHAR(40), | "PROJECT_UUID" VARCHAR(40), | ||||
"NAME" VARCHAR(100) NOT NULL, | "NAME" VARCHAR(100) NOT NULL, | ||||
"URL" VARCHAR(2000) NOT NULL, | "URL" VARCHAR(2000) NOT NULL, | ||||
"UPDATED_AT" BIGINT | "UPDATED_AT" BIGINT | ||||
); | ); | ||||
ALTER TABLE "WEBHOOKS" ADD CONSTRAINT "PK_WEBHOOKS" PRIMARY KEY("UUID"); | ALTER TABLE "WEBHOOKS" ADD CONSTRAINT "PK_WEBHOOKS" PRIMARY KEY("UUID"); | ||||
CREATE INDEX "ORGANIZATION_WEBHOOK" ON "WEBHOOKS"("ORGANIZATION_UUID"); | |||||
CREATE INDEX "PROJECT_WEBHOOK" ON "WEBHOOKS"("PROJECT_UUID"); |
@Test | @Test | ||||
public void test_delete_with_expected_status() { | public void test_delete_with_expected_status() { | ||||
insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1); | insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1); | ||||
insertInProgress(TASK_UUID_2, MAIN_COMPONENT_UUID_1); | |||||
insertInProgress(TASK_UUID_2); | |||||
int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN", null); | int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN", null); | ||||
assertThat(deletedCount).isZero(); | assertThat(deletedCount).isZero(); | ||||
view.setQualifier("VW"); | view.setQualifier("VW"); | ||||
view.setDbKey(view_uuid + "_key"); | view.setDbKey(view_uuid + "_key"); | ||||
view.setUuid(view_uuid); | view.setUuid(view_uuid); | ||||
view.setOrganizationUuid("org_uuid"); | |||||
view.setPrivate(false); | view.setPrivate(false); | ||||
view.setRootUuid(view_uuid); | view.setRootUuid(view_uuid); | ||||
view.setUuidPath("uuid_path"); | view.setUuidPath("uuid_path"); | ||||
branch.setQualifier("TRK"); | branch.setQualifier("TRK"); | ||||
branch.setDbKey(uuid + "_key"); | branch.setDbKey(uuid + "_key"); | ||||
branch.setUuid(uuid); | branch.setUuid(uuid); | ||||
branch.setOrganizationUuid("org_uuid"); | |||||
branch.setPrivate(false); | branch.setPrivate(false); | ||||
branch.setRootUuid(uuid); | branch.setRootUuid(uuid); | ||||
branch.setUuidPath("uuid_path"); | branch.setUuidPath("uuid_path"); | ||||
return dto; | return dto; | ||||
} | } | ||||
private CeQueueDto insertInProgress(String uuid, String componentUuid) { | |||||
private CeQueueDto insertInProgress(String uuid) { | |||||
CeQueueDto ceQueueDto = insertPending(uuid); | CeQueueDto ceQueueDto = insertPending(uuid); | ||||
CeQueueTesting.makeInProgress(db.getSession(), "workerUuid", System2.INSTANCE.now(), ceQueueDto); | CeQueueTesting.makeInProgress(db.getSession(), "workerUuid", System2.INSTANCE.now(), ceQueueDto); | ||||
return underTest.selectByUuid(db.getSession(), uuid).get(); | return underTest.selectByUuid(db.getSession(), uuid).get(); |
"uuid", projectUuid, | "uuid", projectUuid, | ||||
"kee", projectUuid, | "kee", projectUuid, | ||||
"qualifier", "TRK", | "qualifier", "TRK", | ||||
"ORGANIZATION_UUID", "ORGANIZATION_UUID", | |||||
"private", true, | "private", true, | ||||
"updated_at", 1000L, | "updated_at", 1000L, | ||||
"created_at", 1000L); | "created_at", 1000L); | ||||
"uuid", appUuid, | "uuid", appUuid, | ||||
"kee", appUuid, | "kee", appUuid, | ||||
"qualifier", "APP", | "qualifier", "APP", | ||||
"ORGANIZATION_UUID", "ORGANIZATION_UUID", | |||||
"private", true, | "private", true, | ||||
"updated_at", 1000L, | "updated_at", 1000L, | ||||
"created_at", 1000L); | "created_at", 1000L); |
ComponentDto result = underTest.selectByUuid(dbSession, project.uuid()).get(); | ComponentDto result = underTest.selectByUuid(dbSession, project.uuid()).get(); | ||||
assertThat(result).isNotNull(); | assertThat(result).isNotNull(); | ||||
assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid()); | |||||
assertThat(result.uuid()).isEqualTo(project.uuid()); | assertThat(result.uuid()).isEqualTo(project.uuid()); | ||||
assertThat(result.getUuidPath()).isEqualTo("."); | assertThat(result.getUuidPath()).isEqualTo("."); | ||||
assertThat(result.moduleUuid()).isNull(); | assertThat(result.moduleUuid()).isNull(); | ||||
Optional<ComponentDto> optional = underTest.selectByKey(dbSession, file.getDbKey()); | Optional<ComponentDto> optional = underTest.selectByKey(dbSession, file.getDbKey()); | ||||
ComponentDto result = optional.get(); | ComponentDto result = optional.get(); | ||||
assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid()); | |||||
assertThat(result.uuid()).isEqualTo(file.uuid()); | assertThat(result.uuid()).isEqualTo(file.uuid()); | ||||
assertThat(result.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); | assertThat(result.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); | ||||
assertThat(result.path()).isEqualTo("src/RequestContext.java"); | assertThat(result.path()).isEqualTo("src/RequestContext.java"); | ||||
@Test | @Test | ||||
public void updateBEnabledToFalse() { | public void updateBEnabledToFalse() { | ||||
ComponentDto dto1 = newPrivateProjectDto(db.getDefaultOrganization(), "U1"); | |||||
ComponentDto dto2 = newPrivateProjectDto(db.getDefaultOrganization(), "U2"); | |||||
ComponentDto dto3 = newPrivateProjectDto(db.getDefaultOrganization(), "U3"); | |||||
ComponentDto dto1 = newPrivateProjectDto("U1"); | |||||
ComponentDto dto2 = newPrivateProjectDto("U2"); | |||||
ComponentDto dto3 = newPrivateProjectDto("U3"); | |||||
underTest.insert(dbSession, dto1, dto2, dto3); | underTest.insert(dbSession, dto1, dto2, dto3); | ||||
underTest.updateBEnabledToFalse(dbSession, asList("U1", "U2")); | underTest.updateBEnabledToFalse(dbSession, asList("U1", "U2")); | ||||
List<ComponentDto> components = underTest.selectDescendants(dbSession, dbQuery); | List<ComponentDto> components = underTest.selectDescendants(dbSession, dbQuery); | ||||
assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); | assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); | ||||
assertThat(components).extracting("organizationUuid").containsOnly(db.getDefaultOrganization().getUuid()); | |||||
} | } | ||||
@Test | @Test | ||||
// public project - not returned | // public project - not returned | ||||
insertMeasure(11d, db.components().insertPublicProject(b -> b.setName("other")), metric); | insertMeasure(11d, db.components().insertPublicProject(b -> b.setName("other")), metric); | ||||
List<ProjectNclocDistributionDto> result = underTest.selectPrivateProjectsWithNcloc(db.getSession(), db.getDefaultOrganization().getUuid()); | |||||
List<ProjectNclocDistributionDto> result = underTest.selectPrivateProjectsWithNcloc(db.getSession()); | |||||
assertThat(result).extracting(ProjectNclocDistributionDto::getName).containsExactly("foo", "bar"); | assertThat(result).extracting(ProjectNclocDistributionDto::getName).containsExactly("foo", "bar"); | ||||
assertThat(result).extracting(ProjectNclocDistributionDto::getNcloc).containsExactly(30L, 10L); | assertThat(result).extracting(ProjectNclocDistributionDto::getNcloc).containsExactly(30L, 10L); |
@Test | @Test | ||||
public void bulk_update_key_updates_disabled_components() { | public void bulk_update_key_updates_disabled_components() { | ||||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setDbKey("my_project")); | |||||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto("A").setDbKey("my_project")); | |||||
db.components().insertComponent(newModuleDto(project).setDbKey("my_project:module")); | db.components().insertComponent(newModuleDto(project).setDbKey("my_project:module")); | ||||
db.components().insertComponent(newModuleDto(project).setDbKey("my_project:inactive_module").setEnabled(false)); | db.components().insertComponent(newModuleDto(project).setDbKey("my_project:inactive_module").setEnabled(false)); | ||||
.extracting(IssueDto::getKey) | .extracting(IssueDto::getKey) | ||||
.containsExactlyInAnyOrder(Arrays.stream(new IssueDto[] {openIssue1OnFile, openIssue2OnFile, openIssueOnModule}).map(IssueDto::getKey).toArray(String[]::new)); | .containsExactlyInAnyOrder(Arrays.stream(new IssueDto[] {openIssue1OnFile, openIssue2OnFile, openIssueOnModule}).map(IssueDto::getKey).toArray(String[]::new)); | ||||
ComponentDto notPersisted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto notPersisted = ComponentTesting.newPrivateProjectDto(); | |||||
assertThat(underTest.selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(db.getSession(), notPersisted)).isEmpty(); | assertThat(underTest.selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(db.getSession(), notPersisted)).isEmpty(); | ||||
} | } | ||||
@Test | @Test | ||||
public void selectTreeByQuery_with_empty_results() { | public void selectTreeByQuery_with_empty_results() { | ||||
List<LiveMeasureDto> results = new ArrayList<>(); | List<LiveMeasureDto> results = new ArrayList<>(); | ||||
underTest.selectTreeByQuery(db.getSession(), newPrivateProjectDto(db.getDefaultOrganization()), | |||||
underTest.selectTreeByQuery(db.getSession(), newPrivateProjectDto(), | |||||
MeasureTreeQuery.builder().setStrategy(MeasureTreeQuery.Strategy.LEAVES).build(), | MeasureTreeQuery.builder().setStrategy(MeasureTreeQuery.Strategy.LEAVES).build(), | ||||
context -> results.add(context.getResultObject())); | context -> results.add(context.getResultObject())); | ||||
* - anyone | * - anyone | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void selectOrganizationPermissions_for_logged_in_user() { | |||||
public void selectGlobalPermissions_for_logged_in_user() { | |||||
ComponentDto project = db.components().insertPrivateProject(); | ComponentDto project = db.components().insertPrivateProject(); | ||||
db.users().insertMember(group1, user); | db.users().insertMember(group1, user); | ||||
db.users().insertPermissionOnUser(user, "perm1"); | db.users().insertPermissionOnUser(user, "perm1"); |
GroupDto group2 = db.users().insertGroup("Group-2"); | GroupDto group2 = db.users().insertGroup("Group-2"); | ||||
GroupDto group3 = db.users().insertGroup("Group-3"); | GroupDto group3 = db.users().insertGroup("Group-3"); | ||||
ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization())); | |||||
ComponentDto project = db.components().insertPrivateProject(); | |||||
db.users().insertPermissionOnAnyone(SCAN); | db.users().insertPermissionOnAnyone(SCAN); | ||||
db.users().insertPermissionOnAnyone(PROVISION_PROJECTS); | db.users().insertPermissionOnAnyone(PROVISION_PROJECTS); | ||||
db.users().insertPermissionOnGroup(group1, SCAN); | db.users().insertPermissionOnGroup(group1, SCAN); | ||||
GroupDto group2 = db.users().insertGroup("Group-2"); | GroupDto group2 = db.users().insertGroup("Group-2"); | ||||
ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization())); | |||||
ComponentDto project = db.components().insertPrivateProject(); | |||||
db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, project); | db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, project); | ||||
GroupDto group3 = db.users().insertGroup("Group-3"); | GroupDto group3 = db.users().insertGroup("Group-3"); |
PermissionQuery query = PermissionQuery.builder().withAtLeastOnePermission().build(); | PermissionQuery query = PermissionQuery.builder().withAtLeastOnePermission().build(); | ||||
expectPermissions(query, asList(user2.getUuid(), user1.getUuid()), global2, global3, global1); | expectPermissions(query, asList(user2.getUuid(), user1.getUuid()), global2, global3, global1); | ||||
// default query returns all users, whatever their permissions nor organizations | |||||
// default query returns all users, whatever their permissions | |||||
// (that's a non-sense, but still this is required for api/permissions/groups | // (that's a non-sense, but still this is required for api/permissions/groups | ||||
// when filtering users by name) | // when filtering users by name) | ||||
query = PermissionQuery.builder().build(); | query = PermissionQuery.builder().build(); | ||||
expectPermissions(query, emptyList()); | expectPermissions(query, emptyList()); | ||||
// permissions of unknown project | // permissions of unknown project | ||||
query = PermissionQuery.builder().setComponent(newPrivateProjectDto(db.getDefaultOrganization())).withAtLeastOnePermission().build(); | |||||
query = PermissionQuery.builder().setComponent(newPrivateProjectDto()).withAtLeastOnePermission().build(); | |||||
expectPermissions(query, emptyList()); | expectPermissions(query, emptyList()); | ||||
} | } | ||||
assertThat(underTest.selectUserUuidsByQuery(dbSession, query)).isEmpty(); | assertThat(underTest.selectUserUuidsByQuery(dbSession, query)).isEmpty(); | ||||
// on a project without permissions | // on a project without permissions | ||||
query = PermissionQuery.builder().setComponent(newPrivateProjectDto(db.getDefaultOrganization())).withAtLeastOnePermission().build(); | |||||
query = PermissionQuery.builder().setComponent(newPrivateProjectDto()).withAtLeastOnePermission().build(); | |||||
assertThat(underTest.selectUserUuidsByQuery(dbSession, query)).isEmpty(); | assertThat(underTest.selectUserUuidsByQuery(dbSession, query)).isEmpty(); | ||||
// search all users whose name matches "mar", whatever the permissions | // search all users whose name matches "mar", whatever the permissions | ||||
} | } | ||||
@Test | @Test | ||||
public void selectUserUuidsByQueryAndScope_with_organization_scope() { | |||||
public void selectUserUuidsByQueryAndScope_with_global_scope() { | |||||
UserDto user1 = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); | UserDto user1 = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); | ||||
UserDto user2 = insertUser(u -> u.setLogin("login2").setName("Marie").setEmail("email2@email.com")); | UserDto user2 = insertUser(u -> u.setLogin("login2").setName("Marie").setEmail("email2@email.com")); | ||||
ComponentDto project1 = db.components().insertPrivateProject(); | ComponentDto project1 = db.components().insertPrivateProject(); |
import org.sonar.core.util.UuidFactoryFast; | import org.sonar.core.util.UuidFactoryFast; | ||||
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
import org.sonar.db.DbTester; | import org.sonar.db.DbTester; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.user.GroupDto; | import org.sonar.db.user.GroupDto; | ||||
import org.sonar.db.user.UserDto; | import org.sonar.db.user.UserDto; | ||||
.extracting((row) -> row.get("templateUuid"), (row) -> row.get("userUuid"), (row) -> row.get("permission")) | .extracting((row) -> row.get("templateUuid"), (row) -> row.get("userUuid"), (row) -> row.get("permission")) | ||||
.containsOnly(tuple(template.getUuid(), anotherUser.getUuid(), permission)); | .containsOnly(tuple(template.getUuid(), anotherUser.getUuid(), permission)); | ||||
} | } | ||||
private PermissionTemplateDto createTemplate(OrganizationDto organization) { | |||||
UserDto user = db.users().insertUser(); | |||||
GroupDto group = db.users().insertGroup(); | |||||
db.users().insertMember(group, user); | |||||
PermissionTemplateDto template = templateDb.insertTemplate(); | |||||
templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN_EXECUTION); | |||||
templateDb.addProjectCreatorToTemplate(template.getUuid(), UserRole.ADMIN); | |||||
templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER); | |||||
templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.ADMIN); | |||||
templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER); | |||||
templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.ADMIN); | |||||
templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN); | |||||
return template; | |||||
} | |||||
} | } |
Optional<ProjectDto> projectByUuid = projectDao.selectByUuid(db.getSession(), "uuid_o1_p1"); | Optional<ProjectDto> projectByUuid = projectDao.selectByUuid(db.getSession(), "uuid_o1_p1"); | ||||
assertThat(projectByUuid).isPresent(); | assertThat(projectByUuid).isPresent(); | ||||
assertProject(projectByUuid.get(), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
assertProject(projectByUuid.get(), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
assertThat(projectByUuid.get().isPrivate()).isFalse(); | assertThat(projectByUuid.get().isPrivate()).isFalse(); | ||||
} | } | ||||
Optional<ProjectDto> projectByKee = projectDao.selectProjectByKey(db.getSession(), "projectKee_o1_p1"); | Optional<ProjectDto> projectByKee = projectDao.selectProjectByKey(db.getSession(), "projectKee_o1_p1"); | ||||
assertThat(projectByKee).isPresent(); | assertThat(projectByKee).isPresent(); | ||||
assertProject(projectByKee.get(), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
assertProject(projectByKee.get(), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
} | } | ||||
@Test | @Test | ||||
List<ProjectDto> projectsByOrg = projectDao.selectAll(db.getSession()); | List<ProjectDto> projectsByOrg = projectDao.selectAll(db.getSession()); | ||||
assertThat(projectsByOrg) | assertThat(projectsByOrg) | ||||
.extracting(ProjectDto::getName, ProjectDto::getKey, ProjectDto::getOrganizationUuid, ProjectDto::getUuid, ProjectDto::getDescription, | |||||
.extracting(ProjectDto::getName, ProjectDto::getKey, ProjectDto::getUuid, ProjectDto::getDescription, | |||||
ProjectDto::getTagsString, ProjectDto::isPrivate) | ProjectDto::getTagsString, ProjectDto::isPrivate) | ||||
.containsExactlyInAnyOrder( | .containsExactlyInAnyOrder( | ||||
tuple("projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false), | |||||
tuple("projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false), | |||||
tuple("projectName_p1", "projectKee_o2_p1", "org_o2", "uuid_o2_p1", "desc_p1", "tag1,tag2", false)); | |||||
tuple("projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false), | |||||
tuple("projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false), | |||||
tuple("projectName_p1", "projectKee_o2_p1", "uuid_o2_p1", "desc_p1", "tag1,tag2", false)); | |||||
} | } | ||||
@Test | @Test | ||||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | ||||
assertThat(projectsByUuids).hasSize(2); | assertThat(projectsByUuids).hasSize(2); | ||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", null, false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); | |||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", null, false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); | |||||
dto1.setTags(Collections.singletonList("tag3")); | dto1.setTags(Collections.singletonList("tag3")); | ||||
dto2.setTagsString(""); | dto2.setTagsString(""); | ||||
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | ||||
assertThat(projectsByUuids).hasSize(2); | assertThat(projectsByUuids).hasSize(2); | ||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag3", false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", null, false); | |||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag3", false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", null, false); | |||||
assertThat(projectsByUuids.get(0).getTags()).containsOnly("tag3"); | assertThat(projectsByUuids.get(0).getTags()).containsOnly("tag3"); | ||||
} | } | ||||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | ||||
assertThat(projectsByUuids).hasSize(2); | assertThat(projectsByUuids).hasSize(2); | ||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", true); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); | |||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", true); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); | |||||
projectDao.updateVisibility(db.getSession(), dto1.getUuid(), false); | projectDao.updateVisibility(db.getSession(), dto1.getUuid(), false); | ||||
projectDao.updateVisibility(db.getSession(), dto2.getUuid(), true); | projectDao.updateVisibility(db.getSession(), dto2.getUuid(), true); | ||||
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | ||||
assertThat(projectsByUuids).hasSize(2); | assertThat(projectsByUuids).hasSize(2); | ||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", true); | |||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", true); | |||||
} | } | ||||
@Test | @Test | ||||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | ||||
assertThat(projectsByUuids).hasSize(2); | assertThat(projectsByUuids).hasSize(2); | ||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); | |||||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); | |||||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); | |||||
} | } | ||||
@Test | @Test | ||||
assertThat(projectsByUuids).isEmpty(); | assertThat(projectsByUuids).isEmpty(); | ||||
} | } | ||||
private void assertProject(ProjectDto dto, String name, String kee, String org, String uuid, String desc, @Nullable String tags, boolean isPrivate) { | |||||
assertThat(dto).extracting("name", "kee", "key", "organizationUuid", "uuid", "description", "tagsString", "private") | |||||
.containsExactly(name, kee, kee, org, uuid, desc, tags, isPrivate); | |||||
private void assertProject(ProjectDto dto, String name, String kee, String uuid, String desc, @Nullable String tags, boolean isPrivate) { | |||||
assertThat(dto).extracting("name", "kee", "key","uuid", "description", "tagsString", "private") | |||||
.containsExactly(name, kee, kee, uuid, desc, tags, isPrivate); | |||||
} | } | ||||
private ProjectDto createProject(String org, String name) { | private ProjectDto createProject(String org, String name) { | ||||
.setName("projectName_" + name) | .setName("projectName_" + name) | ||||
.setKey("projectKee_" + org + "_" + name) | .setKey("projectKee_" + org + "_" + name) | ||||
.setQualifier(Qualifiers.PROJECT) | .setQualifier(Qualifiers.PROJECT) | ||||
.setOrganizationUuid("org_" + org) | |||||
.setUuid("uuid_" + org + "_" + name) | .setUuid("uuid_" + org + "_" + name) | ||||
.setTags(Arrays.asList("tag1", "tag2")) | .setTags(Arrays.asList("tag1", "tag2")) | ||||
.setDescription("desc_" + name) | .setDescription("desc_" + name) |
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
.hasCreatedAt(INITIAL_DATE); | |||||
assertThatPropertiesRow("global.empty") | assertThatPropertiesRow("global.empty") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
assertThatPropertiesRow("global.text") | assertThatPropertiesRow("global.text") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue("some text") | .hasTextValue("some text") | ||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
assertThatPropertiesRow("global.4000") | assertThatPropertiesRow("global.4000") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue(VALUE_SIZE_4000) | .hasTextValue(VALUE_SIZE_4000) | ||||
.hasCreatedAt(INITIAL_DATE + 5); | |||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
assertThatPropertiesRow("global.clob") | assertThatPropertiesRow("global.clob") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasClobValue(VALUE_SIZE_4001) | .hasClobValue(VALUE_SIZE_4001) | ||||
.hasCreatedAt(INITIAL_DATE + 6); | |||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
} | } | ||||
@Test | @Test | ||||
.hasComponentUuid(componentUuid) | .hasComponentUuid(componentUuid) | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
.hasCreatedAt(INITIAL_DATE); | |||||
assertThatPropertiesRow("component.empty") | assertThatPropertiesRow("component.empty") | ||||
.hasComponentUuid(componentUuid) | .hasComponentUuid(componentUuid) | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
assertThatPropertiesRow("component.text") | assertThatPropertiesRow("component.text") | ||||
.hasComponentUuid(componentUuid) | .hasComponentUuid(componentUuid) | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue("some text") | .hasTextValue("some text") | ||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
assertThatPropertiesRow("component.4000") | assertThatPropertiesRow("component.4000") | ||||
.hasComponentUuid(componentUuid) | .hasComponentUuid(componentUuid) | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue(VALUE_SIZE_4000) | .hasTextValue(VALUE_SIZE_4000) | ||||
.hasCreatedAt(INITIAL_DATE + 5); | |||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
assertThatPropertiesRow("component.clob") | assertThatPropertiesRow("component.clob") | ||||
.hasComponentUuid(componentUuid) | .hasComponentUuid(componentUuid) | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasClobValue(VALUE_SIZE_4001) | .hasClobValue(VALUE_SIZE_4001) | ||||
.hasCreatedAt(INITIAL_DATE + 6); | |||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
} | } | ||||
@Test | @Test | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid(userUuid) | .hasUserUuid(userUuid) | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
.hasCreatedAt(INITIAL_DATE); | |||||
assertThatPropertiesRow("user.empty") | assertThatPropertiesRow("user.empty") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid(userUuid) | .hasUserUuid(userUuid) | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
assertThatPropertiesRow("user.text") | assertThatPropertiesRow("user.text") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid(userUuid) | .hasUserUuid(userUuid) | ||||
.hasTextValue("some text") | .hasTextValue("some text") | ||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
assertThatPropertiesRow("user.4000") | assertThatPropertiesRow("user.4000") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid(userUuid) | .hasUserUuid(userUuid) | ||||
.hasTextValue(VALUE_SIZE_4000) | .hasTextValue(VALUE_SIZE_4000) | ||||
.hasCreatedAt(INITIAL_DATE + 5); | |||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
assertThatPropertiesRow("user.clob") | assertThatPropertiesRow("user.clob") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid(userUuid) | .hasUserUuid(userUuid) | ||||
.hasClobValue(VALUE_SIZE_4001) | .hasClobValue(VALUE_SIZE_4001) | ||||
.hasCreatedAt(INITIAL_DATE + 6); | |||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
} | } | ||||
@Test | @Test | ||||
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
if (newValue == null || newValue.isEmpty()) { | if (newValue == null || newValue.isEmpty()) { | ||||
propertiesRowAssert.isEmpty(); | propertiesRowAssert.isEmpty(); | ||||
} else if (newValue.length() > 4000) { | } else if (newValue.length() > 4000) { | ||||
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | ||||
.hasComponentUuid(componentUuid) | .hasComponentUuid(componentUuid) | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
if (newValue == null || newValue.isEmpty()) { | if (newValue == null || newValue.isEmpty()) { | ||||
propertiesRowAssert.isEmpty(); | propertiesRowAssert.isEmpty(); | ||||
} else if (newValue.length() > 4000) { | } else if (newValue.length() > 4000) { | ||||
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid(userUuid) | .hasUserUuid(userUuid) | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
if (newValue == null || newValue.isEmpty()) { | if (newValue == null || newValue.isEmpty()) { | ||||
propertiesRowAssert.isEmpty(); | propertiesRowAssert.isEmpty(); | ||||
} else if (newValue.length() > 4000) { | } else if (newValue.length() > 4000) { | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
.hasCreatedAt(INITIAL_DATE); | |||||
assertThatPropertiesRow("empty_value_property") | assertThatPropertiesRow("empty_value_property") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.isEmpty() | .isEmpty() | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
assertThatPropertiesRow("text_value_property") | assertThatPropertiesRow("text_value_property") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue("dfdsfsd") | .hasTextValue("dfdsfsd") | ||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
assertThatPropertiesRow("4000_char_value_property") | assertThatPropertiesRow("4000_char_value_property") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue(VALUE_SIZE_4000) | .hasTextValue(VALUE_SIZE_4000) | ||||
.hasCreatedAt(INITIAL_DATE + 5); | |||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
assertThatPropertiesRow("clob_value_property") | assertThatPropertiesRow("clob_value_property") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasClobValue(VALUE_SIZE_4001) | .hasClobValue(VALUE_SIZE_4001) | ||||
.hasCreatedAt(INITIAL_DATE + 6); | |||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
} | } | ||||
@Test | @Test | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue("new value") | .hasTextValue("new value") | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
} | } | ||||
private static Map<String, String> mapOf(String... values) { | private static Map<String, String> mapOf(String... values) { | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasTextValue("bar") | .hasTextValue("bar") | ||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
.hasCreatedAt(INITIAL_DATE); | |||||
assertThatPropertiesRowByUuid(uuid2) | assertThatPropertiesRowByUuid(uuid2) | ||||
.hasKey("new_name") | .hasKey("new_name") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue("doc1") | .hasTextValue("doc1") | ||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
.hasCreatedAt(INITIAL_DATE + 1); | |||||
assertThatPropertiesRowByUuid(uuid3) | assertThatPropertiesRowByUuid(uuid3) | ||||
.hasKey("new_name") | .hasKey("new_name") | ||||
.hasComponentUuid("15") | .hasComponentUuid("15") | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue("doc2") | .hasTextValue("doc2") | ||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
assertThatPropertiesRowByUuid(uuid4) | assertThatPropertiesRowByUuid(uuid4) | ||||
.hasKey("new_name") | .hasKey("new_name") | ||||
.hasComponentUuid("16") | .hasComponentUuid("16") | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasTextValue("doc3") | .hasTextValue("doc3") | ||||
.hasCreatedAt(INITIAL_DATE + 5); | |||||
.hasCreatedAt(INITIAL_DATE + 3); | |||||
assertThatPropertiesRowByUuid(uuid5) | assertThatPropertiesRowByUuid(uuid5) | ||||
.hasKey("new_name") | .hasKey("new_name") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid("100") | .hasUserUuid("100") | ||||
.hasTextValue("doc4") | .hasTextValue("doc4") | ||||
.hasCreatedAt(INITIAL_DATE + 6); | |||||
.hasCreatedAt(INITIAL_DATE + 4); | |||||
assertThatPropertiesRowByUuid(uuid6) | assertThatPropertiesRowByUuid(uuid6) | ||||
.hasKey("new_name") | .hasKey("new_name") | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasUserUuid("101") | .hasUserUuid("101") | ||||
.hasTextValue("doc5") | .hasTextValue("doc5") | ||||
.hasCreatedAt(INITIAL_DATE + 7); | |||||
.hasCreatedAt(INITIAL_DATE + 5); | |||||
} | } | ||||
@Test | @Test | ||||
String uuid = insertProperty("foo", "bar", null, null); | String uuid = insertProperty("foo", "bar", null, null); | ||||
assertThatPropertiesRowByUuid(uuid) | assertThatPropertiesRowByUuid(uuid) | ||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
.hasCreatedAt(INITIAL_DATE); | |||||
underTest.renamePropertyKey("foo", "foo"); | underTest.renamePropertyKey("foo", "foo"); | ||||
.hasNoUserUuid() | .hasNoUserUuid() | ||||
.hasNoComponentUuid() | .hasNoComponentUuid() | ||||
.hasTextValue("bar") | .hasTextValue("bar") | ||||
.hasCreatedAt(INITIAL_DATE + 2); | |||||
.hasCreatedAt(INITIAL_DATE); | |||||
} | } | ||||
@Test | @Test |
@Test | @Test | ||||
public void deleteAnalyses_deletes_rows_in_events_and_event_component_changes() { | public void deleteAnalyses_deletes_rows_in_events_and_event_component_changes() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project); | dbClient.componentDao().insert(dbSession, project); | ||||
SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project); | SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project); | ||||
SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project); | SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_activity_when_deleting_project() { | public void delete_row_in_ce_activity_when_deleting_project() { | ||||
ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject); | dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject); | ||||
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project | // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project | ||||
@Test | @Test | ||||
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_activity_when_deleting_project() { | public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_activity_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeActivityDto projectTask = insertCeActivity(project); | CeActivityDto projectTask = insertCeActivity(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_activity_when_deleting_project() { | public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_activity_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeActivityDto projectTask = insertCeActivity(project); | CeActivityDto projectTask = insertCeActivity(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() { | public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeActivityDto projectTask = insertCeActivity(project); | CeActivityDto projectTask = insertCeActivity(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_activity_when_deleting_project() { | public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_activity_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeActivityDto projectTask = insertCeActivity(project); | CeActivityDto projectTask = insertCeActivity(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() { | public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeQueueDto projectTask = insertCeQueue(project); | CeQueueDto projectTask = insertCeQueue(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() { | public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeQueueDto projectTask = insertCeQueue(project); | CeQueueDto projectTask = insertCeQueue(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() { | public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeQueueDto projectTask = insertCeQueue(project); | CeQueueDto projectTask = insertCeQueue(project); | ||||
@Test | @Test | ||||
public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_queue_when_deleting_project() { | public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_queue_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
CeQueueDto projectTask = insertCeQueue(project); | CeQueueDto projectTask = insertCeQueue(project); | ||||
@Test | @Test | ||||
public void delete_row_in_events_and_event_component_changes_when_deleting_project() { | public void delete_row_in_events_and_event_component_changes_when_deleting_project() { | ||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto project = ComponentTesting.newPrivateProjectDto(); | |||||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | ||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | ||||
SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project); | SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project); | ||||
SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project); | SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project); |
} | } | ||||
@Test | @Test | ||||
public void deleteParamsByRuleParamOfAllOrganizations() { | |||||
public void deleteParamsByRuleParam() { | |||||
ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER); | ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER); | ||||
underTest.insert(dbSession, activeRule1); | underTest.insert(dbSession, activeRule1); | ||||
ActiveRuleParamDto activeRuleParam1 = ActiveRuleParamDto.createFor(rule1Param1).setValue("foo"); | ActiveRuleParamDto activeRuleParam1 = ActiveRuleParamDto.createFor(rule1Param1).setValue("foo"); |
import org.sonar.db.DbClient; | import org.sonar.db.DbClient; | ||||
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
import org.sonar.db.DbTester; | import org.sonar.db.DbTester; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.project.ProjectDto; | import org.sonar.db.project.ProjectDto; | ||||
import static java.util.Arrays.asList; | import static java.util.Arrays.asList; | ||||
assertThat(underTest.selectByUuid(session, otherUser.getUuid())).isNotNull(); | assertThat(underTest.selectByUuid(session, otherUser.getUuid())).isNotNull(); | ||||
} | } | ||||
@Test | |||||
public void clean_users_homepage_when_deleting_organization() { | |||||
UserDto userUnderTest = newUserDto().setHomepageType("ORGANIZATION").setHomepageParameter("dummy-organization-UUID"); | |||||
underTest.insert(session, userUnderTest); | |||||
UserDto untouchedUser = newUserDto().setHomepageType("ORGANIZATION").setHomepageParameter("not-so-dummy-organization-UUID"); | |||||
underTest.insert(session, untouchedUser); | |||||
session.commit(); | |||||
underTest.cleanHomepage(session, new OrganizationDto().setUuid("dummy-organization-UUID")); | |||||
UserDto userWithAHomepageReloaded = underTest.selectByUuid(session, userUnderTest.getUuid()); | |||||
assertThat(userWithAHomepageReloaded.getUpdatedAt()).isEqualTo(NOW); | |||||
assertThat(userWithAHomepageReloaded.getHomepageType()).isNull(); | |||||
assertThat(userWithAHomepageReloaded.getHomepageParameter()).isNull(); | |||||
UserDto untouchedUserReloaded = underTest.selectByUuid(session, untouchedUser.getUuid()); | |||||
assertThat(untouchedUserReloaded.getUpdatedAt()).isEqualTo(untouchedUser.getUpdatedAt()); | |||||
assertThat(untouchedUserReloaded.getHomepageType()).isEqualTo(untouchedUser.getHomepageType()); | |||||
assertThat(untouchedUserReloaded.getHomepageParameter()).isEqualTo(untouchedUser.getHomepageParameter()); | |||||
} | |||||
@Test | @Test | ||||
public void clean_users_homepage_when_deleting_project() { | public void clean_users_homepage_when_deleting_project() { | ||||
import org.sonar.db.project.ProjectDto; | import org.sonar.db.project.ProjectDto; | ||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||||
public class WebhookDaoTest { | public class WebhookDaoTest { | ||||
assertThat(stored.getUuid()).isEqualTo(dto.getUuid()); | assertThat(stored.getUuid()).isEqualTo(dto.getUuid()); | ||||
assertThat(stored.getName()).isEqualTo(dto.getName()); | assertThat(stored.getName()).isEqualTo(dto.getName()); | ||||
assertThat(stored.getUrl()).isEqualTo(dto.getUrl()); | assertThat(stored.getUrl()).isEqualTo(dto.getUrl()); | ||||
assertThat(stored.getOrganizationUuid()).isEqualTo(dbTester.getDefaultOrganization().getUuid()); | |||||
assertThat(stored.getProjectUuid()).isNull(); | assertThat(stored.getProjectUuid()).isNull(); | ||||
assertThat(stored.getSecret()).isEqualTo(dto.getSecret()); | assertThat(stored.getSecret()).isEqualTo(dto.getSecret()); | ||||
assertThat(new Date(stored.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | assertThat(new Date(stored.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | ||||
assertThat(reloaded.getUuid()).isEqualTo(dto.getUuid()); | assertThat(reloaded.getUuid()).isEqualTo(dto.getUuid()); | ||||
assertThat(reloaded.getName()).isEqualTo(dto.getName()); | assertThat(reloaded.getName()).isEqualTo(dto.getName()); | ||||
assertThat(reloaded.getUrl()).isEqualTo(dto.getUrl()); | assertThat(reloaded.getUrl()).isEqualTo(dto.getUrl()); | ||||
assertThat(reloaded.getOrganizationUuid()).isNull(); | |||||
assertThat(reloaded.getProjectUuid()).isEqualTo(dto.getProjectUuid()); | assertThat(reloaded.getProjectUuid()).isEqualTo(dto.getProjectUuid()); | ||||
assertThat(reloaded.getSecret()).isEqualTo(dto.getSecret()); | assertThat(reloaded.getSecret()).isEqualTo(dto.getSecret()); | ||||
assertThat(new Date(reloaded.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | assertThat(new Date(reloaded.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | ||||
assertThat(reloaded.getName()).isEqualTo("a-fancy-webhook"); | assertThat(reloaded.getName()).isEqualTo("a-fancy-webhook"); | ||||
assertThat(reloaded.getUrl()).isEqualTo("http://www.fancy-webhook.io"); | assertThat(reloaded.getUrl()).isEqualTo("http://www.fancy-webhook.io"); | ||||
assertThat(reloaded.getProjectUuid()).isNull(); | assertThat(reloaded.getProjectUuid()).isNull(); | ||||
assertThat(reloaded.getOrganizationUuid()).isEqualTo(dto.getOrganizationUuid()); | |||||
assertThat(reloaded.getSecret()).isNull(); | assertThat(reloaded.getSecret()).isNull(); | ||||
assertThat(reloaded.getCreatedAt()).isEqualTo(dto.getCreatedAt()); | assertThat(reloaded.getCreatedAt()).isEqualTo(dto.getCreatedAt()); | ||||
assertThat(new Date(reloaded.getUpdatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | assertThat(new Date(reloaded.getUpdatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | ||||
assertThat(reloaded.getName()).isEqualTo("a-fancy-webhook"); | assertThat(reloaded.getName()).isEqualTo("a-fancy-webhook"); | ||||
assertThat(reloaded.getUrl()).isEqualTo("http://www.fancy-webhook.io"); | assertThat(reloaded.getUrl()).isEqualTo("http://www.fancy-webhook.io"); | ||||
assertThat(reloaded.getProjectUuid()).isNull(); | assertThat(reloaded.getProjectUuid()).isNull(); | ||||
assertThat(reloaded.getOrganizationUuid()).isEqualTo(dto.getOrganizationUuid()); | |||||
assertThat(reloaded.getSecret()).isEqualTo("a_new_secret"); | assertThat(reloaded.getSecret()).isEqualTo("a_new_secret"); | ||||
assertThat(reloaded.getCreatedAt()).isEqualTo(dto.getCreatedAt()); | assertThat(reloaded.getCreatedAt()).isEqualTo(dto.getCreatedAt()); | ||||
assertThat(new Date(reloaded.getUpdatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | assertThat(new Date(reloaded.getUpdatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | ||||
} | } | ||||
@Test | @Test | ||||
public void set_default_org_if_webhook_does_not_have_a_project_nor_organization() { | |||||
public void set_default_org_if_webhook_does_not_have_a_project() { | |||||
WebhookDto dto = new WebhookDto() | WebhookDto dto = new WebhookDto() | ||||
.setUuid("UUID_1") | .setUuid("UUID_1") | ||||
.setName("NAME_1") | .setName("NAME_1") | ||||
Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid()); | Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid()); | ||||
assertThat(reloaded).isPresent(); | assertThat(reloaded).isPresent(); | ||||
assertThat(reloaded.get().getOrganizationUuid()).isEqualTo(dbTester.getDefaultOrganization().getUuid()); | |||||
} | |||||
@Test | |||||
public void fail_if_webhook_have_both_an_organization_nor_a_project() { | |||||
WebhookDto dto = new WebhookDto() | |||||
.setUuid("UUID_1") | |||||
.setName("NAME_1") | |||||
.setUrl("URL_1") | |||||
.setOrganizationUuid("UUID_2") | |||||
.setProjectUuid("UUID_3"); | |||||
assertThatThrownBy(() -> underTest.insert(dbSession, dto)) | |||||
.isInstanceOf(IllegalStateException.class) | |||||
.hasMessage("A webhook can not be linked to both an organization and a project."); | |||||
} | } | ||||
private WebhookDto selectByUuid(String uuid) { | private WebhookDto selectByUuid(String uuid) { |
private static final long BEFORE = NOW - 1_000L; | private static final long BEFORE = NOW - 1_000L; | ||||
@Rule | @Rule | ||||
public final DbTester dbTester = DbTester.create(System2.INSTANCE).setDisableDefaultOrganization(true); | |||||
public final DbTester dbTester = DbTester.create(System2.INSTANCE); | |||||
@Rule | @Rule | ||||
public ExpectedException expectedException = ExpectedException.none(); | public ExpectedException expectedException = ExpectedException.none(); |
import org.sonar.db.measure.MeasureDbTester; | import org.sonar.db.measure.MeasureDbTester; | ||||
import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; | import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; | ||||
import org.sonar.db.notification.NotificationDbTester; | import org.sonar.db.notification.NotificationDbTester; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.permission.template.PermissionTemplateDbTester; | import org.sonar.db.permission.template.PermissionTemplateDbTester; | ||||
import org.sonar.db.plugin.PluginDbTester; | import org.sonar.db.plugin.PluginDbTester; | ||||
import org.sonar.db.property.InternalComponentPropertyDbTester; | import org.sonar.db.property.InternalComponentPropertyDbTester; | ||||
import org.sonar.db.webhook.WebhookDbTester; | import org.sonar.db.webhook.WebhookDbTester; | ||||
import org.sonar.db.webhook.WebhookDeliveryDbTester; | import org.sonar.db.webhook.WebhookDeliveryDbTester; | ||||
import static com.google.common.base.Preconditions.checkState; | |||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||||
import static org.sonar.db.organization.OrganizationDto.Subscription.FREE; | |||||
/** | /** | ||||
* This class should be called using @Rule. | * This class should be called using @Rule. | ||||
* Data is truncated between each tests. The schema is created between each test. | * Data is truncated between each tests. The schema is created between each test. | ||||
private final System2 system2; | private final System2 system2; | ||||
private DbClient client; | private DbClient client; | ||||
private DbSession session = null; | private DbSession session = null; | ||||
private boolean disableDefaultOrganization = false; | |||||
private boolean started = false; | |||||
private String defaultOrganizationUuid = randomAlphanumeric(40); | |||||
private String defaultOrganizationKey = randomAlphanumeric(40); | |||||
private OrganizationDto defaultOrganization; | |||||
private final UserDbTester userTester; | private final UserDbTester userTester; | ||||
private final ComponentDbTester componentTester; | private final ComponentDbTester componentTester; | ||||
private final ProjectLinkDbTester componentLinkTester; | private final ProjectLinkDbTester componentLinkTester; | ||||
return new DbTester(system2, null); | return new DbTester(system2, null); | ||||
} | } | ||||
public static DbTester createWithExtensionMappers(Class<?> firstMapperClass, Class<?>... otherMapperClasses) { | |||||
return new DbTester(System2.INSTANCE, null, new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses)); | |||||
} | |||||
public static DbTester createWithExtensionMappers(System2 system2, Class<?> firstMapperClass, Class<?>... otherMapperClasses) { | public static DbTester createWithExtensionMappers(System2 system2, Class<?> firstMapperClass, Class<?>... otherMapperClasses) { | ||||
return new DbTester(system2, null, new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses)); | return new DbTester(system2, null, new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses)); | ||||
} | } | ||||
client = new DbClient(db.getDatabase(), db.getMyBatis(), new TestDBSessions(db.getMyBatis()), daos.toArray(new Dao[daos.size()])); | client = new DbClient(db.getDatabase(), db.getMyBatis(), new TestDBSessions(db.getMyBatis()), daos.toArray(new Dao[daos.size()])); | ||||
} | } | ||||
// TODO remove | |||||
@Deprecated | |||||
public DbTester setDisableDefaultOrganization(boolean b) { | |||||
checkState(!started, "DbTester is already started"); | |||||
this.disableDefaultOrganization = b; | |||||
return this; | |||||
} | |||||
// TODO remove | |||||
@Deprecated | |||||
public DbTester setDefaultOrganizationUuid(String uuid) { | |||||
checkState(!started, "DbTester is already started"); | |||||
this.defaultOrganizationUuid = uuid; | |||||
return this; | |||||
} | |||||
// TODO remove | |||||
@Deprecated | |||||
public DbTester setDefaultOrganizationKey(String key) { | |||||
checkState(!started, "DbTester is already started"); | |||||
this.defaultOrganizationKey = key; | |||||
return this; | |||||
} | |||||
@Override | @Override | ||||
protected void before() { | protected void before() { | ||||
db.start(); | db.start(); | ||||
db.truncateTables(); | db.truncateTables(); | ||||
initDbClient(); | initDbClient(); | ||||
if (!disableDefaultOrganization) { | |||||
insertDefaultOrganization(); | |||||
} | |||||
started = true; | |||||
} | |||||
// TODO remove | |||||
@Deprecated | |||||
private void insertDefaultOrganization() { | |||||
defaultOrganization = new OrganizationDto() | |||||
.setName(randomAlphanumeric(64)) | |||||
.setDescription(randomAlphanumeric(256)) | |||||
.setAvatarUrl(randomAlphanumeric(256)) | |||||
// Default quality gate should be set explicitly when needed in tests | |||||
.setDefaultQualityGateUuid("_NOT_SET_") | |||||
.setSubscription(FREE) | |||||
.setUrl(randomAlphanumeric(256)) | |||||
.setUuid(defaultOrganizationUuid) | |||||
.setKey(defaultOrganizationKey); | |||||
try (DbSession dbSession = db.getMyBatis().openSession(false)) { | |||||
client.organizationDao().insert(dbSession, defaultOrganization, false); | |||||
client.internalPropertiesDao().save(dbSession, "organization.default", defaultOrganization.getUuid()); | |||||
dbSession.commit(); | |||||
} | |||||
} | |||||
// TODO remove | |||||
@Deprecated | |||||
public OrganizationDto getDefaultOrganization() { | |||||
checkState(defaultOrganization != null, "Default organization has not been created"); | |||||
return defaultOrganization; | |||||
} | } | ||||
public UserDbTester users() { | public UserDbTester users() { | ||||
session.close(); | session.close(); | ||||
} | } | ||||
db.stop(); | db.stop(); | ||||
started = false; | |||||
} | } | ||||
public DbSession getSession() { | public DbSession getSession() { |
} | } | ||||
public SnapshotDto insertViewAndSnapshot(ComponentDto component) { | public SnapshotDto insertViewAndSnapshot(ComponentDto component) { | ||||
if (component.getOrganizationUuid() == null) { | |||||
component.setOrganizationUuid(db.getDefaultOrganization().getUuid()); | |||||
} | |||||
dbClient.componentDao().insert(dbSession, component); | dbClient.componentDao().insert(dbSession, component); | ||||
return insertSnapshot(component); | return insertSnapshot(component); | ||||
} | } | ||||
private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto> dtoPopulator) { | private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto> dtoPopulator) { | ||||
dtoPopulator.accept(component); | dtoPopulator.accept(component); | ||||
checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag"); | checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag"); | ||||
if (component.getOrganizationUuid() == null) { | |||||
component.setOrganizationUuid(db.getDefaultOrganization().getUuid()); | |||||
} | |||||
dbClient.componentDao().insert(dbSession, component); | dbClient.componentDao().insert(dbSession, component); | ||||
db.commit(); | db.commit(); | ||||
return component; | return component; | ||||
} | } | ||||
private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate) { | |||||
return insertComponentImpl(component, isPrivate, defaults()); | |||||
} | |||||
public void insertComponents(ComponentDto... components) { | public void insertComponents(ComponentDto... components) { | ||||
String defaultOrgUuid = db.getDefaultOrganization().getUuid(); | |||||
Arrays.stream(components).forEach(c -> { | |||||
if (c.getOrganizationUuid() == null) { | |||||
c.setOrganizationUuid(defaultOrgUuid); | |||||
} | |||||
}); | |||||
dbClient.componentDao().insert(dbSession, asList(components)); | dbClient.componentDao().insert(dbSession, asList(components)); | ||||
db.commit(); | db.commit(); | ||||
} | } | ||||
.setUpdatedAt(createTime) | .setUpdatedAt(createTime) | ||||
.setPrivate(componentDto.isPrivate()) | .setPrivate(componentDto.isPrivate()) | ||||
.setDescription(componentDto.description()) | .setDescription(componentDto.description()) | ||||
.setName(componentDto.name()) | |||||
.setOrganizationUuid(componentDto.getOrganizationUuid()); | |||||
.setName(componentDto.name()); | |||||
} | } | ||||
private static <T> Consumer<T> defaults() { | private static <T> Consumer<T> defaults() { |
import org.sonar.api.resources.Qualifiers; | import org.sonar.api.resources.Qualifiers; | ||||
import org.sonar.api.resources.Scopes; | import org.sonar.api.resources.Scopes; | ||||
import org.sonar.core.util.Uuids; | import org.sonar.core.util.Uuids; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.project.ProjectDto; | import org.sonar.db.project.ProjectDto; | ||||
import static com.google.common.base.Preconditions.checkArgument; | import static com.google.common.base.Preconditions.checkArgument; | ||||
return newProjectDto(Uuids.createFast(), true); | return newProjectDto(Uuids.createFast(), true); | ||||
} | } | ||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto) { | |||||
return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), true); | |||||
} | |||||
public static ComponentDto newPrivateProjectDto(String uuid) { | public static ComponentDto newPrivateProjectDto(String uuid) { | ||||
return newProjectDto(uuid, true); | return newProjectDto(uuid, true); | ||||
} | } | ||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto, String uuid) { | |||||
return newProjectDto(organizationDto.getUuid(), uuid, true); | |||||
} | |||||
public static ComponentDto newPublicProjectDto() { | public static ComponentDto newPublicProjectDto() { | ||||
return newProjectDto(Uuids.createFast(), false); | return newProjectDto(Uuids.createFast(), false); | ||||
} | } | ||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto) { | |||||
return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), false); | |||||
} | |||||
public static ComponentDto newPublicProjectDto(String uuid) { | public static ComponentDto newPublicProjectDto(String uuid) { | ||||
return newProjectDto(uuid, false); | return newProjectDto(uuid, false); | ||||
} | } | ||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto, String uuid) { | |||||
return newProjectDto(organizationDto.getUuid(), uuid, false); | |||||
} | |||||
private static ComponentDto newProjectDto(String uuid, boolean isPrivate) { | private static ComponentDto newProjectDto(String uuid, boolean isPrivate) { | ||||
return new ComponentDto() | return new ComponentDto() | ||||
.setUuid(uuid) | .setUuid(uuid) | ||||
.setPrivate(isPrivate); | .setPrivate(isPrivate); | ||||
} | } | ||||
/** | |||||
* use {@link org.sonar.db.component.ComponentTesting#newProjectDto(java.lang.String, boolean)} instead | |||||
*/ | |||||
// TODO remove after getting rid of organization code | |||||
@Deprecated | |||||
private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) { | |||||
return new ComponentDto() | |||||
.setOrganizationUuid(organizationUuid) | |||||
.setUuid(uuid) | |||||
.setUuidPath(UUID_PATH_OF_ROOT) | |||||
.setProjectUuid(uuid) | |||||
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) | |||||
.setRootUuid(uuid) | |||||
.setDbKey("KEY_" + uuid) | |||||
.setName("NAME_" + uuid) | |||||
.setLongName("LONG_NAME_" + uuid) | |||||
.setDescription("DESCRIPTION_" + uuid) | |||||
.setScope(Scopes.PROJECT) | |||||
.setQualifier(Qualifiers.PROJECT) | |||||
.setPath(null) | |||||
.setLanguage(null) | |||||
.setEnabled(true) | |||||
.setPrivate(isPrivate); | |||||
} | |||||
public static ComponentDto newView() { | public static ComponentDto newView() { | ||||
return newView(Uuids.createFast()); | return newView(Uuids.createFast()); | ||||
} | } | ||||
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { | public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { | ||||
return newChildComponent(uuid, view, view) | return newChildComponent(uuid, view, view) | ||||
.setDbKey(view.getDbKey() + project.getDbKey()) | .setDbKey(view.getDbKey() + project.getDbKey()) | ||||
.setOrganizationUuid(project.getOrganizationUuid()) | |||||
.setName(project.name()) | .setName(project.name()) | ||||
.setLongName(project.longName()) | .setLongName(project.longName()) | ||||
.setCopyComponentUuid(project.uuid()) | .setCopyComponentUuid(project.uuid()) | ||||
"private flag inconsistent between moduleOrProject (%s) and parent (%s)", | "private flag inconsistent between moduleOrProject (%s) and parent (%s)", | ||||
moduleOrProject.isPrivate(), parent.isPrivate()); | moduleOrProject.isPrivate(), parent.isPrivate()); | ||||
return new ComponentDto() | return new ComponentDto() | ||||
.setOrganizationUuid(parent.getOrganizationUuid()) | |||||
.setUuid(uuid) | .setUuid(uuid) | ||||
.setUuidPath(formatUuidPathFromParent(parent)) | .setUuidPath(formatUuidPathFromParent(parent)) | ||||
.setProjectUuid(moduleOrProject.projectUuid()) | .setProjectUuid(moduleOrProject.projectUuid()) | ||||
String uuid = branchDto.getUuid(); | String uuid = branchDto.getUuid(); | ||||
return new ComponentDto() | return new ComponentDto() | ||||
.setUuid(uuid) | .setUuid(uuid) | ||||
.setOrganizationUuid(project.getOrganizationUuid()) | |||||
.setUuidPath(UUID_PATH_OF_ROOT) | .setUuidPath(UUID_PATH_OF_ROOT) | ||||
.setProjectUuid(uuid) | .setProjectUuid(uuid) | ||||
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) | .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) | ||||
String uuid = branchDto.getUuid(); | String uuid = branchDto.getUuid(); | ||||
return new ComponentDto() | return new ComponentDto() | ||||
.setUuid(uuid) | .setUuid(uuid) | ||||
.setOrganizationUuid(project.getOrganizationUuid()) | |||||
.setUuidPath(UUID_PATH_OF_ROOT) | .setUuidPath(UUID_PATH_OF_ROOT) | ||||
.setProjectUuid(uuid) | .setProjectUuid(uuid) | ||||
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) | .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) |
public class QualityProfileDbTester { | public class QualityProfileDbTester { | ||||
private final DbClient dbClient; | private final DbClient dbClient; | ||||
private final DbSession dbSession; | private final DbSession dbSession; | ||||
private final DbTester dbTester; | |||||
public QualityProfileDbTester(DbTester dbTester) { | public QualityProfileDbTester(DbTester dbTester) { | ||||
this.dbClient = dbTester.getDbClient(); | this.dbClient = dbTester.getDbClient(); | ||||
this.dbSession = dbTester.getSession(); | this.dbSession = dbTester.getSession(); | ||||
this.dbTester = dbTester; | |||||
} | } | ||||
public Optional<QProfileDto> selectByUuid(String uuid) { | public Optional<QProfileDto> selectByUuid(String uuid) { | ||||
} | } | ||||
/** | /** | ||||
* Create a profile with random field values on the specified organization. | |||||
* Create a profile with random field values. | |||||
*/ | */ | ||||
public QProfileDto insert() { | public QProfileDto insert() { | ||||
return insert(c -> { | return insert(c -> { |
import org.sonar.api.server.rule.RuleParamType; | import org.sonar.api.server.rule.RuleParamType; | ||||
import org.sonar.core.util.Uuids; | import org.sonar.core.util.Uuids; | ||||
import org.sonar.db.DbTester; | import org.sonar.db.DbTester; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.user.UserDto; | import org.sonar.db.user.UserDto; | ||||
import static java.util.Arrays.asList; | import static java.util.Arrays.asList; |
import org.sonar.core.util.UuidFactory; | import org.sonar.core.util.UuidFactory; | ||||
import org.sonar.core.util.UuidFactoryFast; | import org.sonar.core.util.UuidFactoryFast; | ||||
import org.sonar.core.util.Uuids; | import org.sonar.core.util.Uuids; | ||||
import org.sonar.db.organization.OrganizationDto; | |||||
import org.sonar.db.rule.RuleDto.Format; | import org.sonar.db.rule.RuleDto.Format; | ||||
import org.sonar.db.rule.RuleDto.Scope; | import org.sonar.db.rule.RuleDto.Scope; | ||||
import org.sonar.db.user.UserDto; | import org.sonar.db.user.UserDto; | ||||
import static com.google.common.base.Preconditions.checkNotNull; | import static com.google.common.base.Preconditions.checkNotNull; | ||||
import static com.google.common.collect.ImmutableSet.copyOf; | import static com.google.common.collect.ImmutableSet.copyOf; | ||||
import static com.google.common.collect.Sets.newHashSet; | import static com.google.common.collect.Sets.newHashSet; | ||||
import static java.util.Objects.requireNonNull; | |||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | ||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | ||||
import static org.apache.commons.lang.math.RandomUtils.nextInt; | import static org.apache.commons.lang.math.RandomUtils.nextInt; |
} | } | ||||
public List<GlobalPermission> selectPermissionsOfUser(UserDto user) { | public List<GlobalPermission> selectPermissionsOfUser(UserDto user) { | ||||
return toListOfOrganizationPermissions(db.getDbClient().userPermissionDao() | |||||
return toListOfGlobalPermissions(db.getDbClient().userPermissionDao() | |||||
.selectGlobalPermissionsOfUser(db.getSession(), user.getUuid())); | .selectGlobalPermissionsOfUser(db.getSession(), user.getUuid())); | ||||
} | } | ||||
return db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getUuid(), project.uuid()); | return db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getUuid(), project.uuid()); | ||||
} | } | ||||
private static List<GlobalPermission> toListOfOrganizationPermissions(List<String> keys) { | |||||
private static List<GlobalPermission> toListOfGlobalPermissions(List<String> keys) { | |||||
return keys | return keys | ||||
.stream() | .stream() | ||||
.map(GlobalPermission::fromKey) | .map(GlobalPermission::fromKey) |
public WebhookDto insert(WebhookDto dto) { | public WebhookDto insert(WebhookDto dto) { | ||||
DbSession dbSession = dbTester.getSession(); | DbSession dbSession = dbTester.getSession(); | ||||
if (dto.getProjectUuid() == null && dto.getOrganizationUuid() == null) { | |||||
dto.setOrganizationUuid(dbTester.getDefaultOrganization().getUuid()); | |||||
} | |||||
dbTester.getDbClient().webhookDao().insert(dbSession, dto); | dbTester.getDbClient().webhookDao().insert(dbSession, dto); | ||||
dbSession.commit(); | dbSession.commit(); | ||||
return dto; | return dto; |
.add(4200, "Move default project visibility to global properties", MoveDefaultProjectVisibilityToGlobalProperties.class) | .add(4200, "Move default project visibility to global properties", MoveDefaultProjectVisibilityToGlobalProperties.class) | ||||
.add(4201, "Move default quality gate to global properties", MoveDefaultQualityGateToGlobalProperties.class) | .add(4201, "Move default quality gate to global properties", MoveDefaultQualityGateToGlobalProperties.class) | ||||
.add(4202, "Drop organization_uuid in table 'components'", DropOrganizationInComponents.class) | |||||
.add(4203, "Drop organization_uuid in table 'projects'", DropOrganizationInProjects.class) | |||||
.add(4204, "Drop organizations in table 'webhooks'", DropOrganizationInWebhooks.class) | |||||
.add(4205, "Drop table 'org_quality_gates'", DropOrgQualityGatesTable.class) | |||||
.add(4206, "Drop table 'organization_alm_bindings'", DropOrganizationAlmBindingsTable.class) | |||||
.add(4207, "Drop table 'alm_app_installs'", DropAlmAppInstallsTable.class) | |||||
.add(4208, "Drop table 'organizations'", DropOrganizationsTable.class) | |||||
.add(4209, "Drop table 'organization_members'", DropOrgMembersTable.class) | |||||
; | ; | ||||
} | } | ||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropTableBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public class DropAlmAppInstallsTable extends DdlChange { | |||||
private static final String TABLE_NAME = "alm_app_installs"; | |||||
public DropAlmAppInstallsTable(Database db) { | |||||
super(db); | |||||
} | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropConstraintBuilder(getDialect()).setTable(TABLE_NAME).setName("pk_alm_app_installs").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("alm_app_installs_owner").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("alm_app_installs_install").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("alm_app_installs_external_id").build()); | |||||
context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build()); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropTableBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public class DropOrgMembersTable extends DdlChange { | |||||
private static final String TABLE_NAME = "organization_members"; | |||||
public DropOrgMembersTable(Database db) { | |||||
super(db); | |||||
} | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropConstraintBuilder(getDialect()).setTable(TABLE_NAME).setName("pk_organization_members").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("org_members_user_uuid").build()); | |||||
context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build()); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropTableBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public class DropOrgQualityGatesTable extends DdlChange { | |||||
private static final String TABLE_NAME = "org_quality_gates"; | |||||
public DropOrgQualityGatesTable(Database db) { | |||||
super(db); | |||||
} | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropConstraintBuilder(getDialect()).setTable(TABLE_NAME).setName("pk_org_quality_gates").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("uniq_org_quality_gates").build()); | |||||
context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build()); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropTableBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public class DropOrganizationAlmBindingsTable extends DdlChange { | |||||
private static final String TABLE_NAME = "organization_alm_bindings"; | |||||
public DropOrganizationAlmBindingsTable(Database db) { | |||||
super(db); | |||||
} | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropConstraintBuilder(getDialect()).setTable(TABLE_NAME).setName("pk_organization_alm_bindings").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("org_alm_bindings_org").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("org_alm_bindings_install").build()); | |||||
context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build()); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public class DropOrganizationInComponents extends DdlChange { | |||||
private static final String TABLE_NAME = "components"; | |||||
public DropOrganizationInComponents(Database db) { | |||||
super(db); | |||||
} | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("projects_organization").build()); | |||||
context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "organization_uuid").build()); | |||||
} | |||||
} |
* along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
*/ | */ | ||||
package org.sonar.server.organization; | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import org.sonar.db.DbSession; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public interface OrganizationFlags { | |||||
public class DropOrganizationInProjects extends DdlChange { | |||||
private static final String TABLE_NAME = "projects"; | |||||
boolean isEnabled(DbSession dbSession); | |||||
public DropOrganizationInProjects(Database db) { | |||||
super(db); | |||||
} | |||||
/** | |||||
* Ensures that {@link #isEnabled(DbSession)} is {@code true}, | |||||
* otherwise throws {@link IllegalStateException} | |||||
*/ | |||||
void checkEnabled(DbSession dbSession); | |||||
/** | |||||
* Ensures that {@link #isEnabled(DbSession)} is {@code false}, | |||||
* otherwise throws {@link IllegalStateException} | |||||
*/ | |||||
void checkDisabled(DbSession dbSession); | |||||
void enable(DbSession dbSession); | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "organization_uuid").build()); | |||||
} | |||||
} | } |
* along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
*/ | */ | ||||
package org.sonar.db.organization; | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
public class OrganizationWithNclocDto { | |||||
private String id; | |||||
private String kee; | |||||
private String name; | |||||
private long ncloc; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public String getId() { | |||||
return id; | |||||
} | |||||
public OrganizationWithNclocDto setId(String id) { | |||||
this.id = id; | |||||
return this; | |||||
} | |||||
public String getKee() { | |||||
return kee; | |||||
} | |||||
public class DropOrganizationInWebhooks extends DdlChange { | |||||
private static final String TABLE_NAME = "webhooks"; | |||||
public OrganizationWithNclocDto setKee(String kee) { | |||||
this.kee = kee; | |||||
return this; | |||||
public DropOrganizationInWebhooks(Database db) { | |||||
super(db); | |||||
} | } | ||||
public String getName() { | |||||
return name; | |||||
} | |||||
public OrganizationWithNclocDto setName(String name) { | |||||
this.name = name; | |||||
return this; | |||||
} | |||||
public long getNcloc() { | |||||
return ncloc; | |||||
} | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("project_webhook").build()); | |||||
context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "organization_uuid").build()); | |||||
public OrganizationWithNclocDto setNcloc(long ncloc) { | |||||
this.ncloc = ncloc; | |||||
return this; | |||||
} | } | ||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.sonar.db.Database; | |||||
import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||||
import org.sonar.server.platform.db.migration.sql.DropTableBuilder; | |||||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||||
public class DropOrganizationsTable extends DdlChange { | |||||
private static final String TABLE_NAME = "organizations"; | |||||
public DropOrganizationsTable(Database db) { | |||||
super(db); | |||||
} | |||||
@Override | |||||
public void execute(Context context) throws SQLException { | |||||
context.execute(new DropConstraintBuilder(getDialect()).setTable(TABLE_NAME).setName("pk_organizations").build()); | |||||
context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("organization_key").build()); | |||||
context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build()); | |||||
} | |||||
} |
* along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
*/ | */ | ||||
package org.sonarqube.ws.client.navigation; | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import javax.annotation.Generated; | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
/** | |||||
* This is part of the internal API. | |||||
* This is a POST request. | |||||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/navigation/organization">Further information about this action online (including a response example)</a> | |||||
* @since 6.3 | |||||
*/ | |||||
@Generated("sonar-ws-generator") | |||||
public class OrganizationRequest { | |||||
public class DropAlmAppInstallsTableTest { | |||||
private static final String TABLE_NAME = "alm_app_installs"; | |||||
private String organization; | |||||
@Rule | |||||
public CoreDbTester db = CoreDbTester.createForSchema(DropAlmAppInstallsTableTest.class, "schema.sql"); | |||||
/** | |||||
* This is a mandatory parameter. | |||||
* Example value: "my-org" | |||||
*/ | |||||
public OrganizationRequest setOrganization(String organization) { | |||||
this.organization = organization; | |||||
return this; | |||||
} | |||||
private MigrationStep underTest = new DropAlmAppInstallsTable(db.database()); | |||||
public String getOrganization() { | |||||
return organization; | |||||
@Test | |||||
public void execute() throws SQLException { | |||||
db.assertTableExists(TABLE_NAME); | |||||
underTest.execute(); | |||||
db.assertTableDoesNotExist(TABLE_NAME); | |||||
} | } | ||||
} | } |
* along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
*/ | */ | ||||
package org.sonar.server.organization; | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
//TODO remove | |||||
@Deprecated | |||||
public interface DefaultOrganizationProvider { | |||||
/** | |||||
* @throws IllegalStateException if there is no default organization | |||||
*/ | |||||
DefaultOrganization get(); | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
public class DropOrgMembersTableTest { | |||||
@Rule | |||||
public CoreDbTester dbTester = CoreDbTester.createForSchema(DropOrgMembersTableTest.class, "schema.sql"); | |||||
private final MigrationStep underTest = new DropOrgMembersTable(dbTester.database()); | |||||
@Test | |||||
public void table_is_dropped() throws SQLException { | |||||
dbTester.assertTableExists("organization_members"); | |||||
underTest.execute(); | |||||
dbTester.assertTableDoesNotExist("organization_members"); | |||||
} | |||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
public class DropOrgQualityGatesTableTest { | |||||
private static final String TABLE_NAME = "org_quality_gates"; | |||||
@Rule | |||||
public CoreDbTester db = CoreDbTester.createForSchema(DropOrgQualityGatesTableTest.class, "schema.sql"); | |||||
private MigrationStep underTest = new DropOrgQualityGatesTable(db.database()); | |||||
@Test | |||||
public void execute() throws SQLException { | |||||
db.assertTableExists(TABLE_NAME); | |||||
underTest.execute(); | |||||
db.assertTableDoesNotExist(TABLE_NAME); | |||||
} | |||||
} |
* along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
*/ | */ | ||||
package org.sonar.server.organization; | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
import static org.mockito.Mockito.mock; | |||||
import static org.mockito.Mockito.verify; | |||||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||||
public class DropOrganizationAlmBindingsTableTest { | |||||
private static final String TABLE_NAME = "organization_alm_bindings"; | |||||
public class DefaultOrganizationEnforcerTest { | |||||
private DefaultOrganizationProvider defaultOrganizationProvider = mock(DefaultOrganizationProvider.class); | |||||
private DefaultOrganizationEnforcer underTest = new DefaultOrganizationEnforcer(defaultOrganizationProvider); | |||||
@Rule | |||||
public CoreDbTester db = CoreDbTester.createForSchema(DropOrganizationAlmBindingsTableTest.class, "schema.sql"); | |||||
@Test | |||||
public void start_calls_provider_get_method() { | |||||
underTest.start(); | |||||
verify(defaultOrganizationProvider).get(); | |||||
verifyNoMoreInteractions(defaultOrganizationProvider); | |||||
} | |||||
private MigrationStep underTest = new DropOrganizationAlmBindingsTable(db.database()); | |||||
@Test | @Test | ||||
public void stop_does_nothing() { | |||||
underTest.stop(); | |||||
verifyNoMoreInteractions(defaultOrganizationProvider); | |||||
public void execute() throws SQLException { | |||||
db.assertTableExists(TABLE_NAME); | |||||
underTest.execute(); | |||||
db.assertTableDoesNotExist(TABLE_NAME); | |||||
} | } | ||||
} | } |
* along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
*/ | */ | ||||
package org.sonar.server.organization; | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import org.picocontainer.Startable; | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
//TODO remove together with the default organization concept | |||||
@Deprecated | |||||
public class DefaultOrganizationEnforcer implements Startable { | |||||
private final DefaultOrganizationProvider defaultOrganizationProvider; | |||||
public class DropOrganizationInComponentsTest { | |||||
@Rule | |||||
public CoreDbTester dbTester = CoreDbTester.createForSchema(DropOrganizationInComponentsTest.class, "schema.sql"); | |||||
public DefaultOrganizationEnforcer(DefaultOrganizationProvider defaultOrganizationProvider) { | |||||
this.defaultOrganizationProvider = defaultOrganizationProvider; | |||||
} | |||||
private final MigrationStep underTest = new DropOrganizationInComponents(dbTester.database()); | |||||
@Override | |||||
public void start() { | |||||
// get will fail with IllegalStateException if no default organization can be found | |||||
defaultOrganizationProvider.get(); | |||||
@Test | |||||
public void column_has_been_dropped() throws SQLException { | |||||
underTest.execute(); | |||||
dbTester.assertColumnDoesNotExist("components", "organization_uuid"); | |||||
} | } | ||||
@Override | |||||
public void stop() { | |||||
// nothing to do | |||||
} | |||||
} | } |
* along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
*/ | */ | ||||
package org.sonar.server.usergroups; | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import org.sonar.db.DbSession; | |||||
import org.sonar.db.user.GroupDto; | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
public interface DefaultGroupCreator { | |||||
public class DropOrganizationInProjectsTest { | |||||
@Rule | |||||
public CoreDbTester dbTester = CoreDbTester.createForSchema(DropOrganizationInProjectsTest.class, "schema.sql"); | |||||
/** | |||||
* Create the default group | |||||
*/ | |||||
GroupDto create(DbSession dbSession); | |||||
private final MigrationStep underTest = new DropOrganizationInProjects(dbTester.database()); | |||||
@Test | |||||
public void column_has_been_dropped() throws SQLException { | |||||
underTest.execute(); | |||||
dbTester.assertColumnDoesNotExist("projects", "organization_uuid"); | |||||
} | |||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
public class DropOrganizationInWebhooksTest { | |||||
@Rule | |||||
public CoreDbTester dbTester = CoreDbTester.createForSchema(DropOrganizationInWebhooksTest.class, "schema.sql"); | |||||
private final MigrationStep underTest = new DropOrganizationInWebhooks(dbTester.database()); | |||||
@Test | |||||
public void column_has_been_dropped() throws SQLException { | |||||
underTest.execute(); | |||||
dbTester.assertIndexDoesNotExist("webhooks", "project_webhook"); | |||||
dbTester.assertColumnDoesNotExist("webhooks", "organization_uuid"); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.platform.db.migration.version.v87; | |||||
import java.sql.SQLException; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.db.CoreDbTester; | |||||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||||
public class DropOrganizationsTableTest { | |||||
private static final String TABLE_NAME = "organizations"; | |||||
@Rule | |||||
public CoreDbTester db = CoreDbTester.createForSchema(DropOrganizationsTableTest.class, "schema.sql"); | |||||
private MigrationStep underTest = new DropOrganizationsTable(db.database()); | |||||
@Test | |||||
public void execute() throws SQLException { | |||||
db.assertTableExists(TABLE_NAME); | |||||
underTest.execute(); | |||||
db.assertTableDoesNotExist(TABLE_NAME); | |||||
} | |||||
} |
CREATE TABLE "ALM_APP_INSTALLS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"ALM_ID" VARCHAR(40) NOT NULL, | |||||
"OWNER_ID" VARCHAR(4000) NOT NULL, | |||||
"INSTALL_ID" VARCHAR(4000) NOT NULL, | |||||
"IS_OWNER_USER" BOOLEAN NOT NULL, | |||||
"USER_EXTERNAL_ID" VARCHAR(255), | |||||
"CREATED_AT" BIGINT NOT NULL, | |||||
"UPDATED_AT" BIGINT NOT NULL | |||||
); | |||||
ALTER TABLE "ALM_APP_INSTALLS" ADD CONSTRAINT "PK_ALM_APP_INSTALLS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ALM_APP_INSTALLS_OWNER" ON "ALM_APP_INSTALLS"("ALM_ID", "OWNER_ID"); | |||||
CREATE UNIQUE INDEX "ALM_APP_INSTALLS_INSTALL" ON "ALM_APP_INSTALLS"("ALM_ID", "INSTALL_ID"); | |||||
CREATE INDEX "ALM_APP_INSTALLS_EXTERNAL_ID" ON "ALM_APP_INSTALLS"("USER_EXTERNAL_ID"); |
CREATE TABLE "ORGANIZATION_MEMBERS"( | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"USER_UUID" VARCHAR(255) NOT NULL | |||||
); | |||||
ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("USER_UUID", "ORGANIZATION_UUID"); | |||||
CREATE INDEX "ORG_MEMBERS_USER_UUID" ON "ORGANIZATION_MEMBERS"("USER_UUID"); | |||||
CREATE TABLE "ORGANIZATIONS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"KEE" VARCHAR(255) NOT NULL, | |||||
"NAME" VARCHAR(255) NOT NULL, | |||||
"DESCRIPTION" VARCHAR(256), | |||||
"URL" VARCHAR(256), | |||||
"AVATAR_URL" VARCHAR(256), | |||||
"GUARDED" BOOLEAN, | |||||
"DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL, | |||||
"DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), | |||||
"NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, | |||||
"SUBSCRIPTION" VARCHAR(40) NOT NULL, | |||||
"CREATED_AT" BIGINT NOT NULL, | |||||
"UPDATED_AT" BIGINT NOT NULL, | |||||
"DEFAULT_GROUP_UUID" VARCHAR(40) | |||||
); | |||||
ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); |
CREATE TABLE "ORG_QUALITY_GATES"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"QUALITY_GATE_UUID" VARCHAR(40) NOT NULL | |||||
); | |||||
ALTER TABLE "ORG_QUALITY_GATES" ADD CONSTRAINT "PK_ORG_QUALITY_GATES" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "UNIQ_ORG_QUALITY_GATES" ON "ORG_QUALITY_GATES"("ORGANIZATION_UUID", "QUALITY_GATE_UUID"); |
CREATE TABLE "ORGANIZATION_ALM_BINDINGS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"ALM_APP_INSTALL_UUID" VARCHAR(40) NOT NULL, | |||||
"ALM_ID" VARCHAR(40) NOT NULL, | |||||
"URL" VARCHAR(2000) NOT NULL, | |||||
"USER_UUID" VARCHAR(255) NOT NULL, | |||||
"MEMBERS_SYNC_ENABLED" BOOLEAN, | |||||
"CREATED_AT" BIGINT NOT NULL | |||||
); | |||||
ALTER TABLE "ORGANIZATION_ALM_BINDINGS" ADD CONSTRAINT "PK_ORGANIZATION_ALM_BINDINGS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ORG_ALM_BINDINGS_ORG" ON "ORGANIZATION_ALM_BINDINGS"("ORGANIZATION_UUID"); | |||||
CREATE UNIQUE INDEX "ORG_ALM_BINDINGS_INSTALL" ON "ORGANIZATION_ALM_BINDINGS"("ALM_APP_INSTALL_UUID"); |
CREATE TABLE "COMPONENTS"( | |||||
"UUID" VARCHAR(50) NOT NULL, | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"KEE" VARCHAR(400), | |||||
"DEPRECATED_KEE" VARCHAR(400), | |||||
"NAME" VARCHAR(2000), | |||||
"LONG_NAME" VARCHAR(2000), | |||||
"DESCRIPTION" VARCHAR(2000), | |||||
"ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, | |||||
"SCOPE" VARCHAR(3), | |||||
"QUALIFIER" VARCHAR(10), | |||||
"PRIVATE" BOOLEAN NOT NULL, | |||||
"ROOT_UUID" VARCHAR(50) NOT NULL, | |||||
"LANGUAGE" VARCHAR(20), | |||||
"COPY_COMPONENT_UUID" VARCHAR(50), | |||||
"PATH" VARCHAR(2000), | |||||
"UUID_PATH" VARCHAR(1500) NOT NULL, | |||||
"PROJECT_UUID" VARCHAR(50) NOT NULL, | |||||
"MODULE_UUID" VARCHAR(50), | |||||
"MODULE_UUID_PATH" VARCHAR(1500), | |||||
"MAIN_BRANCH_PROJECT_UUID" VARCHAR(50), | |||||
"B_CHANGED" BOOLEAN, | |||||
"B_NAME" VARCHAR(500), | |||||
"B_LONG_NAME" VARCHAR(500), | |||||
"B_DESCRIPTION" VARCHAR(2000), | |||||
"B_ENABLED" BOOLEAN, | |||||
"B_QUALIFIER" VARCHAR(10), | |||||
"B_LANGUAGE" VARCHAR(20), | |||||
"B_COPY_COMPONENT_UUID" VARCHAR(50), | |||||
"B_PATH" VARCHAR(2000), | |||||
"B_UUID_PATH" VARCHAR(1500), | |||||
"B_MODULE_UUID" VARCHAR(50), | |||||
"B_MODULE_UUID_PATH" VARCHAR(1500), | |||||
"CREATED_AT" TIMESTAMP | |||||
); | |||||
CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID"); | |||||
CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE"); | |||||
CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID"); | |||||
CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID"); | |||||
CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER"); | |||||
CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID"); | |||||
CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID"); |
CREATE TABLE "PROJECTS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"KEE" VARCHAR(400) NOT NULL, | |||||
"QUALIFIER" VARCHAR(10) NOT NULL, | |||||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||||
"NAME" VARCHAR(2000), | |||||
"DESCRIPTION" VARCHAR(2000), | |||||
"PRIVATE" BOOLEAN NOT NULL, | |||||
"TAGS" VARCHAR(500), | |||||
"CREATED_AT" BIGINT, | |||||
"UPDATED_AT" BIGINT NOT NULL | |||||
); | |||||
ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "UNIQ_PROJECTS_KEE" ON "PROJECTS"("KEE"); | |||||
CREATE INDEX "IDX_QUALIFIER" ON "PROJECTS"("QUALIFIER"); |
CREATE TABLE "WEBHOOKS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"ORGANIZATION_UUID" VARCHAR(40), | |||||
"PROJECT_UUID" VARCHAR(40), | |||||
"NAME" VARCHAR(100) NOT NULL, | |||||
"URL" VARCHAR(2000) NOT NULL, | |||||
"SECRET" VARCHAR(200), | |||||
"CREATED_AT" BIGINT NOT NULL, | |||||
"UPDATED_AT" BIGINT | |||||
); | |||||
ALTER TABLE "WEBHOOKS" ADD CONSTRAINT "PK_WEBHOOKS" PRIMARY KEY("UUID"); | |||||
CREATE INDEX "ORGANIZATION_WEBHOOK" ON "WEBHOOKS"("ORGANIZATION_UUID"); | |||||
CREATE INDEX "PROJECT_WEBHOOK" ON "WEBHOOKS"("PROJECT_UUID"); | |||||
CREATE TABLE "ORGANIZATIONS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"KEE" VARCHAR(255) NOT NULL, | |||||
"NAME" VARCHAR(255) NOT NULL, | |||||
"DESCRIPTION" VARCHAR(256), | |||||
"URL" VARCHAR(256), | |||||
"AVATAR_URL" VARCHAR(256), | |||||
"GUARDED" BOOLEAN, | |||||
"DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL, | |||||
"DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), | |||||
"NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, | |||||
"SUBSCRIPTION" VARCHAR(40) NOT NULL, | |||||
"CREATED_AT" BIGINT NOT NULL, | |||||
"UPDATED_AT" BIGINT NOT NULL, | |||||
"DEFAULT_GROUP_UUID" VARCHAR(40) | |||||
); | |||||
ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); |
CREATE TABLE "ORGANIZATIONS"( | |||||
"UUID" VARCHAR(40) NOT NULL, | |||||
"KEE" VARCHAR(255) NOT NULL, | |||||
"NAME" VARCHAR(255) NOT NULL, | |||||
"DESCRIPTION" VARCHAR(256), | |||||
"URL" VARCHAR(256), | |||||
"AVATAR_URL" VARCHAR(256), | |||||
"GUARDED" BOOLEAN, | |||||
"DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL, | |||||
"DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40), | |||||
"DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), | |||||
"NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, | |||||
"SUBSCRIPTION" VARCHAR(40) NOT NULL, | |||||
"CREATED_AT" BIGINT NOT NULL, | |||||
"UPDATED_AT" BIGINT NOT NULL, | |||||
"DEFAULT_GROUP_UUID" VARCHAR(40) | |||||
); | |||||
ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID"); | |||||
CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); |
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_KEY; | import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_KEY; | ||||
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME; | import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME; | ||||
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_ORGANIZATION_UUID; | |||||
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_PROJECT_UUID; | import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_PROJECT_UUID; | ||||
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_QUALIFIER; | import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_QUALIFIER; | ||||
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_UUID; | import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_UUID; | ||||
setField(FIELD_QUALIFIER, s); | setField(FIELD_QUALIFIER, s); | ||||
return this; | return this; | ||||
} | } | ||||
public String getOrganization() { | |||||
return getField(FIELD_ORGANIZATION_UUID); | |||||
} | |||||
public ComponentDoc setOrganization(String s) { | |||||
setField(FIELD_ORGANIZATION_UUID, s); | |||||
return this; | |||||
} | |||||
} | } |
public static final IndexType.IndexRelationType TYPE_COMPONENT = IndexType.relation(IndexType.main(DESCRIPTOR, TYPE_AUTHORIZATION), "component"); | public static final IndexType.IndexRelationType TYPE_COMPONENT = IndexType.relation(IndexType.main(DESCRIPTOR, TYPE_AUTHORIZATION), "component"); | ||||
public static final String FIELD_UUID = "uuid"; | public static final String FIELD_UUID = "uuid"; | ||||
public static final String FIELD_PROJECT_UUID = "project_uuid"; | public static final String FIELD_PROJECT_UUID = "project_uuid"; | ||||
public static final String FIELD_ORGANIZATION_UUID = "organization_uuid"; | |||||
public static final String FIELD_KEY = "key"; | public static final String FIELD_KEY = "key"; | ||||
public static final String FIELD_NAME = "name"; | public static final String FIELD_NAME = "name"; | ||||
public static final String FIELD_QUALIFIER = "qualifier"; | public static final String FIELD_QUALIFIER = "qualifier"; | ||||
.build(); | .build(); | ||||
mapping.keywordFieldBuilder(FIELD_QUALIFIER).build(); | mapping.keywordFieldBuilder(FIELD_QUALIFIER).build(); | ||||
mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).disableNorms().build(); | |||||
} | } | ||||
} | } |
.setName(component.name()) | .setName(component.name()) | ||||
.setKey(component.getDbKey()) | .setKey(component.getDbKey()) | ||||
.setProjectUuid(component.projectUuid()) | .setProjectUuid(component.projectUuid()) | ||||
.setOrganization(component.getOrganizationUuid()) | |||||
.setQualifier(component.qualifier()); | .setQualifier(component.qualifier()); | ||||
} | } | ||||
} | } |
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_MEASURES; | import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_MEASURES; | ||||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_NAME; | import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_NAME; | ||||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_NCLOC_DISTRIBUTION; | import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_NCLOC_DISTRIBUTION; | ||||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_ORGANIZATION_UUID; | |||||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_QUALIFIER; | import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_QUALIFIER; | ||||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_QUALITY_GATE_STATUS; | import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_QUALITY_GATE_STATUS; | ||||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS; | import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS; | ||||
return this; | return this; | ||||
} | } | ||||
public String getOrganizationUuid() { | |||||
return getField(FIELD_ORGANIZATION_UUID); | |||||
} | |||||
public ProjectMeasuresDoc setOrganizationUuid(String s) { | |||||
setField(FIELD_ORGANIZATION_UUID, s); | |||||
return this; | |||||
} | |||||
public String getKey() { | public String getKey() { | ||||
return getField(FIELD_KEY); | return getField(FIELD_KEY); | ||||
} | } |
public static final IndexRelationType TYPE_PROJECT_MEASURES = IndexType.relation(TYPE_AUTHORIZATION, "projectmeasure"); | public static final IndexRelationType TYPE_PROJECT_MEASURES = IndexType.relation(TYPE_AUTHORIZATION, "projectmeasure"); | ||||
public static final String FIELD_UUID = "uuid"; | public static final String FIELD_UUID = "uuid"; | ||||
public static final String FIELD_ORGANIZATION_UUID = "organizationUuid"; | |||||
/** | /** | ||||
* Project key. Only projects and applications (qualifier=TRK, APP) | * Project key. Only projects and applications (qualifier=TRK, APP) | ||||
TypeMapping mapping = index.createTypeMapping(TYPE_PROJECT_MEASURES); | TypeMapping mapping = index.createTypeMapping(TYPE_PROJECT_MEASURES); | ||||
mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build(); | mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build(); | ||||
mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).disableNorms().build(); | |||||
mapping.keywordFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build(); | mapping.keywordFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build(); | ||||
mapping.keywordFieldBuilder(FIELD_QUALIFIER).disableNorms().build(); | mapping.keywordFieldBuilder(FIELD_QUALIFIER).disableNorms().build(); | ||||
mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build(); | mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build(); |
Long analysisDate = project.getAnalysisDate(); | Long analysisDate = project.getAnalysisDate(); | ||||
return new ProjectMeasuresDoc() | return new ProjectMeasuresDoc() | ||||
.setId(project.getUuid()) | .setId(project.getUuid()) | ||||
.setOrganizationUuid(project.getOrganizationUuid()) | |||||
.setKey(project.getKey()) | .setKey(project.getKey()) | ||||
.setName(project.getName()) | .setName(project.getName()) | ||||
.setQualifier(project.getQualifier()) | .setQualifier(project.getQualifier()) |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 SonarSource SA | |||||
* mailto:info AT sonarsource DOT com | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU Lesser General Public | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
* Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with this program; if not, write to the Free Software Foundation, | |||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
*/ | |||||
package org.sonar.server.organization; | |||||
import static java.util.Objects.requireNonNull; | |||||
public class DefaultOrganization { | |||||
private final String uuid; | |||||
private final String key; | |||||
private final String name; | |||||
private final long createdAt; | |||||
private final long updatedAt; | |||||
private DefaultOrganization(Builder builder) { | |||||
this.uuid = requireNonNull(builder.uuid, "uuid can't be null"); | |||||
this.key = requireNonNull(builder.key, "key can't be null"); | |||||
this.name = requireNonNull(builder.name, "name can't be null"); | |||||
this.createdAt = requireNonNull(builder.createdAt, "createdAt can't be null"); | |||||
this.updatedAt = requireNonNull(builder.updatedAt, "updatedAt can't be null"); | |||||
} | |||||
public static Builder newBuilder() { | |||||
return new Builder(); | |||||
} | |||||
public String getUuid() { | |||||
return uuid; | |||||
} | |||||
public String getKey() { | |||||
return key; | |||||
} | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public long getCreatedAt() { | |||||
return createdAt; | |||||
} | |||||
public long getUpdatedAt() { | |||||
return updatedAt; | |||||
} | |||||
@Override | |||||
public String toString() { | |||||
return "DefaultOrganization{" + | |||||
"uuid='" + uuid + '\'' + | |||||
", key='" + key + '\'' + | |||||
", name='" + name + '\'' + | |||||
", createdAt=" + createdAt + | |||||
", updatedAt=" + updatedAt + | |||||
'}'; | |||||
} | |||||
public static final class Builder { | |||||
private String uuid; | |||||
private String key; | |||||
private String name; | |||||
private Long createdAt; | |||||
private Long updatedAt; | |||||
public Builder setUuid(String uuid) { | |||||
this.uuid = uuid; | |||||
return this; | |||||
} | |||||
public Builder setKey(String key) { | |||||
this.key = key; | |||||
return this; | |||||
} | |||||
public Builder setName(String name) { | |||||
this.name = name; | |||||
return this; | |||||
} | |||||
public Builder setCreatedAt(long createdAt) { | |||||
this.createdAt = createdAt; | |||||
return this; | |||||
} | |||||
public Builder setUpdatedAt(long updatedAt) { | |||||
this.updatedAt = updatedAt; | |||||
return this; | |||||
} | |||||
public DefaultOrganization build() { | |||||
return new DefaultOrganization(this); | |||||
} | |||||
} | |||||
} |