Search in sources :

Example 41 with BwCategory

use of org.bedework.calfacade.BwCategory 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;
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) TreeSet(java.util.TreeSet) BwCategory(org.bedework.calfacade.BwCategory) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 42 with BwCategory

use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.

the class ProcessRealias method doRealias.

private int doRealias(final EventInfo ei, final String fromHref, final BwXproperty xp, final boolean add, final boolean remove) throws Throwable {
    final BwEvent ev = ei.getEvent();
    int updated = 0;
    boolean changed = false;
    if (!add) {
        // We need to remove the from alias
        boolean found = false;
        for (final BwXproperty xpi : ev.getXproperties(BwXproperty.bedeworkAlias)) {
            if (xpi.getValue().equals(fromHref)) {
                ev.removeXproperty(xpi);
                found = true;
                changed = true;
                break;
            }
        }
        if (!found) {
            warn("Unable to find " + fromHref);
        }
    }
    if (!remove) {
        // Need to add a new one.
        ev.addXproperty(xp);
        changed = true;
    }
    final RealiasResult resp = getSvci().getEventsHandler().reAlias(ei.getEvent());
    if (resp.getStatus() != ok) {
        warn("Status from reAlias was " + resp.getStatus() + " message was " + resp.getMessage());
        return 0;
    }
    if (!add) {
        // Remove all the categories for the from alias
        final Set<BwCategory> fromCats = getCols().getCategorySet(fromHref);
        if (!Util.isEmpty(fromCats) && !Util.isEmpty(ev.getCategories())) {
            for (final BwCategory cat : fromCats) {
                if (ev.getCategories().remove(cat)) {
                    changed = true;
                }
            }
        }
    }
    /* Now we need to adjust for the new alias
     */
    final Set<BwCategory> cats = resp.getCats();
    if (!Util.isEmpty(cats)) {
        for (final BwCategory cat : cats) {
            ev.addCategory(cat);
        }
        changed = true;
    }
    ei.clearChangeset();
    final EventInfo.UpdateResult ur = getSvci().getEventsHandler().update(ei, true);
    if (ur.hasChanged) {
        updated++;
    }
    if (!Util.isEmpty(ei.getOverrides())) {
        for (final EventInfo ovei : ei.getOverrides()) {
            updated += doRealias(ovei, fromHref, xp, add, remove);
        }
    }
    return updated;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwCategory(org.bedework.calfacade.BwCategory) BwEvent(org.bedework.calfacade.BwEvent) RealiasResult(org.bedework.calsvci.EventsI.RealiasResult)

Aggregations

BwCategory (org.bedework.calfacade.BwCategory)42 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)13 BwContact (org.bedework.calfacade.BwContact)11 BwString (org.bedework.calfacade.BwString)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 BwEvent (org.bedework.calfacade.BwEvent)10 BwLocation (org.bedework.calfacade.BwLocation)8 BwXproperty (org.bedework.calfacade.BwXproperty)7 ArrayList (java.util.ArrayList)6 EventInfo (org.bedework.calfacade.svc.EventInfo)6 BwDateTime (org.bedework.calfacade.BwDateTime)5 TreeSet (java.util.TreeSet)4 BwAttendee (org.bedework.calfacade.BwAttendee)4 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)4 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)4 Period (net.fortuna.ical4j.model.Period)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)3 FilterBase (org.bedework.caldav.util.filter.FilterBase)2 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)2