Search in sources :

Example 1 with WidgetResource

use of com.epam.ta.reportportal.ws.model.widget.WidgetResource in project service-api by reportportal.

the class GetWidgetHandlerImpl method getWidget.

@Override
public WidgetResource getWidget(Long widgetId, String[] attributes, MultiValueMap<String, String> params, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Widget widget = getShareableEntityHandler.getPermitted(widgetId, projectDetails);
    WidgetType widgetType = WidgetType.findByName(widget.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_REQUEST, formattedSupplier("Unsupported widget type '{}'", widget.getWidgetType())));
    expect(widgetType.isSupportMultilevelStructure(), Predicate.isEqual(true)).verify(ErrorType.INCORRECT_REQUEST, formattedSupplier("Widget type '{}' does not support multilevel structure.", widgetType));
    Map<String, ?> content;
    if (unfilteredWidgetTypes.contains(widgetType) || isFilteredContentLoadAllowed(widget.getFilters(), projectDetails, user)) {
        params.put(ATTRIBUTES, Lists.newArrayList(attributes));
        content = ofNullable(multilevelLoadContentStrategy.get(widgetType)).map(strategy -> strategy.loadContent(Lists.newArrayList(widget.getContentFields()), buildFilterStrategyMapping.get(widgetType).buildFilter(widget), widget.getWidgetOptions(), attributes, params, widget.getItemsCount())).orElseGet(() -> materializedLoadContentStrategy.loadContent(widget, params));
    } else {
        content = Collections.emptyMap();
    }
    WidgetResource resource = WidgetConverter.TO_WIDGET_RESOURCE.apply(widget);
    resource.setContent(content);
    return resource;
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) WidgetResource(com.epam.ta.reportportal.ws.model.widget.WidgetResource) Widget(com.epam.ta.reportportal.entity.widget.Widget) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType)

Example 2 with WidgetResource

use of com.epam.ta.reportportal.ws.model.widget.WidgetResource in project service-api by reportportal.

the class WidgetConverterTest method toWidgetResource.

@Test
void toWidgetResource() {
    final Widget widget = getWidget();
    final WidgetResource resource = WidgetConverter.TO_WIDGET_RESOURCE.apply(widget);
    assertEquals(resource.getName(), widget.getName());
    assertEquals(resource.getWidgetId(), widget.getId());
    assertEquals(resource.getWidgetType(), widget.getWidgetType());
    assertEquals(resource.getDescription(), widget.getDescription());
    assertEquals(resource.getOwner(), widget.getOwner());
    assertEquals(resource.getContentParameters().getItemsCount(), widget.getItemsCount());
    assertThat(resource.getContentParameters().getContentFields()).containsExactlyElementsOf(widget.getContentFields());
    assertThat(resource.getContentParameters().getWidgetOptions()).containsAllEntriesOf(widget.getWidgetOptions().getOptions());
    assertThat(resource.getAppliedFilters()).hasSize(1);
}
Also used : WidgetResource(com.epam.ta.reportportal.ws.model.widget.WidgetResource) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Test(org.junit.jupiter.api.Test)

Example 3 with WidgetResource

use of com.epam.ta.reportportal.ws.model.widget.WidgetResource in project service-api by reportportal.

the class GetWidgetHandlerImpl method getWidget.

@Override
public WidgetResource getWidget(Long widgetId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Widget widget = getShareableEntityHandler.getPermitted(widgetId, projectDetails);
    WidgetType widgetType = WidgetType.findByName(widget.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_REQUEST, formattedSupplier("Unsupported widget type '{}'", widget.getWidgetType())));
    expect(widgetType.isSupportMultilevelStructure(), Predicate.isEqual(false)).verify(ErrorType.INCORRECT_REQUEST, formattedSupplier("Unsupported widget type '{}'", widgetType));
    Map<String, ?> content;
    if (unfilteredWidgetTypes.contains(widgetType) || isFilteredContentLoadAllowed(widget.getFilters(), projectDetails, user)) {
        content = loadContentStrategy.get(widgetType).loadContent(Lists.newArrayList(widget.getContentFields()), buildFilterStrategyMapping.get(widgetType).buildFilter(widget), widget.getWidgetOptions(), widget.getItemsCount());
    } else {
        content = Collections.emptyMap();
    }
    WidgetResource resource = WidgetConverter.TO_WIDGET_RESOURCE.apply(widget);
    resource.setContent(content);
    return resource;
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) WidgetResource(com.epam.ta.reportportal.ws.model.widget.WidgetResource) Widget(com.epam.ta.reportportal.entity.widget.Widget) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType)

Aggregations

Widget (com.epam.ta.reportportal.entity.widget.Widget)3 WidgetResource (com.epam.ta.reportportal.ws.model.widget.WidgetResource)3 WidgetType (com.epam.ta.reportportal.entity.widget.WidgetType)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)1 Test (org.junit.jupiter.api.Test)1