Search in sources :

Example 1 with ReportService

use of password.pwm.svc.report.ReportService 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 ReportService

use of password.pwm.svc.report.ReportService in project pwm by pwm-project.

the class AdminServlet method processReportData.

@ActionHandler(action = "reportData")
public ProcessStatus processReportData(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
    final int maximum = Math.min(pwmRequest.readParameterAsInt("maximum", 1000), 10 * 1000);
    final ReportService reportService = pwmRequest.getPwmApplication().getReportService();
    final ArrayList<UserCacheRecord> reportData = new ArrayList<>();
    ClosableIterator<UserCacheRecord> cacheBeanIterator = null;
    try {
        cacheBeanIterator = reportService.iterator();
        while (cacheBeanIterator.hasNext() && reportData.size() < maximum) {
            final UserCacheRecord userCacheRecord = cacheBeanIterator.next();
            if (userCacheRecord != null) {
                reportData.add(userCacheRecord);
            }
        }
    } finally {
        if (cacheBeanIterator != null) {
            cacheBeanIterator.close();
        }
    }
    final HashMap<String, Object> returnData = new HashMap<>();
    returnData.put("users", reportData);
    final RestResultBean restResultBean = RestResultBean.withData(returnData);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : UserCacheRecord(password.pwm.svc.report.UserCacheRecord) ReportService(password.pwm.svc.report.ReportService) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

ReportService (password.pwm.svc.report.ReportService)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 PwmApplication (password.pwm.PwmApplication)1 HealthRecord (password.pwm.health.HealthRecord)1 ReportCsvUtility (password.pwm.svc.report.ReportCsvUtility)1 UserCacheRecord (password.pwm.svc.report.UserCacheRecord)1 RestResultBean (password.pwm.ws.server.RestResultBean)1