Search in sources :

Example 1 with EntryCreatedRS

use of com.epam.ta.reportportal.ws.model.EntryCreatedRS 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 EntryCreatedRS

use of com.epam.ta.reportportal.ws.model.EntryCreatedRS in project service-api by reportportal.

the class UserFilterControllerTest method createFilterPositive.

@Test
void createFilterPositive() throws Exception {
    String name = "userFilter";
    String description = "description";
    UpdateUserFilterRQ request = new UpdateUserFilterRQ();
    request.setName(name);
    request.setObjectType("Launch");
    final Order order = new Order();
    order.setIsAsc(false);
    order.setSortingColumnName("startTime");
    request.setOrders(Lists.newArrayList(order));
    request.setDescription(description);
    request.setConditions(Sets.newHashSet(new UserFilterCondition("name", "cnt", "test")));
    MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/filter").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(request)).contentType(APPLICATION_JSON)).andExpect(status().isCreated()).andReturn();
    EntryCreatedRS response = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<EntryCreatedRS>() {
    });
    final Optional<UserFilter> optionalFilter = repository.findById(response.getId());
    assertTrue(optionalFilter.isPresent());
    assertEquals(name, optionalFilter.get().getName());
    assertEquals(description, optionalFilter.get().getDescription());
}
Also used : Order(com.epam.ta.reportportal.ws.model.filter.Order) UpdateUserFilterRQ(com.epam.ta.reportportal.ws.model.filter.UpdateUserFilterRQ) UserFilterCondition(com.epam.ta.reportportal.ws.model.filter.UserFilterCondition) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 3 with EntryCreatedRS

use of com.epam.ta.reportportal.ws.model.EntryCreatedRS in project service-api by reportportal.

the class CreateDashboardHandlerImpl method createDashboard.

@Override
public EntryCreatedRS createDashboard(ReportPortalUser.ProjectDetails projectDetails, CreateDashboardRQ rq, ReportPortalUser user) {
    BusinessRule.expect(dashboardRepository.existsByNameAndOwnerAndProjectId(rq.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, rq.getName());
    Dashboard dashboard = new DashboardBuilder().addDashboardRq(rq).addProject(projectDetails.getProjectId()).addOwner(user.getUsername()).get();
    dashboardRepository.save(dashboard);
    aclHandler.initAcl(dashboard, user.getUsername(), projectDetails.getProjectId(), BooleanUtils.isTrue(rq.getShare()));
    messageBus.publishActivity(new DashboardCreatedEvent(TO_ACTIVITY_RESOURCE.apply(dashboard), user.getUserId(), user.getUsername()));
    return new EntryCreatedRS(dashboard.getId());
}
Also used : DashboardCreatedEvent(com.epam.ta.reportportal.core.events.activity.DashboardCreatedEvent) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) DashboardBuilder(com.epam.ta.reportportal.ws.converter.builders.DashboardBuilder)

Example 4 with EntryCreatedRS

use of com.epam.ta.reportportal.ws.model.EntryCreatedRS in project service-api by reportportal.

the class UpdateUserFilterHandlerImpl method createFilter.

@Override
public EntryCreatedRS createFilter(UpdateUserFilterRQ createFilterRQ, String projectName, ReportPortalUser user) {
    ReportPortalUser.ProjectDetails projectDetails = projectExtractor.extractProjectDetails(user, projectName);
    validateFilterRq(createFilterRQ);
    BusinessRule.expect(userFilterRepository.existsByNameAndOwnerAndProjectId(createFilterRQ.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.USER_FILTER_ALREADY_EXISTS, createFilterRQ.getName(), user.getUsername(), projectName);
    UserFilter filter = new UserFilterBuilder().addFilterRq(createFilterRQ).addProject(projectDetails.getProjectId()).addOwner(user.getUsername()).get();
    userFilterRepository.save(filter);
    aclHandler.initAcl(filter, user.getUsername(), projectDetails.getProjectId(), BooleanUtils.isTrue(createFilterRQ.getShare()));
    messageBus.publishActivity(new FilterCreatedEvent(TO_ACTIVITY_RESOURCE.apply(filter), user.getUserId(), user.getUsername()));
    return new EntryCreatedRS(filter.getId());
}
Also used : UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) FilterCreatedEvent(com.epam.ta.reportportal.core.events.activity.FilterCreatedEvent) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) UserFilterBuilder(com.epam.ta.reportportal.ws.converter.builders.UserFilterBuilder)

Example 5 with EntryCreatedRS

use of com.epam.ta.reportportal.ws.model.EntryCreatedRS in project service-api by reportportal.

the class CreatePluginHandlerTest method shouldUploadPluginWhenValid.

@Test
void shouldUploadPluginWhenValid() throws IOException {
    when(multipartFile.getOriginalFilename()).thenReturn(FILE_NAME);
    when(multipartFile.getInputStream()).thenReturn(inputStream);
    when(pluginInfo.getId()).thenReturn(PLUGIN_ID);
    when(pluginInfo.getVersion()).thenReturn(PLUGIN_VERSION);
    doNothing().when(applicationEventPublisher).publishEvent(any());
    when(pluginBox.uploadPlugin(FILE_NAME, inputStream)).thenReturn(IntegrationTestUtil.getJiraIntegrationType());
    EntryCreatedRS entryCreatedRS = createPluginHandler.uploadPlugin(multipartFile);
    assertNotNull(entryCreatedRS);
    assertEquals(IntegrationTestUtil.getJiraIntegrationType().getId(), entryCreatedRS.getId());
}
Also used : EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) Test(org.junit.jupiter.api.Test)

Aggregations

EntryCreatedRS (com.epam.ta.reportportal.ws.model.EntryCreatedRS)12 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)5 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)5 Project (com.epam.ta.reportportal.entity.project.Project)4 Test (org.junit.jupiter.api.Test)4 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)3 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)3 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)3 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)3 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 Optional.ofNullable (java.util.Optional.ofNullable)3 BooleanUtils (org.apache.commons.lang3.BooleanUtils)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)2 IntegrationCreatedEvent (com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent)2 IntegrationUpdatedEvent (com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent)2 CreateIntegrationHandler (com.epam.ta.reportportal.core.integration.CreateIntegrationHandler)2 IntegrationService (com.epam.ta.reportportal.core.integration.util.IntegrationService)2 IntegrationRepository (com.epam.ta.reportportal.dao.IntegrationRepository)2