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);
}
}
Aggregations