Search in sources :

Example 66 with EventInfo

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

the class BwIndexEsImpl method getIndexStats.

@Override
public IndexStatsResponse getIndexStats(final String indexName) {
    final IndexStatsResponse resp = new IndexStatsResponse(indexName);
    if (indexName == null) {
        return errorReturn(resp, "indexName must be provided");
    }
    final QueryBuilder qb = new FilteredQueryBuilder(null, FilterBuilders.matchAllFilter());
    // 1 minute
    final int timeoutMillis = 60000;
    final TimeValue tv = new TimeValue(timeoutMillis);
    final int batchSize = 100;
    final Client cl = getClient(resp);
    if (cl == null) {
        return resp;
    }
    SearchResponse scrollResp = cl.prepareSearch(indexName).setSearchType(SearchType.SCAN).setScroll(tv).setQuery(qb).setSize(batchSize).execute().actionGet();
    // Scroll until no hits are returned
    while (true) {
        for (final SearchHit hit : scrollResp.getHits().getHits()) {
            resp.incProcessed();
            final String dtype = hit.getType();
            if (dtype.equals(docTypeEvent)) {
                final EventInfo entity = (EventInfo) makeEntity(resp, hit, null);
                if (entity == null) {
                    errorReturn(resp, "Unable to make doc for " + hit.sourceAsString());
                    continue;
                }
                final BwEvent ev = entity.getEvent();
                if (ev instanceof BwEventAnnotation) {
                    final BwEventAnnotation ann = (BwEventAnnotation) ev;
                    if (ann.testOverride()) {
                        resp.incOverrides();
                    }
                }
                if (ev.getRecurring()) {
                    resp.incRecurring();
                }
                if (ev.getRecurrenceId() == null) {
                    resp.incMasters();
                } else {
                    resp.incInstances();
                }
            } else {
                resp.getStats().inc(docToType.getOrDefault(dtype, unreachableEntities));
            }
        }
        scrollResp = cl.prepareSearchScroll(scrollResp.getScrollId()).setScroll(tv).execute().actionGet();
        // Break condition: No hits are returned
        if (scrollResp.getHits().getHits().length == 0) {
            break;
        }
    }
    return resp;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) FilteredQueryBuilder(org.elasticsearch.index.query.FilteredQueryBuilder) BwEvent(org.bedework.calfacade.BwEvent) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FilteredQueryBuilder(org.elasticsearch.index.query.FilteredQueryBuilder) TransportClient(org.elasticsearch.client.transport.TransportClient) Client(org.elasticsearch.client.Client) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) TimeValue(org.elasticsearch.common.unit.TimeValue) IndexStatsResponse(org.bedework.calfacade.indexing.IndexStatsResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 67 with EventInfo

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

the class CoreEvents method updateEvent.

@Override
public UpdateEventResult updateEvent(final EventInfo ei) throws CalFacadeException {
    final BwEvent val = ei.getEvent();
    final Collection<BwEventProxy> overrides = ei.getOverrideProxies();
    final Collection<BwEventProxy> deletedOverrides = ei.getDeletedOverrideProxies(cb.getPrincipalInfo().getPrincipal().getPrincipalRef());
    final UpdateEventResult ue = new UpdateEventResult();
    if (!ac.checkAccess(val, privWrite, true).getAccessAllowed()) {
        // XXX Is this correct?
        try {
            ac.checkAccess(val, privWriteContent, false);
        } catch (final CalFacadeException cfe) {
            throwException(cfe);
        }
    }
    BwEventProxy proxy = null;
    if (val instanceof BwEventProxy) {
        proxy = (BwEventProxy) val;
    }
    final BwCalendar col = getCollection(val.getColPath());
    final boolean shared = col.getPublick() || col.getShared();
    if ((proxy != null) && (proxy.getRef().getOverride())) {
        final BwEventAnnotation ann = proxy.getRef();
        final BwEvent mstr = ann.getMaster();
        if (!proxy.getUid().equals(mstr.getUid())) {
            throwException("org.bedework.cannot.overrideuid");
        }
        if (!proxy.getName().equals(mstr.getName())) {
            throwException("org.bedework.cannot.overridename");
        }
    } else {
        /* The guid must not exist in the same calendar. We assign a guid if
       * one wasn't assigned already. However, the event may have come with a guid
       * (caldav, import, etc) so we need to check here.
       *
       * It also ensures our guid allocation is working OK
       */
        final CollectionInfo collInf = col.getCollectionInfo();
        if (collInf.uniqueKey) {
            String name = calendarGuidExists(val, false, false);
            if (name == null) {
                name = calendarGuidExists(val, true, false);
            }
            if (name != null) {
                throwException(CalFacadeException.duplicateGuid, name);
            }
        }
        /* Similarly for event names which must be unique within a collection
       */
        if (calendarNameExists(val, false, false) || calendarNameExists(val, true, false)) {
            throwException(new CalFacadeDupNameException(val.getName()));
        }
    }
    if (!(val instanceof BwEventProxy)) {
        dao.update(val);
        final Collection<BwDbentity<?>> deleted = val.getDeletedEntities();
        if (deleted != null) {
            for (final BwDbentity ent : deleted) {
                dao.delete(ent);
            }
            deleted.clear();
        }
        if (val.testRecurring()) {
            if (!Util.isEmpty(overrides)) {
                for (final BwEventProxy pxy : overrides) {
                    final BwEventAnnotation ann = pxy.getRef();
                    boolean updated = false;
                    if ((ann.getRecurring() != null) && ann.getRecurring()) {
                        // be safe
                        ann.setRecurring(false);
                        updated = true;
                    }
                    if (ann.getTombstoned() == null) {
                        // be safe
                        ann.setTombstoned(false);
                        updated = true;
                    }
                    if (ann.unsaved()) {
                        dao.save(ann);
                    } else if (updated) {
                        updateProxy(new BwEventProxy(ann));
                    }
                }
            }
            updateRecurrences(ei, ue, overrides, shared);
        }
        if (!val.testRecurring() || (Util.isEmpty(overrides) && Util.isEmpty(deletedOverrides))) {
            notify(SysEvent.SysCode.ENTITY_UPDATED, val, shared);
            indexEntity(ei);
            return ue;
        }
        if (!Util.isEmpty(overrides)) {
            updateOverrides: for (final BwEventProxy pxy : overrides) {
                final BwEventAnnotation ann = pxy.getRef();
                if (ue.deleted != null) {
                    for (final BwRecurrenceInstance ri : ue.deleted) {
                        if (ri.getRecurrenceId().equals(ann.getRecurrenceId())) {
                            continue updateOverrides;
                        }
                    }
                }
                if (ue.added != null) {
                    for (final BwRecurrenceInstance ri : ue.added) {
                        if (ri.getRecurrenceId().equals(ann.getRecurrenceId())) {
                            continue updateOverrides;
                        }
                    }
                }
                // be safe
                ann.setRecurring(false);
                if (ann.getTombstoned() == null) {
                    // be safe
                    ann.setTombstoned(false);
                }
                if (!ann.unsaved()) {
                    updateProxy(new BwEventProxy(ann));
                } else {
                    dao.save(ann);
                    /* See if there is an instance for this override
             */
                    BwRecurrenceInstance ri = dao.getInstance(val, ann.getRecurrenceId());
                    if (ri == null) {
                        final BwDateTime rid = BwDateTime.fromUTC(ann.getRecurrenceId().length() == 8, ann.getRecurrenceId());
                        final Dur dur = new Dur(val.getDuration());
                        final BwDateTime end = rid.addDur(dur);
                        ri = new BwRecurrenceInstance();
                        ri.setDtstart(rid);
                        ri.setDtend(end);
                        ri.setRecurrenceId(rid.getDate());
                        ri.setMaster(val);
                        ri.setOverride(ann);
                        dao.save(ri);
                    } else {
                        ri.setOverride(ann);
                        dao.update(ri);
                    }
                }
                notifyInstanceChange(SysEvent.SysCode.ENTITY_UPDATED, val, shared, ann.getRecurrenceId());
            }
        }
        if (!Util.isEmpty(deletedOverrides)) {
            final Collection<String> rids = new ArrayList<>();
            for (final BwEventProxy pxy : deletedOverrides) {
                rids.add(pxy.getRecurrenceId());
            }
            removeInstances(val, rids, ue, deletedOverrides, shared);
        }
    } else {
        if (proxy.getChangeFlag()) {
            updateProxy(proxy);
        }
    }
    notify(SysEvent.SysCode.ENTITY_UPDATED, val, shared);
    if (proxy != null) {
        if (ei.getRetrievedEvent() == null) {
            warn("No retrieved event for indexer");
        } else {
            final EventInfo rei = ei.getRetrievedEvent();
            rei.addOverride(ei);
            indexEntity(rei);
        }
    } else {
        indexEntity(ei);
    }
    return ue;
}
Also used : Dur(net.fortuna.ical4j.model.Dur) BwDateTime(org.bedework.calfacade.BwDateTime) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) CollectionInfo(org.bedework.calfacade.BwCalendar.CollectionInfo) ArrayList(java.util.ArrayList) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance) CalFacadeDupNameException(org.bedework.calfacade.exc.CalFacadeDupNameException) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwDbentity(org.bedework.calfacade.base.BwDbentity)

