Search in sources :

Example 6 with WidgetType

use of com.epam.ta.reportportal.entity.widget.WidgetType in project service-api by reportportal.

the class DemoDashboardsService method createWidgets.

private List<Widget> createWidgets(ReportPortalUser user, Long projectId, UserFilter filter) {
    try {
        TypeReference<List<WidgetRQ>> type = new TypeReference<>() {
        };
        List<Widget> widgets = objectMapper.readValue(resource.getURL(), type).stream().map(it -> {
            final WidgetBuilder widgetBuilder = new WidgetBuilder().addWidgetRq(it).addProject(projectId).addOwner(user.getUsername());
            final WidgetType widgetType = WidgetType.findByName(it.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_TO_CREATE_WIDGET, "Widget type '" + it.getWidgetType() + "' does not exists"));
            if (!WidgetType.FLAKY_TEST_CASES.equals(widgetType) || !WidgetType.TOP_TEST_CASES.equals(widgetType)) {
                widgetBuilder.addFilters(Sets.newHashSet(filter));
            }
            return widgetBuilder.get();
        }).collect(toList());
        widgetRepository.saveAll(widgets);
        widgets.forEach(it -> aclHandler.initAcl(it, user.getUsername(), projectId, it.isShared()));
        return widgets;
    } catch (IOException e) {
        throw new ReportPortalException("Unable to load demo_widgets.json. " + e.getMessage(), e);
    }
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) ProjectFilter(com.epam.ta.reportportal.commons.querygen.ProjectFilter) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) Value(org.springframework.beans.factory.annotation.Value) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) Service(org.springframework.stereotype.Service) PROJECT_NOT_FOUND(com.epam.ta.reportportal.ws.model.ErrorType.PROJECT_NOT_FOUND) Condition(com.epam.ta.reportportal.commons.querygen.Condition) CRITERIA_NAME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_NAME) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Resource(org.springframework.core.io.Resource) ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) ObjectType(com.epam.ta.reportportal.entity.filter.ObjectType) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) DashboardWidgetId(com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId) Filter(com.epam.ta.reportportal.commons.querygen.Filter) CRITERIA_ITEM_ATTRIBUTE_VALUE(com.epam.ta.reportportal.commons.querygen.constant.ItemAttributeConstant.CRITERIA_ITEM_ATTRIBUTE_VALUE) com.epam.ta.reportportal.dao(com.epam.ta.reportportal.dao) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IOException(java.io.IOException) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort) Sets(com.google.common.collect.Sets) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Optional(java.util.Optional) Widget(com.epam.ta.reportportal.entity.widget.Widget) Transactional(org.springframework.transaction.annotation.Transactional) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType)

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