use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class NotificationsInfo method getDeleted.
/**
* Call for a deleted event
*
* @param currentAuth
* @param ev
* @return resource deleted notification.
* @throws CalFacadeException
*/
public static ResourceChangeType getDeleted(final String currentAuth, final BwEvent ev) throws CalFacadeException {
try {
ResourceChangeType rc = new ResourceChangeType();
DeletedType del = new DeletedType();
del.setHref(getHref(ev));
del.setChangedBy(getChangedBy(currentAuth));
DeletedDetailsType dd = new DeletedDetailsType();
dd.setDeletedComponent(getType(ev));
dd.setDeletedSummary(ev.getSummary());
if (ev.isRecurringEntity()) {
// TODO: Set these correctly.
// dd.setDeletedNextInstance(val);
// dd.setDeletedNextInstanceTzid(val);
// dd.setDeletedHadMoreInstances(val);
}
if (ev.getDtstart() != null) {
ChangedPropertyType start = new ChangedPropertyType();
start.setName(PropertyInfoIndex.DTSTART.name());
start.setDataFrom(String.valueOf(ev.getDtstart()));
dd.getDeletedProps().add(start);
}
if (ev.getDtend() != null) {
ChangedPropertyType end = new ChangedPropertyType();
end.setName(PropertyInfoIndex.DTEND.name());
end.setDataFrom(String.valueOf(ev.getDtend()));
dd.getDeletedProps().add(end);
}
if (ev.getDuration() != null && !ev.getDuration().isEmpty()) {
ChangedPropertyType dur = new ChangedPropertyType();
dur.setName(PropertyInfoIndex.DURATION.name());
dur.setDataFrom(ev.getDuration());
dd.getDeletedProps().add(dur);
}
if (ev.getLocation() != null) {
ChangedPropertyType loc = new ChangedPropertyType();
loc.setName(PropertyInfoIndex.LOCATION.name());
loc.setDataFrom(ev.getLocation().getAddress().getValue());
dd.getDeletedProps().add(loc);
}
if (ev.getDescription() != null) {
ChangedPropertyType desc = new ChangedPropertyType();
desc.setName(PropertyInfoIndex.DESCRIPTION.name());
desc.setDataFrom(ev.getDescription());
dd.getDeletedProps().add(desc);
}
del.setDeletedDetails(dd);
rc.setDeleted(del);
return rc;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class BwEventUtil method processCandidates.
private static void processCandidates(final VPoll val, final EventInfo vpoll, final ChangeTable changes) throws CalFacadeException {
try {
final ComponentList cands = val.getCandidates();
if ((cands == null) || cands.isEmpty()) {
return;
}
final Iterator it = cands.iterator();
final Set<Integer> pids = new TreeSet<>();
final BwEvent event = vpoll.getEvent();
if (!Util.isEmpty(event.getPollItems())) {
event.clearPollItems();
}
while (it.hasNext()) {
final Component comp = (Component) it.next();
final String pollItem = comp.toString();
event.addPollItem(pollItem);
changes.addValue(PropertyInfoIndex.POLL_ITEM, pollItem);
final Property p = comp.getProperty(Property.POLL_ITEM_ID);
if (p == null) {
throw new CalFacadeException("XXX - no poll item id");
}
final int pid = ((PollItemId) p).getPollitemid();
if (pids.contains(pid)) {
throw new CalFacadeException("XXX - duplicate poll item id " + pid);
}
pids.add(pid);
// EventInfo cand = toEvent(cb, cal, ical, (Component)o, true,
// false);
// cand.getEvent().setOwnerHref(vpoll.getEvent().getOwnerHref());
// vpoll.addContainedItem(cand);
}
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class BwFreeBusyUtil method toFreeBusy.
/**
* @param cb
* @param val
* @return BwFreeBusy
* @throws CalFacadeException
*/
public static EventInfo toFreeBusy(final IcalCallback cb, final VFreeBusy val) throws CalFacadeException {
if (val == null) {
return null;
}
boolean debug = getLog().isDebugEnabled();
try {
PropertyList pl = val.getProperties();
if (pl == null) {
// Empty VEvent
return null;
}
BwEvent fb = new BwEventObj();
EventInfo ei = new EventInfo(fb);
ChangeTable chg = ei.getChangeset(cb.getPrincipal().getPrincipalRef());
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
setDates(cb.getPrincipal().getPrincipalRef(), ei, (DtStart) pl.getProperty(Property.DTSTART), (DtEnd) pl.getProperty(Property.DTEND), (Duration) pl.getProperty(Property.DURATION));
Iterator it = pl.iterator();
while (it.hasNext()) {
Property prop = (Property) it.next();
String pval = prop.getValue();
if ((pval != null) && (pval.length() == 0)) {
pval = null;
}
PropertyInfoIndex pi = PropertyInfoIndex.fromName(prop.getName());
if (pi == null) {
debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
continue;
}
switch(pi) {
case ATTENDEE:
/* ------------------- Attendee -------------------- */
BwAttendee att = getAttendee(cb, (Attendee) prop);
fb.addAttendee(att);
chg.addValue(pi, att);
break;
case COMMENT:
/* ------------------- Comment -------------------- */
// LANG
fb.addComment(null, pval);
chg.addValue(pi, pval);
case DTEND:
break;
case DTSTAMP:
/* ------------------- DtStamp -------------------- */
chg.changed(pi, fb.getDtstamp(), pval);
fb.setDtstamp(pval);
case DTSTART:
break;
case FREEBUSY:
/* ------------------- freebusy -------------------- */
FreeBusy fbusy = (FreeBusy) prop;
PeriodList perpl = fbusy.getPeriods();
Parameter par = getParameter(fbusy, "FBTYPE");
int fbtype;
if (par == null) {
fbtype = BwFreeBusyComponent.typeBusy;
} else if (par.equals(FbType.BUSY)) {
fbtype = BwFreeBusyComponent.typeBusy;
} else if (par.equals(FbType.BUSY_TENTATIVE)) {
fbtype = BwFreeBusyComponent.typeBusyTentative;
} else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
fbtype = BwFreeBusyComponent.typeBusyUnavailable;
} else if (par.equals(FbType.FREE)) {
fbtype = BwFreeBusyComponent.typeFree;
} else {
if (debug) {
debugMsg("Unsupported parameter " + par.getName());
}
throw new IcalMalformedException("parameter " + par.getName());
}
BwFreeBusyComponent fbc = new BwFreeBusyComponent();
fbc.setType(fbtype);
Iterator perit = perpl.iterator();
while (perit.hasNext()) {
Period per = (Period) perit.next();
fbc.addPeriod(per);
}
fb.addFreeBusyPeriod(fbc);
chg.addValue(pi, fbc);
break;
case ORGANIZER:
/* ------------------- Organizer -------------------- */
BwOrganizer org = getOrganizer(cb, (Organizer) prop);
fb.setOrganizer(org);
chg.addValue(pi, org);
break;
case UID:
/* ------------------- Uid -------------------- */
chg.changed(pi, fb.getUid(), pval);
fb.setUid(pval);
break;
default:
if (debug) {
debugMsg("Unsupported property with class " + prop.getClass() + " and value " + pval);
}
}
}
return ei;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class Notifications method update.
@Override
public boolean update(final NotificationType val) throws CalFacadeException {
if ((val == null) || (val.getNotification() == null) || (val.getNotification().getElementName() == null)) {
return false;
}
try {
final String xml = val.toXml(true);
if (xml == null) {
return false;
}
final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return false;
}
final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", val.getName()));
if (noteRsrc == null) {
return false;
}
BwResourceContent rc = noteRsrc.getContent();
if (rc == null) {
rc = new BwResourceContent();
noteRsrc.setContent(rc);
}
final byte[] xmlData = xml.getBytes();
rc.setValue(getSvc().getBlob(xmlData));
noteRsrc.setContentLength(xmlData.length);
noteRsrc.setContentType(val.getContentType());
getSvc().getResourcesHandler().update(noteRsrc, true);
getNoteClient().informNotifier(getPrincipalHref(), noteRsrc.getName());
return true;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method validateAlarm.
/**
* Validate an alarm component
*
* @param val
* @return boolean false for failure
* @throws WebdavException
*/
@Override
public boolean validateAlarm(final String val) throws WebdavException {
try {
// Ensure open
getSvci();
StringReader sr = new StringReader(ValidateAlarmPrefix + val + ValidateAlarmSuffix);
Icalendar ic = trans.fromIcal(null, sr);
if ((ic == null) || (ic.getEventInfo() == null)) {
if (debug) {
debug("Not single event");
}
return false;
}
/* There should be alarms in the Calendar object
*/
EventInfo ei = ic.getEventInfo();
BwEvent ev = ei.getEvent();
if ((ev.getAlarms() == null) || ev.getAlarms().isEmpty()) {
return false;
}
return true;
} catch (CalFacadeException cfe) {
if (debug) {
error(cfe);
}
return false;
}
}
Aggregations