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