partial migration to new openAPI

This commit is contained in:
Michele Artini 2022-08-22 13:03:46 +02:00
parent 9b9d37624c
commit c3d2187257
4 changed files with 46 additions and 32 deletions

View File

@ -9,7 +9,6 @@ import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import eu.dnetlib.DnetOpenaireExporterProperties.Swagger;
import eu.dnetlib.common.app.AbstractDnetApp; import eu.dnetlib.common.app.AbstractDnetApp;
import eu.dnetlib.openaire.community.CommunityApiController; import eu.dnetlib.openaire.community.CommunityApiController;
import eu.dnetlib.openaire.context.ContextApiController; import eu.dnetlib.openaire.context.ContextApiController;
@ -77,7 +76,7 @@ public class DNetOpenaireExporterApplication extends AbstractDnetApp {
return newGroupedOpenApi("OpenAIRE Info", InfoController.class.getPackage().getName()); return newGroupedOpenApi("OpenAIRE Info", InfoController.class.getPackage().getName());
} }
private GroupedOpenApi newGroupedOpenApi(final String groupName, final String controllerPackage, final Swagger swag, final String version) { private GroupedOpenApi newGroupedOpenApi(final String groupName, final String controllerPackage) {
return GroupedOpenApi.builder() return GroupedOpenApi.builder()
.group(groupName) .group(groupName)
.packagesToScan(controllerPackage) .packagesToScan(controllerPackage)

View File

@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.openaire.common.AbstractExporterController; import eu.dnetlib.openaire.common.AbstractExporterController;
import eu.dnetlib.openaire.funders.domain.ExtendedFunderDetails; import eu.dnetlib.openaire.funders.domain.ExtendedFunderDetails;
import eu.dnetlib.openaire.funders.domain.FunderDetails; 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.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.responses.ApiResponses;
@ -37,10 +36,10 @@ public class FundersApiController extends AbstractExporterController {
@RequestMapping(value = "/funders", produces = { @RequestMapping(value = "/funders", produces = {
"application/json" "application/json"
}, method = RequestMethod.GET) }, 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) @Operation(summary = "get basic information about funders", description = "basic information about funders: id, name, shortname, last update date, registration date")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", response = FunderDetails[].class), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public List<FunderDetails> getFunders( public List<FunderDetails> getFunders(
@PathVariable final int page, @PathVariable final int page,
@ -52,10 +51,10 @@ public class FundersApiController extends AbstractExporterController {
@RequestMapping(value = "/funder/{id}", produces = { @RequestMapping(value = "/funder/{id}", produces = {
"application/json" "application/json"
}, method = RequestMethod.GET) }, method = RequestMethod.GET)
@Operation(summary = "get the funder details", notes = "complete funder information", response = FunderDbEntry.class) @Operation(summary = "get the funder details", description = "complete funder information")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", response = FunderDbEntry.class), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public ExtendedFunderDetails getFunderDetails( public ExtendedFunderDetails getFunderDetails(
@PathVariable final String id) throws FundersApiException { @PathVariable final String id) throws FundersApiException {
@ -66,10 +65,10 @@ public class FundersApiController extends AbstractExporterController {
@RequestMapping(value = "/funder/ids", produces = { @RequestMapping(value = "/funder/ids", produces = {
"application/json" "application/json"
}, method = RequestMethod.GET) }, method = RequestMethod.GET)
@Operation(summary = "get the list of funder ids", notes = "get the list of funder ids", response = String[].class) @Operation(summary = "get the list of funder ids", description = "get the list of funder ids")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", response = String[].class), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public List<String> getFunderIds( public List<String> getFunderIds(
@PathVariable final int page, @PathVariable final int page,

View File

@ -35,8 +35,6 @@ import eu.dnetlib.openaire.common.AbstractExporterController;
import eu.dnetlib.openaire.common.ExporterConstants; import eu.dnetlib.openaire.common.ExporterConstants;
import eu.dnetlib.openaire.project.dao.JdbcApiDao; import eu.dnetlib.openaire.project.dao.JdbcApiDao;
import eu.dnetlib.openaire.project.dao.ValueCleaner; import eu.dnetlib.openaire.project.dao.ValueCleaner;
import eu.dnetlib.openaire.project.domain.db.ProjectDetails;
import eu.dnetlib.openaire.project.domain.db.ProjectTsv;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.responses.ApiResponses;
@ -64,12 +62,12 @@ public class ProjectsController extends AbstractExporterController {
private ProjectQueryParamsFactory projectQueryParamsFactory; private ProjectQueryParamsFactory projectQueryParamsFactory;
@RequestMapping(value = "/export/**/project/dspace.do", method = RequestMethod.GET) @RequestMapping(value = "/export/**/project/dspace.do", method = RequestMethod.GET)
@Operation(value = "DSpace", notes = "return project information in compatible with the OpenAIRE plugin for DSpace", tags = { @Operation(summary = "DSpace", description = "return project information in compatible with the OpenAIRE plugin for DSpace", tags = {
ExporterConstants.DSPACE ExporterConstants.DSPACE
}, response = String.class) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", response = String.class), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public void processDspace(final HttpServletRequest request, public void processDspace(final HttpServletRequest request,
final ServletResponse response, final ServletResponse response,
@ -92,12 +90,12 @@ public class ProjectsController extends AbstractExporterController {
} }
@RequestMapping(value = "/export/**/project/eprints.do", method = RequestMethod.GET) @RequestMapping(value = "/export/**/project/eprints.do", method = RequestMethod.GET)
@Operation(value = "EPrints", notes = "return project information in compatible with the OpenAIRE plugin for Eprints", tags = { @Operation(summary = "EPrints", description = "return project information in compatible with the OpenAIRE plugin for Eprints", tags = {
ExporterConstants.EPRINT ExporterConstants.EPRINT
}, response = String.class) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", response = String.class), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public void processEprints(final HttpServletRequest request, public void processEprints(final HttpServletRequest request,
final ServletResponse response, final ServletResponse response,
@ -130,12 +128,12 @@ public class ProjectsController extends AbstractExporterController {
} }
@RequestMapping(value = "/noads/project2tsv.do", method = RequestMethod.GET) @RequestMapping(value = "/noads/project2tsv.do", method = RequestMethod.GET)
@Operation(value = "TSV", notes = "download project information in TSV format", tags = { @Operation(summary = "TSV", description = "download project information in TSV format", tags = {
ExporterConstants.TSV ExporterConstants.TSV
}, response = ProjectTsv[].class) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", response = ProjectTsv[].class), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public void processTsv(final HttpServletResponse response, public void processTsv(final HttpServletResponse response,
@RequestParam(value = "funding", required = true) final String funding, @RequestParam(value = "funding", required = true) final String funding,
@ -155,12 +153,12 @@ public class ProjectsController extends AbstractExporterController {
} }
@RequestMapping(value = "/export/streamProjectDetails.do", method = RequestMethod.GET) @RequestMapping(value = "/export/streamProjectDetails.do", method = RequestMethod.GET)
@Operation(value = "Stream projects", notes = "stream project information", tags = { @Operation(summary = "Stream projects", description = "stream project information", tags = {
ExporterConstants.STREAMING ExporterConstants.STREAMING
}, response = ProjectDetails[].class) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", response = ProjectDetails[].class), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error", response = ErrorMessage.class) @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public void streamProjectDetails(final HttpServletResponse response, public void streamProjectDetails(final HttpServletResponse response,
@RequestParam(value = "format", required = true) final String format, @RequestParam(value = "format", required = true) final String format,

View File

@ -21,6 +21,7 @@ import org.supercsv.io.CsvBeanWriter;
import org.supercsv.io.ICsvBeanReader; import org.supercsv.io.ICsvBeanReader;
import org.supercsv.io.ICsvBeanWriter; import org.supercsv.io.ICsvBeanWriter;
import org.supercsv.prefs.CsvPreference; import org.supercsv.prefs.CsvPreference;
import org.supercsv.util.CsvContext;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -89,7 +90,16 @@ public class ProjectDetails {
public static ProjectDetails fromCSV(final String csv) throws IOException { public static ProjectDetails fromCSV(final String csv) throws IOException {
try (ICsvBeanReader beanReader = new CsvBeanReader(new StringReader(csv), CsvPreference.STANDARD_PREFERENCE)) { try (ICsvBeanReader beanReader = new CsvBeanReader(new StringReader(csv), CsvPreference.STANDARD_PREFERENCE)) {
return beanReader.read(ProjectDetails.class, FIELDS, getProcessors((value, context) -> new Gson().fromJson(value.toString(), List.class))); final CellProcessor cp = new CellProcessor() {
@SuppressWarnings("unchecked")
@Override
public <T> T execute(final Object value, final CsvContext context) {
return (T) new Gson().fromJson(value.toString(), List.class);
}
};
return beanReader.read(ProjectDetails.class, FIELDS, getProcessors(cp));
} }
} }
@ -116,7 +126,15 @@ public class ProjectDetails {
public String asCSV() throws IOException { public String asCSV() throws IOException {
final StringWriter sb = new StringWriter(); final StringWriter sb = new StringWriter();
try (ICsvBeanWriter beanWriter = new CsvBeanWriter(sb, CsvPreference.STANDARD_PREFERENCE)) { try (ICsvBeanWriter beanWriter = new CsvBeanWriter(sb, CsvPreference.STANDARD_PREFERENCE)) {
beanWriter.write(this, FIELDS, getProcessors((value, context) -> new Gson().toJson(value))); final CellProcessor cp = new CellProcessor() {
@SuppressWarnings("unchecked")
@Override
public <T> T execute(final Object value, final CsvContext context) {
return (T) new Gson().toJson(value);
}
};
beanWriter.write(this, FIELDS, getProcessors(cp));
beanWriter.flush(); beanWriter.flush();
} }