Search in sources :

Example 6 with LaunchBuilder

use of com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder in project service-api by reportportal.

the class FinishLaunchHandlerImpl method finishLaunch.

@Override
public FinishLaunchRS finishLaunch(String launchId, FinishExecutionRQ finishLaunchRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, String baseUrl) {
    Launch launch = launchRepository.findByUuid(launchId).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, launchId));
    validateRoles(launch, user, projectDetails);
    validate(launch, finishLaunchRQ);
    Optional<StatusEnum> status = StatusEnum.fromValue(finishLaunchRQ.getStatus());
    Long id = launch.getId();
    final int finishedCount = finishHierarchyHandler.finishDescendants(launch, status.orElse(StatusEnum.INTERRUPTED), finishLaunchRQ.getEndTime(), user, projectDetails);
    if (finishedCount > 0) {
        launch.setStatus(launchRepository.hasRootItemsWithStatusNotEqual(id, StatusEnum.PASSED.name(), StatusEnum.INFO.name(), StatusEnum.WARN.name()) ? FAILED : PASSED);
    } else {
        launch.setStatus(status.orElseGet(() -> launchRepository.hasRootItemsWithStatusNotEqual(id, StatusEnum.PASSED.name(), StatusEnum.INFO.name(), StatusEnum.WARN.name()) ? FAILED : PASSED));
    }
    launch = new LaunchBuilder(launch).addDescription(buildDescription(launch.getDescription(), finishLaunchRQ.getDescription())).addAttributes(finishLaunchRQ.getAttributes()).addEndTime(finishLaunchRQ.getEndTime()).get();
    LaunchFinishedEvent event = new LaunchFinishedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user, baseUrl);
    messageBus.publishActivity(event);
    eventPublisher.publishEvent(event);
    FinishLaunchRS response = new FinishLaunchRS();
    response.setId(launch.getUuid());
    response.setNumber(launch.getNumber());
    response.setLink(generateLaunchLink(baseUrl, projectDetails.getProjectName(), String.valueOf(launch.getId())));
    return response;
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) FinishLaunchRS(com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)

Example 7 with LaunchBuilder

use of com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder in project service-api by reportportal.

the class DemoDataLaunchService method finishLaunch.

@Transactional
public void finishLaunch(String launchId) {
    Launch launch = launchRepository.findByUuid(launchId).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, launchId));
    if (testItemRepository.hasItemsInStatusByLaunch(launch.getId(), StatusEnum.IN_PROGRESS)) {
        testItemRepository.interruptInProgressItems(launch.getId());
    }
    launch = new LaunchBuilder(launch).addEndTime(new Date()).get();
    StatusEnum fromStatisticsStatus = PASSED;
    if (launchRepository.hasRootItemsWithStatusNotEqual(launch.getId(), StatusEnum.PASSED.name(), StatusEnum.INFO.name(), StatusEnum.WARN.name())) {
        fromStatisticsStatus = StatusEnum.FAILED;
    }
    launch.setStatus(fromStatisticsStatus);
    launchRepository.save(launch);
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Launch(com.epam.ta.reportportal.entity.launch.Launch) Date(java.util.Date) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Launch (com.epam.ta.reportportal.entity.launch.Launch)7 LaunchBuilder (com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)5 StartLaunchRQ (com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 LaunchFinishedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent)2 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 Project (com.epam.ta.reportportal.entity.project.Project)2 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)2 ItemAttributeResource (com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource)2 StartLaunchEvent (com.epam.reportportal.extension.event.StartLaunchEvent)1 EntityUtils (com.epam.ta.reportportal.commons.EntityUtils)1 TO_LOCAL_DATE_TIME (com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME)1 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)1 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 LaunchFinishForcedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishForcedEvent)1 LaunchStartedEvent (com.epam.ta.reportportal.core.events.activity.LaunchStartedEvent)1