Search in sources :

Example 6 with ProjectIssueType

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.");
}
Also used : ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) Project(com.epam.ta.reportportal.entity.project.Project) DefectTypeDeletedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeDeletedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)6 ProjectIssueType (com.epam.ta.reportportal.entity.project.ProjectIssueType)6 Project (com.epam.ta.reportportal.entity.project.Project)4 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)3 TestItemIssueGroup (com.epam.ta.reportportal.entity.enums.TestItemIssueGroup)3 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)2 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)2 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 IssueTypeRepository (com.epam.ta.reportportal.dao.IssueTypeRepository)2 IssueGroup (com.epam.ta.reportportal.entity.item.issue.IssueGroup)2 PatternTemplate (com.epam.ta.reportportal.entity.pattern.PatternTemplate)2 TO_ACTIVITY_RESOURCE (com.epam.ta.reportportal.ws.converter.converters.IssueTypeConverter.TO_ACTIVITY_RESOURCE)2 PatternTemplateConverter (com.epam.ta.reportportal.ws.converter.converters.PatternTemplateConverter)2 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)2 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)2 ValidationConstraints (com.epam.ta.reportportal.ws.model.ValidationConstraints)2 List (java.util.List)2 Map (java.util.Map)2