Search in sources :

Example 51 with BwEvent

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

the class CoreEvents method postGetEvents.

private Collection<CoreEventInfo> postGetEvents(final Collection evs, final int desiredAccess, final boolean nullForNoAccess, final Filters f) throws CalFacadeException {
    final TreeSet<CoreEventInfo> outevs = new TreeSet<>();
    for (final Object ev1 : evs) {
        final BwEvent ev = (BwEvent) ev1;
        final CoreEventInfo cei = postGetEvent(ev, desiredAccess, nullForNoAccess, f);
        if (cei == null) {
            continue;
        }
        outevs.add(cei);
    }
    return outevs;
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) TreeSet(java.util.TreeSet) BwEvent(org.bedework.calfacade.BwEvent)

Example 52 with BwEvent

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

the class CoreEvents method updateProxy.

/* Called by updateEvent to update a proxied event (annotation) or an
   * override.
   */
private void updateProxy(final BwEventProxy proxy) throws CalFacadeException {
    /* if this is a proxy for a recurrence instance of our own event
       then the recurrence instance should point at this override.
       Otherwise we just update the event annotation.
     */
    final BwEventAnnotation override = proxy.getRef();
    if (debug) {
        debugMsg("Update override event " + override);
    }
    BwEvent mstr = override.getTarget();
    while (mstr instanceof BwEventAnnotation) {
        /* XXX The master may itself be an annotated event. We should really
         stop when we get to that point
       */
        /*
      BwEventProxy tempProxy = new BwEventProxy(mstr);
      if (some-condition-holds) {
        break;
      }
      */
        mstr = ((BwEventAnnotation) mstr).getTarget();
    }
    // if (mstr.getOwner().equals(getUser()) &&
    if (mstr.testRecurring()) {
        // A recurring event - retrieve the instance
        final BwRecurrenceInstance inst = dao.getInstance(mstr, override.getRecurrenceId());
        if (inst == null) {
            if (debug) {
                debugMsg("Cannot locate instance for " + mstr + "with recurrence id " + override.getRecurrenceId());
            }
            throwException(CalFacadeException.cannotLocateInstance, mstr + "with recurrence id " + override.getRecurrenceId());
            // satisfy intellij
            return;
        }
        // XXX Force owner????
        override.setOwnerHref(mstr.getOwnerHref());
        dao.saveOrUpdate(override);
        // sess.flush();
        if (inst.getOverride() == null) {
            inst.setOverride(override);
            dao.save(inst);
        }
        /* Update the lastmod on the master event */
        mstr.setDtstamps(getCurrentTimestamp());
        dao.update(mstr);
    } else {
        dao.saveOrUpdate(override);
    }
    proxy.setChangeFlag(false);
}
Also used : BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwEvent(org.bedework.calfacade.BwEvent)

Example 53 with BwEvent

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

the class CoreEventsDAO method calendarGuidExists.

/* Return the name of any event which has the same uid
   */
protected String calendarGuidExists(final BwEvent val, final boolean annotation, final boolean adding) throws CalFacadeException {
    final HibSession sess = getSess();
    final StringBuilder sb = new StringBuilder();
    if (!annotation) {
        sb.append(calendarGuidExistsQuery);
    } else {
        sb.append(calendarGuidAnnotationExistsQuery);
    }
    BwEvent testEvent = null;
    if (!adding) {
        if (annotation) {
            if (val instanceof BwEventProxy) {
                final BwEventProxy proxy = (BwEventProxy) val;
                testEvent = proxy.getRef();
            }
            sb.append("ev.override=false and ");
        } else if (!(val instanceof BwEventProxy)) {
            testEvent = val;
        }
    }
    if (testEvent != null) {
        sb.append("ev<>:event and ");
    }
    sb.append("ev.colPath=:colPath and ev.uid = :uid");
    sess.createQuery(sb.toString());
    if (testEvent != null) {
        sess.setEntity("event", testEvent);
    }
    sess.setString("colPath", val.getColPath());
    sess.setString("uid", val.getUid());
    final Collection refs = sess.getList();
    String res = null;
    if (refs.size() != 0) {
        res = (String) refs.iterator().next();
    }
    return res;
}
Also used : HibSession(org.bedework.calcorei.HibSession) Collection(java.util.Collection) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 54 with BwEvent

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

the class CoreEventsDAO method calendarNameExists.

