Search in sources :

Example 16 with UserFilter

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"));
}
Also used : AbstractMap(java.util.AbstractMap) HashMap(java.util.HashMap) WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Widget(com.epam.ta.reportportal.entity.widget.Widget) ContentParameters(com.epam.ta.reportportal.ws.model.widget.ContentParameters) Test(org.junit.jupiter.api.Test)

Example 17 with UserFilter

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());
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Widget(com.epam.ta.reportportal.entity.widget.Widget) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)

Example 18 with UserFilter

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.");
}
Also used : WidgetActivityResource(com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource) WidgetUpdatedEvent(com.epam.ta.reportportal.core.events.activity.WidgetUpdatedEvent) Widget(com.epam.ta.reportportal.entity.widget.Widget) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 19 with UserFilter

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());
}
Also used : CreateWidgetHandler(com.epam.ta.reportportal.core.widget.CreateWidgetHandler) Autowired(org.springframework.beans.factory.annotation.Autowired) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) BooleanUtils(org.apache.commons.lang3.BooleanUtils) WidgetCreatedEvent(com.epam.ta.reportportal.core.events.activity.WidgetCreatedEvent) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) ProjectFilter(com.epam.ta.reportportal.commons.querygen.ProjectFilter) CRITERIA_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_ID) WidgetPostProcessor(com.epam.ta.reportportal.core.widget.content.updater.WidgetPostProcessor) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) Condition(com.epam.ta.reportportal.commons.querygen.Condition) Pageable(org.springframework.data.domain.Pageable) Predicates.not(com.epam.ta.reportportal.commons.Predicates.not) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.WidgetConverter.TO_ACTIVITY_RESOURCE) ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) WidgetValidator(com.epam.ta.reportportal.core.widget.content.updater.validator.WidgetValidator) Collectors(java.util.stream.Collectors) WidgetRepository(com.epam.ta.reportportal.dao.WidgetRepository) List(java.util.List) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) UpdateUserFilterHandler(com.epam.ta.reportportal.core.filter.UpdateUserFilterHandler) UserFilterRepository(com.epam.ta.reportportal.dao.UserFilterRepository) Widget(com.epam.ta.reportportal.entity.widget.Widget) Collections(java.util.Collections) WidgetCreatedEvent(com.epam.ta.reportportal.core.events.activity.WidgetCreatedEvent) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Widget(com.epam.ta.reportportal.entity.widget.Widget) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)

Example 20 with UserFilter

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

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