Search in sources :

Example 1 with CeTaskCharacteristicDto

use of org.sonar.db.ce.CeTaskCharacteristicDto in project sonarqube by SonarSource.

the class CeQueueImpl method loadTasks.

private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) {
    // load components, if defined
    Set<String> componentUuids = dtos.stream().flatMap(dto -> Stream.of(dto.getComponentUuid(), dto.getMainComponentUuid())).filter(Objects::nonNull).collect(Collectors.toSet());
    Map<String, ComponentDto> componentsByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuids).stream().collect(uniqueIndex(ComponentDto::uuid));
    // load characteristics
    // TODO could be avoided, characteristics are already present in submissions
    Set<String> taskUuids = dtos.stream().map(CeQueueDto::getUuid).collect(MoreCollectors.toSet(dtos.size()));
    Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, taskUuids).stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
    List<CeTask> result = new ArrayList<>();
    for (CeQueueDto dto : dtos) {
        ComponentDto component = ofNullable(dto.getComponentUuid()).map(componentsByUuid::get).orElse(null);
        ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null);
        Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream().collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
        result.add(convertToTask(dbSession, dto, characteristics, component, mainComponent));
    }
    return result;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask)

Example 2 with CeTaskCharacteristicDto

use of org.sonar.db.ce.CeTaskCharacteristicDto in project sonarqube by SonarSource.

the class CeQueueImpl method addToQueueInDb.

private CeQueueDto addToQueueInDb(DbSession dbSession, CeTaskSubmit submission) {
    for (Map.Entry<String, String> characteristic : submission.getCharacteristics().entrySet()) {
        CeTaskCharacteristicDto characteristicDto = new CeTaskCharacteristicDto();
        characteristicDto.setUuid(uuidFactory.create());
        characteristicDto.setTaskUuid(submission.getUuid());
        characteristicDto.setKey(characteristic.getKey());
        characteristicDto.setValue(characteristic.getValue());
        dbClient.ceTaskCharacteristicsDao().insert(dbSession, characteristicDto);
    }
    CeQueueDto dto = new CeQueueDto();
    dto.setUuid(submission.getUuid());
    dto.setTaskType(submission.getType());
    submission.getComponent().ifPresent(component -> dto.setComponentUuid(component.getUuid()).setMainComponentUuid(component.getMainComponentUuid()));
    dto.setStatus(PENDING);
    dto.setSubmitterUuid(submission.getSubmitterUuid());
    dbClient.ceQueueDao().insert(dbSession, dto);
    return dto;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 3 with CeTaskCharacteristicDto

use of org.sonar.db.ce.CeTaskCharacteristicDto in project sonarqube by SonarSource.

the class ComponentActionTest method insertCharacteristic.

private CeTaskCharacteristicDto insertCharacteristic(String taskUuid, String key, String value) {
    CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto().setUuid(Uuids.createFast()).setTaskUuid(taskUuid).setKey(key).setValue(value);
    db.getDbClient().ceTaskCharacteristicsDao().insert(db.getSession(), Collections.singletonList(dto));
    db.commit();
    return dto;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto)

Example 4 with CeTaskCharacteristicDto

use of org.sonar.db.ce.CeTaskCharacteristicDto in project sonarqube by SonarSource.

the class TaskActionTest method insertCharacteristic.

private CeTaskCharacteristicDto insertCharacteristic(String taskUuid, String key, String value) {
    CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto().setUuid(Uuids.createFast()).setTaskUuid(taskUuid).setKey(key).setValue(value);
    db.getDbClient().ceTaskCharacteristicsDao().insert(db.getSession(), Collections.singletonList(dto));
    db.commit();
    return dto;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto)

Example 5 with CeTaskCharacteristicDto

use of org.sonar.db.ce.CeTaskCharacteristicDto in project sonarqube by SonarSource.

the class ActivityActionTest method insertCharacteristic.

private CeTaskCharacteristicDto insertCharacteristic(String taskUuid, String key, String value) {
    CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto().setUuid(Uuids.createFast()).setTaskUuid(taskUuid).setKey(key).setValue(value);
    db.getDbClient().ceTaskCharacteristicsDao().insert(db.getSession(), singletonList(dto));
    db.commit();
    return dto;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto)

Aggregations

CeTaskCharacteristicDto (org.sonar.db.ce.CeTaskCharacteristicDto)5 CeQueueDto (org.sonar.db.ce.CeQueueDto)2 ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Map (java.util.Map)1 CeTask (org.sonar.ce.task.CeTask)1 ComponentDto (org.sonar.db.component.ComponentDto)1