Search in sources :

Example 1 with BwPreferences

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

the class UserPrefsRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    BwPreferences entity = (BwPreferences) pop();
    globals.counts[globals.userPrefs]++;
    try {
        globals.rintf.restoreUserPrefs(entity);
    } catch (Throwable t) {
        throw new Exception(t);
    }
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences)

Example 2 with BwPreferences

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

the class Calendars method delete.

boolean delete(final BwCalendar val, final boolean emptyIt, final boolean reallyDelete, final boolean sendSchedulingMessage, final boolean unsubscribe) throws CalFacadeException {
    if (!emptyIt) {
        /* Only allow delete if not in use
       */
        if (!getCal().isEmpty(val)) {
            throw new CalFacadeException(CalFacadeException.collectionNotEmpty);
        }
    }
    final BwPreferences prefs = getSvc().getPrefsHandler().get(getSvc().getUsersHandler().getPrincipal(val.getOwnerHref()));
    if (val.getPath().equals(prefs.getDefaultCalendarPath())) {
        throw new CalFacadeException(CalFacadeException.cannotDeleteDefaultCalendar);
    }
    /* Remove any sharing */
    if (val.getCanAlias()) {
        getSvc().getSharingHandler().delete(val);
    }
    if (unsubscribe) {
        getSvc().getSharingHandler().unsubscribe(val);
    }
    getSvc().getSynch().unsubscribe(val, true);
    /* Remove from preferences */
    ((Preferences) getSvc().getPrefsHandler()).updateAdminPrefs(true, val, null, null, null);
    /* If it' an alias we just delete it - otherwise we might need to empty it.
     */
    if (!val.getInternalAlias() && emptyIt) {
        if (val.getCalendarCollection()) {
            final Events events = ((Events) getSvc().getEventsHandler());
            for (final EventInfo ei : events.getSynchEvents(val.getPath(), null)) {
                events.delete(ei, false, sendSchedulingMessage, true);
            }
        }
        /* Remove resources */
        final ResourcesI resI = getSvc().getResourcesHandler();
        final Collection<BwResource> rs = resI.getAll(val.getPath());
        if (!Util.isEmpty(rs)) {
            for (final BwResource r : rs) {
                resI.delete(Util.buildPath(false, r.getColPath(), "/", r.getName()));
            }
        }
        for (final BwCalendar cal : getChildren(val)) {
            if (!delete(cal, true, true, sendSchedulingMessage, true)) {
                // Somebody else at it
                getSvc().rollbackTransaction();
                throw new CalFacadeException(CalFacadeException.collectionNotFound, cal.getPath());
            }
        }
    }
    val.getProperties().clear();
    /* Attempt to tombstone it
     */
    return getSvc().getCal().deleteCalendar(val, reallyDelete);
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) EventInfo(org.bedework.calfacade.svc.EventInfo) BwResource(org.bedework.calfacade.BwResource) ResourcesI(org.bedework.calsvci.ResourcesI) BwCalendar(org.bedework.calfacade.BwCalendar) BwPreferences(org.bedework.calfacade.svc.BwPreferences) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with BwPreferences

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

the class Events method add.

