Search in sources :

Example 1 with RESULT

use of com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT in project service-api by reportportal.

the class LineChartContentLoader method loadContent.

@Override
public Map<String, ?> loadContent(List<String> contentFields, Map<Filter, Sort> filterSortMapping, WidgetOptions widgetOptions, int limit) {
    Filter filter = GROUP_FILTERS.apply(filterSortMapping.keySet());
    Sort sort = GROUP_SORTS.apply(filterSortMapping.values());
    List<ChartStatisticsContent> content = widgetContentRepository.launchStatistics(filter, contentFields, sort, limit);
    String timeLineOption = ofNullable(widgetOptions).map(wo -> WidgetOptionUtil.getValueByKey(TIMELINE, wo)).orElse(Strings.EMPTY);
    if (StringUtils.isNotBlank(timeLineOption)) {
        Optional<Period> period = Period.findByName(timeLineOption);
        if (period.isPresent()) {
            return CollectionUtils.isEmpty(content) ? emptyMap() : singletonMap(RESULT, groupByDate(content, period.get()));
        }
    }
    return CollectionUtils.isEmpty(content) ? emptyMap() : singletonMap(RESULT, content);
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) GROUP_SORTS(com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_SORTS) Collections.emptyMap(java.util.Collections.emptyMap) TIMELINE(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.TIMELINE) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) 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) WidgetContentRepository(com.epam.ta.reportportal.dao.WidgetContentRepository) StringUtils(org.apache.commons.lang3.StringUtils) ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent) List(java.util.List) RESULT(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT) LoadContentStrategy(com.epam.ta.reportportal.core.widget.content.LoadContentStrategy) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) Strings(org.apache.logging.log4j.util.Strings) Optional(java.util.Optional) Sort(org.springframework.data.domain.Sort) Collections.singletonMap(java.util.Collections.singletonMap) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Sort(org.springframework.data.domain.Sort) ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent)

Example 2 with RESULT

use of com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT in project service-api by reportportal.

the class GetProjectInfoHandlerImpl method getActivities.

private Map<String, List<ActivityResource>> getActivities(Project project, InfoInterval infoInterval) {
    String value = Arrays.stream(ActivityAction.values()).filter(not(ACTIVITIES_PROJECT_FILTER)).map(ActivityAction::getValue).collect(joining(","));
    Filter filter = new Filter(Activity.class, Lists.newArrayList(new FilterCondition(IN, false, value, CRITERIA_ACTION), new FilterCondition(EQUALS, false, String.valueOf(project.getId()), CRITERIA_PROJECT_ID), new FilterCondition(GREATER_THAN_OR_EQUALS, false, String.valueOf(Timestamp.valueOf(getStartIntervalDate(infoInterval)).getTime()), CRITERIA_CREATION_DATE)));
    List<Activity> activities = activityRepository.findByFilter(filter, PageRequest.of(0, LIMIT, Sort.by(Sort.Direction.DESC, CRITERIA_CREATION_DATE))).getContent();
    Map<Long, String> userIdLoginMapping = userRepository.findAllById(activities.stream().filter(a -> a.getUserId() != null).map(Activity::getUserId).collect(Collectors.toSet())).stream().collect(toMap(User::getId, User::getLogin));
    return Collections.singletonMap(RESULT, activities.stream().map(a -> ofNullable(a.getUserId()).map(userId -> TO_RESOURCE_WITH_USER.apply(a, userIdLoginMapping.get(userId))).orElseGet(() -> TO_RESOURCE.apply(a))).peek(resource -> resource.setProjectName(project.getName())).collect(toList()));
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) ProjectInfo(com.epam.ta.reportportal.entity.project.ProjectInfo) InfoInterval(com.epam.ta.reportportal.entity.enums.InfoInterval) BAD_REQUEST_ERROR(com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) ZoneOffset(java.time.ZoneOffset) Predicates.not(com.epam.ta.reportportal.commons.Predicates.not) RoundingMode(java.math.RoundingMode) CRITERIA_PROJECT_NAME(com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_NAME) ProjectInfoResource(com.epam.ta.reportportal.ws.model.project.ProjectInfoResource) GetProjectInfoHandler(com.epam.ta.reportportal.core.project.GetProjectInfoHandler) Launch(com.epam.ta.reportportal.entity.launch.Launch) Predicate(java.util.function.Predicate) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Timestamp(java.sql.Timestamp) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PagedResourcesAssembler(com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler) ProjectSettingsConverter(com.epam.ta.reportportal.ws.converter.converters.ProjectSettingsConverter) TO_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.ActivityConverter.TO_RESOURCE) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) LaunchConverter(com.epam.ta.reportportal.ws.converter.converters.LaunchConverter) TO_RESOURCE_WITH_USER(com.epam.ta.reportportal.ws.converter.converters.ActivityConverter.TO_RESOURCE_WITH_USER) Mode(com.epam.ta.reportportal.ws.model.launch.Mode) ActivityResource(com.epam.ta.reportportal.ws.model.ActivityResource) ProjectInfoWidget(com.epam.ta.reportportal.entity.project.email.ProjectInfoWidget) LaunchesPerUser(com.epam.ta.reportportal.ws.model.project.LaunchesPerUser) CRITERIA_PROJECT_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) LocalDateTime(java.time.LocalDateTime) Activity(com.epam.ta.reportportal.entity.activity.Activity) CRITERIA_ACTION(com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_ACTION) CRITERIA_PROJECT_CREATION_DATE(com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_CREATION_DATE) Lists(com.google.common.collect.Lists) 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) ActivityAction(com.epam.ta.reportportal.entity.activity.ActivityAction) Optional.ofNullable(java.util.Optional.ofNullable) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) User(com.epam.ta.reportportal.entity.user.User) com.epam.ta.reportportal.dao(com.epam.ta.reportportal.dao) DecimalFormat(java.text.DecimalFormat) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) CRITERIA_CREATION_DATE(com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_CREATION_DATE) EntityUtils.normalizeId(com.epam.ta.reportportal.commons.EntityUtils.normalizeId) RESULT(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT) Clock(java.time.Clock) Filter(com.epam.ta.reportportal.commons.querygen.Filter) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) Activity(com.epam.ta.reportportal.entity.activity.Activity)

Aggregations

Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 RESULT (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Sort (org.springframework.data.domain.Sort)2 Service (org.springframework.stereotype.Service)2 EntityUtils.normalizeId (com.epam.ta.reportportal.commons.EntityUtils.normalizeId)1 Predicates.not (com.epam.ta.reportportal.commons.Predicates.not)1 Condition (com.epam.ta.reportportal.commons.querygen.Condition)1 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)1 Queryable (com.epam.ta.reportportal.commons.querygen.Queryable)1 CRITERIA_ACTION (com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_ACTION)1 CRITERIA_CREATION_DATE (com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_CREATION_DATE)1 CRITERIA_PROJECT_ID (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID)1 CRITERIA_PROJECT_CREATION_DATE (com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_CREATION_DATE)1 CRITERIA_PROJECT_NAME (com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_NAME)1 GetProjectInfoHandler (com.epam.ta.reportportal.core.project.GetProjectInfoHandler)1 LoadContentStrategy (com.epam.ta.reportportal.core.widget.content.LoadContentStrategy)1 TIMELINE (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.TIMELINE)1 GROUP_FILTERS (com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_FILTERS)1