return Optional.ofNullable(mapper(session).selectByUuid(uuid));
}
+ public boolean hasNonMainBranches(DbSession dbSession) {
+ return mapper(dbSession).countNonMainBranches() > 0L;
+ }
+
private static BranchMapper mapper(DbSession dbSession) {
return dbSession.getMapper(BranchMapper.class);
}
Collection<BranchDto> selectByProjectUuid(@Param("projectUuid") String projectUuid);
List<BranchDto> selectByUuids(@Param("uuids") Collection<String> uuids);
+
+ long countNonMainBranches();
}
pb.uuid = #{uuid, jdbcType=VARCHAR}
</select>
+ <select id="countNonMainBranches" resultType="long">
+ select count(pb.uuid)
+ from project_branches pb
+ where
+ pb.uuid <> pb.project_uuid
+ </select>
+
</mapper>
assertThat(underTest.selectByUuid(db.getSession(), project.uuid())).isNotPresent();
assertThat(underTest.selectByUuid(db.getSession(), "unknown")).isNotPresent();
}
+
+ @Test
+ public void existsNonMainBranch() {
+ assertThat(underTest.hasNonMainBranches(dbSession)).isFalse();
+ ComponentDto project = db.components().insertPrivateProject();
+ assertThat(underTest.hasNonMainBranches(dbSession)).isFalse();
+
+ ComponentDto branch1 = db.components().insertProjectBranch(project);
+ assertThat(underTest.hasNonMainBranches(dbSession)).isTrue();
+
+ ComponentDto branch2 = db.components().insertProjectBranch(project);
+ assertThat(underTest.hasNonMainBranches(dbSession)).isTrue();
+ }
}
private final long ncloc;
private final long userCount;
private final long projectCount;
+ private final boolean usingBranches;
private final Database database;
private final Map<String, Long> projectCountByLanguage;
private final Map<String, Long> nclocByLanguage;
ncloc = builder.projectMeasuresStatistics.getNcloc();
userCount = builder.userCount;
projectCount = builder.projectMeasuresStatistics.getProjectCount();
+ usingBranches = builder.usingBranches;
database = builder.database;
projectCountByLanguage = builder.projectMeasuresStatistics.getProjectCountByLanguage();
nclocByLanguage = builder.projectMeasuresStatistics.getNclocByLanguage();
return projectCount;
}
+ public boolean isUsingBranches() {
+ return usingBranches;
+ }
+
public Database getDatabase() {
return database;
}
private Map<String, String> plugins;
private Database database;
private ProjectMeasuresStatistics projectMeasuresStatistics;
+ private Boolean usingBranches;
private Builder() {
// enforce static factory method
return this;
}
+ Builder setUsingBranches(boolean usingBranches) {
+ this.usingBranches = usingBranches;
+ return this;
+ }
+
TelemetryData build() {
requireNonNull(serverId);
requireNonNull(version);
requireNonNull(plugins);
requireNonNull(projectMeasuresStatistics);
+ requireNonNull(database);
+ requireNonNull(usingBranches);
return new TelemetryData(this);
}
json.endArray();
json.prop("userCount", statistics.getUserCount());
json.prop("projectCount", statistics.getProjectCount());
+ json.prop("usingBranches", statistics.isUsingBranches());
json.prop(LINES_KEY, statistics.getLines());
json.prop(NCLOC_KEY, statistics.getNcloc());
json.name("projectCountByLanguage");
data.setServerId(server.getId());
data.setVersion(server.getVersion());
- data.setDatabase(loadDatabaseMetadata());
Function<PluginInfo, String> getVersion = plugin -> plugin.getVersion() == null ? "undefined" : plugin.getVersion().getName();
Map<String, String> plugins = pluginRepository.getPluginInfos().stream().collect(MoreCollectors.uniqueIndex(PluginInfo::getKey, getVersion));
data.setPlugins(plugins);
data.setUserCount(userCount);
ProjectMeasuresStatistics projectMeasuresStatistics = projectMeasuresIndex.searchTelemetryStatistics();
data.setProjectMeasuresStatistics(projectMeasuresStatistics);
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ data.setDatabase(loadDatabaseMetadata(dbSession));
+ data.setUsingBranches(dbClient.branchDao().hasNonMainBranches(dbSession));
+ }
return data.build();
}
return server.getId();
}
- private Database loadDatabaseMetadata() {
- try (DbSession dbSession = dbClient.openSession(false)) {
+ private static Database loadDatabaseMetadata(DbSession dbSession) {
+ try {
DatabaseMetaData metadata = dbSession.getConnection().getMetaData();
return new Database(metadata.getDatabaseProductName(), metadata.getDatabaseProductVersion());
} catch (SQLException e) {
TestResponse response = ws.newRequest().execute();
// response does not contain empty "Section Three"
assertThat(response.getInput()).isEqualTo("{\"Health\":\"GREEN\",\"Health Causes\":[],\"Section One\":{\"foo\":\"bar\"},\"Section Two\":{\"one\":1,\"two\":2}," +
- "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],\"userCount\":0,\"projectCount\":0,\"lines\":0,\"ncloc\":0," +
- "\"projectCountByLanguage\":[],\"nclocByLanguage\":[]}}");
+ "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],\"userCount\":0,\"projectCount\":0,\"usingBranches\":false," +
+ "\"lines\":0,\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[]}}");
}
private void logInAsSystemAdministrator() {
MetricDto nclocDistrib = db.measures().insertMetric(m -> m.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY));
ComponentDto project1 = db.components().insertMainBranch(db.getDefaultOrganization());
+ ComponentDto project1Branch = db.components().insertProjectBranch(project1);
SnapshotDto analysis1 = db.components().insertSnapshot(project1);
db.measures().insertMeasure(project1, analysis1, lines, m -> m.setValue(200d));
db.measures().insertMeasure(project1, analysis1, ncloc, m -> m.setValue(100d));
],
"userCount": 3,
"projectCount": 2,
+ "usingBranches": true,
"lines": 500,
"ncloc": 300,
"projectCountByLanguage": [
Map<String, String> database = (Map<String, String>) json.get("database");
assertThat(database.get("name")).isNotEmpty();
assertThat(database.get("version")).isNotEmpty();
+ assertThat((Boolean) json.get("usingBranches")).isFalse();
assertThat(getInteger(json.get("userCount"))).isEqualTo(1);
List<String> plugins = ((List<Map<String, String>>) json.get("plugins")).stream().map(p -> p.get("name")).collect(Collectors.toList());
assertThat(plugins).contains("xoo");