Search in sources :

Example 21 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class VEventUtil method doRecurring.

/**
 * Build recurring properties from event.
 *
 * @param val
 * @param pl
 * @throws CalFacadeException
 */
public static void doRecurring(final BwEvent val, final PropertyList pl) throws CalFacadeException {
    try {
        if (val.hasRrules()) {
            for (String s : val.getRrules()) {
                RRule rule = new RRule();
                rule.setValue(s);
                pl.add(rule);
            }
        }
        if (val.hasExrules()) {
            for (String s : val.getExrules()) {
                ExRule rule = new ExRule();
                rule.setValue(s);
                pl.add(rule);
            }
        }
        makeDlp(val, false, val.getRdates(), pl);
        makeDlp(val, true, val.getExdates(), pl);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) BwString(org.bedework.calfacade.BwString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) ExRule(net.fortuna.ical4j.model.property.ExRule)

Example 22 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class Xalarms method toBwAlarm.

/**
 * The generated alarm may not be a valid alarm if it is being used as a
 * selector. It must have at least the action as a selector.
 *
 * @param alarm
 * @param validate - true if alarm must be valid and complete
 * @return ValarmType
 * @throws CalFacadeException
 */
public static BwAlarm toBwAlarm(final ValarmType alarm, final boolean validate) throws CalFacadeException {
    BwAlarm ba = new BwAlarm();
    /* ============ Action =================== */
    ActionPropType action = (ActionPropType) XcalUtil.findProperty(alarm, XcalTags.action);
    if (action == null) {
        throw new CalFacadeException("Invalid alarm - no action");
    }
    String actionVal = action.getText().toUpperCase();
    int atype = -1;
    for (int i = 0; i < BwAlarm.alarmTypes.length; i++) {
        if (actionVal.equals(BwAlarm.alarmTypes[i])) {
            atype = i;
            break;
        }
    }
    if (atype < 0) {
        throw new CalFacadeException("Unhandled alarm action");
    }
    ba.setAlarmType(atype);
    /* ============ Trigger =================== */
    TriggerPropType tr = (TriggerPropType) XcalUtil.findProperty(alarm, XcalTags.trigger);
    if (tr == null) {
        if (validate) {
            throw new CalFacadeException("Invalid alarm - no action");
        }
    } else {
        if (tr.getDateTime() != null) {
            ba.setTrigger(XcalUtil.getIcalFormatDateTime(tr.getDateTime()));
            ba.setTriggerDateTime(true);
        } else {
            ba.setTrigger(tr.getDuration());
            RelatedParamType r = (RelatedParamType) XcalUtil.findParam(tr, XcalTags.related);
            ba.setTriggerStart((r == null) || (r.getText().toUpperCase().equals("START")));
        }
    }
    /* ============ Duration =================== */
    DurationPropType dur = (DurationPropType) XcalUtil.findProperty(alarm, XcalTags.duration);
    if (dur != null) {
        // MUST have repeat
        RepeatPropType rep = (RepeatPropType) XcalUtil.findProperty(alarm, XcalTags.repeat);
        ba.setDuration(dur.getDuration());
        if (rep == null) {
            if (validate) {
                throw new CalFacadeException("Invalid alarm - no repeat");
            }
        } else {
            ba.setRepeat(rep.getInteger().intValue());
        }
    }
    /* ============ Description ============ */
    if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
        DescriptionPropType desc = (DescriptionPropType) XcalUtil.findProperty(alarm, XcalTags.description);
        if (desc != null) {
            ba.setDescription(desc.getText());
        }
    }
    /* ============ Summary ============ */
    if (atype == BwAlarm.alarmTypeEmail) {
        SummaryPropType s = (SummaryPropType) XcalUtil.findProperty(alarm, XcalTags.summary);
        if (s != null) {
            ba.setSummary(s.getText());
        }
    }
    if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
        AttachPropType a = (AttachPropType) XcalUtil.findProperty(alarm, XcalTags.attach);
        // XXX Onl handle 1 attachment
        if ((a != null) && (a.getUri() != null)) {
            ba.setAttach(a.getUri());
        }
    }
    if (atype == BwAlarm.alarmTypeEmail) {
        for (JAXBElement<? extends BasePropertyType> bpel : alarm.getProperties().getBasePropertyOrTzid()) {
            if (!bpel.getName().equals(XcalTags.attendee)) {
                continue;
            }
            AttendeePropType attp = (AttendeePropType) bpel.getValue();
            BwAttendee batt = new BwAttendee();
            batt.setAttendeeUri(attp.getCalAddress());
            ba.addAttendee(batt);
        }
    }
    return ba;
}
Also used : SummaryPropType(ietf.params.xml.ns.icalendar_2.SummaryPropType) TriggerPropType(ietf.params.xml.ns.icalendar_2.TriggerPropType) AttachPropType(ietf.params.xml.ns.icalendar_2.AttachPropType) DurationPropType(ietf.params.xml.ns.icalendar_2.DurationPropType) DescriptionPropType(ietf.params.xml.ns.icalendar_2.DescriptionPropType) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) RelatedParamType(ietf.params.xml.ns.icalendar_2.RelatedParamType) ActionPropType(ietf.params.xml.ns.icalendar_2.ActionPropType) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) RepeatPropType(ietf.params.xml.ns.icalendar_2.RepeatPropType) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 23 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class CalSuites method validateGroup.

/**
 * Ensure the given group is valid for the given calendar suite
 *
 * @param cs
 * @param groupName
 * @return home for the group
 * @throws CalFacadeException
 */
private BwCalendar validateGroup(final BwCalSuite cs, final String groupName) throws CalFacadeException {
    if (groupName.length() > BwCalSuite.maxNameLength) {
        throw new CalFacadeException(CalFacadeException.calsuiteGroupNameTooLong);
    }
    BwAdminGroup agrp = (BwAdminGroup) getSvc().getAdminDirectories().findGroup(groupName);
    if (agrp == null) {
        throw new CalFacadeException(CalFacadeException.groupNotFound, groupName);
    }
    final BwCalSuiteWrapper csw = get(agrp);
    if ((csw != null) && !csw.equals(cs)) {
        // Group already assigned to another cal suite
        throw new CalFacadeException(CalFacadeException.calsuiteGroupAssigned, csw.getName());
    }
    final BwPrincipal eventsOwner = getPrincipal(agrp.getOwnerHref());
    if (eventsOwner == null) {
        throw new CalFacadeException(CalFacadeException.calsuiteBadowner);
    }
    final BwCalendar home = getCols().getHomeDb(eventsOwner, true);
    if (home == null) {
        throw new CalFacadeException(CalFacadeException.missingGroupOwnerHome);
    }
    cs.setGroup(agrp);
    /* Change access on the home for the events creator which is also the
     * owner of the calsuite resources.
     */
    final Collection<Privilege> allPrivs = new ArrayList<>();
    allPrivs.add(Access.all);
    final Collection<Privilege> readPrivs = new ArrayList<>();
    readPrivs.add(Access.read);
    final Collection<Ace> aces = new ArrayList<>();
    try {
        aces.add(Ace.makeAce(AceWho.owner, allPrivs, null));
        aces.add(Ace.makeAce(AceWho.getAceWho(eventsOwner.getAccount(), WhoDefs.whoTypeUser, false), allPrivs, null));
        aces.add(Ace.makeAce(AceWho.getAceWho(null, WhoDefs.whoTypeAuthenticated, false), readPrivs, null));
        aces.add(Ace.makeAce(AceWho.all, readPrivs, null));
        getSvc().changeAccess(home, aces, true);
        /* Same access to the calsuite itself */
        getSvc().changeAccess(cs, aces, true);
        /* Also set access so that categories, locations etc are readable */
        final String aclStr = new String(new Acl(aces).encode());
        eventsOwner.setCategoryAccess(aclStr);
        eventsOwner.setLocationAccess(aclStr);
        eventsOwner.setContactAccess(aclStr);
    } catch (final AccessException ae) {
        throw new CalFacadeException(ae);
    }
    getSvc().getUsersHandler().update(eventsOwner);
    return home;
}
Also used : Ace(org.bedework.access.Ace) ArrayList(java.util.ArrayList) BwCalSuiteWrapper(org.bedework.calfacade.svc.wrappers.BwCalSuiteWrapper) BwCalendar(org.bedework.calfacade.BwCalendar) Acl(org.bedework.access.Acl) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) AccessException(org.bedework.access.AccessException) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup) Privilege(org.bedework.access.Privilege)

Example 24 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class CalSuites method add.

@Override
public BwCalSuiteWrapper add(final String name, final String adminGroupName, final String rootCollectionPath, final String submissionsPath) throws CalFacadeException {
    BwCalSuite cs = getCal().getCalSuite(name);
    if (cs != null) {
        throw new CalFacadeException(CalFacadeException.duplicateCalsuite);
    }
    cs = new BwCalSuite();
    cs.setName(name);
    setRootCol(cs, rootCollectionPath);
    setupSharableEntity(cs, getPrincipal().getPrincipalRef());
    setSubmissionsCol(cs, submissionsPath);
    validateGroup(cs, adminGroupName);
    getCal().saveOrUpdate(cs);
    return wrap(cs, false);
}
Also used : BwCalSuite(org.bedework.calfacade.svc.BwCalSuite) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 25 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class CalSuites method setRootCol.

/**
 * Set root collection if supplied
 *
 * @param cs
 * @param rootCollectionPath
 * @throws CalFacadeException
 */
private void setRootCol(final BwCalSuite cs, final String rootCollectionPath) throws CalFacadeException {
    if ((rootCollectionPath == null) || rootCollectionPath.equals(cs.getRootCollectionPath())) {
        return;
    }
    BwCalendar rootCol = getCols().get(rootCollectionPath);
    if (rootCol == null) {
        throw new CalFacadeException(CalFacadeException.calsuiteUnknownRootCollection, rootCollectionPath);
    }
    cs.setRootCollection(rootCol);
    cs.setRootCollectionPath(rootCol.getPath());
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12