Search in sources :

Example 6 with BwResource

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

the class Notifications method find.

@Override
public NotificationType find(final String name) throws CalFacadeException {
    final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
    if (ncol == null) {
        return null;
    }
    final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", name));
    if (noteRsrc == null) {
        return null;
    }
    return makeNotification(noteRsrc);
}
Also used : BwResource(org.bedework.calfacade.BwResource) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 7 with BwResource

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

the class Notifications method update.

@Override
public boolean update(final NotificationType val) throws CalFacadeException {
    if ((val == null) || (val.getNotification() == null) || (val.getNotification().getElementName() == null)) {
        return false;
    }
    try {
        final String xml = val.toXml(true);
        if (xml == null) {
            return false;
        }
        final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
        if (ncol == null) {
            return false;
        }
        final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", val.getName()));
        if (noteRsrc == null) {
            return false;
        }
        BwResourceContent rc = noteRsrc.getContent();
        if (rc == null) {
            rc = new BwResourceContent();
            noteRsrc.setContent(rc);
        }
        final byte[] xmlData = xml.getBytes();
        rc.setValue(getSvc().getBlob(xmlData));
        noteRsrc.setContentLength(xmlData.length);
        noteRsrc.setContentType(val.getContentType());
        getSvc().getResourcesHandler().update(noteRsrc, true);
        getNoteClient().informNotifier(getPrincipalHref(), noteRsrc.getName());
        return true;
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwResource(org.bedework.calfacade.BwResource) BwResourceContent(org.bedework.calfacade.BwResourceContent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 8 with BwResource

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

the class EntityDAO method getResource.

public BwResource getResource(final String name, final BwCalendar coll, final int desiredAccess) throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(getResourceQuery);
    sess.setString("name", name);
    sess.setString("path", coll.getPath());
    sess.setString("tsenc", BwResource.tombstoned);
    sess.cacheableQuery();
    return (BwResource) sess.getUnique();
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwResource(org.bedework.calfacade.BwResource)

Example 9 with BwResource

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

the class Dumpling method dumpCollection.

private void dumpCollection(final Iterator<T> it) throws Throwable {
    while (it.hasNext()) {
        final DumpEntity d = unwrap(it.next());
        globals.counts[countIndex]++;
        if ((globals.counts[countIndex] % 100) == 0) {
            info("        ... " + globals.counts[countIndex]);
        }
        if (d instanceof BwResource) {
            dumpResource((BwResource) d);
            continue;
        }
        if (d instanceof BwCalendar) {
            dumpCollection((BwCalendar) d);
            continue;
        }
        if (d instanceof BwEvent) {
            dumpEvent((BwEvent) d);
            continue;
        }
        /* Just dump any remaining classes - no special treatment */
        d.dump(xml);
    }
}
Also used : DumpEntity(org.bedework.calfacade.base.DumpEntity) BwResource(org.bedework.calfacade.BwResource) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 10 with BwResource

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

the class BwCalDAVResource method setBinaryContent.

@Override
public void setBinaryContent(final InputStream val) throws WebdavException {
    BwResource r = getRsrc();
    BwResourceContent rc = r.getContent();
    if (rc == null) {
        if (!isNew()) {
            intf.getFileContent(this);
            rc = r.getContent();
        }
        if (rc == null) {
            rc = new BwResourceContent();
            r.setContent(rc);
        }
    }
    try {
        /* If this is a notification we need to unprefix the data */
        final InputStream str;
        if (!isNotification()) {
            str = val;
        } else {
            final NotificationType note = Parser.fromXml(val);
            note.getNotification().unprefixHrefs(intf.getUrlHandler());
            str = new ByteArrayInputStream(note.toXml(true).getBytes());
        }
        final ByteArrayOutputStream outBuff = new ByteArrayOutputStream();
        byte[] inBuffer = new byte[1000];
        long clen = 0;
        int chunkSize;
        int maxSize = intf.getAuthProperties().getMaxUserEntitySize();
        long oldSize = r.getContentLength();
        while (clen <= maxSize) {
            chunkSize = str.read(inBuffer);
            if (chunkSize < 0) {
                break;
            }
            outBuff.write(inBuffer, 0, chunkSize);
            clen += chunkSize;
        }
        if (clen > maxSize) {
            throw new WebdavForbidden(CaldavTags.maxResourceSize);
        }
        rc.setValue(intf.getBlob(outBuff.toByteArray()));
        r.setContentLength(clen);
        if (!intf.updateQuota(getOwner(), clen - oldSize)) {
            throw new WebdavForbidden(WebdavTags.quotaNotExceeded);
        }
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BwResource(org.bedework.calfacade.BwResource) NotificationType(org.bedework.caldav.util.notifications.NotificationType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwResourceContent(org.bedework.calfacade.BwResourceContent) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

BwResource (org.bedework.calfacade.BwResource)16 BwCalendar (org.bedework.calfacade.BwCalendar)10 BwResourceContent (org.bedework.calfacade.BwResourceContent)7 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)7 ArrayList (java.util.ArrayList)3 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 ResourcesI (org.bedework.calsvci.ResourcesI)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 TreeSet (java.util.TreeSet)1 CurrentAccess (org.bedework.access.Acl.CurrentAccess)1 HibSession (org.bedework.calcorei.HibSession)1 CalDAVResource (org.bedework.caldav.server.CalDAVResource)1 NotificationInfo (org.bedework.caldav.util.notifications.NotificationType.NotificationInfo)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwString (org.bedework.calfacade.BwString)1