76 lines
2.4 KiB
Java
76 lines
2.4 KiB
Java
package eu.dnetlib.apps.oai2ftp.controller;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import eu.dnetlib.apps.oai2ftp.model.CollectionInfo;
|
|
import eu.dnetlib.apps.oai2ftp.service.Oai2FtpService;
|
|
|
|
@RestController
|
|
@RequestMapping("/api")
|
|
public class Oai2FtpController {
|
|
|
|
private static final Log log = LogFactory.getLog(Oai2FtpController.class);
|
|
|
|
@Autowired
|
|
private Oai2FtpService service;
|
|
|
|
@GetMapping("/collect")
|
|
public CollectionInfo startCollection(@RequestParam final String oaiBaseUrl,
|
|
@RequestParam(required = false, defaultValue = "oai_dc") final String oaiFormat,
|
|
@RequestParam(required = false) final String oaiSet,
|
|
@RequestParam(required = false) final LocalDateTime oaiFrom,
|
|
@RequestParam(required = false) final LocalDateTime oaiUntil) {
|
|
return service.startCollection(oaiBaseUrl, oaiFormat, oaiSet, oaiFrom, oaiUntil);
|
|
}
|
|
|
|
@GetMapping("/status/{id}")
|
|
public CollectionInfo getExecutionStatus(@PathVariable final String id) {
|
|
return service.getStatus(id);
|
|
}
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
|
public @ResponseBody ErrorMessage handleException(final Exception e) {
|
|
log.error("Error processing http method", e);
|
|
return new ErrorMessage(e);
|
|
}
|
|
|
|
public class ErrorMessage {
|
|
|
|
private final String message;
|
|
private final String stacktrace;
|
|
|
|
public ErrorMessage(final Exception e) {
|
|
this(e.getMessage(), ExceptionUtils.getStackTrace(e));
|
|
}
|
|
|
|
public ErrorMessage(final String message, final String stacktrace) {
|
|
this.message = message;
|
|
this.stacktrace = stacktrace;
|
|
}
|
|
|
|
public String getMessage() {
|
|
return this.message;
|
|
}
|
|
|
|
public String getStacktrace() {
|
|
return this.stacktrace;
|
|
}
|
|
|
|
}
|
|
}
|