use of net.fortuna.ical4j.model.PropertyList in project bw-calendar-engine by Bedework.
the class IcalUtil method getProperties.
/**
* @param comp
* @param name
* @return PropertyList
*/
public static PropertyList getProperties(final Component comp, final String name) {
PropertyList props = comp.getProperties();
props = props.getProperties(name);
if ((props != null) && (props.size() == 0)) {
return null;
}
return props;
}
use of net.fortuna.ical4j.model.PropertyList in project bw-calendar-engine by Bedework.
the class BwFreeBusyUtil method toFreeBusy.
/**
* @param cb
* @param val
* @return BwFreeBusy
* @throws CalFacadeException
*/
public static EventInfo toFreeBusy(final IcalCallback cb, final VFreeBusy val) throws CalFacadeException {
if (val == null) {
return null;
}
boolean debug = getLog().isDebugEnabled();
try {
PropertyList pl = val.getProperties();
if (pl == null) {
// Empty VEvent
return null;
}
BwEvent fb = new BwEventObj();
EventInfo ei = new EventInfo(fb);
ChangeTable chg = ei.getChangeset(cb.getPrincipal().getPrincipalRef());
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
setDates(cb.getPrincipal().getPrincipalRef(), ei, (DtStart) pl.getProperty(Property.DTSTART), (DtEnd) pl.getProperty(Property.DTEND), (Duration) pl.getProperty(Property.DURATION));
Iterator it = pl.iterator();
while (it.hasNext()) {
Property prop = (Property) it.next();
String pval = prop.getValue();
if ((pval != null) && (pval.length() == 0)) {
pval = null;
}
PropertyInfoIndex pi = PropertyInfoIndex.fromName(prop.getName());
if (pi == null) {
debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
continue;
}
switch(pi) {
case ATTENDEE:
/* ------------------- Attendee -------------------- */
BwAttendee att = getAttendee(cb, (Attendee) prop);
fb.addAttendee(att);
chg.addValue(pi, att);
break;
case COMMENT:
/* ------------------- Comment -------------------- */
// LANG
fb.addComment(null, pval);
chg.addValue(pi, pval);
case DTEND:
break;
case DTSTAMP:
/* ------------------- DtStamp -------------------- */
chg.changed(pi, fb.getDtstamp(), pval);
fb.setDtstamp(pval);
case DTSTART:
break;
case FREEBUSY:
/* ------------------- freebusy -------------------- */
FreeBusy fbusy = (FreeBusy) prop;
PeriodList perpl = fbusy.getPeriods();
Parameter par = getParameter(fbusy, "FBTYPE");
int fbtype;
if (par == null) {
fbtype = BwFreeBusyComponent.typeBusy;
} else if (par.equals(FbType.BUSY)) {
fbtype = BwFreeBusyComponent.typeBusy;
} else if (par.equals(FbType.BUSY_TENTATIVE)) {
fbtype = BwFreeBusyComponent.typeBusyTentative;
} else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
fbtype = BwFreeBusyComponent.typeBusyUnavailable;
} else if (par.equals(FbType.FREE)) {
fbtype = BwFreeBusyComponent.typeFree;
} else {
if (debug) {
debugMsg("Unsupported parameter " + par.getName());
}
throw new IcalMalformedException("parameter " + par.getName());
}
BwFreeBusyComponent fbc = new BwFreeBusyComponent();
fbc.setType(fbtype);
Iterator perit = perpl.iterator();
while (perit.hasNext()) {
Period per = (Period) perit.next();
fbc.addPeriod(per);
}
fb.addFreeBusyPeriod(fbc);
chg.addValue(pi, fbc);
break;
case ORGANIZER:
/* ------------------- Organizer -------------------- */
BwOrganizer org = getOrganizer(cb, (Organizer) prop);
fb.setOrganizer(org);
chg.addValue(pi, org);
break;
case UID:
/* ------------------- Uid -------------------- */
chg.changed(pi, fb.getUid(), pval);
fb.setUid(pval);
break;
default:
if (debug) {
debugMsg("Unsupported property with class " + prop.getClass() + " and value " + pval);
}
}
}
return ei;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.model.PropertyList in project ofbiz-framework by apache.
the class ICalConverter method loadRelatedParties.
protected static void loadRelatedParties(List<GenericValue> relatedParties, PropertyList componentProps, Map<String, Object> context) {
PropertyList attendees = componentProps.getProperties("ATTENDEE");
for (GenericValue partyValue : relatedParties) {
if ("CAL_ORGANIZER~CAL_OWNER".contains(partyValue.getString("roleTypeId"))) {
// RFC 2445 4.6.1, 4.6.2, and 4.6.3 ORGANIZER can appear only once
replaceProperty(componentProps, createOrganizer(partyValue, context));
} else {
String partyId = partyValue.getString("partyId");
boolean newAttendee = true;
Attendee attendee = null;
Iterator<Attendee> i = UtilGenerics.cast(attendees.iterator());
while (i.hasNext()) {
attendee = i.next();
Parameter xParameter = attendee.getParameter(partyIdXParamName);
if (xParameter != null && partyId.equals(xParameter.getValue())) {
loadPartyAssignment(attendee, partyValue, context);
newAttendee = false;
break;
}
}
if (newAttendee) {
attendee = createAttendee(partyValue, context);
componentProps.add(attendee);
}
}
}
}
use of net.fortuna.ical4j.model.PropertyList in project ofbiz-framework by apache.
the class ICalConverter method makeCalendar.
protected static Calendar makeCalendar(GenericValue workEffort, Map<String, Object> context) throws GenericEntityException {
String iCalData = null;
GenericValue iCalValue = workEffort.getRelatedOne("WorkEffortIcalData", false);
if (iCalValue != null) {
iCalData = iCalValue.getString("icalData");
}
boolean newCalendar = true;
Calendar calendar = null;
if (iCalData == null) {
if (Debug.verboseOn())
Debug.logVerbose("iCalendar Data not found, creating new Calendar", module);
calendar = new Calendar();
} else {
if (Debug.verboseOn())
Debug.logVerbose("iCalendar Data found, using saved Calendar", module);
StringReader reader = new StringReader(iCalData);
CalendarBuilder builder = new CalendarBuilder();
try {
calendar = builder.build(reader);
newCalendar = false;
} catch (Exception e) {
Debug.logError(e, "Error while parsing saved iCalendar, creating new iCalendar: ", module);
calendar = new Calendar();
}
}
PropertyList propList = calendar.getProperties();
replaceProperty(propList, prodId);
replaceProperty(propList, new XProperty(workEffortIdXPropName, workEffort.getString("workEffortId")));
if (newCalendar) {
propList.add(Version.VERSION_2_0);
propList.add(CalScale.GREGORIAN);
// TODO: Get time zone from publish properties value
java.util.TimeZone tz = java.util.TimeZone.getDefault();
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
net.fortuna.ical4j.model.TimeZone timezone = registry.getTimeZone(tz.getID());
calendar.getComponents().add(timezone.getVTimeZone());
}
return calendar;
}
use of net.fortuna.ical4j.model.PropertyList in project ofbiz-framework by apache.
the class ICalConverter method storeWorkEffort.
protected static ResponseProperties storeWorkEffort(Component component, Map<String, Object> context) throws GenericEntityException {
PropertyList propertyList = component.getProperties();
String workEffortId = fromXProperty(propertyList, workEffortIdXPropName);
Delegator delegator = (Delegator) context.get("delegator");
GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
if (workEffort == null) {
return ICalWorker.createNotFoundResponse(null);
}
if (!hasPermission(workEffortId, "UPDATE", context)) {
return null;
}
Map<String, Object> serviceMap = new HashMap<>();
serviceMap.put("workEffortId", workEffortId);
setWorkEffortServiceMap(component, serviceMap);
invokeService("updateWorkEffort", serviceMap, context);
return storePartyAssignments(workEffortId, component, context);
}
Aggregations