Search in sources :

Example 11 with PropertyList

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;
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList)

Example 12 with PropertyList

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);
    }
}
Also used : BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) EventInfo(org.bedework.calfacade.svc.EventInfo) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) ChangeTable(org.bedework.calfacade.util.ChangeTable) Iterator(java.util.Iterator) Parameter(net.fortuna.ical4j.model.Parameter) Property(net.fortuna.ical4j.model.Property) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 13 with PropertyList

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);
            }
        }
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) PropertyList(net.fortuna.ical4j.model.PropertyList) Parameter(net.fortuna.ical4j.model.Parameter) XParameter(net.fortuna.ical4j.model.parameter.XParameter) Attendee(net.fortuna.ical4j.model.property.Attendee)

Example 14 with PropertyList

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;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) XProperty(net.fortuna.ical4j.model.property.XProperty) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) URISyntaxException(java.net.URISyntaxException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) ParserException(net.fortuna.ical4j.data.ParserException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GeneralException(org.apache.ofbiz.base.util.GeneralException) ValidationException(net.fortuna.ical4j.model.ValidationException) IOException(java.io.IOException) PropertyList(net.fortuna.ical4j.model.PropertyList) StringReader(java.io.StringReader)

Example 15 with PropertyList

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);
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) PropertyList(net.fortuna.ical4j.model.PropertyList) Delegator(org.apache.ofbiz.entity.Delegator) HashMap(java.util.HashMap)

Aggregations

PropertyList (net.fortuna.ical4j.model.PropertyList)41 VEvent (net.fortuna.ical4j.model.component.VEvent)17 Property (net.fortuna.ical4j.model.Property)13 XProperty (net.fortuna.ical4j.model.property.XProperty)12 DateTime (net.fortuna.ical4j.model.DateTime)11 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)11 DtStart (net.fortuna.ical4j.model.property.DtStart)9 Uid (net.fortuna.ical4j.model.property.Uid)9 URISyntaxException (java.net.URISyntaxException)8 Calendar (net.fortuna.ical4j.model.Calendar)8 Description (net.fortuna.ical4j.model.property.Description)8 Date (java.util.Date)7 Period (net.fortuna.ical4j.model.Period)7 DtEnd (net.fortuna.ical4j.model.property.DtEnd)7 Duration (net.fortuna.ical4j.model.property.Duration)7 RecurrenceId (net.fortuna.ical4j.model.property.RecurrenceId)7 Parameter (net.fortuna.ical4j.model.Parameter)6 PeriodList (net.fortuna.ical4j.model.PeriodList)6 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)6 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)6