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