Search in sources :

Example 11 with LaunchFinishedEvent

use of com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent 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)

Aggregations

LaunchFinishedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent)11 Launch (com.epam.ta.reportportal.entity.launch.Launch)10 LaunchActivityResource (com.epam.ta.reportportal.ws.model.activity.LaunchActivityResource)9 Test (org.junit.jupiter.api.Test)8 ProjectAttributeEnum (com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum)7 Project (com.epam.ta.reportportal.entity.project.Project)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 LaunchBuilder (com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)2 LaunchFinishForcedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishForcedEvent)1 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 ItemAttributeResource (com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource)1 FinishLaunchRS (com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS)1 Date (java.util.Date)1