use of com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder in project service-api by reportportal.
the class AnalyzerServiceImpl method updateTestItemIssue.
/**
* Updates issue for a specified test item
*
* @param projectId - Project id
* @param rs - Response from an analyzer
* @param testItem - Test item to be updated
* @return Updated issue entity
*/
private RelevantItemInfo updateTestItemIssue(Long projectId, AnalyzedItemRs rs, TestItem testItem) {
IssueType issueType = issueTypeHandler.defineIssueType(projectId, rs.getLocator());
IssueEntity issueEntity = new IssueEntityBuilder(testItem.getItemResults().getIssue()).addIssueType(issueType).addIgnoreFlag(testItem.getItemResults().getIssue().getIgnoreAnalyzer()).addAutoAnalyzedFlag(true).get();
issueEntity.setIssueId(testItem.getItemId());
issueEntity.setTestItemResults(testItem.getItemResults());
testItem.getItemResults().setIssue(issueEntity);
RelevantItemInfo relevantItemInfo = null;
if (rs.getRelevantItemId() != null) {
Optional<TestItem> relevantItemOptional = testItemRepository.findById(rs.getRelevantItemId());
if (relevantItemOptional.isPresent()) {
relevantItemInfo = updateIssueFromRelevantItem(issueEntity, relevantItemOptional.get());
} else {
LOGGER.error(ErrorType.TEST_ITEM_NOT_FOUND.getDescription(), rs.getRelevantItemId());
}
}
return relevantItemInfo;
}
use of com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder in project service-api by reportportal.
the class UpdateTestItemHandlerImpl method resetItemsIssue.
@Override
public void resetItemsIssue(List<Long> itemIds, Long projectId, ReportPortalUser user) {
itemIds.forEach(itemId -> {
TestItem item = testItemRepository.findById(itemId).orElseThrow(() -> new ReportPortalException(TEST_ITEM_NOT_FOUND, itemId));
TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(item, projectId);
IssueType issueType = issueTypeHandler.defineIssueType(projectId, TestItemIssueGroup.TO_INVESTIGATE.getLocator());
IssueEntity issueEntity = new IssueEntityBuilder(issueEntityRepository.findById(itemId).orElseThrow(() -> new ReportPortalException(ErrorType.ISSUE_TYPE_NOT_FOUND, itemId))).addIssueType(issueType).addAutoAnalyzedFlag(false).get();
issueEntityRepository.save(issueEntity);
item.getItemResults().setIssue(issueEntity);
TestItemActivityResource after = TO_ACTIVITY_RESOURCE.apply(item, projectId);
if (!StringUtils.equalsIgnoreCase(before.getIssueTypeLongName(), after.getIssueTypeLongName())) {
ItemIssueTypeDefinedEvent event = new ItemIssueTypeDefinedEvent(before, after, user.getUserId(), user.getUsername());
messageBus.publishActivity(event);
}
});
}
use of com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder 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;
}
Aggregations