public CeActivityDto(CeQueueDto queueDto) { this.uuid = queueDto.getUuid(); this.taskType = queueDto.getTaskType(); this.componentUuid = queueDto.getComponentUuid(); this.mainComponentUuid = queueDto.getMainComponentUuid(); this.isLastKey = format("%s%s", taskType, Strings.nullToEmpty(componentUuid)); this.mainIsLastKey = format("%s%s", taskType, Strings.nullToEmpty(mainComponentUuid)); this.submitterUuid = queueDto.getSubmitterUuid(); this.workerUuid = queueDto.getWorkerUuid(); this.submittedAt = queueDto.getCreatedAt(); this.startedAt = queueDto.getStartedAt(); }
@Test public void test_selectByUuid() { CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1); assertThat(underTest.selectByUuid(db.getSession(), "TASK_UNKNOWN").isPresent()).isFalse(); CeQueueDto saved = underTest.selectByUuid(db.getSession(), TASK_UUID_1).get(); assertThat(saved.getUuid()).isEqualTo(TASK_UUID_1); assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT); assertThat(saved.getMainComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1); assertThat(saved.getComponentUuid()).isEqualTo(ceQueueDto.getComponentUuid()); assertThat(saved.getStatus()).isEqualTo(PENDING); assertThat(saved.getSubmitterUuid()).isEqualTo("henri"); assertThat(saved.getWorkerUuid()).isNull(); assertThat(saved.getCreatedAt()).isEqualTo(INIT_TIME); assertThat(saved.getUpdatedAt()).isEqualTo(INIT_TIME); assertThat(saved.getStartedAt()).isNull(); }
private Ce.Task formatQueue(CeQueueDto dto, DtoCache cache) { Ce.Task.Builder builder = Ce.Task.newBuilder(); String organizationKey = cache.getOrganizationKey(dto.getComponentUuid()); ofNullable(organizationKey).ifPresent(builder::setOrganization); if (dto.getComponentUuid() != null) { builder.setComponentId(dto.getComponentUuid()); setComponent(builder, dto.getComponentUuid(), cache); } builder.setId(dto.getUuid()); builder.setStatus(Ce.TaskStatus.valueOf(dto.getStatus().name())); builder.setType(dto.getTaskType()); builder.setLogs(false); cache.getUser(dto.getSubmitterUuid()).ifPresent(user -> builder.setSubmitterLogin(user.getLogin())); builder.setSubmittedAt(formatDateTime(new Date(dto.getCreatedAt()))); ofNullable(dto.getStartedAt()).map(DateUtils::formatDateTime).ifPresent(builder::setStartedAt); ofNullable(computeExecutionTimeMs(dto)).ifPresent(builder::setExecutionTimeMs); setBranchOrPullRequest(builder, dto.getUuid(), cache); return builder.build(); }
private void verifyCeQueueDtoForTaskSubmit(CeTaskSubmit taskSubmit) { Optional<CeQueueDto> queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), taskSubmit.getUuid()); assertThat(queueDto.isPresent()).isTrue(); CeQueueDto dto = queueDto.get(); assertThat(dto.getTaskType()).isEqualTo(taskSubmit.getType()); Optional<CeTaskSubmit.Component> component = taskSubmit.getComponent(); if (component.isPresent()) { assertThat(dto.getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid()); assertThat(dto.getComponentUuid()).isEqualTo(component.get().getUuid()); } else { assertThat(dto.getMainComponentUuid()).isNull(); assertThat(dto.getComponentUuid()).isNull(); } assertThat(dto.getSubmitterUuid()).isEqualTo(taskSubmit.getSubmitterUuid()); assertThat(dto.getCreatedAt()).isEqualTo(dto.getUpdatedAt()).isNotNull(); }
CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable ComponentDto mainComponent) { CeTask.Builder builder = new CeTask.Builder() .setUuid(taskDto.getUuid()) .setType(taskDto.getTaskType()) .setCharacteristics(characteristics) .setSubmitter(resolveSubmitter(dbSession, taskDto.getSubmitterUuid())); String componentUuid = taskDto.getComponentUuid(); if (component != null) { builder.setComponent(new CeTask.Component(component.uuid(), component.getDbKey(), component.name())); builder.setOrganizationUuid(component.getOrganizationUuid()); } else if (componentUuid != null) { builder.setComponent(new CeTask.Component(componentUuid, null, null)); } String mainComponentUuid = taskDto.getMainComponentUuid(); if (mainComponent != null) { builder.setMainComponent(new CeTask.Component(mainComponent.uuid(), mainComponent.getDbKey(), mainComponent.name())); } else if (mainComponentUuid != null) { builder.setMainComponent(new CeTask.Component(mainComponentUuid, null, null)); } // FIXME this should be set from the CeQueueDto if (!builder.hasOrganizationUuid()) { builder.setOrganizationUuid(defaultOrganizationProvider.get().getUuid()); } return builder.build(); }
public CeActivityDto(CeQueueDto queueDto) { this.uuid = queueDto.getUuid(); this.taskType = queueDto.getTaskType(); this.componentUuid = queueDto.getComponentUuid(); this.isLastKey = format("%s%s", taskType, Strings.nullToEmpty(componentUuid)); this.submitterLogin = queueDto.getSubmitterLogin(); this.submittedAt = queueDto.getCreatedAt(); this.startedAt = queueDto.getStartedAt(); }
@Override @Nonnull public CeTask apply(@Nonnull CeQueueDto dto) { CeTask.Builder builder = new CeTask.Builder(); builder.setUuid(dto.getUuid()); builder.setType(dto.getTaskType()); builder.setSubmitterUuid(dto.getSubmitterUuid()); String componentUuid = dto.getComponentUuid(); if (componentUuid != null) { builder.setComponentUuid(componentUuid); ComponentDto component = componentDtoByUuid.get(componentUuid); if (component != null) { builder.setOrganizationUuid(component.getOrganizationUuid()); builder.setComponentKey(component.getDbKey()); builder.setComponentName(component.name()); } } // fixme this should be set from the CeQueueDto if (!builder.hasOrganizationUuid()) { builder.setOrganizationUuid(defaultOrganizationUuid); } return builder.build(); } }
private Ce.Task formatQueue(CeQueueDto dto, DtoCache cache) { Ce.Task.Builder builder = Ce.Task.newBuilder(); String organizationKey = cache.getOrganizationKey(dto.getComponentUuid()); setNullable(organizationKey, builder::setOrganization); if (dto.getComponentUuid() != null) { builder.setComponentId(dto.getComponentUuid()); setComponent(builder, dto.getComponentUuid(), cache); } builder.setId(dto.getUuid()); builder.setStatus(Ce.TaskStatus.valueOf(dto.getStatus().name())); builder.setType(dto.getTaskType()); builder.setLogs(false); cache.getUser(dto.getSubmitterUuid()).ifPresent(user -> builder.setSubmitterLogin(user.getLogin())); builder.setSubmittedAt(formatDateTime(new Date(dto.getCreatedAt()))); setNullable(dto.getStartedAt(), builder::setStartedAt, DateUtils::formatDateTime); setNullable(computeExecutionTimeMs(dto), builder::setExecutionTimeMs); setBranchOrPullRequest(builder, dto.getUuid(), cache); return builder.build(); }