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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations