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;
}
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;
}
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);
}
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()));
}
Aggregations