use of org.kuali.kfs.kew.useroptions.UserOptions in project cu-kfs by CU-CommunityApps.
the class PreferencesServiceImpl method getPreferences.
public Preferences getPreferences(String principalId) {
if (LOG.isDebugEnabled()) {
LOG.debug("start preferences fetch user " + principalId);
}
Collection<UserOptions> options = getUserOptionService().findByWorkflowUser(principalId);
Map<String, UserOptions> optionMap = new HashMap<>();
Map<String, String> optionValueMap = new HashMap<>();
Map<String, String> documentTypeNotificationPreferences = new HashMap<>();
for (UserOptions option : options) {
if (option.getOptionId().endsWith(KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_SUFFIX)) {
String preferenceName = option.getOptionId();
preferenceName = StringUtils.substringBeforeLast(preferenceName, KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_SUFFIX);
documentTypeNotificationPreferences.put(preferenceName, option.getOptionVal());
} else {
optionMap.put(option.getOptionId(), option);
}
}
ConfigurationService kcs = CoreApiServiceLocator.getKualiConfigurationService();
boolean isSaveRequired = false;
for (Map.Entry<String, String> entry : USER_OPTION_KEY_DEFAULT_MAP.entrySet()) {
String optionKey = entry.getKey();
String defaultValue = kcs.getPropertyValueAsString(entry.getValue());
if (LOG.isDebugEnabled()) {
LOG.debug("start fetch option " + optionKey + " user " + principalId);
}
UserOptions option = optionMap.get(optionKey);
if (option == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("User option '" + optionKey + "' on user " + principalId + " has no stored value. Preferences will require save.");
}
option = new UserOptions();
option.setWorkflowId(principalId);
option.setOptionId(optionKey);
option.setOptionVal(defaultValue);
// just in case referenced a second time
optionMap.put(optionKey, option);
if (!isSaveRequired) {
if (!optionKey.equals(Preferences.KEYS.USE_OUT_BOX) || ConfigContext.getCurrentContextConfig().getOutBoxOn()) {
isSaveRequired = true;
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("End fetch option " + optionKey + " user " + principalId);
}
optionValueMap.put(optionKey, option.getOptionVal());
}
return Preferences.Builder.create(optionValueMap, documentTypeNotificationPreferences, isSaveRequired).build();
}
Aggregations