Search in sources :

Example 6 with BwLocation

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

the class XbwLocPropUpdater method checkLocation.

private boolean checkLocation(final UpdateInfo ui, final BwEvent ev, final String lang, final String val, final String keyName) throws CalFacadeException {
    final boolean locPresent = ev.getLocation() != null;
    final BwLocation loc;
    if (keyName == null) {
        final BwString sval = new BwString(lang, val);
        loc = ui.getIcalCallback().getLocation(sval);
        if (loc == null) {
            return false;
        }
    } else {
        final GetEntityResponse<BwLocation> resp = ui.getIcalCallback().fetchLocationByKey(keyName, val);
        if (resp.getStatus() != ok) {
            return false;
        }
        loc = resp.getEntity();
    }
    ev.setLocation(loc);
    if (locPresent) {
        ui.getCte(PropertyIndex.PropertyInfoIndex.LOCATION).addChangedValue(loc);
    } else {
        ui.getCte(PropertyIndex.PropertyInfoIndex.LOCATION).addValue(loc);
    }
    return true;
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) BwString(org.bedework.calfacade.BwString)

Example 7 with BwLocation

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

the class AccessUtil method getAclChars.

/* ====================================================================
   *                   Private methods
   * ==================================================================== */
/* If the entity is not a collection we merge the access in with the container
   * access then return the merged aces. We do this because we call getPathInfo
   * with a collection entity. That method will recurse up to the root.
   *
   * For a calendar we just use the access for the calendar.
   *
   * The calendar/container access might be cached in the pathInfoTable.
   */
private char[] getAclChars(final BwShareableDbentity<?> ent) throws CalFacadeException {
    if ((!(ent instanceof BwEventProperty)) && (ent instanceof BwShareableContainedDbentity)) {
        BwCalendar container;
        if (ent instanceof BwCalendar) {
            container = (BwCalendar) ent;
        } else {
            container = getParent((BwShareableContainedDbentity<?>) ent);
        }
        if (container == null) {
            return null;
        }
        final String path = container.getPath();
        CalendarWrapper wcol = (CalendarWrapper) container;
        String aclStr;
        char[] aclChars = null;
        /* Get access for the parent first if we have one */
        BwCalendar parent = getParent(wcol);
        if (parent != null) {
            aclStr = new String(merged(getAclChars(parent), parent.getPath(), wcol.getAccess()));
        } else if (wcol.getAccess() != null) {
            aclStr = wcol.getAccess();
        } else {
            // At root
            throw new CalFacadeException("Collections must have default access set at root");
        }
        if (aclStr != null) {
            aclChars = aclStr.toCharArray();
        }
        if (ent instanceof BwCalendar) {
            return aclChars;
        }
        return merged(aclChars, path, ent.getAccess());
    }
    /* This is a way of making other objects sort of shareable.
     * The objects are locations, sponsors and categories.
     * (also calsuite)
     *
     * We store the default access in the owner principal and manipulate that to give
     * us some degree of sharing.
     *
     * In effect, the owner becomes the container for the object.
     */
    String aclString = null;
    String entAccess = ent.getAccess();
    BwPrincipal owner = (BwPrincipal) cb.getPrincipal(ent.getOwnerHref());
    if (ent instanceof BwCategory) {
        aclString = owner.getCategoryAccess();
    } else if (ent instanceof BwLocation) {
        aclString = owner.getLocationAccess();
    } else if (ent instanceof BwContact) {
        aclString = owner.getContactAccess();
    }
    if (aclString == null) {
        if (entAccess == null) {
            if (ent.getPublick()) {
                return Access.getDefaultPublicAccess().toCharArray();
            }
            return Access.getDefaultPersonalAccess().toCharArray();
        }
        return entAccess.toCharArray();
    }
    if (entAccess == null) {
        return aclString.toCharArray();
    }
    try {
        Acl acl = Acl.decode(entAccess.toCharArray());
        acl = acl.merge(aclString.toCharArray(), "/owner");
        return acl.getEncoded();
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) BwShareableContainedDbentity(org.bedework.calfacade.base.BwShareableContainedDbentity) BwCategory(org.bedework.calfacade.BwCategory) BwEventProperty(org.bedework.calfacade.BwEventProperty) BwCalendar(org.bedework.calfacade.BwCalendar) BwContact(org.bedework.calfacade.BwContact) Acl(org.bedework.access.Acl) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) CalendarWrapper(org.bedework.calfacade.wrappers.CalendarWrapper)

