Search in sources :

Example 6 with Percent

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) + ")";
}
Also used : Percent(password.pwm.util.java.Percent)

Example 7 with Percent

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;
}
Also used : Percent(password.pwm.util.java.Percent) Instant(java.time.Instant) NewUserProfile(password.pwm.config.profile.NewUserProfile) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) TimeDuration(password.pwm.util.java.TimeDuration) NewUserBean(password.pwm.http.bean.NewUserBean) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

Percent (password.pwm.util.java.Percent)7 Instant (java.time.Instant)3 LinkedHashMap (java.util.LinkedHashMap)3 TimeDuration (password.pwm.util.java.TimeDuration)3 BigDecimal (java.math.BigDecimal)2 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PwmSetting (password.pwm.config.PwmSetting)1 StoredValue (password.pwm.config.StoredValue)1 NewUserProfile (password.pwm.config.profile.NewUserProfile)1 ChallengeItemConfiguration (password.pwm.config.value.data.ChallengeItemConfiguration)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 NewUserBean (password.pwm.http.bean.NewUserBean)1 RestResultBean (password.pwm.ws.server.RestResultBean)1