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;
}
Aggregations