private void saveUserFavorites(String userId, UserFavorites favorites) throws PermissionException, InUseException, IdUnusedException, PortalHandlerException { if (userId == null) { return; } PreferencesEdit edit = PreferencesService.edit(userId); ResourcePropertiesEdit props = edit.getPropertiesEdit(org.sakaiproject.user.api.PreferencesService.SITENAV_PREFS_KEY); // Replace all existing values props.removeProperty(FAVORITES_PROPERTY); for (String siteId : favorites.favoriteSiteIds) { props.addPropertyToList(FAVORITES_PROPERTY, siteId); } props.removeProperty(AUTO_FAVORITE_ENABLED_PROPERTY); props.addProperty(AUTO_FAVORITE_ENABLED_PROPERTY, String.valueOf(favorites.autoFavoritesEnabled)); PreferencesService.commit(edit); }
props.addPropertyToList(SEEN_SITES_PROPERTY, userSite.getId()); props.addPropertyToList(FAVORITES_PROPERTY, siteId);
private void saveUserFavorites(String userId, UserFavorites favorites) throws PortalHandlerException { if (userId == null) { return; } PreferencesEdit edit = null; try { edit = PreferencesService.edit(userId); ResourcePropertiesEdit props = edit.getPropertiesEdit(org.sakaiproject.user.api.PreferencesService.SITENAV_PREFS_KEY); // Replace all existing values props.removeProperty(FAVORITES_PROPERTY); for (String siteId : favorites.favoriteSiteIds) { props.addPropertyToList(FAVORITES_PROPERTY, siteId); } props.removeProperty(AUTO_FAVORITE_ENABLED_PROPERTY); props.addProperty(AUTO_FAVORITE_ENABLED_PROPERTY, String.valueOf(favorites.autoFavoritesEnabled)); PreferencesService.commit(edit); } catch (PermissionException | InUseException | IdUnusedException e) { log.info("Exception editing user preferences", e); PreferencesService.cancel(edit); } }
props.addPropertyToList(SEEN_SITES_PROPERTY, userSite.getId()); props.addPropertyToList(FAVORITES_PROPERTY, siteId);