Search in sources :

Example 11 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class Notifier method processAliasInfo.

private boolean processAliasInfo(final AliasesInfo ai, final String authHref, final ResourceChangeType rc) throws CalFacadeException {
    /* We have to notify the sharee of the change. We do not notify the
       * sharee that made the change.
       */
    final String shareeHref = ai.getPrincipalHref();
    if (shareeHref.equals(authHref) || !ai.getVisible()) {
        // This sharee made the change or the event is not visible to this alias. Do not notify, but process other aliases.
        return checkAliases(ai, authHref, rc);
    }
    boolean processed = false;
    // We need this a lot
    final String colHref = ai.getCollection().getPath();
    // We need to push if this is not the current user
    final boolean doPushPrincipal = !shareeHref.equals(getPrincipalHref());
    try {
        if (doPushPrincipal) {
            pushPrincipal(shareeHref);
        }
        if (debug) {
            trace("Change notification for principal " + shareeHref + " and href " + colHref);
        }
        final BwPreferences p = getSvc().getPrefsHandler().get();
        if ((p != null) && (p.getNoNotifications())) {
            if (debug) {
                trace("Notification for principal " + shareeHref + " is suppressed");
            }
            return checkAliases(ai, authHref, rc);
        }
        /* See if we have any notifications for this entity referenced
       * by the href for the current alias
       *
       */
        NotificationType storedNote = null;
        final String resourceHref = Util.buildPath(false, colHref, "/", ai.getEntityName());
        for (final NotificationType n : getNotes().getMatching(AppleServerTags.resourceChange)) {
            final BaseNotificationType bnt = n.getNotification();
            if (!(bnt instanceof ResourceChangeType)) {
                // Don't know what to do with that
                continue;
            }
            // SCHEMA: encoding is the base 64 encoded href
            if (((ResourceChangeType) bnt).sameHref(resourceHref)) {
                storedNote = n;
                break;
            }
        }
        process: {
            if (storedNote == null) {
                // Choice 1 - Just save a copy of this one with our href
                final ResourceChangeType rcCopy = rc.copyForAlias(colHref);
                rcCopy.setHref(resourceHref);
                final NotificationType note = new NotificationType();
                note.setNotification(rcCopy);
                note.setName(getEncodedUuid());
                getNotes().add(note);
                processed = true;
                break process;
            }
            final ResourceChangeType storedRc = (ResourceChangeType) storedNote.getNotification();
            if (rc.getCreated() != null) {
                // Choice 2 above - update the old one
                storedRc.setCollectionChanges(null);
                storedRc.setDeleted(null);
                storedRc.setCreated(rc.getCreated().copyForAlias(colHref));
                getNotes().update(storedNote);
                processed = true;
                break process;
            }
            if (rc.getDeleted() != null) {
                if (storedRc.getCreated() != null) {
                    // Choice 3 above - discard both
                    getNotes().remove(storedNote);
                    processed = true;
                    break process;
                }
                // Choice 4 above - discard updates
                storedRc.setCollectionChanges(null);
                storedRc.setDeleted(rc.getDeleted().copyForAlias(colHref));
                storedRc.clearUpdated();
                getNotes().update(storedNote);
                processed = true;
                break process;
            }
            if (storedRc.getCreated() != null) {
                // Choice 5 above - discard new updates
                break process;
            }
            if (!Util.isEmpty(rc.getUpdated())) {
                // Choices 6 and 7 above
                storedRc.setDeleted(null);
                storedRc.setCreated(null);
                storedRc.setCollectionChanges(null);
                for (final UpdatedType u : rc.getUpdated()) {
                    storedRc.addUpdate(u.copyForAlias(colHref));
                }
                getNotes().update(storedNote);
                processed = true;
            }
        }
    // process:
    } finally {
        if (doPushPrincipal) {
            popPrincipal();
        }
    }
    if (checkAliases(ai, authHref, rc)) {
        processed = true;
    }
    return processed;
}
Also used : BaseNotificationType(org.bedework.caldav.util.notifications.BaseNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType) BwPreferences(org.bedework.calfacade.svc.BwPreferences) ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType) UpdatedType(org.bedework.caldav.util.notifications.UpdatedType) AdminNotificationType(org.bedework.caldav.util.notifications.admin.AdminNotificationType) BaseNotificationType(org.bedework.caldav.util.notifications.BaseNotificationType) SuggestResponseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) ApprovalResponseNotificationType(org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType) SuggestNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestNotificationType) AwaitingApprovalNotificationType(org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)

