use of org.bedework.calfacade.exc.CalFacadeBadRequest in project bw-calendar-engine by Bedework.
the class CalDavParseUtil method parseBwTimeRange.
/**
* The given node must be a time-range element
* <!ELEMENT time-range EMPTY>
*
* <!ATTLIST time-range start CDATA
* end CDATA>
*
* e.g. <C:time-range start="20040902T000000Z"
* end="20040902T235959Z"/>
*
* @param nd
* @param tzid - timezone to use if specified
* @return TimeRange
* @throws CalFacadeException
*/
public static BwTimeRange parseBwTimeRange(Node nd, String tzid) throws CalFacadeException {
BwDateTime start = null;
BwDateTime end = null;
NamedNodeMap nnm = nd.getAttributes();
if ((nnm == null) || (nnm.getLength() == 0)) {
// Infinite time-range?
throw new CalFacadeBadRequest("Infinite time range");
}
int attrCt = nnm.getLength();
try {
Node nmAttr = nnm.getNamedItem("start");
if (nmAttr != null) {
attrCt--;
if (tzid == null) {
start = BwDateTimeUtil.getDateTimeUTC(nmAttr.getNodeValue());
} else {
start = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(), false, false, tzid);
}
}
nmAttr = nnm.getNamedItem("end");
if (nmAttr != null) {
attrCt--;
if (tzid == null) {
end = BwDateTimeUtil.getDateTimeUTC(nmAttr.getNodeValue());
} else {
end = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(), false, false, tzid);
}
}
} catch (Throwable t) {
throw new CalFacadeBadRequest(t);
}
if (attrCt != 0) {
throw new CalFacadeBadRequest();
}
return new BwTimeRange(start, end);
}
use of org.bedework.calfacade.exc.CalFacadeBadRequest in project bw-calendar-engine by Bedework.
the class CoreCalendarsDAO method getSynchCollections.
protected List getSynchCollections(final String path, final String token) throws CalFacadeException {
final HibSession sess = getSess();
if (path == null) {
sess.rollback();
throw new CalFacadeBadRequest("Missing path");
}
if ((token != null) && (token.length() < 18)) {
sess.rollback();
throw new CalFacadeInvalidSynctoken(token);
}
final StringBuilder sb = new StringBuilder();
sb.append("from ");
sb.append(BwCalendar.class.getName());
sb.append(" col ");
sb.append("where col.colPath=:path ");
if (token != null) {
/* We want any undeleted alias or external subscription or
any collection with a later change token.
*/
sb.append(" and ((col.calType=7 or col.calType=8) or " + "(col.lastmod.timestamp>:lastmod" + " or (col.lastmod.timestamp=:lastmod and " + " col.lastmod.sequence>:seq)))");
} else {
// No deleted collections for null sync-token
sb.append("and (col.filterExpr is null or col.filterExpr <> :tsfilter)");
}
sess.createQuery(sb.toString());
sess.setString("path", path);
if (token != null) {
sess.setString("lastmod", token.substring(0, 16));
sess.setInt("seq", Integer.parseInt(token.substring(17), 16));
} else {
sess.setString("tsfilter", BwCalendar.tombstonedFilter);
}
sess.cacheableQuery();
return sess.getList();
}
use of org.bedework.calfacade.exc.CalFacadeBadRequest in project bw-calendar-engine by Bedework.
the class CoreEvents method getSynchEvents.
@Override
public Set<CoreEventInfo> getSynchEvents(final String path, final String token) throws CalFacadeException {
if (path == null) {
dao.rollback();
throw new CalFacadeBadRequest("Missing path");
}
final String fpath = fixPath(path);
final BwCalendar col = getCollection(fpath);
ac.checkAccess(col, privAny, false);
@SuppressWarnings("unchecked") final List<BwEvent> evs = dao.getSynchEventObjects(fpath, token);
if (debug) {
trace(" ----------- number evs = " + evs.size());
}
final Set<CoreEventInfo> res = new TreeSet<>();
for (final BwEvent ev : evs) {
final CurrentAccess ca = new CurrentAccess(true);
res.add(new CoreEventInfo(ev, ca));
}
return res;
}
use of org.bedework.calfacade.exc.CalFacadeBadRequest in project bw-calendar-engine by Bedework.
the class ImplicitSchedulingHandler method implicitSchedule.
@Override
public void implicitSchedule(final EventInfo ei, final boolean noInvites) throws CalFacadeException {
UpdateResult uer = ei.getUpdResult();
if (debug) {
dump(uer);
}
BwEvent ev = ei.getEvent();
boolean organizerSchedulingObject = ev.getOrganizerSchedulingObject();
boolean attendeeSchedulingObject = ev.getAttendeeSchedulingObject();
if (ev.getSuppressed()) {
if (!Util.isEmpty(ei.getOverrides())) {
for (EventInfo oei : ei.getOverrides()) {
uer = oei.getUpdResult();
if (debug) {
dump(uer);
}
BwEvent oev = oei.getEvent();
if (oev.getOrganizerSchedulingObject()) {
organizerSchedulingObject = true;
}
if (oev.getAttendeeSchedulingObject()) {
attendeeSchedulingObject = true;
}
}
}
}
if (!organizerSchedulingObject && !attendeeSchedulingObject) {
// Not a scheduling event
if (debug) {
trace("No a scheduling object: just return");
}
return;
}
if (ev.getOrganizer() == null) {
throw new CalFacadeBadRequest(CalFacadeException.missingEventProperty);
}
if (ev.getOriginator() == null) {
ev.setOriginator(ev.getOrganizer().getOrganizerUri());
}
if (uer.reply) {
int meth;
if (ei.getReplyAttendeeURI() != null) {
meth = ScheduleMethods.methodTypeRefresh;
} else {
meth = ScheduleMethods.methodTypeReply;
}
ev.setScheduleMethod(meth);
uer.schedulingResult = attendeeRespond(ei, meth);
return;
}
if (uer.deleting) {
if (organizerSchedulingObject) {
// if (schedMethod == Icalendar.methodTypeCancel) {
// /* We already canceled this one */
// return;
// }
ev.setScheduleMethod(ScheduleMethods.methodTypeCancel);
} else {
// Reply from attendee setting partstat
ev.setScheduleMethod(ScheduleMethods.methodTypeReply);
}
} else {
ev.setScheduleMethod(ScheduleMethods.methodTypeRequest);
}
if (!noInvites) {
uer.schedulingResult = schedule(ei, ei.getReplyAttendeeURI(), uer.fromAttUri, false);
}
if (!uer.adding && !Util.isEmpty(uer.deletedAttendees)) {
/* Send cancel to removed attendees */
for (BwAttendee att : uer.deletedAttendees) {
if (Util.compareStrings(att.getPartstat(), IcalDefs.partstats[IcalDefs.partstatDeclined]) == 0) {
// Already declined - send nothing
continue;
}
/* Clone is adequate here. For a CANCEL we just send either the master
* or the particular instance.
*/
BwEvent cncl = (BwEvent) ev.clone();
cncl.setAttendees(null);
cncl.addAttendee((BwAttendee) att.clone());
cncl.setRecipients(null);
cncl.addRecipient(att.getAttendeeUri());
cncl.setScheduleMethod(ScheduleMethods.methodTypeCancel);
cncl.setOrganizerSchedulingObject(true);
cncl.setAttendeeSchedulingObject(false);
EventInfo cei = new EventInfo(cncl);
ScheduleResult cnclr = schedule(cei, null, null, false);
if (debug) {
trace(cnclr.toString());
}
}
}
if (ei.getInboxEventName() != null) {
// Delete the given event from the inbox.
EventsI events = getSvc().getEventsHandler();
BwCalendar inbox = getSvc().getCalendarsHandler().getSpecial(BwCalendar.calTypeInbox, true);
final EventInfo inboxei = events.get(inbox.getPath(), ei.getInboxEventName());
if (inboxei != null) {
events.delete(inboxei, false);
}
}
}
Aggregations