use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class ComponentAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, wsRequest.param(PARAM_COMPONENT_ID), wsRequest.param(PARAM_COMPONENT_KEY), COMPONENT_ID_AND_KEY);
userSession.checkComponentPermission(UserRole.USER, component);
List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByComponentUuid(dbSession, component.uuid());
CeTaskQuery activityQuery = new CeTaskQuery().setComponentUuid(component.uuid()).setOnlyCurrents(true);
List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, 0, 1);
ProjectResponse.Builder wsResponseBuilder = ProjectResponse.newBuilder();
wsResponseBuilder.addAllQueue(formatter.formatQueue(dbSession, queueDtos));
if (activityDtos.size() == 1) {
wsResponseBuilder.setCurrent(formatter.formatActivity(dbSession, activityDtos.get(0)));
}
writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
}
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class TaskAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
String taskUuid = wsRequest.mandatoryParam(PARAM_TASK_UUID);
try (DbSession dbSession = dbClient.openSession(false)) {
WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder();
Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
if (queueDto.isPresent()) {
Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
checkPermission(component);
wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get(), component));
} else {
CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
checkPermission(component);
Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
maskErrorStacktrace(ceActivityDto, additionalFields);
wsTaskResponse.setTask(wsTaskFormatter.formatActivity(dbSession, ceActivityDto, component, extractScannerContext(dbSession, ceActivityDto, additionalFields)));
}
writeProtobuf(wsTaskResponse.build(), wsRequest, wsResponse);
}
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class TaskFormatterTest method formatQueue_without_component.
@Test
public void formatQueue_without_component() {
CeQueueDto dto = new CeQueueDto();
dto.setUuid("UUID");
dto.setTaskType("TYPE");
dto.setStatus(CeQueueDto.Status.PENDING);
dto.setCreatedAt(1_450_000_000_000L);
WsCe.Task wsTask = underTest.formatQueue(db.getSession(), dto);
assertThat(wsTask.getType()).isEqualTo("TYPE");
assertThat(wsTask.getId()).isEqualTo("UUID");
assertThat(wsTask.getStatus()).isEqualTo(WsCe.TaskStatus.PENDING);
assertThat(wsTask.getLogs()).isFalse();
assertThat(wsTask.getSubmittedAt()).isEqualTo(DateUtils.formatDateTime(new Date(1_450_000_000_000L)));
assertThat(wsTask.hasScannerContext()).isFalse();
assertThat(wsTask.hasExecutionTimeMs()).isFalse();
assertThat(wsTask.hasSubmitterLogin()).isFalse();
assertThat(wsTask.hasComponentId()).isFalse();
assertThat(wsTask.hasComponentKey()).isFalse();
assertThat(wsTask.hasComponentName()).isFalse();
assertThat(wsTask.hasExecutedAt()).isFalse();
assertThat(wsTask.hasStartedAt()).isFalse();
assertThat(wsTask.hasExecutionTimeMs()).isFalse();
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class TaskFormatterTest method formatQueue_with_component_and_other_fields.
@Test
public void formatQueue_with_component_and_other_fields() throws IOException {
String uuid = "COMPONENT_UUID";
OrganizationDto organizationDto = db.organizations().insert();
db.components().insertProject(organizationDto, (t) -> t.setUuid(uuid).setKey("COMPONENT_KEY").setName("Component Name"));
CeQueueDto dto = new CeQueueDto();
dto.setUuid("UUID");
dto.setTaskType("TYPE");
dto.setStatus(CeQueueDto.Status.IN_PROGRESS);
dto.setCreatedAt(1_450_000_000_000L);
dto.setStartedAt(1_451_000_000_000L);
dto.setComponentUuid(uuid);
dto.setSubmitterLogin("rob");
WsCe.Task wsTask = underTest.formatQueue(db.getSession(), dto);
assertThat(wsTask.getType()).isEqualTo("TYPE");
assertThat(wsTask.getId()).isEqualTo("UUID");
assertThat(wsTask.getComponentId()).isEqualTo(uuid);
assertThat(wsTask.getComponentKey()).isEqualTo("COMPONENT_KEY");
assertThat(wsTask.getComponentName()).isEqualTo("Component Name");
assertThat(wsTask.getComponentQualifier()).isEqualTo("TRK");
assertThat(wsTask.getStatus()).isEqualTo(WsCe.TaskStatus.IN_PROGRESS);
assertThat(wsTask.getLogs()).isFalse();
assertThat(wsTask.getSubmitterLogin()).isEqualTo("rob");
assertThat(wsTask.hasExecutionTimeMs()).isTrue();
assertThat(wsTask.hasExecutedAt()).isFalse();
assertThat(wsTask.hasScannerContext()).isFalse();
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class ComponentActionTest method insertQueue.
private CeQueueDto insertQueue(String taskUuid, String componentUuid, CeQueueDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
queueDto.setComponentUuid(componentUuid);
queueDto.setUuid(taskUuid);
queueDto.setStatus(status);
dbTester.getDbClient().ceQueueDao().insert(dbTester.getSession(), queueDto);
dbTester.getSession().commit();
return queueDto;
}
Aggregations