use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Events method add.
@Override
public UpdateResult add(final EventInfo ei, final boolean noInvites, final boolean schedulingInbox, final boolean autoCreateCollection, final boolean rollbackOnError) throws CalFacadeException {
try {
if (getPrincipalInfo().getSubscriptionsOnly()) {
throw new CalFacadeForbidden("User has read only access");
}
final UpdateResult updResult = ei.getUpdResult();
updResult.adding = true;
updResult.hasChanged = true;
final BwEvent event = ei.getEvent();
adjustEntities(ei);
final BwPreferences prefs = getSvc().getPrefsHandler().get();
if (prefs != null) {
final Collection<BwCategory> cats = getSvc().getCategoriesHandler().get(prefs.getDefaultCategoryUids());
for (final BwCategory cat : cats) {
event.addCategory(cat);
}
}
final RealiasResult raResp = reAlias(event);
if (raResp.getStatus() != ok) {
throw new CalFacadeException(CalFacadeException.badRequest, "Status: " + raResp.getStatus() + " message: " + raResp.getMessage());
}
// Or just validate?
assignGuid(event);
updateEntities(updResult, event);
BwCalendar cal = validate(event, true, schedulingInbox, autoCreateCollection);
BwEventProxy proxy = null;
BwEvent override = null;
if (event instanceof BwEventProxy) {
proxy = (BwEventProxy) event;
override = proxy.getRef();
setupSharableEntity(override, getPrincipal().getPrincipalRef());
} else {
setupSharableEntity(event, getPrincipal().getPrincipalRef());
if (ei.getNumContainedItems() > 0) {
for (final EventInfo aei : ei.getContainedItems()) {
final BwEvent av = aei.getEvent();
av.setParent(event);
setupSharableEntity(av, getPrincipal().getPrincipalRef());
}
}
}
final BwCalendar undereffedCal = cal;
if (cal.getInternalAlias()) {
/* Resolve the alias and put the event in it's proper place */
// XXX This is probably OK for non-public admin
final boolean setCats = getSvc().getPars().getPublicAdmin();
if (!setCats) {
cal = getCols().resolveAlias(cal, true, false);
} else {
while (true) {
final Set<BwCategory> cats = cal.getCategories();
for (final BwCategory cat : cats) {
event.addCategory(cat);
}
if (!cal.getInternalAlias()) {
break;
}
cal = getCols().resolveAlias(cal, false, false);
}
}
event.setColPath(cal.getPath());
}
if (!cal.getCalendarCollection()) {
throw new CalFacadeAccessException();
}
if (!event.getPublick() && Util.isEmpty(event.getAlarms())) {
setDefaultAlarms(ei, undereffedCal);
}
boolean schedulingObject = false;
if (cal.getCollectionInfo().scheduling && (event.getOrganizerSchedulingObject() || event.getAttendeeSchedulingObject())) {
schedulingObject = true;
}
final Integer maxAttendees = getSvc().getAuthProperties().getMaxAttendeesPerInstance();
if ((maxAttendees != null) && !Util.isEmpty(event.getAttendees()) && (event.getAttendees().size() > maxAttendees)) {
throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
}
event.setDtstamps(getCurrentTimestamp());
if (schedulingObject) {
event.updateStag(getCurrentTimestamp());
}
/* All Overrides go in same calendar and have same name */
final Collection<BwEventProxy> overrides = ei.getOverrideProxies();
if (overrides != null) {
for (final BwEventProxy ovei : overrides) {
setScheduleState(ovei, true, schedulingInbox);
if ((maxAttendees != null) && !Util.isEmpty(ovei.getAttendees()) && (ovei.getAttendees().size() > maxAttendees)) {
throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
}
ovei.setDtstamps(getCurrentTimestamp());
if (cal.getCollectionInfo().scheduling && (ovei.getOrganizerSchedulingObject() || ovei.getAttendeeSchedulingObject())) {
schedulingObject = true;
}
if (schedulingObject) {
ovei.updateStag(getCurrentTimestamp());
}
final BwEventAnnotation ann = ovei.getRef();
ann.setColPath(event.getColPath());
ann.setName(event.getName());
}
}
if (event.getOrganizerSchedulingObject()) {
// Set RSVP on all attendees with PARTSTAT = NEEDS_ACTION
for (final BwAttendee att : event.getAttendees()) {
if (att.getPartstat() == IcalDefs.partstatValNeedsAction) {
att.setRsvp(true);
}
}
}
UpdateEventResult uer = getCal().addEvent(ei, schedulingInbox, rollbackOnError);
if (ei.getNumContainedItems() > 0) {
for (final EventInfo oei : ei.getContainedItems()) {
oei.getEvent().setName(event.getName());
final UpdateEventResult auer = getCal().addEvent(oei, schedulingInbox, rollbackOnError);
if (auer.errorCode != null) {
// ?
}
}
}
updResult.failedOverrides = uer.failedOverrides;
if (!noInvites) {
if (event.getAttendeeSchedulingObject()) {
// Attendee replying?
updResult.reply = true;
}
if (cal.getCollectionInfo().scheduling && schedulingObject) {
final SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
sched.implicitSchedule(ei, false);
/* We assume we don't need to update again to set attendee status
* Trying to do an update results in duplicate key errors.
*
* If it turns out the scgedule status is not getting persisted in the
* calendar entry then we need to find a way to set just that value in
* already persisted entity.
*/
}
}
return updResult;
} catch (final Throwable t) {
if (debug) {
error(t);
}
getSvc().rollbackTransaction();
if (t instanceof CalFacadeException) {
throw (CalFacadeException) t;
}
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Events method getEvents.
@Override
public Collection<EventInfo> getEvents(final BwCalendar cal, final FilterBase filter, final BwDateTime startDate, final BwDateTime endDate, final List<BwIcalPropertyInfoEntry> retrieveList, final DeletedState delState, final RecurringRetrievalMode recurRetrieval) throws CalFacadeException {
Collection<BwCalendar> cals = null;
if (cal != null) {
cals = new ArrayList<BwCalendar>();
cals.add(cal);
}
Collection<EventInfo> res = getMatching(cals, filter, startDate, endDate, retrieveList, delState, recurRetrieval, false);
int num = 0;
if (res != null) {
num = res.size();
}
getSvc().postNotification(new EntityFetchEvent(SysCode.ENTITY_FETCHED, num));
return res;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Events method buildCalendarSet.
private void buildCalendarSet(final Collection<BwCalendar> cals, BwCalendar calendar, final boolean freeBusy) throws CalFacadeException {
if (calendar == null) {
return;
}
int desiredAccess = PrivilegeDefs.privRead;
if (freeBusy) {
desiredAccess = PrivilegeDefs.privReadFreeBusy;
}
calendar = getCols().get(calendar.getPath());
if (calendar == null) {
// No access presumably
return;
}
if (!getSvc().checkAccess(calendar, desiredAccess, true).getAccessAllowed()) {
return;
}
if (calendar.getInternalAlias()) {
BwCalendar saveColl = calendar;
getCols().resolveAlias(calendar, true, freeBusy);
while (calendar.getInternalAlias()) {
calendar = calendar.getAliasTarget();
if (calendar == null) {
// No access presumably
saveColl.setLastRefreshStatus(String.valueOf(HttpServletResponse.SC_FORBIDDEN) + ": Forbidden");
return;
}
}
}
if (calendar.getCalendarCollection() || calendar.getExternalSub() || (cals.isEmpty() && calendar.getSpecial())) {
/* It's a calendar collection - add if not 'special' or we're adding all
*/
cals.add(calendar);
return;
}
if (calendar.getCalType() != BwCalendar.calTypeFolder) {
return;
}
for (BwCalendar c : getCols().getChildren(calendar)) {
buildCalendarSet(cals, c, freeBusy);
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Notifications method add.
@Override
public boolean add(final NotificationType val) throws CalFacadeException {
if ((val == null) || (val.getNotification() == null) || (val.getNotification().getElementName() == null)) {
return false;
}
final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return false;
}
final BwResource noteRsrc = new BwResource();
noteRsrc.setName(val.getName());
noteRsrc.setEncoding(val.getNotification().getEncoding());
final BwResourceContent rc = new BwResourceContent();
noteRsrc.setContent(rc);
try {
final String xml = val.toXml(true);
if (xml == null) {
return false;
}
final byte[] xmlData = xml.getBytes();
rc.setValue(getSvc().getBlob(xmlData));
noteRsrc.setContentLength(xmlData.length);
noteRsrc.setContentType(val.getContentType());
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
for (int i = 0; i <= 100; i++) {
if (getRess().saveNotification(ncol.getPath(), noteRsrc)) {
getNoteClient().informNotifier(getPrincipalHref(), noteRsrc.getName());
return true;
}
noteRsrc.setName(val.getName() + "-" + i);
}
throw new CalFacadeException(CalFacadeException.duplicateResource, val.getName());
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class IcalTranslator method fromIcal.
/**
* Convert the Icalendar object to a Collection of Calendar objects
*
* @param col collection the entities will live in - possibly null
* @param ical
* @param diff True if we should assume we are updating existing events.
* @return Icalendar
* @throws CalFacadeException
*/
public Icalendar fromIcal(final BwCalendar col, final IcalendarType ical, final boolean diff) throws CalFacadeException {
Icalendar ic = new Icalendar();
setSystemProperties();
WsXMLTranslator bldr = new WsXMLTranslator(ic);
try {
Calendar cal = bldr.fromXcal(ical);
return makeIc(col, ic, cal, diff, false);
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations