Skip to content

Commit

Permalink
SAK-49493 Gradebook updated preference handling (#12962)
Browse files Browse the repository at this point in the history
  • Loading branch information
ern committed Dec 18, 2024
1 parent e4c8633 commit ad5c4c3
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,28 @@ public String getUserGbPreference(final String prefName) {
public void setUserGbPreference(final String prefName, final String prefValue) {
final String siteId = getCurrentSiteId();
final String currentUserId = getCurrentUser().getId();
PreferencesEdit prefsEdit = null;
PreferencesEdit preference = null;
try {
prefsEdit = preferencesService.edit(currentUserId);
try {
preference = preferencesService.edit(currentUserId);
} catch (IdUnusedException iue) {
preference = preferencesService.add(currentUserId);
}
} catch (Exception e) {
log.warn("Could not get the preferences for user [{}], {}", currentUserId, e.toString());
}
catch (IdUnusedException e) {

if (preference != null) {
try {
prefsEdit = preferencesService.add(currentUserId);
} catch (PermissionException e1) {
log.warn("setUserGbPreference PermissionException attempting to add prefs for user {}, prefName={}", currentUserId, prefName);
} catch (IdUsedException e1) {
log.warn("setUserGbPreference IdUsedException attempting to add prefs for user {}, prefName={}", currentUserId, prefName);
ResourcePropertiesEdit props = preference.getPropertiesEdit(GB_PREF_KEY + siteId);
props.addProperty(prefName, prefValue);
} catch (Exception e) {
log.warn("Could not set the gb preference for user [{}] locale, {}", currentUserId, e.toString());
preferencesService.cancel(preference);
preference = null; // set to null since it was cancelled, prevents commit in finally
} finally {
if (preference != null) preferencesService.commit(preference);
}
} catch (PermissionException e) {
log.warn("setUserGbPreference PermissionException attempting to edit prefs for user {}, prefName={}", currentUserId, prefName);
} catch (InUseException e) {
log.warn("setUserGbPreference InUseException attempting to edit prefs for user {}, prefName={}", currentUserId, prefName);
}
ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(GB_PREF_KEY + siteId);
props.addProperty(prefName, prefValue);
preferencesService.commit(prefsEdit);
}
}

0 comments on commit ad5c4c3

Please sign in to comment.