Search in sources :

Example 51 with CalFacadeException

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

the class JcalHandler method calendarProps.

private static void calendarProps(final JsonGenerator jgen, final int methodType) throws CalFacadeException {
    try {
        jgen.writeString("vcalendar");
        jgen.writeStartArray();
        JsonProperty.addFields(jgen, new ProdId(IcalTranslator.prodId));
        JsonProperty.addFields(jgen, Version.VERSION_2_0);
        if ((methodType > ScheduleMethods.methodTypeNone) && (methodType < ScheduleMethods.methodTypeUnknown)) {
            JsonProperty.addFields(jgen, new Method(ScheduleMethods.methods[methodType]));
        }
        jgen.writeEndArray();
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : Method(net.fortuna.ical4j.model.property.Method) ProdId(net.fortuna.ical4j.model.property.ProdId) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 52 with CalFacadeException

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

the class JcalHandler method outJcal.

public static void outJcal(final Writer wtr, final Collection<EventInfo> vals, final int methodType, final IcalendarType pattern, final String currentPrincipal, final EventTimeZonesRegistry tzreg) throws CalFacadeException {
    try {
        final JsonGenerator jgen = jsonFactory.createJsonGenerator(wtr);
        if (Logger.getLogger(JcalHandler.class).isDebugEnabled()) {
            jgen.useDefaultPrettyPrinter();
        }
        jgen.writeStartArray();
        calendarProps(jgen, methodType);
        // for components
        jgen.writeStartArray();
        for (final EventInfo ei : vals) {
            BwEvent ev = ei.getEvent();
            final Component comp;
            if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
                comp = VFreeUtil.toVFreeBusy(ev);
            } else {
                comp = VEventUtil.toIcalComponent(ei, false, tzreg, currentPrincipal);
            }
            outComp(jgen, comp);
            if (ei.getNumOverrides() > 0) {
                for (final EventInfo oei : ei.getOverrides()) {
                    ev = oei.getEvent();
                    outComp(jgen, VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
                }
            }
        }
        // for components
        jgen.writeEndArray();
        jgen.writeEndArray();
        jgen.flush();
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) BwEvent(org.bedework.calfacade.BwEvent) Component(net.fortuna.ical4j.model.Component) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 53 with CalFacadeException

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

the class JcalHandler method outComp.

private static void outComp(final JsonGenerator jgen, final Component comp) throws CalFacadeException {
    try {
        jgen.writeStartArray();
        jgen.writeString(comp.getName().toLowerCase());
        jgen.writeStartArray();
        for (final Object o : comp.getProperties()) {
            JsonProperty.addFields(jgen, (Property) o);
        }
        // End event properties
        jgen.writeEndArray();
        /* Output subcomponents
       */
        jgen.writeStartArray();
        ComponentList cl = null;
        if (comp instanceof VEvent) {
            cl = ((VEvent) comp).getAlarms();
        } else if (comp instanceof VToDo) {
            cl = ((VToDo) comp).getAlarms();
        // } else if (comp instanceof VJournal) {
        // } else if (comp instanceof VFreeBusy) {
        } else if (comp instanceof VAvailability) {
            cl = ((VAvailability) comp).getAvailable();
        // } else if (comp instanceof Available) {
        } else if (comp instanceof VPoll) {
            cl = ((VPoll) comp).getVoters();
        } else if (comp instanceof VVoter) {
            cl = ((VVoter) comp).getVotes();
        }
        if (cl != null) {
            for (final Object o : cl) {
                outComp(jgen, (Component) o);
            }
            if (comp instanceof VPoll) {
                for (final Object o : ((VPoll) comp).getCandidates()) {
                    outComp(jgen, (Component) o);
                }
            }
        }
        // end subcomponents
        jgen.writeEndArray();
        // end event
        jgen.writeEndArray();
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) VVoter(net.fortuna.ical4j.model.component.VVoter) VPoll(net.fortuna.ical4j.model.component.VPoll) ComponentList(net.fortuna.ical4j.model.ComponentList) VAvailability(net.fortuna.ical4j.model.component.VAvailability) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) VToDo(net.fortuna.ical4j.model.component.VToDo)

Example 54 with CalFacadeException

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

the class JsonParameters method addFields.

public static void addFields(final JsonGenerator jgen, final Property prop) throws CalFacadeException {
    try {
        jgen.writeStartObject();
        ParameterList pl = prop.getParameters();
        if ((pl != null) && (pl.size() > 0)) {
            Iterator it = pl.iterator();
            while (it.hasNext()) {
                Parameter p = (Parameter) it.next();
                String nm = p.getName().toLowerCase();
                jgen.writeFieldName(nm);
                if (multiMap.get(nm) == null) {
                    jgen.writeString(p.getValue());
                } else {
                    outValue(jgen, p);
                }
            }
        }
        jgen.writeEndObject();
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : Iterator(java.util.Iterator) ParameterList(net.fortuna.ical4j.model.ParameterList) Parameter(net.fortuna.ical4j.model.Parameter) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 55 with CalFacadeException

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

the class ResourcesImpl method copyMove.

@Override
public boolean copyMove(final BwResource val, final String to, final String name, final boolean copy, final boolean overwrite) throws CalFacadeException {
    try {
        setupSharableEntity(val, getPrincipal().getPrincipalRef());
        final BwCalendar collTo = getCols().get(to);
        if (collTo == null) {
            throw new CalFacadeException(CalFacadeException.collectionNotFound, to);
        }
        if (collTo.getCalType() != BwCalendar.calTypeFolder) {
            // Only allowed into a folder.
            throw new CalFacadeException(CalFacadeException.badRequest, to);
        }
        final int access;
        if (copy) {
            access = PrivilegeDefs.privWrite;
        } else {
            access = PrivilegeDefs.privBind;
        }
        checkAccess(collTo, access, false);
        BwResource r = getCal().getResource(val.getName(), collTo, access);
        boolean createdNew = false;
        getContent(val);
        if (r != null) {
            /* Update of the target from the source */
            if (!overwrite) {
                throw new CalFacadeException(CalFacadeException.targetExists, val.getName());
            }
            getContent(r);
            r.setContentType(val.getContentType());
            final BwResourceContent rc = r.getContent();
            final BwResourceContent toRc = val.getContent();
            r.setContentLength(toRc.getValue().length());
            r.updateLastmod(getCurrentTimestamp());
            rc.setValue(val.getContent().getValue());
            getCal().saveOrUpdate(r);
            getCal().saveOrUpdate(rc);
        } else {
            /* Create a new resource */
            r = new BwResource();
            setupSharableEntity(r, getPrincipal().getPrincipalRef());
            r.setName(name);
            r.setColPath(collTo.getPath());
            r.setContentType(val.getContentType());
            r.setContentLength(val.getContentLength());
            r.updateLastmod(getCurrentTimestamp());
            getCal().saveOrUpdate(r);
            final BwResourceContent fromRc = val.getContent();
            final BwResourceContent rc = new BwResourceContent();
            rc.setColPath(collTo.getPath());
            rc.setName(val.getName());
            rc.setValue(fromRc.getValue());
            getCal().saveOrUpdate(rc);
            createdNew = true;
        }
        if (!copy) {
            // Delete (tombstone) the old one
            final BwCalendar collFrom = getCols().get(val.getColPath());
            checkAccess(collFrom, PrivilegeDefs.privUnbind, false);
            final BwResourceContent rc = val.getContent();
            getCal().delete(rc);
            /* Remove any previous tombstoned version */
            final BwResource tr = getCal().getResource(val.getName() + BwResource.tombstonedSuffix, collFrom, PrivilegeDefs.privUnbind);
            if (tr != null) {
                getCal().delete(tr);
            }
            val.setContent(null);
            val.tombstone();
            val.updateLastmod(getCurrentTimestamp());
            getCal().saveOrUpdate(val);
            touchCalendar(collFrom);
        }
        touchCalendar(collTo);
        return createdNew;
    } catch (final CalFacadeException cfe) {
        getSvc().rollbackTransaction();
        throw cfe;
    } catch (final Throwable t) {
        getSvc().rollbackTransaction();
        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)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12