Search in sources :

Example 1 with LaunchesPerUser

use of com.epam.ta.reportportal.ws.model.project.LaunchesPerUser 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)

Aggregations

Filter (com.epam.ta.reportportal.commons.querygen.Filter)1 InfoInterval (com.epam.ta.reportportal.entity.enums.InfoInterval)1 Project (com.epam.ta.reportportal.entity.project.Project)1 ProjectInfo (com.epam.ta.reportportal.entity.project.ProjectInfo)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 LaunchesPerUser (com.epam.ta.reportportal.ws.model.project.LaunchesPerUser)1 ProjectInfoResource (com.epam.ta.reportportal.ws.model.project.ProjectInfoResource)1 LocalDateTime (java.time.LocalDateTime)1