protected boolean calendarNameExists(final BwEvent val, final boolean annotation, final boolean adding) throws CalFacadeException {
    final HibSession sess = getSess();
    final StringBuilder sb = new StringBuilder();
    if (!annotation) {
        sb.append(calendarNameExistsQuery);
    } else {
        sb.append(calendarNameAnnotationExistsQuery);
    }
    BwEvent testEvent = null;
    if (!adding) {
        if (annotation) {
            if (val instanceof BwEventProxy) {
                final BwEventProxy proxy = (BwEventProxy) val;
                testEvent = proxy.getRef();
            }
            sb.append("ev.override=false and ");
        } else if (!(val instanceof BwEventProxy)) {
            testEvent = val;
        }
    }
    if (testEvent != null) {
        sb.append("ev<>:event and ");
    }
    sb.append("ev.colPath=:colPath and ");
    sb.append("ev.name = :name");
    sess.createQuery(sb.toString());
    if (testEvent != null) {
        sess.setEntity("event", testEvent);
    }
    sess.setString("colPath", val.getColPath());
    sess.setString("name", val.getName());
    final Collection refs = sess.getList();
    final Object o = refs.iterator().next();
    final boolean res;
    /* Apparently some get a Long - others get Integer */
    if (o instanceof Long) {
        final Long ct = (Long) o;
        res = ct > 0;
    } else {
        final Integer ct = (Integer) o;
        res = ct > 0;
    }
    return res;
}
Also used : HibSession(org.bedework.calcorei.HibSession) Collection(java.util.Collection) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 55 with BwEvent

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

the class BwIndexEsImpl method addOverrides.

private boolean addOverrides(final Response resp, final String indexName, final EventInfo ei) {
    try {
        final BwEvent ev = ei.getEvent();
        if (!ev.testRecurring()) {
            return true;
        }
        /* Fetch any overrides. */
        final ESQueryFilter flts = getFilters(null);
        final int batchSize = 100;
        int start = 0;
        while (true) {
            // Search original for overrides
            final SearchRequestBuilder srb = getClient().prepareSearch(Util.buildPath(false, indexName));
            srb.setSearchType(SearchType.QUERY_THEN_FETCH).setPostFilter(flts.overridesOnly(ev.getUid()));
            srb.setFrom(start);
            srb.setSize(batchSize);
            // if (debug) {
            // debug("Overrides: targetIndex=" + indexName +
            // "; srb=" + srb);
            // }
            final SearchResponse sresp = srb.execute().actionGet();
            if (sresp.status() != RestStatus.OK) {
                errorReturn(resp, "Search returned status " + sresp.status());
                return false;
            }
            final SearchHit[] hits = sresp.getHits().getHits();
            if ((hits == null) || (hits.length == 0)) {
                // No more data - we're done
                break;
            }
            for (final SearchHit hit : hits) {
                final String dtype = hit.getType();
                if (dtype == null) {
                    errorReturn(resp, "org.bedework.index.noitemtype");
                    return false;
                }
                final String kval = hit.getId();
                if (kval == null) {
                    errorReturn(resp, "org.bedework.index.noitemkey");
                    return false;
                }
                final EntityBuilder eb = getEntityBuilder(hit.sourceAsMap());
                final Object entity;
                switch(dtype) {
                    case docTypeEvent:
                    case docTypePoll:
                        entity = eb.makeEvent(kval, false);
                        final EventInfo oei = (EventInfo) entity;
                        final BwEvent oev = oei.getEvent();
                        if ((uidsMap != null) && (oev.getLocationUid() == null)) {
                            String locuid = null;
                            if (uidsOverideMap != null) {
                                locuid = uidsOverideMap.get(oev.getUid() + "|" + oev.getRecurrenceId());
                            }
                            if (locuid == null) {
                                locuid = uidsMap.get(oev.getUid());
                            }
                            if (locuid != null) {
                                uidOverridesSet++;
                                oev.setLocationUid(locuid);
                            }
                            oev.setLocationUid(locuid);
                        }
                        if (!restoreEvProps(resp, oei)) {
                            return false;
                        }
                        if (oev instanceof BwEventAnnotation) {
                            final BwEventAnnotation ann = (BwEventAnnotation) oev;
                            final BwEvent proxy = new BwEventProxy(ann);
                            ann.setTarget(ev);
                            ann.setMaster(ev);
                            ei.addOverride(new EventInfo(proxy));
                            continue;
                        }
                }
                // Unexpected type
                errorReturn(resp, "Expected override only: " + dtype);
                return false;
            }
            if (hits.length < batchSize) {
                // All remaining in this batch - we're done
                break;
            }
            start += batchSize;
        }
        return true;
    } catch (final Throwable t) {
        errorReturn(resp, t);
        return false;
    }
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) SearchResponse(org.elasticsearch.action.search.SearchResponse) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10