Search in sources :

Example 26 with WidgetOptions

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

the class TopTestCasesContentLoader method loadContent.

@Override
public Map<String, ?> loadContent(List<String> contentFields, Map<Filter, Sort> filterSortMapping, WidgetOptions widgetOptions, int limit) {
    String criteria = contentFields.get(0);
    Filter filter = GROUP_FILTERS.apply(filterSortMapping.keySet()).withCondition(new FilterCondition(Condition.EQUALS, false, WidgetOptionUtil.getValueByKey(LAUNCH_NAME_FIELD, widgetOptions), CRITERIA_NAME));
    return launchRepository.findLatestByFilter(filter).map(it -> Pair.of(it, widgetContentRepository.topItemsByCriteria(filter, criteria, limit, ofNullable(widgetOptions.getOptions().get(INCLUDE_METHODS)).map(v -> BooleanUtils.toBoolean(String.valueOf(v))).orElse(false)))).filter(it -> !it.getRight().isEmpty()).map(it -> (Map<String, ?>) ImmutableMap.<String, Object>builder().put(LATEST_LAUNCH, launchConverter.TO_RESOURCE.apply(it.getLeft())).put(RESULT, it.getRight()).build()).orElse(Collections.emptyMap());
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) ImmutableMap(com.google.common.collect.ImmutableMap) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) ContentLoaderConstants(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants) WidgetOptionUtil(com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) GROUP_FILTERS(com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_FILTERS) BooleanUtils(org.apache.commons.lang3.BooleanUtils) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) WidgetContentRepository(com.epam.ta.reportportal.dao.WidgetContentRepository) List(java.util.List) LoadContentStrategy(com.epam.ta.reportportal.core.widget.content.LoadContentStrategy) Pair(org.apache.commons.lang3.tuple.Pair) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) Service(org.springframework.stereotype.Service) Condition(com.epam.ta.reportportal.commons.querygen.Condition) Map(java.util.Map) LaunchConverter(com.epam.ta.reportportal.ws.converter.converters.LaunchConverter) CRITERIA_NAME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_NAME) Sort(org.springframework.data.domain.Sort) Collections(java.util.Collections) Filter(com.epam.ta.reportportal.commons.querygen.Filter) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 27 with WidgetOptions

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

the class HealthCheckTableReadyContentLoader method getParams.

