package eu.dnetlib.openaire.funders; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.openaire.common.AbstractExporterController; import eu.dnetlib.openaire.funders.domain.ExtendedFunderDetails; import eu.dnetlib.openaire.funders.domain.FunderDetails; import eu.dnetlib.openaire.funders.domain.db.FunderDbEntry; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; @RestController @CrossOrigin(origins = { "*" }) @ConditionalOnProperty(value = "openaire.exporter.enable.funders", havingValue = "true") @Tag(name = "OpenAIRE funders API", description = "the OpenAIRE funders API") public class FundersApiController extends AbstractExporterController { private static final Log log = LogFactory.getLog(FundersApiController.class); @Autowired private FunderDao fDao; @RequestMapping(value = "/funders", produces = { "application/json" }, method = RequestMethod.GET) @Operation(value = "get basic information about funders", notes = "basic information about funders: id, name, shortname, last update date, registration date", response = FunderDetails[].class) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK", response = FunderDetails[].class), @ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) }) public List getFunders( @PathVariable final int page, @PathVariable final int size) throws FundersApiException { return fDao.listFunderDetails(page, size); } @RequestMapping(value = "/funder/{id}", produces = { "application/json" }, method = RequestMethod.GET) @Operation(summary = "get the funder details", notes = "complete funder information", response = FunderDbEntry.class) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK", response = FunderDbEntry.class), @ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) }) public ExtendedFunderDetails getFunderDetails( @PathVariable final String id) throws FundersApiException { return fDao.getExtendedFunderDetails(id); } @RequestMapping(value = "/funder/ids", produces = { "application/json" }, method = RequestMethod.GET) @Operation(summary = "get the list of funder ids", notes = "get the list of funder ids", response = String[].class) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK", response = String[].class), @ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) }) public List getFunderIds( @PathVariable final int page, @PathVariable final int size) throws FundersApiException { return fDao.listFunderIds(page, size); } }