use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.
the class InRequest method process.
/**
* @param ei
* @return ScheduleResult
* @throws CalFacadeException
*/
@Override
public ProcessResult process(final EventInfo ei) throws CalFacadeException {
/* We are acting as an attendee getting a request from the organizer, either
* a first invitation or an update
*/
ProcessResult pr = new ProcessResult();
BwPreferences prefs = getSvc().getPrefsHandler().get();
BwEvent ev = ei.getEvent();
String owner = ev.getOwnerHref();
boolean schedAssistant = ev.isSchedulingAssistant();
if (debug) {
trace("InSchedule schedAssistant = " + schedAssistant);
}
/* First we save or update the event in the users default scheduling calendar
*/
SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
String uri = getSvc().getDirectories().principalToCaladdr(getSvc().getPrincipal());
String colPath = null;
EventInfo ourCopy = null;
boolean adding = false;
ev.setAttendeeSchedulingObject(true);
ev.setOrganizerSchedulingObject(false);
check: {
ourCopy = sched.getStoredMeeting(ev);
if (ourCopy != null) {
if (debug) {
trace("InSchedule update for " + owner);
}
colPath = ourCopy.getEvent().getColPath();
final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
if (vpoll) {
if (!updateAttendeePollCopy(ourCopy, ei, uri)) {
break check;
}
} else if (!updateAttendeeCopy(ourCopy, ei, uri)) {
break check;
}
pr.removeInboxEntry = !anySignificantChange(ourCopy);
} else {
/* New invitation - Save in default */
adding = true;
if (debug) {
trace("InSchedule add for " + owner);
}
String prefSched = getSvc().getCalendarsHandler().getPreferred(IcalDefs.entityTypeIcalNames[ev.getEntityType()]);
if (prefSched == null) {
// SCHED - status = no default collection
if (debug) {
trace("InSchedule - no default collection for " + owner);
}
// XXX set error code in request status
pr.removeInboxEntry = true;
return pr;
}
ourCopy = newAttendeeCopy(getSvc(), prefSched, ei, uri);
if (ourCopy == null) {
if (debug) {
trace("InSchedule - unable to add to calendar for " + owner);
}
// XXX set error code in request status
pr.removeInboxEntry = true;
return pr;
}
ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedulingNew, null, "true"));
pr.removeInboxEntry = false;
}
}
if (schedAssistant) {
// Don't need the notification
pr.removeInboxEntry = true;
}
ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedulingEntityPath, null, colPath));
/* We've saved it in the users calendar - now see if they want to auto
* respond.
*/
boolean noInvites = true;
boolean doAutoRespond = !pr.removeInboxEntry && !schedAssistant && prefs.getScheduleAutoRespond();
if (doAutoRespond) {
if (debug) {
trace("InSchedule - auto responding for " + owner);
}
noInvites = !autoRespond(getSvc(), ourCopy, ei, prefs.getScheduleDoubleBook(), uri);
}
if (adding) {
final String namePrefix = ourCopy.getEvent().getUid();
pr.sr.errorCode = sched.addEvent(ourCopy, namePrefix, BwCalendar.calTypeCalendarCollection, noInvites);
if (pr.sr.errorCode != null) {
if (debug) {
trace("Schedule - error " + pr.sr.errorCode + " adding event for " + owner);
}
return pr;
}
} else {
final UpdateResult ur = getSvc().getEventsHandler().update(ourCopy, noInvites, null);
if (debug) {
trace("Schedule - update result " + pr.sr + " for event" + ourCopy.getEvent());
}
if (ur.schedulingResult != null) {
pr.sr = ur.schedulingResult;
}
}
pr.attendeeAccepting = !Util.isEmpty(ev.getXproperties(BwXproperty.bedeworkSchedulingReplyUpdate));
return pr;
}
use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.
the class ProcessCalsuite method process.
@Override
boolean process() throws Throwable {
final String wd = word();
if (wd == null) {
return false;
}
if ("help".equals(wd)) {
pstate.addInfo("calsuite <name>\n" + " switch to event owner for calsuite\n" + "calsuite <name> addapprover <account>\n" + " add an approver\n" + "calsuite <name> remapprover <account>\n" + " remove an approver");
return true;
}
final String account;
try {
open();
final BwCalSuite cs = getSvci().getCalSuitesHandler().get(wd);
if (cs == null) {
error("No calsuite with name " + wd);
return true;
}
final BwAdminGroup adminGrp = cs.getGroup();
if (adminGrp == null) {
error("No admin group for calsuite " + wd);
return true;
}
final String ownerHref = adminGrp.getOwnerHref();
if (ownerHref == null) {
error("No owner href in admin group " + adminGrp + " for calsuite " + wd);
return true;
}
final BwPrincipal ownerPr = getSvci().getPrincipal(ownerHref);
if (ownerPr == null) {
error("No user with owner href " + ownerHref + " in admin group " + adminGrp + " for calsuite " + wd);
return true;
}
final String action = word();
account = ownerPr.getAccount();
if (action == null) {
pstate.setCalsuite(cs);
return true;
}
final boolean addAppprover = "addapprover".equals(action);
if (!addAppprover && !"remapprover".equals(action)) {
error("Expected addapprover or remapprover");
return false;
}
final String appAccount = word();
if (appAccount == null) {
error("Expected an account");
}
final BwPreferences prefs = getSvci().getPrefsHandler().get(ownerPr);
final List<String> approvers = prefs.getCalsuiteApproversList();
if (Util.isEmpty(approvers)) {
if (addAppprover) {
prefs.setCalsuiteApprovers(appAccount);
}
} else {
if (addAppprover) {
if (!approvers.contains(appAccount)) {
approvers.add(appAccount);
}
} else {
approvers.remove(appAccount);
}
prefs.setCalsuiteApprovers(String.join(",", approvers));
}
getSvci().getPrefsHandler().update(prefs);
} finally {
close();
}
setUser(account, false);
return true;
}
use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.
the class ProcessPrefs method process.
@Override
boolean process() throws Throwable {
String wd = word();
if (wd == null) {
return false;
}
if ("help".equals(wd)) {
addInfo("prefs <preference>* \n" + " set given prefs for current user\n\n" + "<preference> is one or more of\n" + " defaultCategory = \"word\"\n" + " defaultViewMode = \"list\"\n" + " viewPeriod = \"dayView\"\n" + " defaultTzid = \"America/New_York\"\n" + " pageSize = \"10\"\n" + " preferredEndType = \"duration\"\n" + " preferredView = \"All\"\n" + " hour24 = \"false\"");
return true;
}
try {
open();
final BwPreferences prefs = getPrefs();
if (prefs == null) {
error("Unable to fetch prefs for current user");
// No change
return true;
}
Set<String> catUids = new TreeSet<>();
while (wd != null) {
switch(wd) {
case "defaultImageDirectory":
final BwCalendar cal = getCal();
if (cal == null) {
error("Unknown calendar");
return true;
}
prefs.setDefaultImageDirectory(cal.getPath());
break;
case "preferredView":
/*if (cl.getView(str) == null) {
form.getErr().emit(ClientError.unknownView, str);
return forwardNotFound;
}*/
prefs.setPreferredView(quotedVal());
break;
case "defaultCategory":
final String catwd = wordOrQuotedVal();
if (catwd == null) {
error("Expect category uid");
return true;
}
if (catwd.equals("removeall")) {
// Remove all
prefs.removeProperties(BwPreferences.propertyDefaultCategory);
break;
}
final BwCategory cat = getCat(null, catwd);
if (cat == null) {
error("Unknown category " + catwd);
return true;
}
catUids.add(cat.getUid());
break;
case "hour24":
prefs.setHour24(Boolean.valueOf(word()));
break;
case "skin":
prefs.setSkinName(wordOrQuotedVal());
break;
case "skinStyle":
prefs.setSkinStyle(wordOrQuotedVal());
break;
case "email":
prefs.setEmail(quotedVal());
break;
case "preferredEndType":
final String str = word();
if (BwPreferences.preferredEndTypeDuration.equals(str) || BwPreferences.preferredEndTypeDate.equals(str)) {
prefs.setPreferredEndType(str);
} else {
error("Invalid end type " + str);
return true;
}
break;
}
// switch
wd = word();
}
if (!Util.isEmpty(catUids)) {
prefs.setDefaultCategoryUids(catUids);
}
getSvci().getPrefsHandler().update(prefs);
} finally {
close();
}
return true;
}
Aggregations