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

69 lines
3.0 KiB
Java

package eu.dnetlib.openaire.funders;
import java.util.List;
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.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
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.*;
@RestController
@CrossOrigin(origins = { "*" })
@ConditionalOnProperty(value = "openaire.exporter.enable.funders", havingValue = "true")
@io.swagger.annotations.Api(tags = "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<FunderDetails> 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<String> getFunderIds(
@PathVariable final int page,
@PathVariable final int size
) throws FundersApiException {
return fDao.listFunderIds(page, size);
}
}