Search in sources :

Example 1 with ProjectEvent

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());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ProjectType(com.epam.ta.reportportal.entity.enums.ProjectType) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) Date(java.util.Date) ProjectEvent(com.epam.reportportal.extension.event.ProjectEvent)

Example 2 with ProjectEvent

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.");
}
Also used : ProjectAttributesActivityResource(com.epam.ta.reportportal.ws.model.activity.ProjectAttributesActivityResource) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ProjectAnalyzerConfigEvent(com.epam.ta.reportportal.core.events.activity.ProjectAnalyzerConfigEvent) ProjectUpdatedEvent(com.epam.ta.reportportal.core.events.activity.ProjectUpdatedEvent) ProjectEvent(com.epam.reportportal.extension.event.ProjectEvent) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

ProjectEvent (com.epam.reportportal.extension.event.ProjectEvent)2 Project (com.epam.ta.reportportal.entity.project.Project)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 ProjectAnalyzerConfigEvent (com.epam.ta.reportportal.core.events.activity.ProjectAnalyzerConfigEvent)1 ProjectUpdatedEvent (com.epam.ta.reportportal.core.events.activity.ProjectUpdatedEvent)1 ProjectType (com.epam.ta.reportportal.entity.enums.ProjectType)1 ProjectAttribute (com.epam.ta.reportportal.entity.project.ProjectAttribute)1 ProjectUser (com.epam.ta.reportportal.entity.user.ProjectUser)1 User (com.epam.ta.reportportal.entity.user.User)1 EntryCreatedRS (com.epam.ta.reportportal.ws.model.EntryCreatedRS)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 ProjectAttributesActivityResource (com.epam.ta.reportportal.ws.model.activity.ProjectAttributesActivityResource)1 Date (java.util.Date)1