@@ -1,5 +0,0 @@ | |||
#!/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" |
@@ -269,7 +269,12 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor | |||
this.scmRevisionId = scmRevisionId; | |||
} | |||
/** | |||
* | |||
* @deprecated since 8.7. No longer used - it's always empty. | |||
*/ | |||
@Override | |||
@Deprecated | |||
public Optional<Organization> getOrganization() { | |||
return empty(); | |||
} |
@@ -49,7 +49,6 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentUpdateDto; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import static java.util.Optional.ofNullable; | |||
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; | |||
@@ -68,11 +67,10 @@ public class PersistComponentsStep implements ComputationStep { | |||
private final AnalysisMetadataHolder analysisMetadataHolder; | |||
private final BranchPersister branchPersister; | |||
private final ProjectPersister projectPersister; | |||
private final DefaultOrganizationProvider defaultOrganizationProvider; | |||
public PersistComponentsStep(DbClient dbClient, TreeRootHolder treeRootHolder, System2 system2, | |||
MutableDisabledComponentsHolder disabledComponentsHolder, AnalysisMetadataHolder analysisMetadataHolder, | |||
BranchPersister branchPersister, ProjectPersister projectPersister, DefaultOrganizationProvider defaultOrganizationProvider) { | |||
BranchPersister branchPersister, ProjectPersister projectPersister) { | |||
this.dbClient = dbClient; | |||
this.treeRootHolder = treeRootHolder; | |||
this.system2 = system2; | |||
@@ -80,7 +78,6 @@ public class PersistComponentsStep implements ComputationStep { | |||
this.analysisMetadataHolder = analysisMetadataHolder; | |||
this.branchPersister = branchPersister; | |||
this.projectPersister = projectPersister; | |||
this.defaultOrganizationProvider = defaultOrganizationProvider; | |||
} | |||
@Override | |||
@@ -364,7 +361,6 @@ public class PersistComponentsStep implements ComputationStep { | |||
String componentUuid = component.getUuid(); | |||
ComponentDto componentDto = new ComponentDto(); | |||
componentDto.setOrganizationUuid(defaultOrganizationProvider.get().getUuid()); | |||
componentDto.setUuid(componentUuid); | |||
componentDto.setDbKey(componentKey); | |||
componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); |
@@ -155,7 +155,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
@Test | |||
@UseDataProvider("booleanValues") | |||
public void organization_is_null_when_organization_are_disabled(boolean allStepsExecuted) { | |||
public void organization_is_null(boolean allStepsExecuted) { | |||
underTest.finished(allStepsExecuted); | |||
verify(postProjectAnalysisTask).finished(taskContextCaptor.capture()); |
@@ -33,7 +33,6 @@ import org.sonar.ce.task.step.TestComputationStepContext; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import static java.util.Collections.emptyList; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
@@ -70,7 +69,6 @@ public class PersistComponentsStepTest { | |||
mock(MutableDisabledComponentsHolder.class), | |||
mock(AnalysisMetadataHolder.class), | |||
mock(BranchPersister.class), | |||
mock(ProjectPersister.class), | |||
mock(DefaultOrganizationProvider.class)).execute(new TestComputationStepContext()); | |||
mock(ProjectPersister.class)).execute(new TestComputationStepContext()); | |||
} | |||
} |
@@ -48,8 +48,6 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDto; | |||
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 static org.apache.commons.lang.StringUtils.isEmpty; | |||
@@ -74,7 +72,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
public DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
@Rule | |||
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | |||
@Rule | |||
@@ -93,8 +90,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
BranchPersister branchPersister = mock(BranchPersister.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 | |||
@@ -125,7 +121,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
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.longName()).isEqualTo("src/main/java/dir"); | |||
assertThat(directoryDto.description()).isNull(); | |||
@@ -142,7 +137,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
assertThat(directoryDto.getCreatedAt()).isEqualTo(now); | |||
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.longName()).isEqualTo("src/main/java/dir/Foo.java"); | |||
assertThat(fileDto.description()).isNull(); | |||
@@ -184,7 +178,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
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.longName()).isEqualTo("src/main/java/dir"); | |||
assertThat(directoryDto.description()).isNull(); | |||
@@ -201,7 +194,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
assertThat(directoryDto.getCreatedAt()).isEqualTo(now); | |||
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.longName()).isEqualTo("src/main/java/dir/Foo.java"); | |||
assertThat(fileDto.description()).isNull(); |
@@ -50,7 +50,7 @@ import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY; | |||
import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto; | |||
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 QProfileDto sonarWayJava = newProfile("sonar-way-java"); | |||
private QProfileDto sonarWayPhp = newProfile("sonar-way-php"); |
@@ -48,8 +48,6 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
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.mockito.Mockito.RETURNS_DEEP_STUBS; | |||
@@ -81,8 +79,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
public DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester); | |||
@Rule | |||
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | |||
@Rule | |||
@@ -103,8 +99,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
analysisMetadataHolder.setBranch(new DefaultBranchImpl()); | |||
BranchPersister branchPersister = mock(BranchPersister.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 | |||
@@ -485,7 +480,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
private ComponentDto newViewDto() { | |||
return ComponentTesting.newView(VIEW_UUID) | |||
.setOrganizationUuid(defaultOrganizationProvider.get().getUuid()) | |||
.setDbKey(VIEW_KEY) | |||
.setName(VIEW_NAME); | |||
} | |||
@@ -499,7 +493,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
* Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} | |||
*/ | |||
private void assertDtoIsView(ComponentDto dto) { | |||
assertThat(dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||
assertThat(dto.name()).isEqualTo(VIEW_NAME); | |||
assertThat(dto.longName()).isEqualTo(VIEW_NAME); | |||
assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); | |||
@@ -519,7 +512,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
* Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} | |||
*/ | |||
private void assertDtoIsApplication(ComponentDto dto) { | |||
assertThat(dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||
assertThat(dto.name()).isEqualTo(VIEW_NAME); | |||
assertThat(dto.longName()).isEqualTo(VIEW_NAME); | |||
assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); | |||
@@ -539,7 +531,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
* Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)} | |||
*/ | |||
private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) { | |||
assertThat(sv1Dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); | |||
assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME); | |||
assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME); | |||
assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION); | |||
@@ -556,7 +547,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
} | |||
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.longName()).isEqualTo(PROJECT_VIEW_1_NAME); | |||
assertThat(pv1Dto.description()).isNull(); |
@@ -115,7 +115,6 @@ import org.sonar.server.metric.UnanalyzedLanguageMetrics; | |||
import org.sonar.server.notification.DefaultNotificationManager; | |||
import org.sonar.server.notification.NotificationService; | |||
import org.sonar.server.notification.email.EmailNotificationChannel; | |||
import org.sonar.server.organization.DefaultOrganizationProviderImpl; | |||
import org.sonar.server.platform.OfficialDistribution; | |||
import org.sonar.server.platform.ServerFileSystemImpl; | |||
import org.sonar.server.platform.ServerImpl; | |||
@@ -352,7 +351,6 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { | |||
ServerIdChecksum.class, | |||
UriReader.class, | |||
ServerImpl.class, | |||
DefaultOrganizationProviderImpl.class, | |||
SynchronousAsyncExecution.class); | |||
} | |||
@@ -35,7 +35,6 @@ public final class SqTables { | |||
public static final Set<String> TABLES = unmodifiableSet(new HashSet<>(asList( | |||
"active_rules", | |||
"active_rule_parameters", | |||
"alm_app_installs", | |||
"alm_settings", | |||
"alm_pats", | |||
"analysis_properties", | |||
@@ -67,11 +66,7 @@ public final class SqTables { | |||
"metrics", | |||
"new_code_periods", | |||
"notifications", | |||
"organizations", | |||
"organization_alm_bindings", | |||
"organization_members", | |||
"org_qprofiles", | |||
"org_quality_gates", | |||
"permission_templates", | |||
"perm_templates_users", | |||
"perm_templates_groups", |
@@ -26,11 +26,9 @@ import org.apache.commons.lang.StringUtils; | |||
* Data is truncated between each tests. The schema is created between each test. | |||
*/ | |||
public class CoreDbTester extends AbstractDbTester<CoreTestDb> { | |||
private final DefaultOrganizationTesting defaultOrganizationTesting; | |||
private CoreDbTester(CoreTestDb testDb) { | |||
super(testDb); | |||
this.defaultOrganizationTesting = new DefaultOrganizationTesting(this); | |||
} | |||
public static CoreDbTester createForSchema(Class testClass, String filename) { | |||
@@ -57,8 +55,4 @@ public class CoreDbTester extends AbstractDbTester<CoreTestDb> { | |||
protected void after() { | |||
db.stop(); | |||
} | |||
public DefaultOrganizationTesting defaultOrganization() { | |||
return defaultOrganizationTesting; | |||
} | |||
} |
@@ -1,66 +0,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; | |||
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); | |||
} | |||
} |
@@ -52,7 +52,6 @@ import org.sonar.db.measure.custom.CustomMeasureDao; | |||
import org.sonar.db.metric.MetricDao; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | |||
import org.sonar.db.notification.NotificationQueueDao; | |||
import org.sonar.db.organization.OrganizationDao; | |||
import org.sonar.db.permission.AuthorizationDao; | |||
import org.sonar.db.permission.GroupPermissionDao; | |||
import org.sonar.db.permission.UserPermissionDao; | |||
@@ -131,7 +130,6 @@ public class DaoModule extends Module { | |||
MetricDao.class, | |||
NewCodePeriodDao.class, | |||
NotificationQueueDao.class, | |||
OrganizationDao.class, | |||
PermissionTemplateCharacteristicDao.class, | |||
PermissionTemplateDao.class, | |||
PluginDao.class, |
@@ -50,7 +50,6 @@ import org.sonar.db.measure.custom.CustomMeasureDao; | |||
import org.sonar.db.metric.MetricDao; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | |||
import org.sonar.db.notification.NotificationQueueDao; | |||
import org.sonar.db.organization.OrganizationDao; | |||
import org.sonar.db.permission.AuthorizationDao; | |||
import org.sonar.db.permission.GroupPermissionDao; | |||
import org.sonar.db.permission.UserPermissionDao; | |||
@@ -97,7 +96,6 @@ public class DbClient { | |||
private final SchemaMigrationDao schemaMigrationDao; | |||
private final AuthorizationDao authorizationDao; | |||
private final OrganizationDao organizationDao; | |||
private final QualityProfileDao qualityProfileDao; | |||
private final QualityProfileExportDao qualityProfileExportDao; | |||
private final PropertiesDao propertiesDao; | |||
@@ -177,7 +175,6 @@ public class DbClient { | |||
projectAlmSettingDao = getDao(map, ProjectAlmSettingDao.class); | |||
schemaMigrationDao = getDao(map, SchemaMigrationDao.class); | |||
authorizationDao = getDao(map, AuthorizationDao.class); | |||
organizationDao = getDao(map, OrganizationDao.class); | |||
qualityProfileDao = getDao(map, QualityProfileDao.class); | |||
qualityProfileExportDao = getDao(map, QualityProfileExportDao.class); | |||
propertiesDao = getDao(map, PropertiesDao.class); | |||
@@ -273,10 +270,6 @@ public class DbClient { | |||
return authorizationDao; | |||
} | |||
public OrganizationDao organizationDao() { | |||
return organizationDao; | |||
} | |||
public IssueDao issueDao() { | |||
return issueDao; | |||
} |
@@ -83,8 +83,6 @@ import org.sonar.db.metric.MetricMapper; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodMapper; | |||
import org.sonar.db.notification.NotificationQueueDto; | |||
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.GroupPermissionDto; | |||
import org.sonar.db.permission.GroupPermissionMapper; | |||
@@ -191,7 +189,6 @@ public class MyBatis implements Startable { | |||
confBuilder.loadAlias("Issue", IssueDto.class); | |||
confBuilder.loadAlias("Measure", MeasureDto.class); | |||
confBuilder.loadAlias("NotificationQueue", NotificationQueueDto.class); | |||
confBuilder.loadAlias("Organization", OrganizationDto.class); | |||
confBuilder.loadAlias("PermissionTemplateCharacteristic", PermissionTemplateCharacteristicDto.class); | |||
confBuilder.loadAlias("PermissionTemplateGroup", PermissionTemplateGroupDto.class); | |||
confBuilder.loadAlias("PermissionTemplate", PermissionTemplateDto.class); | |||
@@ -257,7 +254,6 @@ public class MyBatis implements Startable { | |||
MetricMapper.class, | |||
NewCodePeriodMapper.class, | |||
NotificationQueueMapper.class, | |||
OrganizationMapper.class, | |||
PermissionTemplateCharacteristicMapper.class, | |||
PermissionTemplateMapper.class, | |||
PluginMapper.class, |
@@ -359,8 +359,8 @@ public class ComponentDao implements Dao { | |||
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) { |
@@ -23,6 +23,7 @@ import com.google.common.base.Splitter; | |||
import com.google.common.base.Strings; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.Objects; | |||
import java.util.regex.Pattern; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
@@ -54,11 +55,6 @@ public class ComponentDto { | |||
public static final String UUID_PATH_OF_ROOT = UUID_PATH_SEPARATOR; | |||
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. | |||
*/ | |||
@@ -156,19 +152,6 @@ public class ComponentDto { | |||
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() { | |||
return uuid; | |||
} | |||
@@ -409,7 +392,7 @@ public class ComponentDto { | |||
return false; | |||
} | |||
ComponentDto that = (ComponentDto) o; | |||
return uuid != null ? uuid.equals(that.uuid) : (that.uuid == null); | |||
return Objects.equals(uuid, that.uuid); | |||
} | |||
@@ -444,7 +427,6 @@ public class ComponentDto { | |||
public ComponentDto copy() { | |||
ComponentDto copy = new ComponentDto(); | |||
copy.projectUuid = projectUuid; | |||
copy.organizationUuid = organizationUuid; | |||
copy.kee = kee; | |||
copy.uuid = uuid; | |||
copy.uuidPath = uuidPath; |
@@ -63,14 +63,6 @@ public interface ComponentMapper { | |||
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); | |||
int countByQuery(@Param("query") ComponentQuery query); | |||
@@ -149,7 +141,7 @@ public interface ComponentMapper { | |||
List<KeyWithUuidDto> selectAllSiblingComponentKeysHavingOpenIssues(@Param("referenceBranchUuid") String referenceBranchUuid, | |||
@Param("currentBranchUuid") String currentBranchUuid); | |||
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(@Param("organizationUuid") String organizationUuid); | |||
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(); | |||
List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(String projectKey); | |||
@@ -72,7 +72,7 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea | |||
CoreMetrics.NEW_LINES_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 " + | |||
"LEFT OUTER JOIN snapshots s ON s.component_uuid=p.uuid AND s.islast=? " + | |||
"WHERE p.qualifier in (?, ?)"; | |||
@@ -110,14 +110,13 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea | |||
try (PreparedStatement stmt = createProjectsStatement(session, projectUuid); | |||
ResultSet rs = stmt.executeQuery()) { | |||
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); | |||
} | |||
return projects; | |||
@@ -228,7 +227,6 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea | |||
} | |||
public static class Project { | |||
private final String organizationUuid; | |||
private final String uuid; | |||
private final String key; | |||
private final String name; | |||
@@ -236,8 +234,7 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea | |||
private final Long analysisDate; | |||
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.key = key; | |||
this.name = name; | |||
@@ -246,10 +243,6 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea | |||
this.analysisDate = analysisDate; | |||
} | |||
public String getOrganizationUuid() { | |||
return organizationUuid; | |||
} | |||
public String getUuid() { | |||
return uuid; | |||
} |
@@ -1,166 +0,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.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()); | |||
} | |||
} |
@@ -1,217 +0,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.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 + | |||
'}'; | |||
} | |||
} |
@@ -1,47 +0,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 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; | |||
} | |||
} |
@@ -1,82 +0,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); | |||
} |
@@ -1,98 +0,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.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); | |||
} | |||
} | |||
} |
@@ -1,24 +0,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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.db.organization; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -49,7 +49,7 @@ public class AuthorizationDao implements Dao { | |||
} | |||
/** | |||
* 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) { | |||
return mapper(dbSession).selectGlobalPermissionsOfAnonymous(); |
@@ -38,7 +38,7 @@ public class GroupPermissionDao implements Dao { | |||
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}. | |||
* @return group names, sorted in alphabetical order | |||
*/ | |||
@@ -55,7 +55,7 @@ public class GroupPermissionDao implements Dao { | |||
} | |||
/** | |||
* 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}. | |||
*/ | |||
public List<GroupPermissionDto> selectByGroupUuids(DbSession dbSession, List<String> groupUuids, @Nullable String projectUuid) { |
@@ -39,7 +39,6 @@ public class ProjectDto { | |||
private String tags; | |||
private long createdAt; | |||
private long updatedAt; | |||
private String organizationUuid; | |||
public ProjectDto() { | |||
// nothing to do here | |||
@@ -128,19 +127,6 @@ public class ProjectDto { | |||
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() { | |||
return name; | |||
} |
@@ -206,8 +206,7 @@ public class PropertiesDao implements Dao { | |||
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); | |||
long now = system2.now(); |
@@ -65,8 +65,6 @@ public interface PropertiesMapper { | |||
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 deleteProjectProperties(@Param("key") String key, @Param("value") String value); |
@@ -47,7 +47,7 @@ public class GroupDao implements Dao { | |||
/** | |||
* @param dbSession | |||
* @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) { | |||
return Optional.ofNullable(mapper(dbSession).selectByName(name)); |
@@ -35,7 +35,6 @@ import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static java.util.Locale.ENGLISH; | |||
@@ -121,10 +120,6 @@ public class UserDao implements Dao { | |||
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) { | |||
mapper(dbSession).clearHomepages("PROJECT", project.getUuid(), system2.now()); | |||
} |
@@ -24,20 +24,14 @@ import java.util.Optional; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.organization.OrganizationDto; | |||
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 { | |||
private final System2 system2; | |||
private final InternalPropertiesDao internalPropertiesDao; | |||
public WebhookDao(System2 system2, InternalPropertiesDao internalPropertiesDao) { | |||
public WebhookDao(System2 system2) { | |||
this.system2 = system2; | |||
this.internalPropertiesDao = internalPropertiesDao; | |||
} | |||
public List<WebhookDto> selectAll(DbSession dbSession) { | |||
@@ -52,31 +46,11 @@ public class WebhookDao implements Dao { | |||
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) { | |||
return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid()); | |||
} | |||
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())); | |||
} | |||
@@ -30,9 +30,6 @@ public class WebhookDto { | |||
/** URL, can't be null */ | |||
private String url; | |||
@Nullable | |||
private String organizationUuid; | |||
@Nullable | |||
private String projectUuid; | |||
@@ -60,11 +57,6 @@ public class WebhookDto { | |||
return this; | |||
} | |||
public WebhookDto setOrganizationUuid(@Nullable String organizationUuid) { | |||
this.organizationUuid = organizationUuid; | |||
return this; | |||
} | |||
public WebhookDto setProjectUuid(@Nullable String projectUuid) { | |||
this.projectUuid = projectUuid; | |||
return this; | |||
@@ -97,11 +89,6 @@ public class WebhookDto { | |||
return url; | |||
} | |||
@Nullable | |||
public String getOrganizationUuid() { | |||
return organizationUuid; | |||
} | |||
@Nullable | |||
public String getProjectUuid() { | |||
return projectUuid; |
@@ -32,19 +32,13 @@ public interface WebhookMapper { | |||
List<WebhookDto> selectGlobalWebhooksOrderedByName(); | |||
// TODO remove | |||
@Deprecated | |||
List<WebhookDto> selectForProjectUuidOrderedByName(@Param("projectUuid") String projectUuid); | |||
// TODO remove | |||
@Deprecated | |||
List<WebhookDto> selectForOrganizationUuidOrderedByName(@Param("organizationUuid") String organizationUuid); | |||
void insert(WebhookDto dto); | |||
void update(WebhookDto dto); | |||
void delete(@Param("uuid") String uuid); | |||
void deleteForProjectUuid(@Param("projectUuid") String organizationUuid); | |||
void deleteForProjectUuid(@Param("projectUuid") String projectUuid); | |||
} |
@@ -19,7 +19,6 @@ | |||
<sql id="projectColumns"> | |||
p.uuid as uuid, | |||
p.organization_uuid as organizationUuid, | |||
p.kee as kee, | |||
p.qualifier as qualifier, | |||
p.name as name, |
@@ -3,7 +3,6 @@ | |||
<mapper namespace="org.sonar.db.component.ComponentMapper"> | |||
<sql id="componentColumns"> | |||
p.organization_uuid as organizationUuid, | |||
p.uuid as uuid, | |||
p.uuid_path as uuidPath, | |||
p.project_uuid as projectUuid, | |||
@@ -67,7 +66,7 @@ | |||
select | |||
<include refid="componentColumns"/> | |||
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 | |||
root.uuid=#{projectUuid,jdbcType=VARCHAR} | |||
</select> | |||
@@ -140,7 +139,6 @@ | |||
INNER JOIN components child ON | |||
child.root_uuid=p.uuid | |||
and child.enabled=${_true} | |||
and child.organization_uuid=p.organization_uuid | |||
where | |||
p.enabled=${_true} | |||
and p.scope='PRJ' | |||
@@ -160,7 +158,6 @@ | |||
<sql id="modulesTreeQuery"> | |||
INNER JOIN components module ON | |||
module.project_uuid = p.project_uuid | |||
and module.organization_uuid = p.organization_uuid | |||
and module.uuid = #{moduleUuid} | |||
and module.scope='PRJ' AND module.enabled = ${_true} | |||
where | |||
@@ -189,7 +186,6 @@ | |||
FROM components root | |||
INNER JOIN components p on | |||
p.project_uuid=root.uuid | |||
and p.organization_uuid=root.organization_uuid | |||
and p.enabled=${_true} | |||
and p.scope='FIL' | |||
INNER JOIN file_sources fs ON | |||
@@ -242,15 +238,6 @@ | |||
and p.qualifier = 'BRC' | |||
</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 | |||
<include refid="componentColumns"/> | |||
@@ -516,7 +503,6 @@ | |||
<insert id="insert" parameterType="Component"> | |||
INSERT INTO components ( | |||
organization_uuid, | |||
kee, | |||
uuid, | |||
uuid_path, | |||
@@ -550,7 +536,6 @@ | |||
b_qualifier | |||
) | |||
VALUES ( | |||
#{organizationUuid,jdbcType=VARCHAR}, | |||
#{kee,jdbcType=VARCHAR}, | |||
#{uuid,jdbcType=VARCHAR}, | |||
#{uuidPath,jdbcType=VARCHAR}, | |||
@@ -719,7 +704,6 @@ | |||
and p.scope = 'PRJ' | |||
and p.qualifier = 'TRK' | |||
and p.copy_component_uuid is null | |||
and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} | |||
group by p.kee, p.name | |||
order by ncloc desc | |||
</select> |
@@ -65,39 +65,6 @@ | |||
</if> | |||
</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 INTO issues (kee, rule_uuid, severity, manual_severity, | |||
message, line, locations, gap, effort, status, tags, |
@@ -1,284 +0,0 @@ | |||
<?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> |
@@ -4,7 +4,6 @@ | |||
<sql id="projectColumns"> | |||
p.uuid as uuid, | |||
p.organization_uuid as organizationUuid, | |||
p.kee as kee, | |||
p.qualifier as qualifier, | |||
p.name as name, | |||
@@ -108,7 +107,6 @@ | |||
<insert id="insert" parameterType="Project"> | |||
INSERT INTO projects ( | |||
organization_uuid, | |||
kee, | |||
qualifier, | |||
uuid, | |||
@@ -120,7 +118,6 @@ | |||
updated_at | |||
) | |||
VALUES ( | |||
#{organizationUuid,jdbcType=VARCHAR}, | |||
#{kee,jdbcType=VARCHAR}, | |||
#{qualifier,jdbcType=VARCHAR}, | |||
#{uuid,jdbcType=VARCHAR}, |
@@ -8,7 +8,6 @@ | |||
uuid, | |||
name, | |||
url, | |||
organization_uuid as organizationUuid, | |||
project_uuid as projectUuid, | |||
secret, | |||
created_at as createdAt, | |||
@@ -34,13 +33,6 @@ | |||
order by name asc | |||
</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 <include refid="sqlColumns" /> | |||
from webhooks | |||
@@ -53,7 +45,6 @@ | |||
uuid, | |||
name, | |||
url, | |||
organization_uuid, | |||
project_uuid, | |||
secret, | |||
created_at, | |||
@@ -62,7 +53,6 @@ | |||
#{uuid,jdbcType=VARCHAR}, | |||
#{name,jdbcType=VARCHAR}, | |||
#{url,jdbcType=VARCHAR}, | |||
#{organizationUuid,jdbcType=VARCHAR}, | |||
#{projectUuid,jdbcType=VARCHAR}, | |||
#{secret,jdbcType=VARCHAR}, | |||
#{createdAt,jdbcType=BIGINT}, | |||
@@ -85,12 +75,6 @@ | |||
uuid = #{uuid,jdbcType=VARCHAR} | |||
</delete> | |||
<delete id="deleteForOrganizationUuid" parameterType="String"> | |||
delete from webhooks | |||
where | |||
organization_uuid = #{organizationUuid,jdbcType=VARCHAR} | |||
</delete> | |||
<delete id="deleteForProjectUuid" parameterType="String"> | |||
delete from webhooks | |||
where |
@@ -35,21 +35,6 @@ CREATE TABLE "ACTIVE_RULES"( | |||
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 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"( | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"PAT" VARCHAR(2000) NOT NULL, | |||
@@ -203,7 +188,6 @@ CREATE INDEX "CTM_MESSAGE_TYPE" ON "CE_TASK_MESSAGE"("MESSAGE_TYPE"); | |||
CREATE TABLE "COMPONENTS"( | |||
"UUID" VARCHAR(50) NOT NULL, | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"KEE" VARCHAR(400), | |||
"DEPRECATED_KEE" VARCHAR(400), | |||
"NAME" VARCHAR(2000), | |||
@@ -236,7 +220,6 @@ CREATE TABLE "COMPONENTS"( | |||
"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"); | |||
@@ -528,56 +511,6 @@ ALTER TABLE "ORG_QPROFILES" ADD CONSTRAINT "PK_ORG_QPROFILES" PRIMARY KEY("UUID" | |||
CREATE INDEX "QPROFILES_RP_UUID" ON "ORG_QPROFILES"("RULES_PROFILE_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"( | |||
"PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, | |||
"CREATED_AT" TIMESTAMP, | |||
@@ -722,7 +655,6 @@ 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, | |||
@@ -1011,7 +943,6 @@ CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID"); | |||
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, | |||
@@ -1020,5 +951,3 @@ CREATE TABLE "WEBHOOKS"( | |||
"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"); |
@@ -261,7 +261,7 @@ public class CeQueueDaoTest { | |||
@Test | |||
public void test_delete_with_expected_status() { | |||
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); | |||
assertThat(deletedCount).isZero(); | |||
@@ -704,7 +704,6 @@ public class CeQueueDaoTest { | |||
view.setQualifier("VW"); | |||
view.setDbKey(view_uuid + "_key"); | |||
view.setUuid(view_uuid); | |||
view.setOrganizationUuid("org_uuid"); | |||
view.setPrivate(false); | |||
view.setRootUuid(view_uuid); | |||
view.setUuidPath("uuid_path"); | |||
@@ -718,7 +717,6 @@ public class CeQueueDaoTest { | |||
branch.setQualifier("TRK"); | |||
branch.setDbKey(uuid + "_key"); | |||
branch.setUuid(uuid); | |||
branch.setOrganizationUuid("org_uuid"); | |||
branch.setPrivate(false); | |||
branch.setRootUuid(uuid); | |||
branch.setUuidPath("uuid_path"); | |||
@@ -765,7 +763,7 @@ public class CeQueueDaoTest { | |||
return dto; | |||
} | |||
private CeQueueDto insertInProgress(String uuid, String componentUuid) { | |||
private CeQueueDto insertInProgress(String uuid) { | |||
CeQueueDto ceQueueDto = insertPending(uuid); | |||
CeQueueTesting.makeInProgress(db.getSession(), "workerUuid", System2.INSTANCE.now(), ceQueueDto); | |||
return underTest.selectByUuid(db.getSession(), uuid).get(); |
@@ -126,7 +126,6 @@ public class ApplicationProjectsDaoTest { | |||
"uuid", projectUuid, | |||
"kee", projectUuid, | |||
"qualifier", "TRK", | |||
"ORGANIZATION_UUID", "ORGANIZATION_UUID", | |||
"private", true, | |||
"updated_at", 1000L, | |||
"created_at", 1000L); | |||
@@ -137,7 +136,6 @@ public class ApplicationProjectsDaoTest { | |||
"uuid", appUuid, | |||
"kee", appUuid, | |||
"qualifier", "APP", | |||
"ORGANIZATION_UUID", "ORGANIZATION_UUID", | |||
"private", true, | |||
"updated_at", 1000L, | |||
"created_at", 1000L); |
@@ -120,7 +120,6 @@ public class ComponentDaoTest { | |||
ComponentDto result = underTest.selectByUuid(dbSession, project.uuid()).get(); | |||
assertThat(result).isNotNull(); | |||
assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid()); | |||
assertThat(result.uuid()).isEqualTo(project.uuid()); | |||
assertThat(result.getUuidPath()).isEqualTo("."); | |||
assertThat(result.moduleUuid()).isNull(); | |||
@@ -198,7 +197,6 @@ public class ComponentDaoTest { | |||
Optional<ComponentDto> optional = underTest.selectByKey(dbSession, file.getDbKey()); | |||
ComponentDto result = optional.get(); | |||
assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid()); | |||
assertThat(result.uuid()).isEqualTo(file.uuid()); | |||
assertThat(result.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); | |||
assertThat(result.path()).isEqualTo("src/RequestContext.java"); | |||
@@ -1246,9 +1244,9 @@ public class ComponentDaoTest { | |||
@Test | |||
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.updateBEnabledToFalse(dbSession, asList("U1", "U2")); | |||
@@ -1708,7 +1706,6 @@ public class ComponentDaoTest { | |||
List<ComponentDto> components = underTest.selectDescendants(dbSession, dbQuery); | |||
assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); | |||
assertThat(components).extracting("organizationUuid").containsOnly(db.getDefaultOrganization().getUuid()); | |||
} | |||
@Test | |||
@@ -1774,7 +1771,7 @@ public class ComponentDaoTest { | |||
// public project - not returned | |||
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::getNcloc).containsExactly(30L, 10L); |
@@ -300,7 +300,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
@Test | |||
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:inactive_module").setEnabled(false)); | |||
@@ -183,7 +183,7 @@ public class IssueDaoTest { | |||
.extracting(IssueDto::getKey) | |||
.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(); | |||
} | |||
@@ -278,7 +278,7 @@ public class LiveMeasureDaoTest { | |||
@Test | |||
public void selectTreeByQuery_with_empty_results() { | |||
List<LiveMeasureDto> results = new ArrayList<>(); | |||
underTest.selectTreeByQuery(db.getSession(), newPrivateProjectDto(db.getDefaultOrganization()), | |||
underTest.selectTreeByQuery(db.getSession(), newPrivateProjectDto(), | |||
MeasureTreeQuery.builder().setStrategy(MeasureTreeQuery.Strategy.LEAVES).build(), | |||
context -> results.add(context.getResultObject())); | |||
@@ -95,7 +95,7 @@ public class AuthorizationDaoTest { | |||
* - anyone | |||
*/ | |||
@Test | |||
public void selectOrganizationPermissions_for_logged_in_user() { | |||
public void selectGlobalPermissions_for_logged_in_user() { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
db.users().insertMember(group1, user); | |||
db.users().insertPermissionOnUser(user, "perm1"); |
@@ -188,7 +188,7 @@ public class GroupPermissionDaoTest { | |||
GroupDto group2 = db.users().insertGroup("Group-2"); | |||
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(PROVISION_PROJECTS); | |||
@@ -295,7 +295,7 @@ public class GroupPermissionDaoTest { | |||
db.users().insertPermissionOnGroup(group1, SCAN); | |||
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); | |||
GroupDto group3 = db.users().insertGroup("Group-3"); |
@@ -79,7 +79,7 @@ public class UserPermissionDaoTest { | |||
PermissionQuery query = PermissionQuery.builder().withAtLeastOnePermission().build(); | |||
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 | |||
// when filtering users by name) | |||
query = PermissionQuery.builder().build(); | |||
@@ -148,7 +148,7 @@ public class UserPermissionDaoTest { | |||
expectPermissions(query, emptyList()); | |||
// permissions of unknown project | |||
query = PermissionQuery.builder().setComponent(newPrivateProjectDto(db.getDefaultOrganization())).withAtLeastOnePermission().build(); | |||
query = PermissionQuery.builder().setComponent(newPrivateProjectDto()).withAtLeastOnePermission().build(); | |||
expectPermissions(query, emptyList()); | |||
} | |||
@@ -268,7 +268,7 @@ public class UserPermissionDaoTest { | |||
assertThat(underTest.selectUserUuidsByQuery(dbSession, query)).isEmpty(); | |||
// 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(); | |||
// search all users whose name matches "mar", whatever the permissions | |||
@@ -285,7 +285,7 @@ public class UserPermissionDaoTest { | |||
} | |||
@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 user2 = insertUser(u -> u.setLogin("login2").setName("Marie").setEmail("email2@email.com")); | |||
ComponentDto project1 = db.components().insertPrivateProject(); |
@@ -32,7 +32,6 @@ import org.sonar.core.util.UuidFactory; | |||
import org.sonar.core.util.UuidFactoryFast; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.UserDto; | |||
@@ -392,19 +391,4 @@ public class PermissionTemplateDaoTest { | |||
.extracting((row) -> row.get("templateUuid"), (row) -> row.get("userUuid"), (row) -> row.get("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; | |||
} | |||
} |
@@ -52,7 +52,7 @@ public class ProjectDaoTest { | |||
Optional<ProjectDto> projectByUuid = projectDao.selectByUuid(db.getSession(), "uuid_o1_p1"); | |||
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(); | |||
} | |||
@@ -64,7 +64,7 @@ public class ProjectDaoTest { | |||
Optional<ProjectDto> projectByKee = projectDao.selectProjectByKey(db.getSession(), "projectKee_o1_p1"); | |||
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 | |||
@@ -91,12 +91,12 @@ public class ProjectDaoTest { | |||
List<ProjectDto> projectsByOrg = projectDao.selectAll(db.getSession()); | |||
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) | |||
.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 | |||
@@ -109,8 +109,8 @@ public class ProjectDaoTest { | |||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
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")); | |||
dto2.setTagsString(""); | |||
@@ -119,8 +119,8 @@ public class ProjectDaoTest { | |||
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
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"); | |||
} | |||
@@ -135,16 +135,16 @@ public class ProjectDaoTest { | |||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
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(), dto2.getUuid(), true); | |||
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
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 | |||
@@ -159,8 +159,8 @@ public class ProjectDaoTest { | |||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
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 | |||
@@ -177,9 +177,9 @@ public class ProjectDaoTest { | |||
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) { | |||
@@ -187,7 +187,6 @@ public class ProjectDaoTest { | |||
.setName("projectName_" + name) | |||
.setKey("projectKee_" + org + "_" + name) | |||
.setQualifier(Qualifiers.PROJECT) | |||
.setOrganizationUuid("org_" + org) | |||
.setUuid("uuid_" + org + "_" + name) | |||
.setTags(Arrays.asList("tag1", "tag2")) | |||
.setDescription("desc_" + name) |
@@ -688,27 +688,27 @@ public class PropertiesDaoTest { | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
.hasCreatedAt(INITIAL_DATE); | |||
assertThatPropertiesRow("global.empty") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
assertThatPropertiesRow("global.text") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasTextValue("some text") | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
assertThatPropertiesRow("global.4000") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasTextValue(VALUE_SIZE_4000) | |||
.hasCreatedAt(INITIAL_DATE + 5); | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
assertThatPropertiesRow("global.clob") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasClobValue(VALUE_SIZE_4001) | |||
.hasCreatedAt(INITIAL_DATE + 6); | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
} | |||
@Test | |||
@@ -724,27 +724,27 @@ public class PropertiesDaoTest { | |||
.hasComponentUuid(componentUuid) | |||
.hasNoUserUuid() | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
.hasCreatedAt(INITIAL_DATE); | |||
assertThatPropertiesRow("component.empty") | |||
.hasComponentUuid(componentUuid) | |||
.hasNoUserUuid() | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
assertThatPropertiesRow("component.text") | |||
.hasComponentUuid(componentUuid) | |||
.hasNoUserUuid() | |||
.hasTextValue("some text") | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
assertThatPropertiesRow("component.4000") | |||
.hasComponentUuid(componentUuid) | |||
.hasNoUserUuid() | |||
.hasTextValue(VALUE_SIZE_4000) | |||
.hasCreatedAt(INITIAL_DATE + 5); | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
assertThatPropertiesRow("component.clob") | |||
.hasComponentUuid(componentUuid) | |||
.hasNoUserUuid() | |||
.hasClobValue(VALUE_SIZE_4001) | |||
.hasCreatedAt(INITIAL_DATE + 6); | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
} | |||
@Test | |||
@@ -760,27 +760,27 @@ public class PropertiesDaoTest { | |||
.hasNoComponentUuid() | |||
.hasUserUuid(userUuid) | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
.hasCreatedAt(INITIAL_DATE); | |||
assertThatPropertiesRow("user.empty") | |||
.hasNoComponentUuid() | |||
.hasUserUuid(userUuid) | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
assertThatPropertiesRow("user.text") | |||
.hasNoComponentUuid() | |||
.hasUserUuid(userUuid) | |||
.hasTextValue("some text") | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
assertThatPropertiesRow("user.4000") | |||
.hasNoComponentUuid() | |||
.hasUserUuid(userUuid) | |||
.hasTextValue(VALUE_SIZE_4000) | |||
.hasCreatedAt(INITIAL_DATE + 5); | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
assertThatPropertiesRow("user.clob") | |||
.hasNoComponentUuid() | |||
.hasUserUuid(userUuid) | |||
.hasClobValue(VALUE_SIZE_4001) | |||
.hasCreatedAt(INITIAL_DATE + 6); | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
} | |||
@Test | |||
@@ -796,7 +796,7 @@ public class PropertiesDaoTest { | |||
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
if (newValue == null || newValue.isEmpty()) { | |||
propertiesRowAssert.isEmpty(); | |||
} else if (newValue.length() > 4000) { | |||
@@ -819,7 +819,7 @@ public class PropertiesDaoTest { | |||
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | |||
.hasComponentUuid(componentUuid) | |||
.hasNoUserUuid() | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
if (newValue == null || newValue.isEmpty()) { | |||
propertiesRowAssert.isEmpty(); | |||
} else if (newValue.length() > 4000) { | |||
@@ -843,7 +843,7 @@ public class PropertiesDaoTest { | |||
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") | |||
.hasNoComponentUuid() | |||
.hasUserUuid(userUuid) | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
if (newValue == null || newValue.isEmpty()) { | |||
propertiesRowAssert.isEmpty(); | |||
} else if (newValue.length() > 4000) { | |||
@@ -1082,27 +1082,27 @@ public class PropertiesDaoTest { | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
.hasCreatedAt(INITIAL_DATE); | |||
assertThatPropertiesRow("empty_value_property") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.isEmpty() | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
assertThatPropertiesRow("text_value_property") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasTextValue("dfdsfsd") | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
assertThatPropertiesRow("4000_char_value_property") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasTextValue(VALUE_SIZE_4000) | |||
.hasCreatedAt(INITIAL_DATE + 5); | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
assertThatPropertiesRow("clob_value_property") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasClobValue(VALUE_SIZE_4001) | |||
.hasCreatedAt(INITIAL_DATE + 6); | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
} | |||
@Test | |||
@@ -1118,7 +1118,7 @@ public class PropertiesDaoTest { | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasTextValue("new value") | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
} | |||
private static Map<String, String> mapOf(String... values) { | |||
@@ -1147,37 +1147,37 @@ public class PropertiesDaoTest { | |||
.hasNoUserUuid() | |||
.hasNoComponentUuid() | |||
.hasTextValue("bar") | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
.hasCreatedAt(INITIAL_DATE); | |||
assertThatPropertiesRowByUuid(uuid2) | |||
.hasKey("new_name") | |||
.hasNoComponentUuid() | |||
.hasNoUserUuid() | |||
.hasTextValue("doc1") | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
.hasCreatedAt(INITIAL_DATE + 1); | |||
assertThatPropertiesRowByUuid(uuid3) | |||
.hasKey("new_name") | |||
.hasComponentUuid("15") | |||
.hasNoUserUuid() | |||
.hasTextValue("doc2") | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
assertThatPropertiesRowByUuid(uuid4) | |||
.hasKey("new_name") | |||
.hasComponentUuid("16") | |||
.hasNoUserUuid() | |||
.hasTextValue("doc3") | |||
.hasCreatedAt(INITIAL_DATE + 5); | |||
.hasCreatedAt(INITIAL_DATE + 3); | |||
assertThatPropertiesRowByUuid(uuid5) | |||
.hasKey("new_name") | |||
.hasNoComponentUuid() | |||
.hasUserUuid("100") | |||
.hasTextValue("doc4") | |||
.hasCreatedAt(INITIAL_DATE + 6); | |||
.hasCreatedAt(INITIAL_DATE + 4); | |||
assertThatPropertiesRowByUuid(uuid6) | |||
.hasKey("new_name") | |||
.hasNoComponentUuid() | |||
.hasUserUuid("101") | |||
.hasTextValue("doc5") | |||
.hasCreatedAt(INITIAL_DATE + 7); | |||
.hasCreatedAt(INITIAL_DATE + 5); | |||
} | |||
@Test | |||
@@ -1185,7 +1185,7 @@ public class PropertiesDaoTest { | |||
String uuid = insertProperty("foo", "bar", null, null); | |||
assertThatPropertiesRowByUuid(uuid) | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
.hasCreatedAt(INITIAL_DATE); | |||
underTest.renamePropertyKey("foo", "foo"); | |||
@@ -1194,7 +1194,7 @@ public class PropertiesDaoTest { | |||
.hasNoUserUuid() | |||
.hasNoComponentUuid() | |||
.hasTextValue("bar") | |||
.hasCreatedAt(INITIAL_DATE + 2); | |||
.hasCreatedAt(INITIAL_DATE); | |||
} | |||
@Test |
@@ -331,7 +331,7 @@ public class PurgeDaoTest { | |||
@Test | |||
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); | |||
SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project); | |||
SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project); | |||
@@ -644,8 +644,8 @@ public class PurgeDaoTest { | |||
@Test | |||
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); | |||
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project | |||
@@ -663,10 +663,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeActivityDto projectTask = insertCeActivity(project); | |||
@@ -695,10 +695,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeActivityDto projectTask = insertCeActivity(project); | |||
@@ -727,10 +727,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeActivityDto projectTask = insertCeActivity(project); | |||
@@ -759,10 +759,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeActivityDto projectTask = insertCeActivity(project); | |||
@@ -829,10 +829,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeQueueDto projectTask = insertCeQueue(project); | |||
@@ -861,10 +861,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeQueueDto projectTask = insertCeQueue(project); | |||
@@ -894,10 +894,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeQueueDto projectTask = insertCeQueue(project); | |||
@@ -927,10 +927,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
CeQueueDto projectTask = insertCeQueue(project); | |||
@@ -960,10 +960,10 @@ public class PurgeDaoTest { | |||
@Test | |||
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 anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project); | |||
SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project); |
@@ -562,7 +562,7 @@ public class ActiveRuleDaoTest { | |||
} | |||
@Test | |||
public void deleteParamsByRuleParamOfAllOrganizations() { | |||
public void deleteParamsByRuleParam() { | |||
ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER); | |||
underTest.insert(dbSession, activeRule1); | |||
ActiveRuleParamDto activeRuleParam1 = ActiveRuleParamDto.createFor(rule1Param1).setValue("foo"); |
@@ -34,7 +34,6 @@ import org.sonar.db.DatabaseUtils; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static java.util.Arrays.asList; | |||
@@ -478,30 +477,6 @@ public class UserDaoTest { | |||
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 | |||
public void clean_users_homepage_when_deleting_project() { | |||
@@ -32,7 +32,6 @@ import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class WebhookDaoTest { | |||
@@ -110,7 +109,6 @@ public class WebhookDaoTest { | |||
assertThat(stored.getUuid()).isEqualTo(dto.getUuid()); | |||
assertThat(stored.getName()).isEqualTo(dto.getName()); | |||
assertThat(stored.getUrl()).isEqualTo(dto.getUrl()); | |||
assertThat(stored.getOrganizationUuid()).isEqualTo(dbTester.getDefaultOrganization().getUuid()); | |||
assertThat(stored.getProjectUuid()).isNull(); | |||
assertThat(stored.getSecret()).isEqualTo(dto.getSecret()); | |||
assertThat(new Date(stored.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | |||
@@ -133,7 +131,6 @@ public class WebhookDaoTest { | |||
assertThat(reloaded.getUuid()).isEqualTo(dto.getUuid()); | |||
assertThat(reloaded.getName()).isEqualTo(dto.getName()); | |||
assertThat(reloaded.getUrl()).isEqualTo(dto.getUrl()); | |||
assertThat(reloaded.getOrganizationUuid()).isNull(); | |||
assertThat(reloaded.getProjectUuid()).isEqualTo(dto.getProjectUuid()); | |||
assertThat(reloaded.getSecret()).isEqualTo(dto.getSecret()); | |||
assertThat(new Date(reloaded.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | |||
@@ -156,7 +153,6 @@ public class WebhookDaoTest { | |||
assertThat(reloaded.getName()).isEqualTo("a-fancy-webhook"); | |||
assertThat(reloaded.getUrl()).isEqualTo("http://www.fancy-webhook.io"); | |||
assertThat(reloaded.getProjectUuid()).isNull(); | |||
assertThat(reloaded.getOrganizationUuid()).isEqualTo(dto.getOrganizationUuid()); | |||
assertThat(reloaded.getSecret()).isNull(); | |||
assertThat(reloaded.getCreatedAt()).isEqualTo(dto.getCreatedAt()); | |||
assertThat(new Date(reloaded.getUpdatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | |||
@@ -178,7 +174,6 @@ public class WebhookDaoTest { | |||
assertThat(reloaded.getName()).isEqualTo("a-fancy-webhook"); | |||
assertThat(reloaded.getUrl()).isEqualTo("http://www.fancy-webhook.io"); | |||
assertThat(reloaded.getProjectUuid()).isNull(); | |||
assertThat(reloaded.getOrganizationUuid()).isEqualTo(dto.getOrganizationUuid()); | |||
assertThat(reloaded.getSecret()).isEqualTo("a_new_secret"); | |||
assertThat(reloaded.getCreatedAt()).isEqualTo(dto.getCreatedAt()); | |||
assertThat(new Date(reloaded.getUpdatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); | |||
@@ -209,7 +204,7 @@ public class WebhookDaoTest { | |||
} | |||
@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() | |||
.setUuid("UUID_1") | |||
.setName("NAME_1") | |||
@@ -219,21 +214,6 @@ public class WebhookDaoTest { | |||
Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid()); | |||
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) { |
@@ -40,7 +40,7 @@ public class WebhookDeliveryDaoTest { | |||
private static final long BEFORE = NOW - 1_000L; | |||
@Rule | |||
public final DbTester dbTester = DbTester.create(System2.INSTANCE).setDisableDefaultOrganization(true); | |||
public final DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); |
@@ -42,7 +42,6 @@ import org.sonar.db.issue.IssueDbTester; | |||
import org.sonar.db.measure.MeasureDbTester; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; | |||
import org.sonar.db.notification.NotificationDbTester; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.permission.template.PermissionTemplateDbTester; | |||
import org.sonar.db.plugin.PluginDbTester; | |||
import org.sonar.db.property.InternalComponentPropertyDbTester; | |||
@@ -56,10 +55,6 @@ import org.sonar.db.user.UserDbTester; | |||
import org.sonar.db.webhook.WebhookDbTester; | |||
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. | |||
* Data is truncated between each tests. The schema is created between each test. | |||
@@ -70,12 +65,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> { | |||
private final System2 system2; | |||
private DbClient client; | |||
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 ComponentDbTester componentTester; | |||
private final ProjectLinkDbTester componentLinkTester; | |||
@@ -136,10 +125,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> { | |||
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) { | |||
return new DbTester(system2, null, new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses)); | |||
} | |||
@@ -156,67 +141,11 @@ public class DbTester extends AbstractDbTester<TestDbImpl> { | |||
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 | |||
protected void before() { | |||
db.start(); | |||
db.truncateTables(); | |||
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() { | |||
@@ -314,7 +243,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> { | |||
session.close(); | |||
} | |||
db.stop(); | |||
started = false; | |||
} | |||
public DbSession getSession() { |
@@ -51,10 +51,6 @@ public class ComponentDbTester { | |||
} | |||
public SnapshotDto insertViewAndSnapshot(ComponentDto component) { | |||
if (component.getOrganizationUuid() == null) { | |||
component.setOrganizationUuid(db.getDefaultOrganization().getUuid()); | |||
} | |||
dbClient.componentDao().insert(dbSession, component); | |||
return insertSnapshot(component); | |||
} | |||
@@ -282,27 +278,13 @@ public class ComponentDbTester { | |||
private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto> dtoPopulator) { | |||
dtoPopulator.accept(component); | |||
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); | |||
db.commit(); | |||
return component; | |||
} | |||
private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate) { | |||
return insertComponentImpl(component, isPrivate, defaults()); | |||
} | |||
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)); | |||
db.commit(); | |||
} | |||
@@ -397,8 +379,7 @@ public class ComponentDbTester { | |||
.setUpdatedAt(createTime) | |||
.setPrivate(componentDto.isPrivate()) | |||
.setDescription(componentDto.description()) | |||
.setName(componentDto.name()) | |||
.setOrganizationUuid(componentDto.getOrganizationUuid()); | |||
.setName(componentDto.name()); | |||
} | |||
private static <T> Consumer<T> defaults() { |
@@ -24,7 +24,6 @@ import javax.annotation.Nullable; | |||
import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.resources.Scopes; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
@@ -125,42 +124,18 @@ public class ComponentTesting { | |||
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) { | |||
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() { | |||
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) { | |||
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) { | |||
return new ComponentDto() | |||
.setUuid(uuid) | |||
@@ -180,31 +155,6 @@ public class ComponentTesting { | |||
.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() { | |||
return newView(Uuids.createFast()); | |||
} | |||
@@ -228,7 +178,6 @@ public class ComponentTesting { | |||
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { | |||
return newChildComponent(uuid, view, view) | |||
.setDbKey(view.getDbKey() + project.getDbKey()) | |||
.setOrganizationUuid(project.getOrganizationUuid()) | |||
.setName(project.name()) | |||
.setLongName(project.longName()) | |||
.setCopyComponentUuid(project.uuid()) | |||
@@ -243,7 +192,6 @@ public class ComponentTesting { | |||
"private flag inconsistent between moduleOrProject (%s) and parent (%s)", | |||
moduleOrProject.isPrivate(), parent.isPrivate()); | |||
return new ComponentDto() | |||
.setOrganizationUuid(parent.getOrganizationUuid()) | |||
.setUuid(uuid) | |||
.setUuidPath(formatUuidPathFromParent(parent)) | |||
.setProjectUuid(moduleOrProject.projectUuid()) | |||
@@ -288,7 +236,6 @@ public class ComponentTesting { | |||
String uuid = branchDto.getUuid(); | |||
return new ComponentDto() | |||
.setUuid(uuid) | |||
.setOrganizationUuid(project.getOrganizationUuid()) | |||
.setUuidPath(UUID_PATH_OF_ROOT) | |||
.setProjectUuid(uuid) | |||
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) | |||
@@ -315,7 +262,6 @@ public class ComponentTesting { | |||
String uuid = branchDto.getUuid(); | |||
return new ComponentDto() | |||
.setUuid(uuid) | |||
.setOrganizationUuid(project.getOrganizationUuid()) | |||
.setUuidPath(UUID_PATH_OF_ROOT) | |||
.setProjectUuid(uuid) | |||
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) |
@@ -40,12 +40,10 @@ import static org.sonar.db.qualityprofile.ActiveRuleDto.createFor; | |||
public class QualityProfileDbTester { | |||
private final DbClient dbClient; | |||
private final DbSession dbSession; | |||
private final DbTester dbTester; | |||
public QualityProfileDbTester(DbTester dbTester) { | |||
this.dbClient = dbTester.getDbClient(); | |||
this.dbSession = dbTester.getSession(); | |||
this.dbTester = dbTester; | |||
} | |||
public Optional<QProfileDto> selectByUuid(String uuid) { | |||
@@ -53,7 +51,7 @@ public class QualityProfileDbTester { | |||
} | |||
/** | |||
* Create a profile with random field values on the specified organization. | |||
* Create a profile with random field values. | |||
*/ | |||
public QProfileDto insert() { | |||
return insert(c -> { |
@@ -27,7 +27,6 @@ import org.sonar.api.rules.RuleType; | |||
import org.sonar.api.server.rule.RuleParamType; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.user.UserDto; | |||
import static java.util.Arrays.asList; |
@@ -32,7 +32,6 @@ import org.sonar.api.server.rule.RuleParamType; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.core.util.UuidFactoryFast; | |||
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.Scope; | |||
import org.sonar.db.user.UserDto; | |||
@@ -40,7 +39,6 @@ import org.sonar.db.user.UserDto; | |||
import static com.google.common.base.Preconditions.checkNotNull; | |||
import static com.google.common.collect.ImmutableSet.copyOf; | |||
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.randomAlphanumeric; | |||
import static org.apache.commons.lang.math.RandomUtils.nextInt; |
@@ -321,7 +321,7 @@ public class UserDbTester { | |||
} | |||
public List<GlobalPermission> selectPermissionsOfUser(UserDto user) { | |||
return toListOfOrganizationPermissions(db.getDbClient().userPermissionDao() | |||
return toListOfGlobalPermissions(db.getDbClient().userPermissionDao() | |||
.selectGlobalPermissionsOfUser(db.getSession(), user.getUuid())); | |||
} | |||
@@ -329,7 +329,7 @@ public class UserDbTester { | |||
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 | |||
.stream() | |||
.map(GlobalPermission::fromKey) |
@@ -45,9 +45,6 @@ public class WebhookDbTester { | |||
public WebhookDto insert(WebhookDto dto) { | |||
DbSession dbSession = dbTester.getSession(); | |||
if (dto.getProjectUuid() == null && dto.getOrganizationUuid() == null) { | |||
dto.setOrganizationUuid(dbTester.getDefaultOrganization().getUuid()); | |||
} | |||
dbTester.getDbClient().webhookDao().insert(dbSession, dto); | |||
dbSession.commit(); | |||
return dto; |
@@ -30,6 +30,15 @@ public class DbVersion87 implements DbVersion { | |||
.add(4200, "Move default project visibility to global properties", MoveDefaultProjectVisibilityToGlobalProperties.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) | |||
; | |||
} | |||
} |
@@ -0,0 +1,44 @@ | |||
/* | |||
* 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()); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
/* | |||
* 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()); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
/* | |||
* 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()); | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
/* | |||
* 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()); | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
/* | |||
* 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()); | |||
} | |||
} |
@@ -17,25 +17,22 @@ | |||
* 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; | |||
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()); | |||
} | |||
} |
@@ -17,47 +17,25 @@ | |||
* 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; | |||
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; | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
/* | |||
* 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()); | |||
} | |||
} |
@@ -17,31 +17,26 @@ | |||
* 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.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); | |||
} | |||
} |
@@ -17,14 +17,24 @@ | |||
* 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; | |||
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"); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
/* | |||
* 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); | |||
} | |||
} |
@@ -17,30 +17,26 @@ | |||
* 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; | |||
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; | |||
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 | |||
public void stop_does_nothing() { | |||
underTest.stop(); | |||
verifyNoMoreInteractions(defaultOrganizationProvider); | |||
public void execute() throws SQLException { | |||
db.assertTableExists(TABLE_NAME); | |||
underTest.execute(); | |||
db.assertTableDoesNotExist(TABLE_NAME); | |||
} | |||
} |
@@ -17,27 +17,24 @@ | |||
* 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; | |||
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 | |||
} | |||
} |
@@ -17,16 +17,24 @@ | |||
* 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.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"); | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
/* | |||
* 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"); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
/* | |||
* 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); | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
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"); |
@@ -0,0 +1,28 @@ | |||
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"); |
@@ -0,0 +1,7 @@ | |||
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"); |
@@ -0,0 +1,13 @@ | |||
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"); |
@@ -0,0 +1,42 @@ | |||
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"); |
@@ -0,0 +1,15 @@ | |||
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"); |
@@ -0,0 +1,34 @@ | |||
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"); |
@@ -0,0 +1,20 @@ | |||
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"); |
@@ -26,7 +26,6 @@ import org.sonar.server.permission.index.AuthorizationDoc; | |||
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_ORGANIZATION_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_UUID; | |||
@@ -88,13 +87,4 @@ public class ComponentDoc extends BaseDoc { | |||
setField(FIELD_QUALIFIER, s); | |||
return this; | |||
} | |||
public String getOrganization() { | |||
return getField(FIELD_ORGANIZATION_UUID); | |||
} | |||
public ComponentDoc setOrganization(String s) { | |||
setField(FIELD_ORGANIZATION_UUID, s); | |||
return this; | |||
} | |||
} |
@@ -42,7 +42,6 @@ public class ComponentIndexDefinition implements IndexDefinition { | |||
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_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_NAME = "name"; | |||
public static final String FIELD_QUALIFIER = "qualifier"; | |||
@@ -94,6 +93,5 @@ public class ComponentIndexDefinition implements IndexDefinition { | |||
.build(); | |||
mapping.keywordFieldBuilder(FIELD_QUALIFIER).build(); | |||
mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).disableNorms().build(); | |||
} | |||
} |
@@ -187,7 +187,6 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe | |||
.setName(component.name()) | |||
.setKey(component.getDbKey()) | |||
.setProjectUuid(component.projectUuid()) | |||
.setOrganization(component.getOrganizationUuid()) | |||
.setQualifier(component.qualifier()); | |||
} | |||
} |
@@ -40,7 +40,6 @@ import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIEL | |||
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_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_QUALITY_GATE_STATUS; | |||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS; | |||
@@ -70,15 +69,6 @@ public class ProjectMeasuresDoc extends BaseDoc { | |||
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() { | |||
return getField(FIELD_KEY); | |||
} |
@@ -41,7 +41,6 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition { | |||
public static final IndexRelationType TYPE_PROJECT_MEASURES = IndexType.relation(TYPE_AUTHORIZATION, "projectmeasure"); | |||
public static final String FIELD_UUID = "uuid"; | |||
public static final String FIELD_ORGANIZATION_UUID = "organizationUuid"; | |||
/** | |||
* Project key. Only projects and applications (qualifier=TRK, APP) | |||
@@ -96,7 +95,6 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition { | |||
TypeMapping mapping = index.createTypeMapping(TYPE_PROJECT_MEASURES); | |||
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_QUALIFIER).disableNorms().build(); | |||
mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build(); |
@@ -172,7 +172,6 @@ public class ProjectMeasuresIndexer implements ProjectIndexer, NeedAuthorization | |||
Long analysisDate = project.getAnalysisDate(); | |||
return new ProjectMeasuresDoc() | |||
.setId(project.getUuid()) | |||
.setOrganizationUuid(project.getOrganizationUuid()) | |||
.setKey(project.getKey()) | |||
.setName(project.getName()) | |||
.setQualifier(project.getQualifier()) |
@@ -1,110 +0,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.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); | |||
} | |||
} | |||
} |