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