Example 8 with BwLocation

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

the class LocationPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final BwEvent ev = ui.getEvent();
        final ChangeTableEntry cte = ui.getCte();
        BwString val = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
        final BwLocation evLoc = ev.getLocation();
        BwString evVal = null;
        if (evLoc != null) {
            evVal = evLoc.getAddress();
        }
        if (ui.isRemove()) {
            if (evVal == null) {
                return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
            }
            val = null;
        } else if (ui.isAdd()) {
            if (evVal != null) {
                return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
            }
        } else if (!ui.isChange()) {
            final ParameterUpdater.UpdateInfo langUpd = UpdaterUtil.findLangUpdate(ui.getParamUpdates());
            if (langUpd == null) {
                return new UpdateResult("No update specified for " + ui.getPropName());
            }
            String lang = val.getLang();
            if (langUpd.isRemove()) {
                lang = null;
            } else if (langUpd.isAdd()) {
                lang = ((TextParameterType) langUpd.getParam()).getText();
            } else if (langUpd.getUpdparam() != null) {
                lang = ((TextParameterType) langUpd.getUpdparam()).getText();
            }
            if (!Util.equalsString(lang, val.getLang())) {
                val = new BwString(lang, val.getValue());
            }
        } else {
            if (!val.equals(evVal)) {
                return new UpdateResult("Values don't match for update to " + ui.getPropName());
            }
            val = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
        }
        if (val == null) {
            cte.setDeleted(ev.getLocation());
            ev.setLocation(null);
        } else if (Util.cmpObjval(val, evVal) != 0) {
            BwLocation loc = ui.getIcalCallback().findLocation(val);
            if (loc == null) {
                loc = BwLocation.makeLocation();
                loc.setAddress(val);
                ui.getIcalCallback().addLocation(loc);
            }
            if (cte.setChanged(evLoc, loc)) {
                ev.setLocation(loc);
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) TextParameterType(ietf.params.xml.ns.icalendar_2.TextParameterType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) ParameterUpdater(org.bedework.caldav.bwserver.ParameterUpdater) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 9 with BwLocation

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

the class BwIndexEsImpl method fetchLocation.

@Override
public BwLocation fetchLocation(final String val, final PropertyInfoIndex... index) throws CalFacadeException {
    final EntityBuilder eb = fetchEntity(docTypeLocation, val, index);
    if (eb == null) {
        return null;
    }
    final BwLocation entity = eb.makeLocation();
    if (entity == null) {
        return null;
    }
    locations.put(entity);
    return entity;
}
Also used : BwLocation(org.bedework.calfacade.BwLocation)

Example 10 with BwLocation

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

the class Restorer method restoreLocations.

protected void restoreLocations() throws CalFacadeException {
    try {
        final Path p = openDir(Defs.locationsDirName);
        if (p == null) {
            return;
        }
        final DirRestore<BwLocation> dirRestore = new DirRestore<>(p, restoreLoc);
        final EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
        Files.walkFileTree(p, opts, Integer.MAX_VALUE, dirRestore);
    } catch (final IOException ie) {
        throw new CalFacadeException(ie);
    } finally {
        popPath();
    }
}
Also used : Path(java.nio.file.Path) BwLocation(org.bedework.calfacade.BwLocation) FileVisitOption(java.nio.file.FileVisitOption) IOException(java.io.IOException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwLocation (org.bedework.calfacade.BwLocation)28 BwString (org.bedework.calfacade.BwString)11 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)10 BwContact (org.bedework.calfacade.BwContact)9 BwEvent (org.bedework.calfacade.BwEvent)9 BwCategory (org.bedework.calfacade.BwCategory)8 BwXproperty (org.bedework.calfacade.BwXproperty)4 Period (net.fortuna.ical4j.model.Period)3 BwAttendee (org.bedework.calfacade.BwAttendee)3 EventInfo (org.bedework.calfacade.svc.EventInfo)3 File (java.io.File)2 Parameter (net.fortuna.ical4j.model.Parameter)2 XParameter (net.fortuna.ical4j.model.parameter.XParameter)2 BwAttachment (org.bedework.calfacade.BwAttachment)2 BwDateTime (org.bedework.calfacade.BwDateTime)2 BwEventProxy (org.bedework.calfacade.BwEventProxy)2 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)2 BwGeo (org.bedework.calfacade.BwGeo)2 BwOrganizer (org.bedework.calfacade.BwOrganizer)2 BwRelatedTo (org.bedework.calfacade.BwRelatedTo)2