use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class CalintfHelper method postGetEvent.
/* Post processing of event access has been checked
*/
protected CoreEventInfo postGetEvent(final BwEvent ev, final Filters f, final Acl.CurrentAccess ca) throws CalFacadeException {
/* XXX-ALARM
if (currentMode == userMode) {
ev.setAlarms(getAlarms(ev, user));
}
*/
BwEvent event;
if (ev instanceof BwEventAnnotation) {
event = new BwEventProxy((BwEventAnnotation) ev);
if ((f != null) && !f.postFilter(ev, currentPrincipal())) {
return null;
}
} else {
event = ev;
}
CoreEventInfo cei = new CoreEventInfo(event, ca);
return cei;
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class CalintfImpl method getFreeBusy.
/* ====================================================================
* Free busy
* ==================================================================== */
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> cals, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final boolean returnAll, final boolean ignoreTransparency) throws CalFacadeException {
if (who.getKind() != WhoDefs.whoTypeUser) {
throw new CalFacadeException("Unsupported: non user principal for free-busy");
}
final Collection<CoreEventInfo> events = getFreeBusyEntities(cals, start, end, ignoreTransparency);
final BwEvent fb = new BwEventObj();
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
fb.setOwnerHref(who.getPrincipalRef());
fb.setDtstart(start);
fb.setDtend(end);
try {
final TreeSet<EventPeriod> eventPeriods = new TreeSet<>();
for (final CoreEventInfo ei : events) {
final BwEvent ev = ei.getEvent();
// Ignore if times were specified and this event is outside the times
final BwDateTime estart = ev.getDtstart();
final BwDateTime eend = ev.getDtend();
/* Don't report out of the requested period */
final String dstart;
final String dend;
if (estart.before(start)) {
dstart = start.getDtval();
} else {
dstart = estart.getDtval();
}
if (eend.after(end)) {
dend = end.getDtval();
} else {
dend = eend.getDtval();
}
final DateTime psdt = new DateTime(dstart);
final DateTime pedt = new DateTime(dend);
psdt.setUtc(true);
pedt.setUtc(true);
int type = BwFreeBusyComponent.typeBusy;
if (BwEvent.statusTentative.equals(ev.getStatus())) {
type = BwFreeBusyComponent.typeBusyTentative;
}
eventPeriods.add(new EventPeriod(psdt, pedt, type));
}
/* iterate through the sorted periods combining them where they are
adjacent or overlap */
Period p = null;
/* For the moment just build a single BwFreeBusyComponent
*/
BwFreeBusyComponent fbc = null;
int lastType = 0;
for (final EventPeriod ep : eventPeriods) {
if (debug) {
debug(ep.toString());
}
if (p == null) {
p = new Period(ep.getStart(), ep.getEnd());
lastType = ep.getType();
} else if ((lastType != ep.getType()) || ep.getStart().after(p.getEnd())) {
// Non adjacent periods
if (fbc == null) {
fbc = new BwFreeBusyComponent();
fbc.setType(lastType);
fb.addFreeBusyPeriod(fbc);
}
fbc.addPeriod(p.getStart(), p.getEnd());
if (lastType != ep.getType()) {
fbc = null;
}
p = new Period(ep.getStart(), ep.getEnd());
lastType = ep.getType();
} else if (ep.getEnd().after(p.getEnd())) {
// Extend the current period
p = new Period(p.getStart(), ep.getEnd());
}
// else it falls within the existing period
}
if (p != null) {
if ((fbc == null) || (lastType != fbc.getType())) {
fbc = new BwFreeBusyComponent();
fbc.setType(lastType);
fb.addFreeBusyPeriod(fbc);
}
fbc.addPeriod(p.getStart(), p.getEnd());
}
} catch (final Throwable t) {
if (debug) {
error(t);
}
throw new CalFacadeException(t);
}
return fb;
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class CalintfImpl method getFreeBusyEntities.
private Collection<CoreEventInfo> getFreeBusyEntities(final Collection<BwCalendar> cals, final BwDateTime start, final BwDateTime end, final boolean ignoreTransparency) throws CalFacadeException {
/* Only events and freebusy for freebusy reports. */
final FilterBase filter = new OrFilter();
try {
filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "event", false));
filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "freeAndBusy", false));
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
final RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded, start, end);
final Collection<CoreEventInfo> evs = getEvents(cals, filter, start, end, null, DeletedState.noDeleted, rrm, true);
// Filter out transparent and cancelled events
final Collection<CoreEventInfo> events = new TreeSet<>();
for (final CoreEventInfo cei : evs) {
final BwEvent ev = cei.getEvent();
if (!ignoreTransparency && IcalDefs.transparencyTransparent.equals(ev.getPeruserTransparency(this.getPrincipal().getPrincipalRef()))) {
// Ignore this one.
continue;
}
if (ev.getSuppressed() || BwEvent.statusCancelled.equals(ev.getStatus())) {
// Ignore this one.
continue;
}
events.add(cei);
}
return events;
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class XbwContactPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xcontacts = ev.getXproperties(BwXproperty.xBedeworkContact);
final Set<BwContact> contacts = ev.getContacts();
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = ((TextPropertyType) ui.getProp()).getText();
final BwString cstr = new BwString(lang, xval);
if (ui.isRemove()) {
if (Util.isEmpty(xcontacts)) {
// Nothing to remove
return UpdateResult.getOkResult();
}
for (final BwXproperty xp : xcontacts) {
if (!xp.getValue().equals(xval)) {
continue;
}
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
/* Do we have a corresponding contact */
for (final BwContact c : contacts) {
if (c.getCn().equals(cstr)) {
ev.removeContact(c);
cte.addRemovedValue(c);
break;
}
}
return UpdateResult.getOkResult();
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
for (final BwXproperty xp : xcontacts) {
if (xp.getValue().equals(xval)) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
}
}
/* Add the xprop or a contact */
if (!checkContact(ui, ev, contacts, lang, xval)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addAddedValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
for (final BwXproperty xp : xcontacts) {
if (xp.getValue().equals(xval)) {
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
if (!checkContact(ui, ev, contacts, nlang, nxval)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
ev.addXproperty(nxp);
cte.addAddedValue(nxp);
}
return UpdateResult.getOkResult();
}
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class XbwLocPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xlocs = ev.getXproperties(xBedeworkLocation);
// Should only be one or zero
final BwXproperty xloc;
if (Util.isEmpty(xlocs)) {
xloc = null;
} else {
xloc = xlocs.get(0);
}
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = ((TextPropertyType) ui.getProp()).getText();
final BaseParameterType keyParam = XcalUtil.findParam(ui.getProp(), XcalTags.xBedeworkLocationKey);
final String keyName;
if (keyParam != null) {
keyName = ((TextParameterType) keyParam).getText();
} else {
keyName = null;
}
final BwLocation evLoc = ev.getLocation();
if (ui.isRemove()) {
if (xlocs == null) {
// Nothing to remove
return UpdateResult.getOkResult();
}
// TODO - match values?
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
if (evLoc != null) {
ev.setLocation(null);
cte.addRemovedValue(evLoc);
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (xloc != null) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
}
if (!checkLocation(ui, ev, lang, xval, null)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addAddedValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
if (xloc == null) {
return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot change");
}
if (CalFacadeUtil.cmpObjval(xval, xloc.getValue()) != 0) {
return new UpdateResult("Values don't match for update to " + ui.getPropName());
}
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
if (!checkLocation(ui, ev, nlang, nxval, keyName)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
if (keyName != null) {
nxp.getParameters().add(new Xpar(XcalTags.xBedeworkLocationKey.getLocalPart(), keyName));
}
ev.addXproperty(nxp);
cte.addAddedValue(nxp);
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
Aggregations