@Test public void findProjectsByStartDateAndEndDateTest() throws Exception { Date snapshotDate = new Date(System.currentTimeMillis()); Project p = new ProjectBuilder().gitHubProjectId(1).organizationName(ORGANIZATION1).snapshotDate(snapshotDate) .starsCount(4).commitsCount(6).contributorsCount(2).score(20).forksCount(0).create(); Project p1 = new ProjectBuilder().gitHubProjectId(2).organizationName(ORGANIZATION1).days(1).starsCount(1) .commitsCount(2).contributorsCount(1).score(20).forksCount(0).create(); when(projectRepository.findProjects(ORGANIZATION1, snapshotDate, empty(), empty())) .thenReturn(singletonList(p)); when(projectRepository.findProjects(ORGANIZATION1, p1.getSnapshotDate(), empty(), empty())) .thenReturn(singletonList(p1)); List<Project> projectList = (List<Project>) projectService.findProjects(ORGANIZATION1, empty(), empty(), Optional.ofNullable(p1.getSnapshotDate()), Optional.ofNullable(p.getSnapshotDate()), empty(), empty(), empty()); assertThat(projectList, hasSize(1)); assertThat(projectList.get(0), equalTo(p)); }
@Override public Iterable<Project> findProjects(final String organizations, final Optional<Integer> limit, final Optional<Integer> offset, final Optional<Date> startDate, final Optional<Date> endDate, final Optional<String> sortBy, final Optional<String> query, final Optional<String> language) { List<Project> resultList = new ArrayList<>(); for (String organization : getOrganizations(organizations)) { if (startDate.isPresent() && endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (startDate.isPresent() && !endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, query,language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (!startDate.isPresent() && endDate.isPresent()) { List<Project> projects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(projects); } else { List<Project> projects = projectRepository.findProjects(organization, query, language); resultList.addAll(projects); } } resultList = getSortedResultList(resultList, sortBy); Integer limitVal = limit.orElse(DEFAULT_LIMIT); Integer offsetVal = offset.orElse(DEFAULT_OFFSET); return resultList.stream().skip(offsetVal).limit(limitVal).collect(Collectors.toList()); }
ProjectServiceImpl implements ProjectService { @Override public Iterable<Project> findProjects(final String organizations, final Optional<Integer> limit, final Optional<Integer> offset, final Optional<Date> startDate, final Optional<Date> endDate, final Optional<String> sortBy, final Optional<String> query, final Optional<String> language) { List<Project> resultList = new ArrayList<>(); for (String organization : getOrganizations(organizations)) { if (startDate.isPresent() && endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (startDate.isPresent() && !endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, query,language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (!startDate.isPresent() && endDate.isPresent()) { List<Project> projects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(projects); } else { List<Project> projects = projectRepository.findProjects(organization, query, language); resultList.addAll(projects); } } resultList = getSortedResultList(resultList, sortBy); Integer limitVal = limit.orElse(DEFAULT_LIMIT); Integer offsetVal = offset.orElse(DEFAULT_OFFSET); return resultList.stream().skip(offsetVal).limit(limitVal).collect(Collectors.toList()); } }
ProjectServiceImpl implements ProjectService { @Override public Iterable<Project> findProjects(final String organizations, final Optional<Integer> limit, final Optional<Integer> offset, final Optional<Date> startDate, final Optional<Date> endDate, final Optional<String> sortBy, final Optional<String> query, final Optional<String> language) { List<Project> resultList = new ArrayList<>(); for (String organization : getOrganizations(organizations)) { if (startDate.isPresent() && endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (startDate.isPresent() && !endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, query,language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (!startDate.isPresent() && endDate.isPresent()) { List<Project> projects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(projects); } else { List<Project> projects = projectRepository.findProjects(organization, query, language); resultList.addAll(projects); } } resultList = getSortedResultList(resultList, sortBy); Integer limitVal = limit.orElse(DEFAULT_LIMIT); Integer offsetVal = offset.orElse(DEFAULT_OFFSET); return resultList.stream().skip(offsetVal).limit(limitVal).collect(Collectors.toList()); } @Autowired  ProjectServiceImpl(ProjectRepository projectRepository, Environment env); }
ProjectServiceImpl implements ProjectService { @Override public Iterable<Project> findProjects(final String organizations, final Optional<Integer> limit, final Optional<Integer> offset, final Optional<Date> startDate, final Optional<Date> endDate, final Optional<String> sortBy, final Optional<String> query, final Optional<String> language) { List<Project> resultList = new ArrayList<>(); for (String organization : getOrganizations(organizations)) { if (startDate.isPresent() && endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (startDate.isPresent() && !endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, query,language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (!startDate.isPresent() && endDate.isPresent()) { List<Project> projects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(projects); } else { List<Project> projects = projectRepository.findProjects(organization, query, language); resultList.addAll(projects); } } resultList = getSortedResultList(resultList, sortBy); Integer limitVal = limit.orElse(DEFAULT_LIMIT); Integer offsetVal = offset.orElse(DEFAULT_OFFSET); return resultList.stream().skip(offsetVal).limit(limitVal).collect(Collectors.toList()); } @Autowired  ProjectServiceImpl(ProjectRepository projectRepository, Environment env); @Override Iterable<Project> findProjects(final String organizations, final Optional<Integer> limit,
                                          final Optional<Integer> offset, final Optional<Date> startDate, final Optional<Date> endDate,
                                          final Optional<String> sortBy, final Optional<String> query, final Optional<String> language); }
ProjectServiceImpl implements ProjectService { @Override public Iterable<Project> findProjects(final String organizations, final Optional<Integer> limit, final Optional<Integer> offset, final Optional<Date> startDate, final Optional<Date> endDate, final Optional<String> sortBy, final Optional<String> query, final Optional<String> language) { List<Project> resultList = new ArrayList<>(); for (String organization : getOrganizations(organizations)) { if (startDate.isPresent() && endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (startDate.isPresent() && !endDate.isPresent()) { List<Project> startProjects = projectRepository.findProjects(organization, startDate.get(), query,language); List<Project> endProjects = projectRepository.findProjects(organization, query,language); resultList.addAll(getMergedProjectList(startProjects, endProjects)); } else if (!startDate.isPresent() && endDate.isPresent()) { List<Project> projects = projectRepository.findProjects(organization, endDate.get(), query, language); resultList.addAll(projects); } else { List<Project> projects = projectRepository.findProjects(organization, query, language); resultList.addAll(projects); } } resultList = getSortedResultList(resultList, sortBy); Integer limitVal = limit.orElse(DEFAULT_LIMIT); Integer offsetVal = offset.orElse(DEFAULT_OFFSET); return resultList.stream().skip(offsetVal).limit(limitVal).collect(Collectors.toList()); } @Autowired  ProjectServiceImpl(ProjectRepository projectRepository, Environment env); @Override Iterable<Project> findProjects(final String organizations, final Optional<Integer> limit,
                                          final Optional<Integer> offset, final Optional<Date> startDate, final Optional<Date> endDate,
                                          final Optional<String> sortBy, final Optional<String> query, final Optional<String> language);  }