use of password.pwm.svc.wordlist.StoredWordlistDataBean in project pwm by pwm-project.
the class ConfigManagerWordlistServlet method restReadWordlistData.
void restReadWordlistData(final PwmRequest pwmRequest) throws IOException {
final LinkedHashMap<WordlistType, WordlistDataBean> outputData = new LinkedHashMap<>();
final NumberFormat numberFormat = NumberFormat.getInstance(pwmRequest.getLocale());
for (final WordlistType wordlistType : WordlistType.values()) {
final Wordlist wordlist = wordlistType.forType(pwmRequest.getPwmApplication());
final StoredWordlistDataBean storedWordlistDataBean = wordlist.readMetadata();
final WordlistConfiguration wordlistConfiguration = wordlistType.forType(pwmRequest.getPwmApplication()).getConfiguration();
final WordlistDataBean wordlistDataBean = new WordlistDataBean();
{
final Map<String, String> presentableValues = new LinkedHashMap<>();
presentableValues.put("Population Status", storedWordlistDataBean.isCompleted() ? "Completed" : "In-Progress");
presentableValues.put("List Source", storedWordlistDataBean.getSource() == null ? StoredWordlistDataBean.Source.BuiltIn.getLabel() : storedWordlistDataBean.getSource().getLabel());
if (wordlistConfiguration.getAutoImportUrl() != null) {
presentableValues.put("Configured Source URL", wordlistConfiguration.getAutoImportUrl());
}
if (storedWordlistDataBean.isCompleted()) {
presentableValues.put("Word Count", numberFormat.format(storedWordlistDataBean.getSize()));
if (StoredWordlistDataBean.Source.BuiltIn != storedWordlistDataBean.getSource()) {
presentableValues.put("Population Timestamp", JavaHelper.toIsoDate(storedWordlistDataBean.getStoreDate()));
}
presentableValues.put("SHA1 Checksum Hash", storedWordlistDataBean.getSha1hash());
}
if (wordlist.getAutoImportError() != null) {
presentableValues.put("Error During Import", wordlist.getAutoImportError().getDetailedErrorMsg());
presentableValues.put("Last Import Attempt", JavaHelper.toIsoDate(wordlist.getAutoImportError().getDate()));
}
wordlistDataBean.getPresentableData().putAll(presentableValues);
}
if (storedWordlistDataBean.isCompleted()) {
if (wordlistConfiguration.getAutoImportUrl() == null) {
wordlistDataBean.setAllowUpload(true);
}
if (wordlistConfiguration.getAutoImportUrl() != null || storedWordlistDataBean.getSource() != StoredWordlistDataBean.Source.BuiltIn) {
wordlistDataBean.setAllowClear(true);
}
}
outputData.put(wordlistType, wordlistDataBean);
}
pwmRequest.outputJsonResult(RestResultBean.withData(outputData));
}
Aggregations