Search in sources :

Example 1 with PersistedLog

use of org.eclipse.openvsx.entities.PersistedLog in project openvsx by eclipse.

the class AdminAPI method getLog.

@GetMapping(path = "/admin/log", produces = MediaType.TEXT_PLAIN_VALUE)
public String getLog(@RequestParam(name = "period", required = false) String periodString) {
    try {
        admins.checkAdminUser();
        Streamable<PersistedLog> logs;
        if (Strings.isNullOrEmpty(periodString)) {
            logs = repositories.findAllPersistedLogs();
        } else {
            try {
                var period = Period.parse(periodString);
                var now = TimeUtil.getCurrentUTC();
                logs = repositories.findPersistedLogsAfter(now.minus(period));
            } catch (DateTimeParseException exc) {
                throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid period");
            }
        }
        return logs.stream().map(this::toString).collect(Collectors.joining("\n")) + "\n";
    } catch (ErrorResultException exc) {
        var status = exc.getStatus() != null ? exc.getStatus() : HttpStatus.BAD_REQUEST;
        throw new ResponseStatusException(status);
    }
}
Also used : ErrorResultException(org.eclipse.openvsx.util.ErrorResultException) DateTimeParseException(java.time.format.DateTimeParseException) PersistedLog(org.eclipse.openvsx.entities.PersistedLog) ResponseStatusException(org.springframework.web.server.ResponseStatusException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

DateTimeParseException (java.time.format.DateTimeParseException)1 PersistedLog (org.eclipse.openvsx.entities.PersistedLog)1 ErrorResultException (org.eclipse.openvsx.util.ErrorResultException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1