Search in sources :

Example 1 with InfoInterval

use of com.epam.ta.reportportal.entity.enums.InfoInterval in project service-api by reportportal.

the class GetProjectInfoHandlerImpl method getProjectInfoWidgetContent.

@Override
public Map<String, ?> getProjectInfoWidgetContent(String projectName, String interval, String widgetCode) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
    InfoInterval infoInterval = InfoInterval.findByInterval(interval).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, interval));
    ProjectInfoWidget widgetType = ProjectInfoWidget.findByCode(widgetCode).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, widgetCode));
    List<Launch> launches = launchRepository.findByProjectIdAndStartTimeGreaterThanAndMode(project.getId(), getStartIntervalDate(infoInterval), LaunchModeEnum.DEFAULT);
    Map<String, ?> result;
    switch(widgetType) {
        case INVESTIGATED:
            result = dataConverter.getInvestigatedProjectInfo(launches, infoInterval);
            break;
        case CASES_STATISTIC:
            result = dataConverter.getTestCasesStatisticsProjectInfo(launches);
            break;
        case LAUNCHES_QUANTITY:
            result = dataConverter.getLaunchesQuantity(launches, infoInterval);
            break;
        case ISSUES_CHART:
            result = dataConverter.getLaunchesIssues(launches, infoInterval);
            break;
        case ACTIVITIES:
            result = getActivities(project, infoInterval);
            break;
        case LAST_LAUNCH:
            result = getLastLaunchStatistics(project.getId());
            break;
        default:
            // empty result
            result = Collections.emptyMap();
    }
    return result;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ProjectInfoWidget(com.epam.ta.reportportal.entity.project.email.ProjectInfoWidget) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) InfoInterval(com.epam.ta.reportportal.entity.enums.InfoInterval) Launch(com.epam.ta.reportportal.entity.launch.Launch)

Example 2 with InfoInterval

use of com.epam.ta.reportportal.entity.enums.InfoInterval in project service-api by reportportal.

the class GetProjectInfoHandlerImpl method getProjectInfo.

@Override
public ProjectInfoResource getProjectInfo(String projectName, String interval) {
    Project project = projectRepository.findByName(normalizeId(projectName)).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
    InfoInterval infoInterval = InfoInterval.findByInterval(interval).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, interval));
    Filter filter = Filter.builder().withTarget(ProjectInfo.class).withCondition(FilterCondition.builder().eq(CRITERIA_PROJECT_NAME, project.getName()).build()).build();
    Page<ProjectInfo> result = projectRepository.findProjectInfoByFilter(filter, Pageable.unpaged());
    ProjectInfoResource projectInfoResource = ProjectSettingsConverter.TO_PROJECT_INFO_RESOURCE.apply(result.get().findFirst().orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName)));
    LocalDateTime startIntervalDate = getStartIntervalDate(infoInterval);
    Map<String, Integer> countPerUser = launchRepository.countLaunchesGroupedByOwner(project.getId(), LaunchModeEnum.DEFAULT.toString(), startIntervalDate);
    projectInfoResource.setUniqueTickets(ticketRepository.findUniqueCountByProjectBefore(project.getId(), startIntervalDate));
    projectInfoResource.setLaunchesPerUser(countPerUser.entrySet().stream().map(e -> new LaunchesPerUser(e.getKey(), e.getValue())).collect(Collectors.toList()));
    if (projectInfoResource.getLaunchesQuantity() != 0) {
        formatter.setRoundingMode(RoundingMode.HALF_UP);
        double value = projectInfoResource.getLaunchesQuantity() / (infoInterval.getCount() * WEEKS_IN_MONTH);
        projectInfoResource.setLaunchesPerWeek(formatter.format(value));
    } else {
        projectInfoResource.setLaunchesPerWeek(formatter.format(0));
    }
    return projectInfoResource;
}
Also used : LocalDateTime(java.time.LocalDateTime) InfoInterval(com.epam.ta.reportportal.entity.enums.InfoInterval) LaunchesPerUser(com.epam.ta.reportportal.ws.model.project.LaunchesPerUser) ProjectInfoResource(com.epam.ta.reportportal.ws.model.project.ProjectInfoResource) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Filter(com.epam.ta.reportportal.commons.querygen.Filter) ProjectInfo(com.epam.ta.reportportal.entity.project.ProjectInfo)

Example 3 with InfoInterval

use of com.epam.ta.reportportal.entity.enums.InfoInterval in project service-api by reportportal.

the class ProjectInfoWidgetDataConverterTest method setUp.

@BeforeEach
void setUp() {
    converter = new ProjectInfoWidgetDataConverter(ImmutableMap.<InfoInterval, ProjectInfoWidgetDataConverter.ProjectInfoGroup>builder().put(InfoInterval.ONE_MONTH, ProjectInfoWidgetDataConverter.ProjectInfoGroup.BY_DAY).put(InfoInterval.THREE_MONTHS, ProjectInfoWidgetDataConverter.ProjectInfoGroup.BY_WEEK).put(InfoInterval.SIX_MONTHS, ProjectInfoWidgetDataConverter.ProjectInfoGroup.BY_WEEK).build());
    thisWeekFormattedDate = LocalDate.now(ZoneOffset.UTC).format(new DateTimeFormatterBuilder().appendValue(IsoFields.WEEK_BASED_YEAR, 4).appendLiteral("-W").appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2).toFormatter());
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    LocalDate now = LocalDate.now(ZoneOffset.UTC);
    today = now.getDayOfWeek().equals(DayOfWeek.MONDAY) ? now.plusDays(2) : now;
    yesterday = today.minusDays(1);
    todayString = today.format(formatter);
    yesterdayString = yesterday.format(formatter);
}
Also used : InfoInterval(com.epam.ta.reportportal.entity.enums.InfoInterval) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with InfoInterval

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

InfoInterval (com.epam.ta.reportportal.entity.enums.InfoInterval)4 Project (com.epam.ta.reportportal.entity.project.Project)3 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 Launch (com.epam.ta.reportportal.entity.launch.Launch)2 ProjectInfo (com.epam.ta.reportportal.entity.project.ProjectInfo)2 ProjectInfoWidget (com.epam.ta.reportportal.entity.project.email.ProjectInfoWidget)2 LaunchesPerUser (com.epam.ta.reportportal.ws.model.project.LaunchesPerUser)2 ProjectInfoResource (com.epam.ta.reportportal.ws.model.project.ProjectInfoResource)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