dnet-applications/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/funders/FunderDao.java

41 lines
1.3 KiB
Java
Raw Normal View History

2022-02-04 10:12:15 +01:00
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;
2024-01-29 15:01:03 +01:00
import eu.dnetlib.openaire.funders.domain.db.FunderDbEntry;
2022-02-07 10:09:18 +01:00
2022-02-04 10:12:15 +01:00
@Component
@ConditionalOnProperty(value = "openaire.exporter.enable.funders", havingValue = "true")
public class FunderDao {
@Autowired
private FunderRepository funderRepository;
2024-01-29 15:01:03 +01:00
public FunderDbEntry findFunder(final String funderId) throws FundersApiException {
return funderRepository.findById(funderId).orElseThrow(() -> new FundersApiException("Funder not found. ID: " + funderId));
2022-02-04 10:12:15 +01:00
}
2024-01-29 15:01:03 +01:00
public List<FunderDbEntry> listFunders(final int page, final int size) throws FundersApiException {
2022-02-04 10:12:15 +01:00
return funderRepository.findAll(PageRequest.of(page, size))
2024-01-29 15:01:03 +01:00
.getContent()
.stream()
.collect(Collectors.toList());
2022-02-04 10:12:15 +01:00
}
public List<String> listFunderIds(final int page, final int size) throws FundersApiException {
return funderRepository.findAll(PageRequest.of(page, size))
2024-01-29 15:01:03 +01:00
.getContent()
.stream()
.map(FunderDbEntry::getId)
.collect(Collectors.toList());
2022-02-04 10:12:15 +01:00
}
}