private HealthCheckTableGetParams getParams(WidgetOptions widgetOptions, List<String> attributeValues) {
    List<String> attributeKeys = WidgetOptionUtil.getListByKey(ATTRIBUTE_KEYS, widgetOptions);
    int currentLevel = attributeValues.size();
    BusinessRule.expect(attributeKeys, keys -> keys.size() > currentLevel).verify(ErrorType.UNABLE_LOAD_WIDGET_CONTENT, "Incorrect level definition");
    String viewName = ofNullable(WidgetOptionUtil.getValueByKey(VIEW_NAME, widgetOptions)).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_LOAD_WIDGET_CONTENT, "Widget view name not provided"));
    String currentLevelKey = attributeKeys.get(currentLevel);
    boolean includeCustomColumn = ofNullable(WidgetOptionUtil.getValueByKey(CUSTOM_COLUMN, widgetOptions)).isPresent();
    return HealthCheckTableGetParams.of(viewName, currentLevelKey, resolveSort(widgetOptions), includeCustomColumn, getLevelEntries(attributeKeys, attributeValues));
}
Also used : IntStream(java.util.stream.IntStream) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) ContentLoaderConstants(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) EXECUTIONS_PASSED(com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.EXECUTIONS_PASSED) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) CollectionUtils(org.apache.commons.collections.CollectionUtils) HealthCheckTableGetParams(com.epam.ta.reportportal.entity.widget.content.healthcheck.HealthCheckTableGetParams) Service(org.springframework.stereotype.Service) Map(java.util.Map) LevelEntry(com.epam.ta.reportportal.entity.widget.content.healthcheck.LevelEntry) Sort(org.springframework.data.domain.Sort) RoundingMode(java.math.RoundingMode) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Collections.emptyMap(java.util.Collections.emptyMap) SortEntry(com.epam.ta.reportportal.ws.model.widget.SortEntry) ImmutableMap(com.google.common.collect.ImmutableMap) VIEW_NAME(com.epam.ta.reportportal.core.widget.content.loader.materialized.handler.MaterializedWidgetStateHandler.VIEW_NAME) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WidgetOptionUtil(com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) MultiValueMap(org.springframework.util.MultiValueMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WidgetContentRepository(com.epam.ta.reportportal.dao.WidgetContentRepository) Collectors(java.util.stream.Collectors) List(java.util.List) HealthCheckTableContent(com.epam.ta.reportportal.entity.widget.content.healthcheck.HealthCheckTableContent) Widget(com.epam.ta.reportportal.entity.widget.Widget) EXECUTIONS_TOTAL(com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.EXECUTIONS_TOTAL) Collections(java.util.Collections) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Example 28 with WidgetOptions

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

the class ComponentHealthCheckContentValidator method validateWidgetOptions.

private void validateWidgetOptions(WidgetOptions widgetOptions) {
    BusinessRule.expect(widgetOptions, Objects::nonNull).verify(ErrorType.UNABLE_LOAD_WIDGET_CONTENT, "Widgets options not provided");
    Integer passingRate = WidgetOptionUtil.getIntegerByKey(MIN_PASSING_RATE, widgetOptions).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_LOAD_WIDGET_CONTENT, "Minimum passing rate option was not specified"));
    BusinessRule.expect(passingRate, v -> v >= 0 && v <= 100).verify(ErrorType.UNABLE_LOAD_WIDGET_CONTENT, "Minimum passing rate value should be greater or equal to 0 and less or equal to 100");
}
Also used : BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) java.util(java.util) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) WidgetOptionUtil(com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) ATTRIBUTE_KEYS(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.ATTRIBUTE_KEYS) Sort(org.springframework.data.domain.Sort) MIN_PASSING_RATE(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.MIN_PASSING_RATE) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Example 29 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions 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 30 with WidgetOptions

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

the class LaunchesTableContentValidatorTest method testValidateWithException.

@Test
public void testValidateWithException() {
    Exception exception = assertThrows(ReportPortalException.class, () -> {
        HashMap<Filter, Sort> filterSortMap = new HashMap<>();
        filterSortMap.put(Filter.builder().withTarget(Launch.class).withCondition(FilterCondition.builder().eq("id", "1").build()).build(), Sort.unsorted());
        launchesTableContentValidator.validate(new ArrayList<>(), filterSortMap, new WidgetOptions(), 5);
    });
    String expectedMessage = "Content fields should not be empty";
    String actualMessage = exception.getMessage();
    assertTrue(actualMessage.contains(expectedMessage));
}
Also used : Filter(com.epam.ta.reportportal.commons.querygen.Filter) HashMap(java.util.HashMap) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) Sort(org.springframework.data.domain.Sort) Launch(com.epam.ta.reportportal.entity.launch.Launch) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Test(org.junit.jupiter.api.Test)

Aggregations

WidgetOptions (com.epam.ta.reportportal.entity.widget.WidgetOptions)34 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)20 Test (org.junit.jupiter.api.Test)20 Sort (org.springframework.data.domain.Sort)15 Filter (com.epam.ta.reportportal.commons.querygen.Filter)13 WidgetOptionUtil (com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil)10 Launch (com.epam.ta.reportportal.entity.launch.Launch)10 HashMap (java.util.HashMap)10 Optional.ofNullable (java.util.Optional.ofNullable)10 WidgetContentRepository (com.epam.ta.reportportal.dao.WidgetContentRepository)8 Map (java.util.Map)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Service (org.springframework.stereotype.Service)7 ContentLoaderConstants (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants)6 GROUP_FILTERS (com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_FILTERS)6 List (java.util.List)6 CollectionUtils (org.apache.commons.collections.CollectionUtils)6 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)5 LoadContentStrategy (com.epam.ta.reportportal.core.widget.content.LoadContentStrategy)5 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)5