Search in sources :

Example 1 with FilterSort

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

the class ProductStatusFilterStrategy method buildFilterSortMap.

@Override
protected Map<Filter, Sort> buildFilterSortMap(Widget widget, Long projectId) {
    Map<Filter, Sort> filterSortMap = Maps.newLinkedHashMap();
    Optional.ofNullable(widget.getFilters()).orElse(Collections.emptySet()).forEach(userFilter -> {
        Filter filter = new Filter(userFilter.getId(), userFilter.getTargetClass().getClassObject(), Lists.newArrayList(userFilter.getFilterCondition()));
        filter.withConditions(buildDefaultFilter(widget, projectId).getFilterConditions());
        Optional<Set<FilterSort>> filterSorts = ofNullable(userFilter.getFilterSorts());
        Sort sort = Sort.by(filterSorts.map(filterSort -> filterSort.stream().map(s -> Sort.Order.by(s.getField()).with(s.getDirection())).collect(Collectors.toList())).orElseGet(Collections::emptyList));
        filterSortMap.put(filter, sort);
    });
    return filterSortMap;
}
Also used : Set(java.util.Set) Filter(com.epam.ta.reportportal.commons.querygen.Filter) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort) Sort(org.springframework.data.domain.Sort)

Example 2 with FilterSort

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

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

the class UserFilterBuilderTest method userFilterBuilder.

@Test
void userFilterBuilder() {
    final UpdateUserFilterRQ request = new UpdateUserFilterRQ();
    final String name = "name";
    request.setName(name);
    final String objectType = "Launch";
    request.setObjectType(objectType);
    request.setConditions(Sets.newHashSet(new UserFilterCondition("name", "eq", "value")));
    final Order order = new Order();
    order.setIsAsc(false);
    order.setSortingColumnName("column");
    request.setOrders(Collections.singletonList(order));
    final String description = "description";
    request.setDescription(description);
    final boolean share = true;
    request.setShare(share);
    final String owner = "owner";
    final Long projectId = 1L;
    final UserFilter userFilter = new UserFilterBuilder().addFilterRq(request).addOwner(owner).addProject(projectId).get();
    assertEquals(name, userFilter.getName());
    assertEquals(description, userFilter.getDescription());
    assertEquals(share, userFilter.isShared());
    assertEquals(owner, userFilter.getOwner());
    assertEquals(projectId, userFilter.getProject().getId());
    assertEquals(Launch.class, userFilter.getTargetClass().getClassObject());
    assertThat(userFilter.getFilterCondition()).containsExactlyInAnyOrder(FilterCondition.builder().eq("name", "value").build());
    final FilterSort filterSort = new FilterSort();
    filterSort.setDirection(Sort.Direction.DESC);
    filterSort.setField("column");
    assertThat(userFilter.getFilterSorts()).containsExactlyInAnyOrder(filterSort);
}
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) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort) Test(org.junit.jupiter.api.Test)

Example 4 with FilterSort

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

the class AbstractStatisticsFilterStrategy method buildFilterSortMap.

protected Map<Filter, Sort> buildFilterSortMap(Widget widget, Long projectId) {
    Map<Filter, Sort> filterSortMap = Maps.newLinkedHashMap();
    Set<UserFilter> userFilters = Optional.ofNullable(widget.getFilters()).orElse(Collections.emptySet());
    Filter defaultFilter = buildDefaultFilter(widget, projectId);
    Optional.ofNullable(defaultFilter).ifPresent(f -> filterSortMap.put(defaultFilter, Sort.unsorted()));
    userFilters.forEach(userFilter -> {
        Filter filter = new Filter(userFilter.getId(), userFilter.getTargetClass().getClassObject(), Lists.newArrayList(userFilter.getFilterCondition()));
        Optional<Set<FilterSort>> filterSorts = ofNullable(userFilter.getFilterSorts());
        Sort sort = Sort.by(filterSorts.map(filterSort -> filterSort.stream().map(s -> Sort.Order.by(s.getField()).with(s.getDirection())).collect(Collectors.toList())).orElseGet(Collections::emptyList));
        filterSortMap.put(filter, sort);
    });
    return filterSortMap;
}
Also used : Set(java.util.Set) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Filter(com.epam.ta.reportportal.commons.querygen.Filter) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort) Sort(org.springframework.data.domain.Sort)

Example 5 with FilterSort

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

the class WidgetConverterTest method getWidget.

private Widget getWidget() {
    final Widget widget = new Widget();
    widget.setDescription("description");
    widget.setItemsCount(10);
    widget.setWidgetType("widgetType");
    widget.setName("name");
    widget.setShared(true);
    final Project project = new Project();
    project.setId(3L);
    widget.setProject(project);
    final WidgetOptions widgetOptions = new WidgetOptions();
    final HashMap<String, Object> options = new HashMap<>();
    options.put("option1", "val1");
    options.put("option2", "val2");
    widgetOptions.setOptions(options);
    widget.setWidgetOptions(widgetOptions);
    final UserFilter filter = new UserFilter();
    filter.setId(1L);
    filter.setOwner("owner");
    filter.setName("name");
    filter.setTargetClass(ObjectType.Launch);
    filter.setDescription("filter description");
    filter.setFilterCondition(Sets.newHashSet(FilterCondition.builder().eq(CRITERIA_LAUNCH_ID, "100").build()));
    widget.setFilters(Sets.newHashSet(filter));
    final FilterSort filterSort = new FilterSort();
    filterSort.setField("name");
    filterSort.setDirection(Sort.Direction.ASC);
    filterSort.setId(2L);
    filter.setFilterSorts(Sets.newHashSet(filterSort));
    return widget;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) HashMap(java.util.HashMap) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort)

Aggregations

FilterSort (com.epam.ta.reportportal.entity.filter.FilterSort)6 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)5 Set (java.util.Set)3 Sort (org.springframework.data.domain.Sort)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 Project (com.epam.ta.reportportal.entity.project.Project)2 Order (com.epam.ta.reportportal.ws.model.filter.Order)2 UpdateUserFilterRQ (com.epam.ta.reportportal.ws.model.filter.UpdateUserFilterRQ)2 UserFilterCondition (com.epam.ta.reportportal.ws.model.filter.UserFilterCondition)2 Condition (com.epam.ta.reportportal.commons.querygen.Condition)1 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)1 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)1 ObjectType (com.epam.ta.reportportal.entity.filter.ObjectType)1 Widget (com.epam.ta.reportportal.entity.widget.Widget)1 WidgetOptions (com.epam.ta.reportportal.entity.widget.WidgetOptions)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional.ofNullable (java.util.Optional.ofNullable)1