diff --git a/pom.xml b/pom.xml index 50acf19..a7a5640 100644 --- a/pom.xml +++ b/pom.xml @@ -106,6 +106,7 @@ org.springframework.boot spring-boot-configuration-processor + true org.apache.solr diff --git a/src/main/java/eu/openaire/api/controllers/ScholixController.java b/src/main/java/eu/openaire/api/controllers/ScholixController.java index cc03a73..92641a9 100644 --- a/src/main/java/eu/openaire/api/controllers/ScholixController.java +++ b/src/main/java/eu/openaire/api/controllers/ScholixController.java @@ -1,8 +1,6 @@ package eu.openaire.api.controllers; -import eu.dnetlib.dhp.oa.model.graph.Datasource; import eu.dnetlib.dhp.schema.sx.api.model.v2.PageResultType; -import eu.openaire.api.dto.request.validators.AllowableFieldsValidator; import eu.openaire.api.dto.request.validators.PaginationValidator; import eu.openaire.api.errors.ErrorResponse; import eu.openaire.api.services.ScholixService; @@ -17,43 +15,37 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.InitBinder; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/relations") @RequiredArgsConstructor -@Tag(name = "Scholix Relations", description = "API endpoints to explore scholix relations") +@Tag(name = "Scholix Relations", description = "API endpoints to explore scholix") public class ScholixController { private final ScholixService scholixService; - - // common validator to check api allowable fields - private final AllowableFieldsValidator allowableFieldsValidator; - - // common validator to check pagination parameters private final PaginationValidator paginationValidator; @InitBinder protected void initBinder(WebDataBinder binder) { - binder.addValidators(allowableFieldsValidator, paginationValidator); + binder.addValidators(paginationValidator); } @Operation( - summary = "Retrieve scholix links by sourcePid and sourceType", - description = "Retrieve scholix links by sourcePid and sourceType" - ) + summary = "Retrieve scholix links by openaire id", + description = "Retrieve scholix links by openaire id") @ApiResponses({ - @ApiResponse(responseCode = "200", content = { @Content(schema = @Schema(implementation = Datasource.class), mediaType = "application/json") }), + @ApiResponse(responseCode = "200", content = { @Content(schema = @Schema(implementation = PageResultType.class), mediaType = "application/json") }), @ApiResponse(responseCode = "404", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") }), @ApiResponse(responseCode = "500", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") }) }) - @GetMapping - public PageResultType getRelationships(@RequestParam @Parameter(description = "The OpenAIRE ID") String sourcePid, - @RequestParam(required = false) @Parameter(description = "The Source Type") String sourceType, - @RequestParam(required = true, defaultValue = "0") - @Parameter(description = "Page number of the results") int page) { + @GetMapping("links") + public PageResultType getLinks( + @RequestParam + @Parameter(description = "The OpenAIRE ID") String openaireId, - return scholixService.getLinks(sourcePid, sourceType, page); + @RequestParam(defaultValue = "0") + @Parameter(description = "Page number of the results") int page) { + + return scholixService.getLinks(openaireId, page); } } diff --git a/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java b/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java index 97e4ade..3616da5 100644 --- a/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java +++ b/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java @@ -5,12 +5,10 @@ import eu.openaire.api.errors.exceptions.NotFoundException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.client.RestClientResponseException; import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.resource.NoResourceFoundException; @@ -62,22 +60,6 @@ public class ServiceExceptionHandler { return this.handleException(e.getMessage(), request, HttpStatus.INTERNAL_SERVER_ERROR); } - @ExceptionHandler(RestClientResponseException.class) - public ResponseEntity handleRestClientResponseException(RestClientResponseException e, WebRequest request) { - HttpStatusCode status = e.getStatusCode(); - String path = ((ServletWebRequest) request).getRequest().getRequestURI(); - - ErrorResponse response = ErrorResponse.builder() - .message(e.getMessage()) - .error(status.toString()) - .code(status.value()) - .timestamp(new Date()) - .path(path) - .build(); - - return ResponseEntity.status(status.value()).body(response); - } - private ResponseEntity handleException(String message, WebRequest request, HttpStatus httpStatus) { var req = ((ServletWebRequest)request).getRequest(); String path = String.format("%s?%s", req.getRequestURI(), req.getQueryString()); diff --git a/src/main/java/eu/openaire/api/services/ScholixService.java b/src/main/java/eu/openaire/api/services/ScholixService.java index 14da114..186e467 100644 --- a/src/main/java/eu/openaire/api/services/ScholixService.java +++ b/src/main/java/eu/openaire/api/services/ScholixService.java @@ -14,24 +14,26 @@ public class ScholixService { private final RestClient restClient; private final Logger log = LogManager.getLogger(this.getClass()); + private static final String V2_OPENAIRE_LINKS_PATH = "v2/OpenAIRELinks"; + private static final String OPENAIRE_ID_PREFIX = "50|"; @Timed - public PageResultType getLinks(String sourcePid, String sourceType, int page) { + public PageResultType getLinks(String sourcePid, int page) { try { - PageResultType pageResultType = new PageResultType(); + PageResultType pageResultType; pageResultType = restClient.get() .uri(uriBuilder -> uriBuilder - .path("/v2/Links") //v2/OpenAIRELinks - .queryParam("sourcePid", sourcePid) - .queryParam("sourceType", sourceType) + .path(V2_OPENAIRE_LINKS_PATH) + .queryParam("sourcePid", OPENAIRE_ID_PREFIX + sourcePid) .queryParam("page", page) .build()) .retrieve() .body(PageResultType.class); return pageResultType; } catch (Exception e) { - throw new RuntimeException("Unexpected error: " + e.getMessage(), e); + log.error(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } }