use of com.epam.ta.reportportal.entity.widget.WidgetType 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.entity.widget.WidgetType in project service-api by reportportal.
the class MaterializedWidgetProviderHandlerImpl method updateProviderParams.
private WidgetType updateProviderParams(ReportPortalUser.ProjectDetails projectDetails, Map<String, String> providerParams) {
Long widgetId = Optional.ofNullable(providerParams.get(WIDGET_ID_PARAM)).map(ControllerUtils::safeParseLong).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Widget id must be provided for widget based items provider"));
Widget widget = getShareableEntityHandler.getPermitted(widgetId, projectDetails);
validateState(widget.getWidgetOptions());
WidgetType widgetType = WidgetType.findByName(widget.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.UNCLASSIFIED_REPORT_PORTAL_ERROR));
providerParams.put(VIEW_NAME, widget.getWidgetOptions().getOptions().get(VIEW_NAME).toString());
return widgetType;
}
use of com.epam.ta.reportportal.entity.widget.WidgetType 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;
}
use of com.epam.ta.reportportal.entity.widget.WidgetType 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.widget.WidgetType in project service-api by reportportal.
the class GenerateWidgetViewEventHandler method onApplicationEvent.
@Async
@Transactional(propagation = Propagation.REQUIRES_NEW)
@TransactionalEventListener
public void onApplicationEvent(GenerateWidgetViewEvent event) {
widgetRepository.findById(event.getWidgetId()).ifPresent(widget -> {
WidgetType widgetType = WidgetType.findByName(widget.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_TO_CREATE_WIDGET, formattedSupplier("Unsupported widget type '{}'", widget.getWidgetType())));
Map<Filter, Sort> filterSortMapping = buildFilterStrategyMapping.get(widgetType).buildFilter(widget);
Filter launchesFilter = GROUP_FILTERS.apply(filterSortMapping.keySet());
Sort launchesSort = GROUP_SORTS.apply(filterSortMapping.values());
ofNullable(viewGeneratorMapping.get(widgetType)).ifPresent(viewGenerator -> widgetViewExecutor.execute(() -> viewGenerator.generate(BooleanUtils.toBoolean(event.getParams().getFirst(REFRESH)), generateViewName(widget), widget, launchesFilter, launchesSort, event.getParams())));
});
}
Aggregations