class 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 public  ProjectServiceImpl(ProjectRepository projectRepository, Environment env);

}