Example 68 with EventInfo

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

the class AttachmentRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    BwAttachment entity = (BwAttachment) pop();
    EventInfo ei = (EventInfo) getTop(EventInfo.class, name);
    BwEvent e = ei.getEvent();
    if (e instanceof BwEventProxy) {
        e = ((BwEventProxy) e).getRef();
    }
    // Mark unsaved
    entity.setId(CalFacadeDefs.unsavedItemKey);
    e.addAttachment(entity);
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwAttachment(org.bedework.calfacade.BwAttachment) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 69 with EventInfo

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

the class AttendeeRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    BwAttendee entity = (BwAttendee) pop();
    EventInfo ei = (EventInfo) getTop(EventInfo.class, name);
    BwEvent e = ei.getEvent();
    if (e instanceof BwEventProxy) {
        e = ((BwEventProxy) e).getRef();
    }
    // Mark unsaved
    entity.setId(CalFacadeDefs.unsavedItemKey);
    e.addAttendee(entity);
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 70 with EventInfo

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

the class BwLongStringRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    if (name.equals("bwlongstring")) {
        // 3.5 onwards we wrapped with a tag. Do nothing
        return;
    }
    BwLongString entity;
    try {
        entity = (BwLongString) pop();
        if (top() instanceof BwFilterDef) {
            BwFilterDef f = (BwFilterDef) top();
            if (name.equals("subaddr")) {
                f.addDescription(entity);
            } else {
                throw new Exception("unknown tag " + name);
            }
            return;
        }
        EventInfo ei = (EventInfo) top();
        BwEvent e = ei.getEvent();
        if (e instanceof BwEventProxy) {
            e = ((BwEventProxy) e).getRef();
        }
        if (name.equals("description")) {
            e.addDescription(entity);
        } else {
            throw new Exception("unknown tag " + name);
        }
    } catch (Throwable t) {
        handleException(t);
    }
}
Also used : BwLongString(org.bedework.calfacade.BwLongString) EventInfo(org.bedework.calfacade.svc.EventInfo) BwFilterDef(org.bedework.calfacade.BwFilterDef) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

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