@Override
public UpdateResult add(final EventInfo ei, final boolean noInvites, final boolean schedulingInbox, final boolean autoCreateCollection, final boolean rollbackOnError) throws CalFacadeException {
    try {
        if (getPrincipalInfo().getSubscriptionsOnly()) {
            throw new CalFacadeForbidden("User has read only access");
        }
        final UpdateResult updResult = ei.getUpdResult();
        updResult.adding = true;
        updResult.hasChanged = true;
        final BwEvent event = ei.getEvent();
        adjustEntities(ei);
        final BwPreferences prefs = getSvc().getPrefsHandler().get();
        if (prefs != null) {
            final Collection<BwCategory> cats = getSvc().getCategoriesHandler().get(prefs.getDefaultCategoryUids());
            for (final BwCategory cat : cats) {
                event.addCategory(cat);
            }
        }
        final RealiasResult raResp = reAlias(event);
        if (raResp.getStatus() != ok) {
            throw new CalFacadeException(CalFacadeException.badRequest, "Status: " + raResp.getStatus() + " message: " + raResp.getMessage());
        }
        // Or just validate?
        assignGuid(event);
        updateEntities(updResult, event);
        BwCalendar cal = validate(event, true, schedulingInbox, autoCreateCollection);
        BwEventProxy proxy = null;
        BwEvent override = null;
        if (event instanceof BwEventProxy) {
            proxy = (BwEventProxy) event;
            override = proxy.getRef();
            setupSharableEntity(override, getPrincipal().getPrincipalRef());
        } else {
            setupSharableEntity(event, getPrincipal().getPrincipalRef());
            if (ei.getNumContainedItems() > 0) {
                for (final EventInfo aei : ei.getContainedItems()) {
                    final BwEvent av = aei.getEvent();
                    av.setParent(event);
                    setupSharableEntity(av, getPrincipal().getPrincipalRef());
                }
            }
        }
        final BwCalendar undereffedCal = cal;
        if (cal.getInternalAlias()) {
            /* Resolve the alias and put the event in it's proper place */
            // XXX This is probably OK for non-public admin
            final boolean setCats = getSvc().getPars().getPublicAdmin();
            if (!setCats) {
                cal = getCols().resolveAlias(cal, true, false);
            } else {
                while (true) {
                    final Set<BwCategory> cats = cal.getCategories();
                    for (final BwCategory cat : cats) {
                        event.addCategory(cat);
                    }
                    if (!cal.getInternalAlias()) {
                        break;
                    }
                    cal = getCols().resolveAlias(cal, false, false);
                }
            }
            event.setColPath(cal.getPath());
        }
        if (!cal.getCalendarCollection()) {
            throw new CalFacadeAccessException();
        }
        if (!event.getPublick() && Util.isEmpty(event.getAlarms())) {
            setDefaultAlarms(ei, undereffedCal);
        }
        boolean schedulingObject = false;
        if (cal.getCollectionInfo().scheduling && (event.getOrganizerSchedulingObject() || event.getAttendeeSchedulingObject())) {
            schedulingObject = true;
        }
        final Integer maxAttendees = getSvc().getAuthProperties().getMaxAttendeesPerInstance();
        if ((maxAttendees != null) && !Util.isEmpty(event.getAttendees()) && (event.getAttendees().size() > maxAttendees)) {
            throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
        }
        event.setDtstamps(getCurrentTimestamp());
        if (schedulingObject) {
            event.updateStag(getCurrentTimestamp());
        }
        /* All Overrides go in same calendar and have same name */
        final Collection<BwEventProxy> overrides = ei.getOverrideProxies();
        if (overrides != null) {
            for (final BwEventProxy ovei : overrides) {
                setScheduleState(ovei, true, schedulingInbox);
                if ((maxAttendees != null) && !Util.isEmpty(ovei.getAttendees()) && (ovei.getAttendees().size() > maxAttendees)) {
                    throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
                }
                ovei.setDtstamps(getCurrentTimestamp());
                if (cal.getCollectionInfo().scheduling && (ovei.getOrganizerSchedulingObject() || ovei.getAttendeeSchedulingObject())) {
                    schedulingObject = true;
                }
                if (schedulingObject) {
                    ovei.updateStag(getCurrentTimestamp());
                }
                final BwEventAnnotation ann = ovei.getRef();
                ann.setColPath(event.getColPath());
                ann.setName(event.getName());
            }
        }
        if (event.getOrganizerSchedulingObject()) {
            // Set RSVP on all attendees with PARTSTAT = NEEDS_ACTION
            for (final BwAttendee att : event.getAttendees()) {
                if (att.getPartstat() == IcalDefs.partstatValNeedsAction) {
                    att.setRsvp(true);
                }
            }
        }
        UpdateEventResult uer = getCal().addEvent(ei, schedulingInbox, rollbackOnError);
        if (ei.getNumContainedItems() > 0) {
            for (final EventInfo oei : ei.getContainedItems()) {
                oei.getEvent().setName(event.getName());
                final UpdateEventResult auer = getCal().addEvent(oei, schedulingInbox, rollbackOnError);
                if (auer.errorCode != null) {
                // ?
                }
            }
        }
        updResult.failedOverrides = uer.failedOverrides;
        if (!noInvites) {
            if (event.getAttendeeSchedulingObject()) {
                // Attendee replying?
                updResult.reply = true;
            }
            if (cal.getCollectionInfo().scheduling && schedulingObject) {
                final SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
                sched.implicitSchedule(ei, false);
            /* We assume we don't need to update again to set attendee status
           * Trying to do an update results in duplicate key errors.
           *
           * If it turns out the scgedule status is not getting persisted in the
           * calendar entry then we need to find a way to set just that value in
           * already persisted entity.
           */
            }
        }
        return updResult;
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        getSvc().rollbackTransaction();
        if (t instanceof CalFacadeException) {
            throw (CalFacadeException) t;
        }
        throw new CalFacadeException(t);
    }
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwCategory(org.bedework.calfacade.BwCategory) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwEvent(org.bedework.calfacade.BwEvent) SchedulingIntf(org.bedework.calsvc.scheduling.SchedulingIntf) BwCalendar(org.bedework.calfacade.BwCalendar) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult) UpdateEventResult(org.bedework.calcorei.CoreEventsI.UpdateEventResult)

Example 4 with BwPreferences

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

the class Users method remove.

@Override
public void remove(final BwPrincipal pr) throws CalFacadeException {
    final String userRoot = getSvc().getPrincipalInfo().getCalendarHomePath(pr);
    /* views */
    final Collection<BwView> views = getSvc().getViewsHandler().getAll(pr);
    for (final BwView view : views) {
        getSvc().getViewsHandler().remove(view);
    }
    /* Set default calendar to null so we don't get blocked. */
    final BwPreferences prefs = getSvc().getPrefsHandler().get(pr);
    if (prefs != null) {
        prefs.setDefaultCalendarPath(null);
        getSvc().getPrefsHandler().update(prefs);
    }
    /* collections and user home */
    final BwCalendar home = getSvc().getCalendarsHandler().get(userRoot);
    if (home != null) {
        ((Calendars) getCols()).delete(home, true, true, false, true);
    }
    /* Remove preferences */
    getSvc().getPrefsHandler().delete(prefs);
    getCal().delete(pr);
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwCalendar(org.bedework.calfacade.BwCalendar) BwView(org.bedework.calfacade.svc.BwView)

Example 5 with BwPreferences

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

the class Views method remove.

/* (non-Javadoc)
   * @see org.bedework.calsvci.ViewsI#remove(org.bedework.calfacade.svc.BwView)
   */
@Override
public boolean remove(final BwView val) throws CalFacadeException {
    if (val == null) {
        return false;
    }
    BwPreferences prefs = getSvc().getPrefsHandler().get();
    checkOwnerOrSuper(prefs);
    // setupOwnedEntity(val, getUser());
    Collection<BwView> views = prefs.getViews();
    if ((views == null) || (!views.contains(val))) {
        return false;
    }
    String name = val.getName();
    views.remove(val);
    if (name.equals(prefs.getPreferredView())) {
        prefs.setPreferredView(null);
    }
    getSvc().getPrefsHandler().update(prefs);
    return true;
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwView(org.bedework.calfacade.svc.BwView)

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