*/
public long sumNclocOfBiggestBranch(DbSession dbSession, SumNclocDbQuery dbQuery) {
Long ncloc = mapper(dbSession).sumNclocOfBiggestBranch(
- NCLOC_KEY, BranchType.BRANCH, dbQuery.getOrganizationUuid(), dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude());
+ NCLOC_KEY, BranchType.BRANCH, dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude());
return ncloc == null ? 0L : ncloc;
}
Long sumNclocOfBiggestBranch(
@Param("ncloc") String nclocKey,
@Param("branchType") BranchType branchType,
- @Param("organizationUuid") String organizationUuid,
@Param("private") Boolean privateProject,
@Nullable @Param("projectUuidToExclude") String projectUuidToExclude);
public class SumNclocDbQuery {
private final String projectUuidToExclude;
- private final String organizationUuid;
private final Boolean onlyPrivateProjects;
public SumNclocDbQuery(Builder builder) {
projectUuidToExclude = builder.projectUuidToExclude;
- organizationUuid = builder.organizationUuid;
onlyPrivateProjects = builder.onlyPrivateProjects;
}
return projectUuidToExclude;
}
- public String getOrganizationUuid() {
- return organizationUuid;
- }
-
public Boolean getOnlyPrivateProjects() {
return onlyPrivateProjects;
}
public static class Builder {
private String projectUuidToExclude;
- private String organizationUuid;
private Boolean onlyPrivateProjects;
private Builder() {
return this;
}
- public Builder setOrganizationUuid(String organizationUuid) {
- this.organizationUuid = organizationUuid;
- return this;
- }
-
public Builder setOnlyPrivateProjects(Boolean onlyPrivateProjects) {
this.onlyPrivateProjects = onlyPrivateProjects;
return this;
}
public SumNclocDbQuery build() {
- checkNotNull(organizationUuid);
checkNotNull(onlyPrivateProjects);
return new SumNclocDbQuery(this);
}
<select id="selectByComponentUuidsAndMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
select <include refid="columns"/> from live_measures lm
where
- lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator="," close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
+ lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator=","
+ close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
and lm.component_uuid in
<foreach item="componentUuid" collection="componentUuids" open="(" separator="," close=")">
#{componentUuid, jdbcType=VARCHAR}
select b.project_uuid as projectUuid, 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
+ inner join project_branches b on b.uuid = lm.component_uuid and b.branch_type = #{branchType, jdbcType=VARCHAR}
+ inner join projects p on p.uuid = b.project_uuid and p.qualifier = 'TRK'
<where>
m.name = #{ncloc, jdbcType=VARCHAR}
<if test="private">
and p.private=${_true}
</if>
- and p.enabled = ${_true}
- and p.scope = 'PRJ'
- and p.qualifier = 'TRK'
- and p.copy_component_uuid is null
- and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- and b.branch_type = #{branchType, jdbcType=VARCHAR}
<if test="projectUuidToExclude != null">
and b.project_uuid <> #{projectUuidToExclude,jdbcType=VARCHAR}
</if>
</sql>
<select id="scrollSelectByComponentUuidAndMetricKeys" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}"
- resultSetType="FORWARD_ONLY">
+ resultSetType="FORWARD_ONLY">
select <include refid="columns"/> from live_measures lm
inner join metrics m on m.uuid = lm.metric_uuid
where
and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR}
</select>
- <select id="selectTreeByQuery" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+ <select id="selectTreeByQuery" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}"
+ resultSetType="FORWARD_ONLY">
select <include refid="columns"/> from live_measures lm
inner join components p on p.uuid = lm.component_uuid
<!-- TODO do we really need another join on components ? Using lm.project_uuid should be enough -->
<where>
<if test="query.getMetricUuids() != null">
lm.metric_uuid in
- <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach>
+ <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator=","
+ close=")">#{metricUuid,jdbcType=VARCHAR}</foreach>
</if>
and p.enabled = ${_true}
<if test="query.qualifiers != null">
<where>
<if test="query.getMetricUuids() != null">
lm.metric_uuid in
- <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach>
+ <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator=","
+ close=")">#{metricUuid,jdbcType=VARCHAR}</foreach>
</if>
and p.enabled = ${_true}
<if test="query.qualifiers != null">
SumNclocDbQuery query = SumNclocDbQuery.builder()
.setOnlyPrivateProjects(false)
- .setOrganizationUuid(organization.getUuid())
.build();
long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query);
db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString()));
SumNclocDbQuery query = SumNclocDbQuery.builder()
.setOnlyPrivateProjects(false)
- .setOrganizationUuid(db.getDefaultOrganization().getUuid())
.build();
long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query);
db.measures().insertLiveMeasure(projectToExcludeBranch, ncloc, m -> m.setValue(400d));
SumNclocDbQuery query = SumNclocDbQuery.builder()
- .setOrganizationUuid(organization.getUuid())
.setProjectUuidToExclude(projectToExclude.uuid())
.setOnlyPrivateProjects(false)
.build();
private final UserIndex userIndex;
private final ProjectMeasuresIndex projectMeasuresIndex;
private final PlatformEditionProvider editionProvider;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
private final InternalProperties internalProperties;
private final DockerSupport dockerSupport;
@CheckForNull
private final LicenseReader licenseReader;
public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex,
- PlatformEditionProvider editionProvider, DefaultOrganizationProvider defaultOrganizationProvider, InternalProperties internalProperties, DockerSupport dockerSupport) {
- this(server, dbClient, pluginRepository, userIndex, projectMeasuresIndex, editionProvider, defaultOrganizationProvider, internalProperties, dockerSupport, null);
+ PlatformEditionProvider editionProvider, InternalProperties internalProperties, DockerSupport dockerSupport) {
+ this(server, dbClient, pluginRepository, userIndex, projectMeasuresIndex, editionProvider, internalProperties, dockerSupport, null);
}
public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex,
- PlatformEditionProvider editionProvider, DefaultOrganizationProvider defaultOrganizationProvider, InternalProperties internalProperties,
+ PlatformEditionProvider editionProvider, InternalProperties internalProperties,
DockerSupport dockerSupport, @Nullable LicenseReader licenseReader) {
this.server = server;
this.dbClient = dbClient;
this.userIndex = userIndex;
this.projectMeasuresIndex = projectMeasuresIndex;
this.editionProvider = editionProvider;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
this.internalProperties = internalProperties;
this.dockerSupport = dockerSupport;
this.licenseReader = licenseReader;
data.setUsingBranches(dbClient.branchDao().hasNonMainBranches(dbSession));
SumNclocDbQuery query = SumNclocDbQuery.builder()
.setOnlyPrivateProjects(false)
- .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.build();
data.setNcloc(dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query));
long numberOfUnanalyzedCMeasures = dbClient.liveMeasureDao().countProjectsHavingMeasure(dbSession, UNANALYZED_C_KEY);
private final LicenseReader licenseReader = mock(LicenseReader.class);
private final TelemetryDataLoader communityUnderTest = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, new UserIndex(es.client(), system2),
- new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, dockerSupport, null);
+ new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, internalProperties, dockerSupport, null);
private final TelemetryDataLoader commercialUnderTest = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, new UserIndex(es.client(), system2),
- new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, dockerSupport, licenseReader);
+ new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, internalProperties, dockerSupport, licenseReader);
@Test
public void send_telemetry_data() {
private final UserSession userSession;
private final Server server;
private final DbClient dbClient;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public MarketplaceAction(UserSession userSession, Server server, DbClient dbClient, DefaultOrganizationProvider defaultOrganizationProvider) {
+ public MarketplaceAction(UserSession userSession, Server server, DbClient dbClient) {
this.userSession = userSession;
this.server = server;
this.dbClient = dbClient;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
}
@Override
try (DbSession dbSession = dbClient.openSession(false)) {
SumNclocDbQuery query = SumNclocDbQuery.builder()
.setOnlyPrivateProjects(false)
- .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.build();
return dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query);
}
private Server server = mock(Server.class);
private DbClient dbClient = db.getDbClient();
- private MarketplaceAction underTest = new MarketplaceAction(userSessionRule, server, dbClient, new DefaultOrganizationProviderImpl(dbClient));
+ private MarketplaceAction underTest = new MarketplaceAction(userSessionRule, server, dbClient);
private WsActionTester ws = new WsActionTester(underTest);