9720: call to v2/OpenAIRELinks
This commit is contained in:
parent
33f6b8469f
commit
10bc85e54c
1
pom.xml
1
pom.xml
|
@ -106,6 +106,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.solr</groupId>
|
<groupId>org.apache.solr</groupId>
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package eu.openaire.api.controllers;
|
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.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.dto.request.validators.PaginationValidator;
|
||||||
import eu.openaire.api.errors.ErrorResponse;
|
import eu.openaire.api.errors.ErrorResponse;
|
||||||
import eu.openaire.api.services.ScholixService;
|
import eu.openaire.api.services.ScholixService;
|
||||||
|
@ -17,43 +15,37 @@ import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.InitBinder;
|
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.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/relations")
|
|
||||||
@RequiredArgsConstructor
|
@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 {
|
public class ScholixController {
|
||||||
private final ScholixService scholixService;
|
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;
|
private final PaginationValidator paginationValidator;
|
||||||
|
|
||||||
@InitBinder
|
@InitBinder
|
||||||
protected void initBinder(WebDataBinder binder) {
|
protected void initBinder(WebDataBinder binder) {
|
||||||
binder.addValidators(allowableFieldsValidator, paginationValidator);
|
binder.addValidators(paginationValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Retrieve scholix links by sourcePid and sourceType",
|
summary = "Retrieve scholix links by openaire id",
|
||||||
description = "Retrieve scholix links by sourcePid and sourceType"
|
description = "Retrieve scholix links by openaire id")
|
||||||
)
|
|
||||||
@ApiResponses({
|
@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 = "404", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") }),
|
||||||
@ApiResponse(responseCode = "500", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") })
|
@ApiResponse(responseCode = "500", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") })
|
||||||
})
|
})
|
||||||
@GetMapping
|
@GetMapping("links")
|
||||||
public PageResultType getRelationships(@RequestParam @Parameter(description = "The OpenAIRE ID") String sourcePid,
|
public PageResultType getLinks(
|
||||||
@RequestParam(required = false) @Parameter(description = "The Source Type") String sourceType,
|
@RequestParam
|
||||||
@RequestParam(required = true, defaultValue = "0")
|
@Parameter(description = "The OpenAIRE ID") String openaireId,
|
||||||
@Parameter(description = "Page number of the results") int page) {
|
|
||||||
|
|
||||||
return scholixService.getLinks(sourcePid, sourceType, page);
|
@RequestParam(defaultValue = "0")
|
||||||
|
@Parameter(description = "Page number of the results") int page) {
|
||||||
|
|
||||||
|
return scholixService.getLinks(openaireId, page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,10 @@ import eu.openaire.api.errors.exceptions.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.HttpStatusCode;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
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.ServletWebRequest;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
||||||
|
@ -62,22 +60,6 @@ public class ServiceExceptionHandler {
|
||||||
return this.handleException(e.getMessage(), request, HttpStatus.INTERNAL_SERVER_ERROR);
|
return this.handleException(e.getMessage(), request, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(RestClientResponseException.class)
|
|
||||||
public ResponseEntity<ErrorResponse> 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<ErrorResponse> handleException(String message, WebRequest request, HttpStatus httpStatus) {
|
private ResponseEntity<ErrorResponse> handleException(String message, WebRequest request, HttpStatus httpStatus) {
|
||||||
var req = ((ServletWebRequest)request).getRequest();
|
var req = ((ServletWebRequest)request).getRequest();
|
||||||
String path = String.format("%s?%s", req.getRequestURI(), req.getQueryString());
|
String path = String.format("%s?%s", req.getRequestURI(), req.getQueryString());
|
||||||
|
|
|
@ -14,24 +14,26 @@ public class ScholixService {
|
||||||
|
|
||||||
private final RestClient restClient;
|
private final RestClient restClient;
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
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
|
@Timed
|
||||||
public PageResultType getLinks(String sourcePid, String sourceType, int page) {
|
public PageResultType getLinks(String sourcePid, int page) {
|
||||||
try {
|
try {
|
||||||
PageResultType pageResultType = new PageResultType();
|
PageResultType pageResultType;
|
||||||
|
|
||||||
pageResultType = restClient.get()
|
pageResultType = restClient.get()
|
||||||
.uri(uriBuilder -> uriBuilder
|
.uri(uriBuilder -> uriBuilder
|
||||||
.path("/v2/Links") //v2/OpenAIRELinks
|
.path(V2_OPENAIRE_LINKS_PATH)
|
||||||
.queryParam("sourcePid", sourcePid)
|
.queryParam("sourcePid", OPENAIRE_ID_PREFIX + sourcePid)
|
||||||
.queryParam("sourceType", sourceType)
|
|
||||||
.queryParam("page", page)
|
.queryParam("page", page)
|
||||||
.build())
|
.build())
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.body(PageResultType.class);
|
.body(PageResultType.class);
|
||||||
return pageResultType;
|
return pageResultType;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
|
log.error(e.getMessage());
|
||||||
|
throw new RuntimeException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue