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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations