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;
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations