Search in sources :

Example 6 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter 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 7 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class CreateWidgetHandlerImpl method getUserFilters.

private List<UserFilter> getUserFilters(List<Long> filterIds, Long projectId, String username) {
    if (CollectionUtils.isNotEmpty(filterIds)) {
        String ids = filterIds.stream().map(String::valueOf).collect(Collectors.joining(","));
        Filter defaultFilter = new Filter(UserFilter.class, Condition.IN, false, ids, CRITERIA_ID);
        List<UserFilter> userFilters = filterRepository.getPermitted(ProjectFilter.of(defaultFilter, projectId), Pageable.unpaged(), username).getContent();
        BusinessRule.expect(userFilters, not(List::isEmpty)).verify(ErrorType.USER_FILTER_NOT_FOUND, filterIds, projectId, username);
        return userFilters;
    }
    return Collections.emptyList();
}
Also used : ProjectFilter(com.epam.ta.reportportal.commons.querygen.ProjectFilter) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Filter(com.epam.ta.reportportal.commons.querygen.Filter) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) List(java.util.List)

Example 8 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class DemoDashboardsService method createDemoFilter.

private UserFilter createDemoFilter(ReportPortalUser user, Project project) {
    List<UserFilter> existedFilterList = userFilterRepository.getPermitted(ProjectFilter.of(Filter.builder().withTarget(UserFilter.class).withCondition(FilterCondition.builder().withCondition(Condition.EQUALS).withSearchCriteria(CRITERIA_NAME).withValue(FILTER_NAME).build()).build(), project.getId()), Pageable.unpaged(), user.getUsername()).getContent();
    if (!existedFilterList.isEmpty()) {
        return existedFilterList.get(0);
    }
    UserFilter userFilter = new UserFilter();
    userFilter.setName(FILTER_NAME);
    userFilter.setTargetClass(ObjectType.Launch);
    userFilter.setProject(project);
    userFilter.setFilterCondition(Sets.newHashSet(FilterCondition.builder().withSearchCriteria(CRITERIA_ITEM_ATTRIBUTE_VALUE).withCondition(Condition.HAS).withValue("demo").build()));
    FilterSort filterSort = new FilterSort();
    filterSort.setDirection(Sort.Direction.DESC);
    filterSort.setField(START_TIME_SORTING);
    userFilter.setFilterSorts(Sets.newHashSet(filterSort));
    userFilter.setOwner(user.getUsername());
    userFilter.setShared(SHARED);
    userFilterRepository.save(userFilter);
    aclHandler.initAcl(userFilter, user.getUsername(), project.getId(), SHARED);
    return userFilter;
}
Also used : UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort)

Example 9 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class GetTestItemHandlerImplTest method getItemsForIncorrectTargetClass.

@Test
public void getItemsForIncorrectTargetClass() {
    final ReportPortalUser rpUser = getRpUser("test", UserRole.USER, ProjectRole.MEMBER, 1L);
    TestItem item = new TestItem();
    Launch launch = new Launch();
    launch.setId(1L);
    launch.setProjectId(2L);
    item.setLaunchId(launch.getId());
    UserFilter filter = new UserFilter();
    filter.setTargetClass(ObjectType.TestItem);
    when(getShareableEntityHandler.getPermitted(1L, extractProjectDetails(rpUser, "test_project"))).thenReturn(filter);
    final Executable executable = () -> handler.getTestItems(Filter.builder().withTarget(TestItem.class).withCondition(FilterCondition.builder().withSearchCriteria(CRITERIA_TEST_ITEM_ID).withValue("100").withCondition(Condition.EQUALS).build()).build(), PageRequest.of(0, 10), extractProjectDetails(rpUser, "test_project"), rpUser, null, 1L, false, 0);
    final ReportPortalException exception = assertThrows(ReportPortalException.class, executable);
    assertEquals("Error in handled Request. Please, check specified parameters: 'Incorrect filter target - 'TestItem'. Allowed: 'Launch''", exception.getMessage());
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Executable(org.junit.jupiter.api.function.Executable) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Example 10 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class GetTestItemHandlerImplTest method getItemsForIncorrectLaunchesLimit.

@Test
public void getItemsForIncorrectLaunchesLimit() {
    final ReportPortalUser rpUser = getRpUser("test", UserRole.USER, ProjectRole.MEMBER, 1L);
    TestItem item = new TestItem();
    Launch launch = new Launch();
    launch.setId(1L);
    launch.setProjectId(2L);
    item.setLaunchId(launch.getId());
    UserFilter filter = new UserFilter();
    filter.setTargetClass(ObjectType.Launch);
    when(getShareableEntityHandler.getPermitted(1L, extractProjectDetails(rpUser, "test_project"))).thenReturn(filter);
    final Executable executable = () -> handler.getTestItems(Filter.builder().withTarget(TestItem.class).withCondition(FilterCondition.builder().withSearchCriteria(CRITERIA_TEST_ITEM_ID).withValue("100").withCondition(Condition.EQUALS).build()).build(), PageRequest.of(0, 10), extractProjectDetails(rpUser, "test_project"), rpUser, null, 1L, false, 0);
    final ReportPortalException exception = assertThrows(ReportPortalException.class, executable);
    assertEquals("Error in handled Request. Please, check specified parameters: 'Launches limit should be greater than 0'", exception.getMessage());
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Executable(org.junit.jupiter.api.function.Executable) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Aggregations

UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)23 Filter (com.epam.ta.reportportal.commons.querygen.Filter)7 Widget (com.epam.ta.reportportal.entity.widget.Widget)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)7 Test (org.junit.jupiter.api.Test)7 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)6 FilterSort (com.epam.ta.reportportal.entity.filter.FilterSort)5 ProjectFilter (com.epam.ta.reportportal.commons.querygen.ProjectFilter)4 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)4 Condition (com.epam.ta.reportportal.commons.querygen.Condition)3 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)3 ObjectType (com.epam.ta.reportportal.entity.filter.ObjectType)3 Project (com.epam.ta.reportportal.entity.project.Project)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)3 Order (com.epam.ta.reportportal.ws.model.filter.Order)3 UpdateUserFilterRQ (com.epam.ta.reportportal.ws.model.filter.UpdateUserFilterRQ)3 UserFilterCondition (com.epam.ta.reportportal.ws.model.filter.UserFilterCondition)3 WidgetRQ (com.epam.ta.reportportal.ws.model.widget.WidgetRQ)3 List (java.util.List)3