@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_DELETE + "')")
@Override
public List<BatchResponseItem> deleteExecutions(
final String key,
final Date startedBefore, final Date startedAfter, final Date endedBefore, final Date endedAfter) {
Report report = reportDAO.find(key);
if (report == null) {
throw new NotFoundException("Report " + key);
}
List<BatchResponseItem> batchResponseItems = new ArrayList<>();
reportExecDAO.findAll(report, startedBefore, startedAfter, endedBefore, endedAfter).forEach(exec -> {
BatchResponseItem item = new BatchResponseItem();
item.getHeaders().put(RESTHeaders.RESOURCE_KEY, Arrays.asList(exec.getKey()));
batchResponseItems.add(item);
try {
reportExecDAO.delete(exec);
item.setStatus(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error deleting execution {} of report {}", exec.getKey(), key, e);
item.setStatus(Response.Status.BAD_REQUEST.getStatusCode());
item.setContent(ExceptionUtils2.getFullStackTrace(e));
}
});
return batchResponseItems;
}