Search in sources :

Example 21 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class WidgetConverterTest method getWidget.

private Widget getWidget() {
    final Widget widget = new Widget();
    widget.setDescription("description");
    widget.setItemsCount(10);
    widget.setWidgetType("widgetType");
    widget.setName("name");
    widget.setShared(true);
    final Project project = new Project();
    project.setId(3L);
    widget.setProject(project);
    final WidgetOptions widgetOptions = new WidgetOptions();
    final HashMap<String, Object> options = new HashMap<>();
    options.put("option1", "val1");
    options.put("option2", "val2");
    widgetOptions.setOptions(options);
    widget.setWidgetOptions(widgetOptions);
    final UserFilter filter = new UserFilter();
    filter.setId(1L);
    filter.setOwner("owner");
    filter.setName("name");
    filter.setTargetClass(ObjectType.Launch);
    filter.setDescription("filter description");
    filter.setFilterCondition(Sets.newHashSet(FilterCondition.builder().eq(CRITERIA_LAUNCH_ID, "100").build()));
    widget.setFilters(Sets.newHashSet(filter));
    final FilterSort filterSort = new FilterSort();
    filterSort.setField("name");
    filterSort.setDirection(Sort.Direction.ASC);
    filterSort.setId(2L);
    filter.setFilterSorts(Sets.newHashSet(filterSort));
    return widget;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) HashMap(java.util.HashMap) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort)

Example 22 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class DemoDashboardsService method generate.

@Transactional
public Optional<Dashboard> generate(ReportPortalUser user, Long projectId) {
    Project project = projectRepository.findById(projectId).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectId));
    if (dashboardRepository.existsByNameAndOwnerAndProjectId(DASHBOARD_NAME, user.getUsername(), projectId)) {
        return Optional.empty();
    }
    UserFilter filter = createDemoFilter(user, project);
    List<Widget> widgets = createWidgets(user, projectId, filter);
    return Optional.of(createDemoDashboard(widgets, user, project, DASHBOARD_NAME));
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter 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

UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)23 Filter (com.epam.ta.reportportal.commons.querygen.Filter)7 Widget (com.epam.ta.reportportal.entity.widget.Widget)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)7 Test (org.junit.jupiter.api.Test)7 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)6 FilterSort (com.epam.ta.reportportal.entity.filter.FilterSort)5 ProjectFilter (com.epam.ta.reportportal.commons.querygen.ProjectFilter)4 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)4 Condition (com.epam.ta.reportportal.commons.querygen.Condition)3 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)3 ObjectType (com.epam.ta.reportportal.entity.filter.ObjectType)3 Project (com.epam.ta.reportportal.entity.project.Project)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)3 Order (com.epam.ta.reportportal.ws.model.filter.Order)3 UpdateUserFilterRQ (com.epam.ta.reportportal.ws.model.filter.UpdateUserFilterRQ)3 UserFilterCondition (com.epam.ta.reportportal.ws.model.filter.UserFilterCondition)3 WidgetRQ (com.epam.ta.reportportal.ws.model.widget.WidgetRQ)3 List (java.util.List)3