Search in sources :

Example 1 with BwCommonUserPrefs

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);
        }
    }
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) CategoryPref(org.bedework.calfacade.svc.prefs.CategoryPref) ContactPref(org.bedework.calfacade.svc.prefs.ContactPref) BwCommonUserPrefs(org.bedework.calfacade.svc.prefs.BwCommonUserPrefs) CalendarPref(org.bedework.calfacade.svc.prefs.CalendarPref) BwCategory(org.bedework.calfacade.BwCategory) LocationPref(org.bedework.calfacade.svc.prefs.LocationPref)

Aggregations

BwCategory (org.bedework.calfacade.BwCategory)1 BwAuthUser (org.bedework.calfacade.svc.BwAuthUser)1 BwCommonUserPrefs (org.bedework.calfacade.svc.prefs.BwCommonUserPrefs)1 CalendarPref (org.bedework.calfacade.svc.prefs.CalendarPref)1 CategoryPref (org.bedework.calfacade.svc.prefs.CategoryPref)1 ContactPref (org.bedework.calfacade.svc.prefs.ContactPref)1 LocationPref (org.bedework.calfacade.svc.prefs.LocationPref)1