use of com.epam.ta.reportportal.entity.project.ProjectIssueType in project service-api by reportportal.
the class DeleteProjectSettingsHandlerImpl method deleteProjectIssueSubType.
@Override
public OperationCompletionRS deleteProjectIssueSubType(String projectName, ReportPortalUser user, Long id) {
Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
ProjectIssueType type = project.getProjectIssueTypes().stream().filter(projectIssueType -> projectIssueType.getIssueType().getId().equals(id)).findFirst().orElseThrow(() -> new ReportPortalException(ISSUE_TYPE_NOT_FOUND, id));
expect(type.getIssueType().getLocator(), not(in(Sets.newHashSet(AUTOMATION_BUG.getLocator(), PRODUCT_BUG.getLocator(), SYSTEM_ISSUE.getLocator(), NO_DEFECT.getLocator(), TO_INVESTIGATE.getLocator())))).verify(FORBIDDEN_OPERATION, "You cannot remove predefined global issue types.");
String issueField = "statistics$defects$" + TestItemIssueGroup.fromValue(type.getIssueType().getIssueGroup().getTestItemIssueGroup().getValue()).orElseThrow(() -> new ReportPortalException(ISSUE_TYPE_NOT_FOUND, type.getIssueType().getIssueGroup())).getValue().toLowerCase() + "$" + type.getIssueType().getLocator();
statisticsFieldRepository.deleteByName(issueField);
IssueType defaultGroupIssueType = issueTypeRepository.findByLocator(type.getIssueType().getIssueGroup().getTestItemIssueGroup().getLocator()).orElseThrow(() -> new ReportPortalException(ErrorType.ISSUE_TYPE_NOT_FOUND, type.getIssueType()));
List<IssueEntity> allByIssueTypeId = issueEntityRepository.findAllByIssueTypeId(id);
allByIssueTypeId.forEach(issueEntity -> issueEntity.setIssueType(defaultGroupIssueType));
project.getProjectIssueTypes().remove(type);
projectRepository.save(project);
issueTypeRepository.delete(type.getIssueType());
updateWidgets(project, type.getIssueType());
DefectTypeDeletedEvent defectTypeDeletedEvent = new DefectTypeDeletedEvent(TO_ACTIVITY_RESOURCE.apply(type.getIssueType()), user.getUserId(), user.getUsername(), project.getId());
messageBus.publishActivity(defectTypeDeletedEvent);
eventPublisher.publishEvent(defectTypeDeletedEvent);
return new OperationCompletionRS("Issue sub-type delete operation completed successfully.");
}
Aggregations