use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.
the class WidgetBuilderTest method widgetBuilderTest.
@Test
void widgetBuilderTest() {
final WidgetRQ widgetRQ = new WidgetRQ();
final String name = "name";
widgetRQ.setName(name);
final String description = "description";
widgetRQ.setDescription(description);
final boolean share = true;
widgetRQ.setShare(share);
final String widgetType = "oldLineChart";
widgetRQ.setWidgetType(widgetType);
final ContentParameters contentParameters = new ContentParameters();
contentParameters.setContentFields(Collections.singletonList("contentField"));
contentParameters.setItemsCount(10);
final HashMap<String, Object> widgetOptions = new HashMap<>();
widgetOptions.put("param", "val");
contentParameters.setWidgetOptions(widgetOptions);
widgetRQ.setContentParameters(contentParameters);
final String owner = "owner";
final UserFilter userFilter = new UserFilter();
userFilter.setId(1L);
final Widget widget = new WidgetBuilder().addWidgetRq(widgetRQ).addFilters(Collections.singletonList(userFilter)).addOwner(owner).get();
assertEquals(name, widget.getName());
assertEquals(description, widget.getDescription());
assertEquals(share, widget.isShared());
assertEquals(owner, widget.getOwner());
assertEquals(widgetType, widget.getWidgetType());
assertThat(widget.getFilters()).containsExactly(userFilter);
assertThat(widget.getContentFields()).containsExactly("contentField");
assertThat(widget.getWidgetOptions().getOptions()).containsExactly(new AbstractMap.SimpleEntry<>("param", "val"));
}
use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.
the class GetWidgetHandlerImpl method getWidgetPreview.
@Override
public Map<String, ?> getWidgetPreview(WidgetPreviewRQ previewRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
WidgetType widgetType = WidgetType.findByName(previewRQ.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_REQUEST, formattedSupplier("Unsupported widget type '{}'", previewRQ.getWidgetType())));
List<UserFilter> userFilter = null;
if (CollectionUtils.isNotEmpty(previewRQ.getFilterIds())) {
userFilter = getPermittedFilters(previewRQ.getFilterIds().toArray(Long[]::new), projectDetails, user);
}
if (!unfilteredWidgetTypes.contains(widgetType) && CollectionUtils.isEmpty(userFilter)) {
return Collections.emptyMap();
}
Widget widget = new WidgetBuilder().addWidgetPreviewRq(previewRQ).addProject(projectDetails.getProjectId()).addFilters(userFilter).get();
if (widgetType.isSupportMultilevelStructure()) {
return multilevelLoadContentStrategy.get(widgetType).loadContent(Lists.newArrayList(widget.getContentFields()), buildFilterStrategyMapping.get(widgetType).buildFilter(widget), widget.getWidgetOptions(), null, null, widget.getItemsCount());
} else {
return loadContentStrategy.get(widgetType).loadContent(Lists.newArrayList(widget.getContentFields()), buildFilterStrategyMapping.get(widgetType).buildFilter(widget), widget.getWidgetOptions(), widget.getItemsCount());
}
}
use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.
the class UpdateWidgetHandlerImpl method updateWidget.
@Override
public OperationCompletionRS updateWidget(Long widgetId, WidgetRQ updateRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
Widget widget = getShareableEntityHandler.getAdministrated(widgetId, projectDetails);
widgetContentFieldsValidator.validate(widget);
if (!widget.getName().equals(updateRQ.getName())) {
BusinessRule.expect(widgetRepository.existsByNameAndOwnerAndProjectId(updateRQ.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, updateRQ.getName());
}
WidgetActivityResource before = TO_ACTIVITY_RESOURCE.apply(widget);
List<UserFilter> userFilter = getUserFilters(updateRQ.getFilterIds(), projectDetails.getProjectId(), user.getUsername());
String widgetOptionsBefore = parseWidgetOptions(widget);
updateSharing(widget, projectDetails.getProjectId(), updateRQ.getShare());
widget = new WidgetBuilder(widget).addWidgetRq(updateRQ).addFilters(userFilter).get();
widgetRepository.save(widget);
messageBus.publishActivity(new WidgetUpdatedEvent(before, TO_ACTIVITY_RESOURCE.apply(widget), widgetOptionsBefore, parseWidgetOptions(widget), user.getUserId(), user.getUsername()));
return new OperationCompletionRS("Widget with ID = '" + widget.getId() + "' successfully updated.");
}
use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.
the class CreateWidgetHandlerImpl method createWidget.
@Override
public EntryCreatedRS createWidget(WidgetRQ createWidgetRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
List<UserFilter> userFilter = getUserFilters(createWidgetRQ.getFilterIds(), projectDetails.getProjectId(), user.getUsername());
BusinessRule.expect(widgetRepository.existsByNameAndOwnerAndProjectId(createWidgetRQ.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, createWidgetRQ.getName());
Widget widget = new WidgetBuilder().addWidgetRq(createWidgetRQ).addProject(projectDetails.getProjectId()).addFilters(userFilter).addOwner(user.getUsername()).get();
widgetContentFieldsValidator.validate(widget);
widgetPostProcessors.stream().filter(widgetPostProcessor -> widgetPostProcessor.supports(widget)).forEach(widgetPostProcessor -> widgetPostProcessor.postProcess(widget));
widgetRepository.save(widget);
aclHandler.initAcl(widget, user.getUsername(), projectDetails.getProjectId(), BooleanUtils.isTrue(createWidgetRQ.getShare()));
if (widget.isShared()) {
ofNullable(widget.getFilters()).ifPresent(filters -> updateUserFilterHandler.updateSharing(filters, projectDetails.getProjectId(), widget.isShared()));
}
messageBus.publishActivity(new WidgetCreatedEvent(TO_ACTIVITY_RESOURCE.apply(widget), user.getUserId(), user.getUsername()));
return new EntryCreatedRS(widget.getId());
}
use of com.epam.ta.reportportal.entity.filter.UserFilter 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;
}
Aggregations