Search in sources :

Example 1 with TestItemStatusChangedEvent

use of com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent in project service-api by reportportal.

the class ChangeStatusHandlerImpl method changeParentStatus.

@Override
public void changeParentStatus(TestItem childItem, Long projectId, ReportPortalUser user) {
    ofNullable(childItem.getParentId()).flatMap(testItemRepository::findById).ifPresent(parent -> {
        if (parent.isHasChildren()) {
            ofNullable(parent.getItemResults().getIssue()).map(IssueEntity::getIssueId).ifPresent(issueEntityRepository::deleteById);
        }
        if (isParentStatusUpdateRequired(parent)) {
            StatusEnum resolvedStatus = resolveStatus(parent.getItemId());
            if (parent.getItemResults().getStatus() != resolvedStatus) {
                TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(parent, projectId);
                changeStatus(parent, resolvedStatus, user);
                messageBus.publishActivity(new TestItemStatusChangedEvent(before, TO_ACTIVITY_RESOURCE.apply(parent, projectId), user.getUserId(), user.getUsername()));
                changeParentStatus(parent, projectId, user);
            }
        }
    });
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) TestItemStatusChangedEvent(com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)

Example 2 with TestItemStatusChangedEvent

use of com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent in project service-api by reportportal.

the class UpdateTestItemHandlerImpl method updateTestItem.

@Override
public OperationCompletionRS updateTestItem(ReportPortalUser.ProjectDetails projectDetails, Long itemId, UpdateTestItemRQ rq, ReportPortalUser user) {
    TestItem testItem = testItemRepository.findById(itemId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, itemId));
    validate(projectDetails, user, testItem);
    Optional<StatusEnum> providedStatus = StatusEnum.fromValue(rq.getStatus());
    if (providedStatus.isPresent() && !providedStatus.get().equals(testItem.getItemResults().getStatus())) {
        expect(testItem.isHasChildren() && !testItem.getType().sameLevel(TestItemTypeEnum.STEP), equalTo(FALSE)).verify(INCORRECT_REQUEST, "Unable to change status on test item with children");
        checkInitialStatusAttribute(testItem, rq);
        StatusChangingStrategy strategy = statusChangingStrategyMapping.get(providedStatus.get());
        expect(strategy, notNull()).verify(INCORRECT_REQUEST, formattedSupplier("Actual status: '{}' cannot be changed to '{}'.", testItem.getItemResults().getStatus(), providedStatus.get()));
        TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId());
        strategy.changeStatus(testItem, providedStatus.get(), user);
        messageBus.publishActivity(new TestItemStatusChangedEvent(before, TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId()), user.getUserId(), user.getUsername()));
    }
    testItem = new TestItemBuilder(testItem).overwriteAttributes(rq.getAttributes()).addDescription(rq.getDescription()).get();
    testItemRepository.save(testItem);
    return COMPOSE_UPDATE_RESPONSE.apply(itemId);
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) TestItemStatusChangedEvent(com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Aggregations

TestItemStatusChangedEvent (com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 TestItemActivityResource (com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)2 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)1 TestItem (com.epam.ta.reportportal.entity.item.TestItem)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 JStatusEnum (com.epam.ta.reportportal.jooq.enums.JStatusEnum)1 TestItemBuilder (com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder)1