use of password.pwm.util.java.Percent in project pwm by pwm-project.
the class LocalDBLoggerTest method figureEventsInDbStat.
private String figureEventsInDbStat() {
final long maxEvents = config.readSettingAsLong(PwmSetting.EVENTS_PWMDB_MAX_EVENTS);
final long eventCount = localDBLogger.getStoredEventCount();
final Percent percent = new Percent(eventCount, maxEvents);
return numberFormat.format(localDBLogger.getStoredEventCount()) + "/" + numberFormat.format(maxEvents) + " (" + percent.pretty(2) + ")";
}
use of password.pwm.util.java.Percent in project pwm by pwm-project.
the class NewUserServlet method restCheckProgress.
@ActionHandler(action = "checkProgress")
private ProcessStatus restCheckProgress(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final NewUserBean newUserBean = getNewUserBean(pwmRequest);
final Instant startTime = newUserBean.getCreateStartTime();
if (startTime == null) {
pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
return ProcessStatus.Halt;
}
final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
final Instant completeTime = Instant.ofEpochMilli(startTime.toEpochMilli() + minWaitTime);
final BigDecimal percentComplete;
final boolean complete;
// be sure minimum wait time has passed
if (Instant.now().isAfter(completeTime)) {
percentComplete = new BigDecimal("100");
complete = true;
} else {
final TimeDuration elapsedTime = TimeDuration.fromCurrent(startTime);
complete = false;
percentComplete = new Percent(elapsedTime.getTotalMilliseconds(), minWaitTime).asBigDecimal();
}
final LinkedHashMap<String, Object> outputMap = new LinkedHashMap<>();
outputMap.put("percentComplete", percentComplete);
outputMap.put("complete", complete);
final RestResultBean restResultBean = RestResultBean.withData(outputMap);
LOGGER.trace(pwmRequest, "returning result for restCheckProgress: " + JsonUtil.serialize(restResultBean));
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
Aggregations