package eu.dnetlib.openaire.funders; import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Component; import eu.dnetlib.openaire.exporter.exceptions.FundersApiException; import eu.dnetlib.openaire.funders.domain.db.FunderDbEntry; @Component @ConditionalOnProperty(value = "openaire.exporter.enable.funders", havingValue = "true") public class FunderDao { @Autowired private FunderRepository funderRepository; public FunderDbEntry findFunder(final String funderId) throws FundersApiException { return funderRepository.findById(funderId).orElseThrow(() -> new FundersApiException("Funder not found. ID: " + funderId)); } public List listFunders(final int page, final int size) throws FundersApiException { return funderRepository.findAll(PageRequest.of(page, size)) .getContent() .stream() .collect(Collectors.toList()); } public List listFunderIds(final int page, final int size) throws FundersApiException { return funderRepository.findAll(PageRequest.of(page, size)) .getContent() .stream() .map(FunderDbEntry::getId) .collect(Collectors.toList()); } }