use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class VEventUtil method doRecurring.
/**
* Build recurring properties from event.
*
* @param val
* @param pl
* @throws CalFacadeException
*/
public static void doRecurring(final BwEvent val, final PropertyList pl) throws CalFacadeException {
try {
if (val.hasRrules()) {
for (String s : val.getRrules()) {
RRule rule = new RRule();
rule.setValue(s);
pl.add(rule);
}
}
if (val.hasExrules()) {
for (String s : val.getExrules()) {
ExRule rule = new ExRule();
rule.setValue(s);
pl.add(rule);
}
}
makeDlp(val, false, val.getRdates(), pl);
makeDlp(val, true, val.getExdates(), pl);
} 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 Xalarms method toBwAlarm.
/**
* The generated alarm may not be a valid alarm if it is being used as a
* selector. It must have at least the action as a selector.
*
* @param alarm
* @param validate - true if alarm must be valid and complete
* @return ValarmType
* @throws CalFacadeException
*/
public static BwAlarm toBwAlarm(final ValarmType alarm, final boolean validate) throws CalFacadeException {
BwAlarm ba = new BwAlarm();
/* ============ Action =================== */
ActionPropType action = (ActionPropType) XcalUtil.findProperty(alarm, XcalTags.action);
if (action == null) {
throw new CalFacadeException("Invalid alarm - no action");
}
String actionVal = action.getText().toUpperCase();
int atype = -1;
for (int i = 0; i < BwAlarm.alarmTypes.length; i++) {
if (actionVal.equals(BwAlarm.alarmTypes[i])) {
atype = i;
break;
}
}
if (atype < 0) {
throw new CalFacadeException("Unhandled alarm action");
}
ba.setAlarmType(atype);
/* ============ Trigger =================== */
TriggerPropType tr = (TriggerPropType) XcalUtil.findProperty(alarm, XcalTags.trigger);
if (tr == null) {
if (validate) {
throw new CalFacadeException("Invalid alarm - no action");
}
} else {
if (tr.getDateTime() != null) {
ba.setTrigger(XcalUtil.getIcalFormatDateTime(tr.getDateTime()));
ba.setTriggerDateTime(true);
} else {
ba.setTrigger(tr.getDuration());
RelatedParamType r = (RelatedParamType) XcalUtil.findParam(tr, XcalTags.related);
ba.setTriggerStart((r == null) || (r.getText().toUpperCase().equals("START")));
}
}
/* ============ Duration =================== */
DurationPropType dur = (DurationPropType) XcalUtil.findProperty(alarm, XcalTags.duration);
if (dur != null) {
// MUST have repeat
RepeatPropType rep = (RepeatPropType) XcalUtil.findProperty(alarm, XcalTags.repeat);
ba.setDuration(dur.getDuration());
if (rep == null) {
if (validate) {
throw new CalFacadeException("Invalid alarm - no repeat");
}
} else {
ba.setRepeat(rep.getInteger().intValue());
}
}
/* ============ Description ============ */
if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
DescriptionPropType desc = (DescriptionPropType) XcalUtil.findProperty(alarm, XcalTags.description);
if (desc != null) {
ba.setDescription(desc.getText());
}
}
/* ============ Summary ============ */
if (atype == BwAlarm.alarmTypeEmail) {
SummaryPropType s = (SummaryPropType) XcalUtil.findProperty(alarm, XcalTags.summary);
if (s != null) {
ba.setSummary(s.getText());
}
}
if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
AttachPropType a = (AttachPropType) XcalUtil.findProperty(alarm, XcalTags.attach);
// XXX Onl handle 1 attachment
if ((a != null) && (a.getUri() != null)) {
ba.setAttach(a.getUri());
}
}
if (atype == BwAlarm.alarmTypeEmail) {
for (JAXBElement<? extends BasePropertyType> bpel : alarm.getProperties().getBasePropertyOrTzid()) {
if (!bpel.getName().equals(XcalTags.attendee)) {
continue;
}
AttendeePropType attp = (AttendeePropType) bpel.getValue();
BwAttendee batt = new BwAttendee();
batt.setAttendeeUri(attp.getCalAddress());
ba.addAttendee(batt);
}
}
return ba;
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class CalSuites method validateGroup.
/**
* Ensure the given group is valid for the given calendar suite
*
* @param cs
* @param groupName
* @return home for the group
* @throws CalFacadeException
*/
private BwCalendar validateGroup(final BwCalSuite cs, final String groupName) throws CalFacadeException {
if (groupName.length() > BwCalSuite.maxNameLength) {
throw new CalFacadeException(CalFacadeException.calsuiteGroupNameTooLong);
}
BwAdminGroup agrp = (BwAdminGroup) getSvc().getAdminDirectories().findGroup(groupName);
if (agrp == null) {
throw new CalFacadeException(CalFacadeException.groupNotFound, groupName);
}
final BwCalSuiteWrapper csw = get(agrp);
if ((csw != null) && !csw.equals(cs)) {
// Group already assigned to another cal suite
throw new CalFacadeException(CalFacadeException.calsuiteGroupAssigned, csw.getName());
}
final BwPrincipal eventsOwner = getPrincipal(agrp.getOwnerHref());
if (eventsOwner == null) {
throw new CalFacadeException(CalFacadeException.calsuiteBadowner);
}
final BwCalendar home = getCols().getHomeDb(eventsOwner, true);
if (home == null) {
throw new CalFacadeException(CalFacadeException.missingGroupOwnerHome);
}
cs.setGroup(agrp);
/* Change access on the home for the events creator which is also the
* owner of the calsuite resources.
*/
final Collection<Privilege> allPrivs = new ArrayList<>();
allPrivs.add(Access.all);
final Collection<Privilege> readPrivs = new ArrayList<>();
readPrivs.add(Access.read);
final Collection<Ace> aces = new ArrayList<>();
try {
aces.add(Ace.makeAce(AceWho.owner, allPrivs, null));
aces.add(Ace.makeAce(AceWho.getAceWho(eventsOwner.getAccount(), WhoDefs.whoTypeUser, false), allPrivs, null));
aces.add(Ace.makeAce(AceWho.getAceWho(null, WhoDefs.whoTypeAuthenticated, false), readPrivs, null));
aces.add(Ace.makeAce(AceWho.all, readPrivs, null));
getSvc().changeAccess(home, aces, true);
/* Same access to the calsuite itself */
getSvc().changeAccess(cs, aces, true);
/* Also set access so that categories, locations etc are readable */
final String aclStr = new String(new Acl(aces).encode());
eventsOwner.setCategoryAccess(aclStr);
eventsOwner.setLocationAccess(aclStr);
eventsOwner.setContactAccess(aclStr);
} catch (final AccessException ae) {
throw new CalFacadeException(ae);
}
getSvc().getUsersHandler().update(eventsOwner);
return home;
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class CalSuites method add.
@Override
public BwCalSuiteWrapper add(final String name, final String adminGroupName, final String rootCollectionPath, final String submissionsPath) throws CalFacadeException {
BwCalSuite cs = getCal().getCalSuite(name);
if (cs != null) {
throw new CalFacadeException(CalFacadeException.duplicateCalsuite);
}
cs = new BwCalSuite();
cs.setName(name);
setRootCol(cs, rootCollectionPath);
setupSharableEntity(cs, getPrincipal().getPrincipalRef());
setSubmissionsCol(cs, submissionsPath);
validateGroup(cs, adminGroupName);
getCal().saveOrUpdate(cs);
return wrap(cs, false);
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class CalSuites method setRootCol.
/**
* Set root collection if supplied
*
* @param cs
* @param rootCollectionPath
* @throws CalFacadeException
*/
private void setRootCol(final BwCalSuite cs, final String rootCollectionPath) throws CalFacadeException {
if ((rootCollectionPath == null) || rootCollectionPath.equals(cs.getRootCollectionPath())) {
return;
}
BwCalendar rootCol = getCols().get(rootCollectionPath);
if (rootCol == null) {
throw new CalFacadeException(CalFacadeException.calsuiteUnknownRootCollection, rootCollectionPath);
}
cs.setRootCollection(rootCol);
cs.setRootCollectionPath(rootCol.getPath());
}
Aggregations