use of com.epam.ta.reportportal.ws.converter.builders.IssueTypeBuilder in project service-api by reportportal.
the class CreateProjectSettingsHandlerImpl method createProjectIssueSubType.
@Override
public IssueSubTypeCreatedRS createProjectIssueSubType(String projectName, ReportPortalUser user, CreateIssueSubTypeRQ rq) {
Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
expect(NOT_ISSUE_FLAG.getValue().equalsIgnoreCase(rq.getTypeRef()), equalTo(false)).verify(INCORRECT_REQUEST, "Impossible to create sub-type for 'Not Issue' type.");
/* Check if global issue type reference is valid */
TestItemIssueGroup expectedGroup = TestItemIssueGroup.fromValue(rq.getTypeRef()).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, rq.getTypeRef()));
List<ProjectIssueType> existingSubTypes = project.getProjectIssueTypes().stream().filter(projectIssueType -> projectIssueType.getIssueType().getIssueGroup().getTestItemIssueGroup().equals(expectedGroup)).collect(Collectors.toList());
expect(existingSubTypes.size() < ValidationConstraints.MAX_ISSUE_SUBTYPES, equalTo(true)).verify(INCORRECT_REQUEST, "Sub Issues count is bound of size limit");
String locator = PREFIX.get(expectedGroup.getValue()) + shortUUID();
IssueType subType = new IssueTypeBuilder().addLocator(locator).addIssueGroup(issueGroupRepository.findByTestItemIssueGroup(expectedGroup)).addLongName(rq.getLongName()).addShortName(rq.getShortName()).addHexColor(rq.getColor()).get();
ProjectIssueType projectIssueType = new ProjectIssueType();
projectIssueType.setIssueType(subType);
projectIssueType.setProject(project);
project.getProjectIssueTypes().add(projectIssueType);
issueTypeRepository.save(subType);
projectRepository.save(project);
updateWidgets(project, subType);
messageBus.publishActivity(new DefectTypeCreatedEvent(TO_ACTIVITY_RESOURCE.apply(subType), user.getUserId(), user.getUsername(), project.getId()));
return new IssueSubTypeCreatedRS(subType.getId(), subType.getLocator());
}
Aggregations