use of com.epam.reportportal.extension.event.ProjectEvent in project service-api by reportportal.
the class CreateProjectHandlerImpl method createProject.
@Override
public EntryCreatedRS createProject(CreateProjectRQ createProjectRQ, ReportPortalUser user) {
String projectName = createProjectRQ.getProjectName().toLowerCase().trim();
expect(projectName, not(equalTo(RESERVED_PROJECT_NAME))).verify(ErrorType.INCORRECT_REQUEST, Suppliers.formattedSupplier("Project with name '{}' is reserved by system", projectName));
expect(projectName, com.epam.ta.reportportal.util.Predicates.SPECIAL_CHARS_ONLY.negate()).verify(ErrorType.INCORRECT_REQUEST, Suppliers.formattedSupplier("Project name '{}' consists only of special characters", projectName));
Optional<Project> existProject = projectRepository.findByName(projectName);
expect(existProject, not(isPresent())).verify(ErrorType.PROJECT_ALREADY_EXISTS, projectName);
ProjectType projectType = ProjectType.findByName(createProjectRQ.getEntryType()).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, createProjectRQ.getEntryType()));
expect(projectType, equalTo(ProjectType.INTERNAL)).verify(ErrorType.BAD_REQUEST_ERROR, "Only internal projects can be created via API");
User dbUser = userRepository.findRawById(user.getUserId()).orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, user.getUsername()));
Project project = new Project();
project.setName(projectName);
project.setCreationDate(new Date());
project.setProjectIssueTypes(ProjectUtils.defaultIssueTypes(project, issueTypeRepository.getDefaultIssueTypes()));
Set<ProjectAttribute> projectAttributes = ProjectUtils.defaultProjectAttributes(project, attributeRepository.getDefaultProjectAttributes());
project.setProjectType(projectType);
project.setProjectAttributes(projectAttributes);
ProjectUser projectUser = new ProjectUser().withProject(project).withUser(dbUser).withProjectRole(ProjectRole.PROJECT_MANAGER);
projectRepository.save(project);
projectUserRepository.save(projectUser);
applicationEventPublisher.publishEvent(new ProjectEvent(project.getId(), CREATE_KEY));
return new EntryCreatedRS(project.getId());
}
use of com.epam.reportportal.extension.event.ProjectEvent in project service-api by reportportal.
the class UpdateProjectHandlerImpl method updateProject.
@Override
public OperationCompletionRS updateProject(String projectName, UpdateProjectRQ updateProjectRQ, ReportPortalUser user) {
Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
ProjectAttributesActivityResource before = TO_ACTIVITY_RESOURCE.apply(project);
updateProjectConfiguration(updateProjectRQ.getConfiguration(), project);
ofNullable(updateProjectRQ.getUserRoles()).ifPresent(roles -> updateProjectUserRoles(roles, project, user));
projectRepository.save(project);
ProjectAttributesActivityResource after = TO_ACTIVITY_RESOURCE.apply(project);
applicationEventPublisher.publishEvent(new ProjectEvent(project.getId(), UPDATE_EVENT));
messageBus.publishActivity(new ProjectUpdatedEvent(before, after, user.getUserId(), user.getUsername()));
messageBus.publishActivity(new ProjectAnalyzerConfigEvent(before, after, user.getUserId(), user.getUsername()));
return new OperationCompletionRS("Project with name = '" + project.getName() + "' is successfully updated.");
}
Aggregations