Search in sources :

Example 1 with ReportStatusInfo

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

the class ReportStatusBean method makeReportStatusData.

public static ReportStatusBean makeReportStatusData(final ReportService reportService, final Locale locale) throws LocalDBException {
    final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
    final ReportStatusBean returnMap = new ReportStatusBean();
    final ReportStatusInfo reportInfo = reportService.getReportStatusInfo();
    final LinkedHashMap<String, Object> presentableMap = new LinkedHashMap<>();
    final Set<ReportService.ReportCommand> availableCommands = new HashSet<>();
    presentableMap.put("Job Engine", reportInfo.getCurrentProcess().getLabel());
    switch(reportInfo.getCurrentProcess()) {
        case RollOver:
            {
                presentableMap.put("Users Processed", numberFormat.format(reportService.getSummaryData().getTotalUsers()) + " of " + numberFormat.format(reportService.getTotalRecords()));
                availableCommands.add(ReportService.ReportCommand.Stop);
            }
            break;
        case ReadData:
            {
                presentableMap.put("Users Processed", numberFormat.format(reportInfo.getCount()));
                presentableMap.put("Users Remaining", numberFormat.format(reportService.getWorkQueueSize()));
                if (reportInfo.getJobDuration() != null) {
                    presentableMap.put("Job Time", reportInfo.getJobDuration().asLongString(locale));
                }
                if (reportInfo.getCount() > 0) {
                    final BigDecimal eventRate = reportService.getEventRate().setScale(2, RoundingMode.UP);
                    presentableMap.put("Users/Second", eventRate);
                    if (!eventRate.equals(BigDecimal.ZERO)) {
                        final int usersRemaining = reportService.getWorkQueueSize();
                        final float secondsRemaining = usersRemaining / eventRate.floatValue();
                        final TimeDuration remainingDuration = new TimeDuration(((int) secondsRemaining) * 1000);
                        presentableMap.put("Estimated Time Remaining", remainingDuration.asLongString(locale));
                    }
                }
                availableCommands.add(ReportService.ReportCommand.Stop);
            }
            break;
        case None:
            {
                if (reportInfo.getFinishDate() != null) {
                    presentableMap.put("Last Job Completed", reportInfo.getFinishDate());
                }
                availableCommands.add(ReportService.ReportCommand.Start);
                if (reportService.getTotalRecords() > 0) {
                    availableCommands.add(ReportService.ReportCommand.Clear);
                }
            }
            break;
        default:
            break;
    }
    {
        if (reportInfo.getErrors() > 0) {
            presentableMap.put("Error Count", numberFormat.format(reportInfo.getErrors()));
        }
        if (reportInfo.getLastError() != null) {
            presentableMap.put("Last Error", reportInfo.getLastError().toDebugStr());
        }
        final int totalRecords = reportService.getTotalRecords();
        presentableMap.put("Records in Cache", numberFormat.format(totalRecords));
        if (totalRecords > 0) {
            presentableMap.put("Mean Record Cache Time", reportService.getSummaryData().getMeanCacheTime());
        }
    }
    returnMap.setControllable(true);
    returnMap.setRaw(reportInfo);
    returnMap.setPresentable(presentableMap);
    returnMap.setAvailableCommands(availableCommands);
    return returnMap;
}
Also used : PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) ReportStatusInfo(password.pwm.svc.report.ReportStatusInfo) TimeDuration(password.pwm.util.java.TimeDuration) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Aggregations

BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ReportStatusInfo (password.pwm.svc.report.ReportStatusInfo)1 PwmNumberFormat (password.pwm.util.java.PwmNumberFormat)1 TimeDuration (password.pwm.util.java.TimeDuration)1