Example 12 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class PrincipalsAndPrefsDAO method getPreferences.

public BwPreferences getPreferences(final String principalHref) throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(getOwnerPreferencesQuery);
    sess.setString("ownerHref", principalHref);
    sess.cacheableQuery();
    return (BwPreferences) sess.getUnique();
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwPreferences(org.bedework.calfacade.svc.BwPreferences)

Example 13 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class RestorePrincipal method doRestore.

/**
 * Restore everything owned by this principal
 *
 * @throws CalFacadeException on error
 */
public boolean doRestore() throws CalFacadeException {
    try {
        final String prPath = topPath();
        final File pdir = Utils.directory(prPath);
        if (pdir == null) {
            addInfo("No user data found at " + prPath);
            return false;
        }
        final XmlFile prXml = new XmlFile(pdir, "principal.xml", false);
        final XmlFile prefsXml = new XmlFile(pdir, "preferences.xml", false);
        final BwPrincipal pr = fxml.fromXml(prXml.getRoot(), BwUser.class, BwPrincipal.getRestoreCallback());
        final BwPreferences prefs = fxml.fromXml(prefsXml.getRoot(), BwPreferences.class, BwPreferences.getRestoreCallback());
        incCount(Counters.users);
        incCount(Counters.userPrefs);
        if (getGlobals().getDryRun()) {
            info(pr.toString());
            info(prefs.toString());
        } else {
            getRi().restorePrincipal(pr);
            getRi().restoreUserPrefs(prefs);
        }
        restoreCategories();
        restoreContacts();
        restoreLocations();
        restoreCollections();
    } catch (final CalFacadeException ce) {
        throw ce;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return true;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) XmlFile(org.bedework.dumprestore.restore.XmlFile) File(java.io.File) XmlFile(org.bedework.dumprestore.restore.XmlFile) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 14 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class DumpPrincipal method doDump.

/**
 * Dump everything owned by this principal
 *
 * @throws CalFacadeException on error
 */
public void doDump() throws CalFacadeException {
    final File f = makeFile("principal.xml");
    pr.dump(f);
    final BwPreferences prefs = getSvc().getPrefsHandler().get();
    if (prefs == null) {
        warn("No preferences for " + pr.getPrincipalRef());
    } else {
        incCount(DumpGlobals.userPrefs);
        prefs.dump(makeFile("preferences.xml"));
    }
    dumpCategories(false);
    dumpContacts(false);
    dumpLocations(false);
    try {
        makeDir(Defs.collectionsDirName, false);
        final CalendarsI cols = getSvc().getCalendarsHandler();
        final BwCalendar home = cols.getHome();
        if (home == null) {
            warn("No home for " + pr.getPrincipalRef());
            return;
        }
        dumpCol(home, true);
    } finally {
        popPath();
    }
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) CalendarsI(org.bedework.calsvci.CalendarsI) BwCalendar(org.bedework.calfacade.BwCalendar) File(java.io.File)

Example 15 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class UserPrefsFieldRule method processViewEnd.

private void processViewEnd(final BwView view) throws Throwable {
    pop();
    BwPreferences p = (BwPreferences) getTop(BwPreferences.class, "view");
    p.addView(view);
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences)

Aggregations

BwPreferences (org.bedework.calfacade.svc.BwPreferences)28 BwView (org.bedework.calfacade.svc.BwView)7 BwCalendar (org.bedework.calfacade.BwCalendar)6 BwPrincipal (org.bedework.calfacade.BwPrincipal)6 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 EventInfo (org.bedework.calfacade.svc.EventInfo)5 BwEvent (org.bedework.calfacade.BwEvent)4 File (java.io.File)2 BwCategory (org.bedework.calfacade.BwCategory)2 UpdateResult (org.bedework.calfacade.svc.EventInfo.UpdateResult)2 SchedulingIntf (org.bedework.calsvc.scheduling.SchedulingIntf)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 TreeSet (java.util.TreeSet)1 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)1 UpdateEventResult (org.bedework.calcorei.CoreEventsI.UpdateEventResult)1 HibSession (org.bedework.calcorei.HibSession)1 BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)1 NotificationType (org.bedework.caldav.util.notifications.NotificationType)1 ResourceChangeType (org.bedework.caldav.util.notifications.ResourceChangeType)1 UpdatedType (org.bedework.caldav.util.notifications.UpdatedType)1