Search in sources :

Example 1 with 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, 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 WidgetType

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

Example 3 with 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;
}
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 4 with WidgetType

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());
    }
}
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 5 with WidgetType

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())));
    });
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Sort(org.springframework.data.domain.Sort) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) Async(org.springframework.scheduling.annotation.Async) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

WidgetType (com.epam.ta.reportportal.entity.widget.WidgetType)6 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)6 Widget (com.epam.ta.reportportal.entity.widget.Widget)5 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)2 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)2 WidgetResource (com.epam.ta.reportportal.ws.model.widget.WidgetResource)2 Sort (org.springframework.data.domain.Sort)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)1 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 Condition (com.epam.ta.reportportal.commons.querygen.Condition)1 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)1 ProjectFilter (com.epam.ta.reportportal.commons.querygen.ProjectFilter)1 CRITERIA_NAME (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_NAME)1 CRITERIA_ITEM_ATTRIBUTE_VALUE (com.epam.ta.reportportal.commons.querygen.constant.ItemAttributeConstant.CRITERIA_ITEM_ATTRIBUTE_VALUE)1 com.epam.ta.reportportal.dao (com.epam.ta.reportportal.dao)1 Dashboard (com.epam.ta.reportportal.entity.dashboard.Dashboard)1 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)1 DashboardWidgetId (com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId)1