Search in sources :

Example 51 with EventInfo

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

the class MessageProcessor method getIndexer.

@SuppressWarnings("rawtypes")
private BwIndexer getIndexer(final CalSvcI svci, final Object val) throws CalFacadeException {
    boolean publick = false;
    String principal = null;
    final BwOwnedDbentity ent;
    if (val instanceof BwOwnedDbentity) {
        ent = (BwOwnedDbentity) val;
    } else if (val instanceof EventInfo) {
        ent = ((EventInfo) val).getEvent();
    } else {
        error("Cannot index class: " + val.getClass());
        throw new CalFacadeException("org.bedework.index.unexpected.class");
    }
    if (ent != null) {
        if (ent.getPublick() == null) {
            debug("This is wrong");
        }
        publick = ent.getPublick();
        principal = ent.getOwnerHref();
    }
    return getIndexer(svci, publick, principal);
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwOwnedDbentity(org.bedework.calfacade.base.BwOwnedDbentity) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 52 with EventInfo

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

the class ProcessMove method moveEvent.

private void moveEvent(final String fromPath, final String toPath, final String name, final Collection<BwCategory> cats, final Collection<String> aliases, final boolean setname) throws Throwable {
    final EventInfo ei = getEvent(fromPath, name);
    final BwEvent ev = ei.getEvent();
    if (debug) {
        final StringBuilder sb = new StringBuilder("Moving event ");
        sb.append(ev.getUid());
        if (ev.getRecurring()) {
            sb.append(" recurring");
        }
        sb.append(" from ");
        sb.append(fromPath);
        sb.append(" to ");
        sb.append(toPath);
        debug(sb.toString());
    }
    ev.setColPath(toPath);
    for (final BwCategory cat : cats) {
        ev.addCategory(cat);
    }
    for (final String alias : aliases) {
        final BwXproperty x = new BwXproperty();
        x.setName(BwXproperty.bedeworkAlias);
        x.setValue(alias);
        ev.addXproperty(x);
    }
    if (setname) {
        final String nm = ev.getName();
        final String nnm = ev.getUid() + ".ics";
        if (!nm.equals(nnm)) {
            ev.setName(nnm);
        }
    }
    if (ei.getOverrideProxies() != null) {
        for (final BwEvent oev : ei.getOverrideProxies()) {
            oev.setColPath(toPath);
        }
    }
    try {
        getSvci().getEventsHandler().update(ei, false, null);
    } catch (final CalFacadeDupNameException cdne) {
        pstate.addError("Duplicate name " + ev.getName() + " uid: " + ev.getUid() + " from: " + fromPath);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) CalFacadeDupNameException(org.bedework.calfacade.exc.CalFacadeDupNameException) BwXproperty(org.bedework.calfacade.BwXproperty) BwCategory(org.bedework.calfacade.BwCategory) BwEvent(org.bedework.calfacade.BwEvent)

Example 53 with EventInfo

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

the class ProcessRealias method realiasEvents.

private boolean realiasEvents() throws Throwable {
    boolean add = false;
    boolean remove = false;
    BwXproperty xp = null;
    /* Expect from (possibly quoted)
     *        to  (possibly quoted)
     */
    try {
        open();
        final String fromHref = getAliasPath();
        if (fromHref == null) {
            return false;
        }
        final String wd = word();
        if (wd == null) {
            return false;
        }
        if ("remove".equals(wd)) {
            remove = true;
        } else {
            if ("add".equals(wd)) {
                add = true;
            } else if ("replace".equals(wd)) {
                remove = true;
            } else {
                error("Expect add | remove | replace");
                return false;
            }
            final BwCalendar col = getCal();
            if (col == null) {
                return false;
            }
            /* At the moment an alias is represented by an x-property with 
           the form:
           X-BEDEWORK-ALIAS; \
             X-BEDEWORK-PARAM-DISPLAYNAME=Jobs;\
             X-BEDEWORK-PARAM-PATH=/public/aliases/Browse By Topic/Jobs;\
             X-BEDEWORK-PARAM-ALIASPATH=/public/cals/MainCal:\
             /user/agrp_calsuite-MainCampus/Browse By Topic/Jobs"
        
           That is - it appears the displayname comes from the top level
           the path is what it points to
           the aliaspath is the path of the final target 
           the value is the path of the alias itself.
         */
            final BwCalendar aliasTarget = getAliasTarget(col);
            xp = new BwXproperty();
            xp.setName("X-BEDEWORK-ALIAS");
            xp.setPars("X-BEDEWORK-PARAM-DISPLAYNAME=" + col.getName() + ";X-BEDEWORK-PARAM-PATH=" + col.getAliasUri().substring(BwCalendar.internalAliasUriPrefix.length()) + ";X-BEDEWORK-PARAM-ALIASPATH=" + aliasTarget.getPath());
            xp.setValue(col.getPath());
        }
        final FilterBase fltr = parseQuery("topical_area=\"\t" + fromHref + "\"");
        if (fltr == null) {
            return false;
        }
        close();
        /* Now we need to process the stuff in batches */
        open();
        final BwIndexer idx = getIndexer();
        final SearchResult sr = idx.search(null, false, fltr, null, null, null, null, batchSize, includeDeleted, RecurringRetrievalMode.entityOnly);
        if (sr.getFound() == 0) {
            warn("No events found");
            return false;
        }
        for (; ; ) {
            final List<SearchResultEntry> sres = idx.getSearchResult(sr, BwIndexer.Position.next, PrivilegeDefs.privAny);
            if (Util.isEmpty(sres)) {
                break;
            }
            int updated = 0;
            for (final SearchResultEntry sre : sres) {
                final Object o = sre.getEntity();
                if (!(o instanceof EventInfo)) {
                    warn("Unhandled entity " + o.getClass());
                    continue;
                }
                EventInfo ei = (EventInfo) o;
                /* Fetch the persistent version
           */
                final String colPath = ei.getEvent().getColPath();
                final String name = ei.getEvent().getName();
                ei = getEvents().get(colPath, name);
                if (ei == null) {
                    warn("Unable to retrieve persistent copy of " + colPath + " " + name);
                    continue;
                }
                updated += doRealias(ei, fromHref, xp, add, remove);
                if ((updated % 10) == 0) {
                    info("done " + updated);
                }
            }
            info("Total updated: " + updated);
        }
        return true;
    } finally {
        close();
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwIndexer(org.bedework.calfacade.indexing.BwIndexer) SearchResult(org.bedework.calfacade.indexing.SearchResult) BwCalendar(org.bedework.calfacade.BwCalendar) FilterBase(org.bedework.caldav.util.filter.FilterBase) SearchResultEntry(org.bedework.calfacade.indexing.SearchResultEntry)

Example 54 with EventInfo

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

the class BwSysIntfImpl method checkStatus.

/**
 * @param sr schedule result
 * @return recipient results
 * @throws WebdavException
 */
private Collection<SchedRecipientResult> checkStatus(final ScheduleResult sr) throws WebdavException {
    if ((sr.errorCode == null) || (sr.errorCode.equals(CalFacadeException.schedulingNoRecipients))) {
        final Collection<SchedRecipientResult> srrs = new ArrayList<>();
        for (final ScheduleRecipientResult bwsrr : sr.recipientResults.values()) {
            final SchedRecipientResult srr = new SchedRecipientResult();
            srr.recipient = bwsrr.recipient;
            srr.status = bwsrr.getStatus();
            if (bwsrr.freeBusy != null) {
                srr.freeBusy = new BwCalDAVEvent(this, new EventInfo(bwsrr.freeBusy));
            }
            srrs.add(srr);
        }
        return srrs;
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingBadMethod)) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, "Bad METHOD");
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingBadAttendees)) {
        throw new WebdavForbidden(CaldavTags.attendeeAllowed, "Bad attendees");
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingAttendeeAccessDisallowed)) {
        throw new WebdavForbidden(CaldavTags.attendeeAllowed, "attendeeAccessDisallowed");
    }
    throw new WebdavForbidden(sr.errorCode);
}
Also used : ScheduleRecipientResult(org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList)

