class CompetitionSearchPopulator {

    public CompetitionSearchViewModel createItemSearchViewModel(Optional<Long> innovationAreaId, Optional<String> keywords, Optional<Integer> pageNumber) {
        CompetitionSearchViewModel viewModel = new CompetitionSearchViewModel();
        viewModel.setInnovationAreas(categoryRestService.getInnovationAreas().getSuccess());

        PublicContentItemPageResource pageResource = publicContentItemRestService.getByFilterValues(
                innovationAreaId,
                keywords,
                pageNumber,
                CompetitionSearchViewModel.PAGE_SIZE).getSuccess();

        innovationAreaId.ifPresent(viewModel::setSelectedInnovationAreaId);
        keywords.ifPresent(viewModel::setSearchKeywords);

        if (pageNumber.isPresent()) {
            viewModel.setPageNumber(pageNumber.get());
        } else {
            viewModel.setPageNumber(0);
        }

        viewModel.setPublicContentItems(pageResource.getContent().stream()
                .map(this::createPublicContentItemViewModel).collect(Collectors.toList()));
        viewModel.setTotalResults(pageResource.getTotalElements());
        viewModel.setNextPageLink(createPageLink(innovationAreaId, keywords, pageNumber, 1));
        viewModel.setPreviousPageLink(createPageLink(innovationAreaId, keywords, pageNumber, -1));

        return viewModel;
    }

}