Search in sources :

Example 1 with ReportCsvUtility

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.");
}
Also used : PwmApplication(password.pwm.PwmApplication) HealthRecord(password.pwm.health.HealthRecord) ReportService(password.pwm.svc.report.ReportService) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) ReportCsvUtility(password.pwm.svc.report.ReportCsvUtility) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with ReportCsvUtility

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) OutputStream(java.io.OutputStream) ReportCsvUtility(password.pwm.svc.report.ReportCsvUtility) LocalDBException(password.pwm.util.localdb.LocalDBException) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) DatabaseException(password.pwm.util.db.DatabaseException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 3 with ReportCsvUtility

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) OutputStream(java.io.OutputStream) ReportCsvUtility(password.pwm.svc.report.ReportCsvUtility) ReportColumnFilter(password.pwm.svc.report.ReportColumnFilter) LocalDBException(password.pwm.util.localdb.LocalDBException) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) DatabaseException(password.pwm.util.db.DatabaseException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 PwmApplication (password.pwm.PwmApplication)3 ReportCsvUtility (password.pwm.svc.report.ReportCsvUtility)3 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)2 ServletException (javax.servlet.ServletException)2 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmException (password.pwm.error.PwmException)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 DatabaseException (password.pwm.util.db.DatabaseException)2 LocalDBException (password.pwm.util.localdb.LocalDBException)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 HealthRecord (password.pwm.health.HealthRecord)1 ReportColumnFilter (password.pwm.svc.report.ReportColumnFilter)1 ReportService (password.pwm.svc.report.ReportService)1