Search in sources :

Example 1 with AccessType

use of org.bedework.caldav.util.sharing.AccessType in project bw-calendar-engine by Bedework.

the class Sharing method reply.

@Override
public ReplyResult reply(final BwCalendar col, final InviteReplyType reply) throws CalFacadeException {
    final BwCalendar home = getCols().getHome();
    if (!home.getPath().equals(col.getPath())) {
        throw new CalFacadeForbidden("Not calendar home");
    }
    /* We must have at least read access to the shared collection */
    final BwCalendar sharerCol = getCols().get(Util.buildPath(colPathEndsWithSlash, reply.getHostUrl()));
    if (sharerCol == null) {
        // Bad hosturl
        throw new CalFacadeForbidden("Bad hosturl or no access");
    }
    final Holder<AccessType> access = new Holder<>();
    if (!updateSharingStatus(sharerCol.getOwnerHref(), sharerCol.getPath(), reply, access)) {
        return null;
    }
    /* Accepted */
    final AccessType at = access.value;
    final boolean sharedWritable = (at != null) && at.testReadWrite();
    /* This may be a change in access or a new sharing request. See if an alias
     * already exists to the shared collection. If it does we're done.
     * Otherwise we need to create an alias in the calendar home using the
     * reply summary as the display name */
    final List<BwCalendar> aliases = findAlias(sharerCol.getPath());
    if (!Util.isEmpty(aliases)) {
        final BwCalendar alias = aliases.get(0);
        alias.setSharedWritable(sharedWritable);
        getCols().update(alias);
        return ReplyResult.success(alias.getPath());
    }
    final BwCalendar alias = new BwCalendar();
    String summary = reply.getSummary();
    if ((summary == null) || (summary.length() == 0)) {
        summary = "Shared Calendar";
    }
    alias.setName(reply.getInReplyTo());
    alias.setSummary(summary);
    alias.setCalType(BwCalendar.calTypeAlias);
    // alias.setPath(home.getPath() + "/" + UUID.randomUUID().toString());
    alias.setAliasUri("bwcal://" + sharerCol.getPath());
    alias.setShared(true);
    alias.setSharedWritable(sharedWritable);
    final BwCalendar createdAlias = getCols().add(alias, home.getPath());
    return ReplyResult.success(createdAlias.getPath());
}
Also used : Holder(javax.xml.ws.Holder) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwCalendar(org.bedework.calfacade.BwCalendar) AccessType(org.bedework.caldav.util.sharing.AccessType)

Example 2 with AccessType

use of org.bedework.caldav.util.sharing.AccessType in project bw-calendar-engine by Bedework.

the class NotificationConf method sendInvite.

/* ========================================================================
   * Operations
   * ======================================================================== */
@Override
public String sendInvite(final String cua, final String href) {
    try {
        final ShareType share = new ShareType();
        final SetType set = new SetType();
        set.setHref(cua);
        set.setSummary("Test Collection");
        final AccessType at = new AccessType();
        at.setRead(true);
        set.setAccess(at);
        share.getSet().add(set);
        try (CalSvcI svci = getSvci(getNotifierId())) {
            final BwCalendar col = svci.getCalendarsHandler().get(href);
            if (col == null) {
                return "No such collection";
            }
            svci.getSharingHandler().share(col, share);
        }
        svci.endTransaction();
        return "ok";
    } catch (final Throwable t) {
        error(t);
        return t.getLocalizedMessage();
    }
}
Also used : SetType(org.bedework.caldav.util.sharing.SetType) CalSvcI(org.bedework.calsvci.CalSvcI) BwCalendar(org.bedework.calfacade.BwCalendar) AccessType(org.bedework.caldav.util.sharing.AccessType) ShareType(org.bedework.caldav.util.sharing.ShareType)

Aggregations

AccessType (org.bedework.caldav.util.sharing.AccessType)2 BwCalendar (org.bedework.calfacade.BwCalendar)2 Holder (javax.xml.ws.Holder)1 SetType (org.bedework.caldav.util.sharing.SetType)1 ShareType (org.bedework.caldav.util.sharing.ShareType)1 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)1 CalSvcI (org.bedework.calsvci.CalSvcI)1