use of password.pwm.svc.report.ReportCsvUtility in project pwm by pwm-project.
the class UserReportCommand method doCommand.
@Override
@SuppressFBWarnings("DM_EXIT")
void doCommand() throws Exception {
final File outputFile = (File) cliEnvironment.getOptions().get(OUTPUT_FILE_OPTIONNAME);
try (OutputStream outputFileStream = new BufferedOutputStream(new FileOutputStream(outputFile))) {
final PwmApplication pwmApplication = cliEnvironment.getPwmApplication();
final ReportService userReport = pwmApplication.getReportService();
if (userReport.status() != PwmService.STATUS.OPEN) {
out("report service is not open or enabled");
final List<HealthRecord> healthIssues = userReport.healthCheck();
if (healthIssues != null) {
for (final HealthRecord record : healthIssues) {
out("report health status: " + record.toDebugString(Locale.getDefault(), pwmApplication.getConfig()));
}
}
return;
}
final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
reportCsvUtility.outputToCsv(outputFileStream, true, PwmConstants.DEFAULT_LOCALE);
} catch (IOException e) {
out("unable to open file '" + outputFile.getAbsolutePath() + "' for writing");
System.exit(-1);
throw new Exception();
}
out("report output complete.");
}
use of password.pwm.svc.report.ReportCsvUtility in project pwm by pwm-project.
the class AdminServlet method downloadUserSummaryCsv.
@ActionHandler(action = "downloadUserSummaryCsv")
private ProcessStatus downloadUserSummaryCsv(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
pwmRequest.getPwmResponse().markAsDownload(HttpContentType.csv, pwmApplication.getConfig().readAppProperty(AppProperty.DOWNLOAD_FILENAME_USER_REPORT_SUMMARY_CSV));
final OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream();
try {
final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
reportCsvUtility.outputSummaryToCsv(outputStream, pwmRequest.getLocale());
} catch (Exception e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
pwmRequest.respondWithError(errorInformation);
} finally {
outputStream.close();
}
return ProcessStatus.Halt;
}
use of password.pwm.svc.report.ReportCsvUtility in project pwm by pwm-project.
the class AdminServlet method downloadUserReportCsv.
@ActionHandler(action = "downloadUserReportCsv")
private ProcessStatus downloadUserReportCsv(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
pwmRequest.getPwmResponse().markAsDownload(HttpContentType.csv, pwmApplication.getConfig().readAppProperty(AppProperty.DOWNLOAD_FILENAME_USER_REPORT_RECORDS_CSV));
final OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream();
try {
final String selectedColumns = pwmRequest.readParameterAsString("selectedColumns", "");
final ReportColumnFilter columnFilter = ReportUtils.toReportColumnFilter(selectedColumns);
final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
reportCsvUtility.outputToCsv(outputStream, true, pwmRequest.getLocale(), columnFilter);
} catch (Exception e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
pwmRequest.respondWithError(errorInformation);
} finally {
outputStream.close();
}
return ProcessStatus.Halt;
}
Aggregations