Search in sources :

Example 11 with BwCalSuite

use of org.bedework.calfacade.svc.BwCalSuite 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;
}
Also used : BwCalSuite(org.bedework.calfacade.svc.BwCalSuite) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Aggregations

BwCalSuite (org.bedework.calfacade.svc.BwCalSuite)11 HibSession (org.bedework.calcorei.HibSession)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 TreeSet (java.util.TreeSet)1 PrivilegeSet (org.bedework.access.PrivilegeSet)1 BwPrincipalInfo (org.bedework.calfacade.BwPrincipalInfo)1 BwString (org.bedework.calfacade.BwString)1 Directories (org.bedework.calfacade.ifs.Directories)1 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)1 BwPreferences (org.bedework.calfacade.svc.BwPreferences)1 BwCalSuiteWrapper (org.bedework.calfacade.svc.wrappers.BwCalSuiteWrapper)1