Example 55 with EventInfo

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

the class BwSysIntfImpl method getSpecialFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#getSpecialFreeBusy(java.lang.String, java.util.Set, java.lang.String, org.bedework.caldav.util.TimeRange, java.io.Writer)
   */
@Override
public void getSpecialFreeBusy(final String cua, final Set<String> recipients, final String originator, final TimeRange tr, final Writer wtr) throws WebdavException {
    BwOrganizer org = new BwOrganizer();
    org.setOrganizerUri(cua);
    BwEvent ev = new BwEventObj();
    ev.setDtstart(getBwDt(tr.getStart()));
    ev.setDtend(getBwDt(tr.getEnd()));
    ev.setEntityType(IcalDefs.entityTypeFreeAndBusy);
    ev.setScheduleMethod(ScheduleMethods.methodTypeRequest);
    ev.setRecipients(recipients);
    ev.setOriginator(originator);
    ev.setOrganizer(org);
    Collection<SchedRecipientResult> srrs = requestFreeBusy(new BwCalDAVEvent(this, new EventInfo(ev)), false);
    for (SchedRecipientResult srr : srrs) {
        // We expect one only
        BwCalDAVEvent rfb = (BwCalDAVEvent) srr.freeBusy;
        if (rfb != null) {
            rfb.getEv().setOrganizer(org);
            try {
                VFreeBusy vfreeBusy = VFreeUtil.toVFreeBusy(rfb.getEv());
                net.fortuna.ical4j.model.Calendar ical = IcalTranslator.newIcal(ScheduleMethods.methodTypeReply);
                ical.getComponents().add(vfreeBusy);
                IcalTranslator.writeCalendar(ical, wtr);
            } catch (Throwable t) {
                if (debug) {
                    error(t);
                }
                throw new WebdavException(t);
            }
        }
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) Calendar(net.fortuna.ical4j.model.Calendar) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Aggregations

EventInfo (org.bedework.calfacade.svc.EventInfo)111 BwEvent (org.bedework.calfacade.BwEvent)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)37 BwCalendar (org.bedework.calfacade.BwCalendar)27 BwEventProxy (org.bedework.calfacade.BwEventProxy)24 BwAttendee (org.bedework.calfacade.BwAttendee)19 ArrayList (java.util.ArrayList)16 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)15 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)15 BwString (org.bedework.calfacade.BwString)11 BwDateTime (org.bedework.calfacade.BwDateTime)10 BwEventObj (org.bedework.calfacade.BwEventObj)10 TreeSet (java.util.TreeSet)9 BwXproperty (org.bedework.calfacade.BwXproperty)9 BwPrincipal (org.bedework.calfacade.BwPrincipal)7 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)7 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)7 Calendar (net.fortuna.ical4j.model.Calendar)6 Period (net.fortuna.ical4j.model.Period)6 BwOrganizer (org.bedework.calfacade.BwOrganizer)6