use of org.bedework.calfacade.svc.prefs.BwCommonUserPrefs in project bw-calendar-engine by Bedework.
the class Preferences method updateAdminPrefs.
/* (non-Javadoc)
* @see org.bedework.calsvci.PreferencesI#updateAdminPrefs(boolean, org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwCategory, org.bedework.calfacade.BwLocation, org.bedework.calfacade.BwContact)
*/
public void updateAdminPrefs(final boolean remove, final BwCalendar cal, final Collection<BwCategory> cats, final BwLocation loc, final BwContact ctct) throws CalFacadeException {
BwCommonUserPrefs prefs = null;
boolean update = false;
BwAuthUser au = null;
if (getPars().getPublicAdmin()) {
au = getSvc().getUserAuth().getUser(getPars().getAuthUser());
if (au != null) {
prefs = au.getPrefs();
}
}
if (prefs == null) {
// XXX until we get non admin user preferred calendars etc
return;
}
if (cal != null) {
if (!remove) {
if (cal.getCalendarCollection()) {
CalendarPref p = prefs.getCalendarPrefs();
if (p.getAutoAdd() && p.add(cal)) {
update = true;
}
}
} else {
getSvc().removeFromAllPrefs(cal);
}
}
if (!Util.isEmpty(cats)) {
for (final BwCategory cat : cats) {
if (!remove) {
CategoryPref p = prefs.getCategoryPrefs();
if (p.getAutoAdd() && p.add(cat)) {
update = true;
}
} else {
getSvc().removeFromAllPrefs(cat);
}
}
}
if (loc != null) {
if (!remove) {
LocationPref p = prefs.getLocationPrefs();
if (p.getAutoAdd() && p.add(loc)) {
update = true;
}
} else {
getSvc().removeFromAllPrefs(loc);
}
}
if (ctct != null) {
if (!remove) {
ContactPref p = prefs.getContactPrefs();
if (p.getAutoAdd() && p.add(ctct)) {
update = true;
}
} else {
getSvc().removeFromAllPrefs(ctct);
}
}
if (update) {
if (getPars().getPublicAdmin()) {
getSvc().getUserAuth().updateUser(au);
}
}
}
Aggregations