Search in sources :

Example 6 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource in project service-api by reportportal.

the class UpdateTestItemHandlerImpl method defineTestItemsIssues.

@Override
public List<Issue> defineTestItemsIssues(ReportPortalUser.ProjectDetails projectDetails, DefineIssueRQ defineIssue, ReportPortalUser user) {
    Project project = projectRepository.findById(projectDetails.getProjectId()).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectDetails.getProjectId()));
    List<String> errors = new ArrayList<>();
    List<IssueDefinition> definitions = defineIssue.getIssues();
    expect(CollectionUtils.isEmpty(definitions), equalTo(false)).verify(FAILED_TEST_ITEM_ISSUE_TYPE_DEFINITION);
    List<Issue> updated = new ArrayList<>(defineIssue.getIssues().size());
    List<ItemIssueTypeDefinedEvent> events = new ArrayList<>();
    List<TestItem> itemsForIndexUpdate = new ArrayList<>();
    List<Long> itemsForIndexRemove = new ArrayList<>();
    definitions.forEach(issueDefinition -> {
        try {
            TestItem testItem = testItemRepository.findById(issueDefinition.getId()).orElseThrow(() -> new BusinessRuleViolationException(formattedSupplier("Cannot update issue type for test item '{}', cause it is not found.", issueDefinition.getId()).get()));
            verifyTestItem(testItem, issueDefinition.getId());
            TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId());
            Issue issue = issueDefinition.getIssue();
            IssueType issueType = issueTypeHandler.defineIssueType(projectDetails.getProjectId(), issue.getIssueType());
            IssueEntity issueEntity = new IssueEntityBuilder(testItem.getItemResults().getIssue()).addIssueType(issueType).addDescription(issue.getComment()).addIgnoreFlag(issue.getIgnoreAnalyzer()).addAutoAnalyzedFlag(issue.getAutoAnalyzed()).get();
            externalTicketHandler.updateLinking(user.getUsername(), issueEntity, issueDefinition.getIssue().getExternalSystemIssues());
            testItem.getItemResults().setIssue(issueEntity);
            issueEntity.setTestItemResults(testItem.getItemResults());
            testItemRepository.save(testItem);
            if (ITEM_CAN_BE_INDEXED.test(testItem)) {
                itemsForIndexUpdate.add(testItem);
            } else {
                itemsForIndexRemove.add(testItem.getItemId());
            }
            updated.add(IssueConverter.TO_MODEL.apply(issueEntity));
            TestItemActivityResource after = TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId());
            events.add(new ItemIssueTypeDefinedEvent(before, after, user.getUserId(), user.getUsername()));
        } catch (BusinessRuleViolationException e) {
            errors.add(e.getMessage());
        }
    });
    expect(errors.isEmpty(), equalTo(TRUE)).verify(FAILED_TEST_ITEM_ISSUE_TYPE_DEFINITION, errors.toString());
    logIndexerService.indexDefectsUpdate(project.getId(), AnalyzerUtils.getAnalyzerConfig(project), itemsForIndexUpdate);
    logIndexerService.indexItemsRemoveAsync(project.getId(), itemsForIndexRemove);
    events.forEach(messageBus::publishActivity);
    return updated;
}
Also used : Issue(com.epam.ta.reportportal.ws.model.issue.Issue) ItemIssueTypeDefinedEvent(com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) BusinessRuleViolationException(com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException) IssueEntityBuilder(com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 7 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource in project service-api by reportportal.

the class LinkTicketEventTest method getTestItem.

private static TestItemActivityResource getTestItem(String tickets) {
    TestItemActivityResource testItem = new TestItemActivityResource();
    testItem.setProjectId(3L);
    testItem.setStatus("FAILED");
    testItem.setIssueTypeLongName("issueTypeName");
    testItem.setIssueDescription("desc");
    testItem.setIgnoreAnalyzer(false);
    testItem.setAutoAnalyzed(false);
    testItem.setName("name");
    testItem.setId(2L);
    testItem.setTickets(tickets);
    return testItem;
}
Also used : TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)

Example 8 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource in project service-api by reportportal.

the class TicketPostedEventTest method getTestItem.

private static TestItemActivityResource getTestItem() {
    TestItemActivityResource testItem = new TestItemActivityResource();
    testItem.setProjectId(3L);
    testItem.setStatus("FAILED");
    testItem.setIssueTypeLongName("Product Bug");
    testItem.setIssueDescription("Description");
    testItem.setIgnoreAnalyzer(false);
    testItem.setAutoAnalyzed(true);
    testItem.setName("name");
    testItem.setId(2L);
    testItem.setTickets(TicketPostedEventTest.EXISTED_TICKETS);
    return testItem;
}
Also used : TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)

Example 9 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource in project service-api by reportportal.

the class FinishTestItemHandlerImpl method updateFinishedItem.

private void updateFinishedItem(TestItemResults testItemResults, StatusEnum actualStatus, Optional<IssueEntity> resolvedIssue, TestItem testItem, ReportPortalUser user, Long projectId) {
    resolvedIssue.ifPresent(issue -> deleteOldIssueIndex(actualStatus, testItem, testItemResults, projectId));
    if (testItemResults.getStatus() != actualStatus) {
        TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(testItem, projectId);
        Optional<StatusChangingStrategy> statusChangingStrategy = ofNullable(statusChangingStrategyMapping.get(actualStatus));
        if (statusChangingStrategy.isPresent()) {
            statusChangingStrategy.get().changeStatus(testItem, actualStatus, user);
        } else {
            testItemResults.setStatus(actualStatus);
        }
        publishUpdateActivity(before, TO_ACTIVITY_RESOURCE.apply(testItem, projectId), user);
    }
    resolvedIssue.ifPresent(issue -> {
        updateItemIssue(testItemResults, issue);
        if (ITEM_CAN_BE_INDEXED.test(testItem)) {
            eventPublisher.publishEvent(new ItemFinishedEvent(testItem.getItemId(), testItem.getLaunchId(), projectId));
        }
    });
}
Also used : ItemFinishedEvent(com.epam.ta.reportportal.core.events.item.ItemFinishedEvent) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)

Example 10 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource in project service-api by reportportal.

the class UpdateTestItemHandlerImpl method processExternalIssues.

@Override
public List<OperationCompletionRS> processExternalIssues(ExternalIssueRQ request, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    List<String> errors = new ArrayList<>();
    List<TestItem> testItems = testItemRepository.findAllById(request.getTestItemIds());
    testItems.forEach(testItem -> {
        try {
            verifyTestItem(testItem, testItem.getItemId());
        } catch (Exception e) {
            errors.add(e.getMessage());
        }
    });
    expect(errors.isEmpty(), equalTo(TRUE)).verify(FAILED_TEST_ITEM_ISSUE_TYPE_DEFINITION, errors.toString());
    List<TestItemActivityResource> before = testItems.stream().map(it -> TO_ACTIVITY_RESOURCE.apply(it, projectDetails.getProjectId())).collect(Collectors.toList());
    if (LinkExternalIssueRQ.class.equals(request.getClass())) {
        LinkExternalIssueRQ linkRequest = (LinkExternalIssueRQ) request;
        externalTicketHandler.linkExternalTickets(user.getUsername(), testItems.stream().map(it -> it.getItemResults().getIssue()).collect(Collectors.toList()), linkRequest.getIssues());
    }
    if (UnlinkExternalIssueRQ.class.equals(request.getClass())) {
        externalTicketHandler.unlinkExternalTickets(testItems, (UnlinkExternalIssueRQ) request);
    }
    testItemRepository.saveAll(testItems);
    List<TestItemActivityResource> after = testItems.stream().map(it -> TO_ACTIVITY_RESOURCE.apply(it, projectDetails.getProjectId())).collect(Collectors.toList());
    before.forEach(it -> messageBus.publishActivity(new LinkTicketEvent(it, after.stream().filter(t -> t.getId().equals(it.getId())).findFirst().get(), user.getUserId(), user.getUsername(), ActivityAction.LINK_ISSUE)));
    return testItems.stream().map(TestItem::getItemId).map(COMPOSE_UPDATE_RESPONSE).collect(toList());
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) TestItemService(com.epam.ta.reportportal.core.item.TestItemService) LogIndexerService(com.epam.ta.reportportal.core.analyzer.auto.impl.LogIndexerService) Autowired(org.springframework.beans.factory.annotation.Autowired) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) UnlinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) Predicates(com.epam.ta.reportportal.commons.Predicates) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) Suppliers.formattedSupplier(com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemStatusChangedEvent(com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent) Predicate(java.util.function.Predicate) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) IssueConverter(com.epam.ta.reportportal.ws.converter.converters.IssueConverter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) Collectors(java.util.stream.Collectors) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) AnalyzerUtils(com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) Stream(java.util.stream.Stream) ITEM_CAN_BE_INDEXED(com.epam.ta.reportportal.util.Predicates.ITEM_CAN_BE_INDEXED) IssueEntityRepository(com.epam.ta.reportportal.dao.IssueEntityRepository) BusinessRuleViolationException(com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException) UpdateTestItemHandler(com.epam.ta.reportportal.core.item.UpdateTestItemHandler) ItemInfoUtils.extractAttributeResource(com.epam.ta.reportportal.util.ItemInfoUtils.extractAttributeResource) TRUE(java.lang.Boolean.TRUE) TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) TestItem(com.epam.ta.reportportal.entity.item.TestItem) ItemInfoUtils.extractAttribute(com.epam.ta.reportportal.util.ItemInfoUtils.extractAttribute) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) Function(java.util.function.Function) ExternalTicketHandler(com.epam.ta.reportportal.core.item.ExternalTicketHandler) ItemIssueTypeDefinedEvent(com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) CollectionUtils(org.apache.commons.collections.CollectionUtils) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) Service(org.springframework.stereotype.Service) UserRole(com.epam.ta.reportportal.entity.user.UserRole) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ActivityAction(com.epam.ta.reportportal.entity.activity.ActivityAction) FALSE(java.lang.Boolean.FALSE) ExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.ExternalIssueRQ) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter.TO_ACTIVITY_RESOURCE) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) IssueEntityBuilder(com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) LinkTicketEvent(com.epam.ta.reportportal.core.events.activity.LinkTicketEvent) ItemAttributeConverter(com.epam.ta.reportportal.ws.converter.converters.ItemAttributeConverter) ItemInfoUtils(com.epam.ta.reportportal.util.ItemInfoUtils) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) LinkTicketEvent(com.epam.ta.reportportal.core.events.activity.LinkTicketEvent) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) BusinessRuleViolationException(com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Aggregations

TestItemActivityResource (com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)13 TestItem (com.epam.ta.reportportal.entity.item.TestItem)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)6 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)4 ItemIssueTypeDefinedEvent (com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent)3 TestItemStatusChangedEvent (com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent)3 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)3 IssueEntity (com.epam.ta.reportportal.entity.item.issue.IssueEntity)3 IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)3 IssueEntityBuilder (com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)2 BusinessRuleViolationException (com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException)2 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)2 Project (com.epam.ta.reportportal.entity.project.Project)2 TestItemBuilder (com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder)2 BtsConstants (com.epam.reportportal.extension.bugtracking.BtsConstants)1 BtsExtension (com.epam.reportportal.extension.bugtracking.BtsExtension)1 Predicates (com.epam.ta.reportportal.commons.Predicates)1