use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.
the class ExportNewCodePeriodsStep method execute.
@Override
public void execute(Context context) {
long count = 0L;
try (StreamWriter<ProjectDump.NewCodePeriod> output = dumpWriter.newStreamWriter(DumpElement.NEW_CODE_PERIODS);
DbSession dbSession = dbClient.openSession(false)) {
final ProjectDump.NewCodePeriod.Builder builder = ProjectDump.NewCodePeriod.newBuilder();
final List<NewCodePeriodDto> newCodePeriods = dbSession.getMapper(ProjectExportMapper.class).selectNewCodePeriodsForExport(projectHolder.projectDto().getUuid());
for (NewCodePeriodDto newCodePeriod : newCodePeriods) {
builder.clear().setUuid(newCodePeriod.getUuid()).setProjectUuid(newCodePeriod.getProjectUuid()).setType(newCodePeriod.getType().name());
if (newCodePeriod.getBranchUuid() != null) {
builder.setBranchUuid(newCodePeriod.getBranchUuid());
}
if (newCodePeriod.getValue() != null) {
builder.setValue(newCodePeriod.getValue());
}
output.write(builder.build());
++count;
}
Loggers.get(getClass()).debug("{} new code periods exported", count);
} catch (Exception e) {
throw new IllegalStateException(format("New Code Periods Export failed after processing %d new code periods successfully", count), e);
}
}
use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.
the class ExportNewCodePeriodsStepTest method test_exported_fields.
@Test
public void test_exported_fields() {
NewCodePeriodDto dto = newDto("uuid1", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
insertNewCodePeriods(dto);
underTest.execute(new TestComputationStepContext());
ProjectDump.NewCodePeriod exportedNewCodePeriod = dumpWriter.getWrittenMessagesOf(DumpElement.NEW_CODE_PERIODS).get(0);
assertThat(exportedNewCodePeriod.getUuid()).isEqualTo(dto.getUuid());
assertThat(exportedNewCodePeriod.getProjectUuid()).isEqualTo(dto.getProjectUuid());
assertThat(exportedNewCodePeriod.getBranchUuid()).isEqualTo(dto.getBranchUuid());
assertThat(exportedNewCodePeriod.getType()).isEqualTo(dto.getType().name());
assertThat(exportedNewCodePeriod.getValue()).isEqualTo(dto.getValue());
}
use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.
the class SetAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.getParam(PARAM_PROJECT).emptyAsNull().or(() -> null);
String branchKey = request.getParam(PARAM_BRANCH).emptyAsNull().or(() -> null);
if (projectKey == null && branchKey != null) {
throw new IllegalArgumentException("If branch key is specified, project key needs to be specified too");
}
try (DbSession dbSession = dbClient.openSession(false)) {
String typeStr = request.mandatoryParam(PARAM_TYPE);
String valueStr = request.getParam(PARAM_VALUE).emptyAsNull().or(() -> null);
boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
NewCodePeriodType type = validateType(typeStr, projectKey == null, branchKey != null || isCommunityEdition);
NewCodePeriodDto dto = new NewCodePeriodDto();
dto.setType(type);
ProjectDto project = null;
BranchDto branch = null;
if (projectKey != null) {
project = getProject(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.ADMIN, project);
if (branchKey != null) {
branch = getBranch(dbSession, project, branchKey);
dto.setBranchUuid(branch.getUuid());
} else if (isCommunityEdition) {
// in CE set main branch value instead of project value
branch = getMainBranch(dbSession, project);
dto.setBranchUuid(branch.getUuid());
}
dto.setProjectUuid(project.getUuid());
} else {
userSession.checkIsSystemAdministrator();
}
setValue(dbSession, dto, type, project, branch, valueStr);
newCodePeriodDao.upsert(dbSession, dto);
dbSession.commit();
}
}
use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.
the class PurgeDaoTest method selectPurgeableAnalyses_does_not_return_the_baseline.
@Test
public void selectPurgeableAnalyses_does_not_return_the_baseline() {
ComponentDto project1 = db.components().insertPublicProject("master");
SnapshotDto analysis1 = db.components().insertSnapshot(newSnapshot().setComponentUuid(project1.uuid()).setStatus(STATUS_PROCESSED).setLast(false));
dbClient.newCodePeriodDao().insert(dbSession, new NewCodePeriodDto().setProjectUuid(project1.uuid()).setBranchUuid(project1.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(analysis1.getUuid()));
ComponentDto project2 = db.components().insertPrivateProject();
SnapshotDto analysis2 = db.components().insertSnapshot(newSnapshot().setComponentUuid(project2.uuid()).setStatus(STATUS_PROCESSED).setLast(false));
db.components().insertProjectBranch(project2);
assertThat(underTest.selectPurgeableAnalyses(project1.uuid(), dbSession)).isEmpty();
assertThat(underTest.selectPurgeableAnalyses(project2.uuid(), dbSession)).extracting(PurgeableAnalysisDto::getAnalysisUuid).containsOnly(analysis2.getUuid());
}
use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.
the class PurgeDaoTest method selectPurgeableAnalyses_does_not_return_the_baseline_of_specific_branch.
@Test
public void selectPurgeableAnalyses_does_not_return_the_baseline_of_specific_branch() {
ComponentDto project = db.components().insertPublicProject("master");
SnapshotDto analysisProject = db.components().insertSnapshot(newSnapshot().setComponentUuid(project.uuid()).setStatus(STATUS_PROCESSED).setLast(false));
dbClient.newCodePeriodDao().insert(dbSession, new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(project.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(analysisProject.getUuid()));
ComponentDto branch1 = db.components().insertProjectBranch(project);
SnapshotDto analysisBranch1 = db.components().insertSnapshot(newSnapshot().setComponentUuid(branch1.uuid()).setStatus(STATUS_PROCESSED).setLast(false));
ComponentDto branch2 = db.components().insertProjectBranch(project);
SnapshotDto analysisBranch2 = db.components().insertSnapshot(newSnapshot().setComponentUuid(branch2.uuid()).setStatus(STATUS_PROCESSED).setLast(false));
dbClient.newCodePeriodDao().insert(dbSession, new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(branch2.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(analysisBranch2.getUuid()));
dbSession.commit();
assertThat(underTest.selectPurgeableAnalyses(project.uuid(), dbSession)).isEmpty();
assertThat(underTest.selectPurgeableAnalyses(branch1.uuid(), dbSession)).extracting(PurgeableAnalysisDto::getAnalysisUuid).containsOnly(analysisBranch1.getUuid());
assertThat(underTest.selectPurgeableAnalyses(branch2.uuid(), dbSession)).isEmpty();
}
Aggregations