Search in sources :

Example 26 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project openhab1-addons by openhab.

the class EventReloaderJob method readCategory.

/**
     * Returns a list of categories or an empty list if none found.
     *
     * @param vEvent
     * @return
     */
private List<String> readCategory(VEvent vEvent) {
    PropertyList propertyCategoryList = vEvent.getProperties(Property.CATEGORIES);
    ArrayList<String> splittedCategoriesToReturn = new ArrayList<String>();
    if (propertyCategoryList != null) {
        for (int categoriesLineNum = 0; categoriesLineNum < propertyCategoryList.size(); categoriesLineNum++) {
            Property propertyCategory = propertyCategoryList.get(categoriesLineNum);
            String categories = propertyCategory.getValue();
            if (categories != null) {
                String[] categoriesSplit = StringUtils.split(categories, ",");
                for (String category : categoriesSplit) {
                    if (!splittedCategoriesToReturn.contains(category)) {
                        splittedCategoriesToReturn.add(category);
                    }
                }
            }
        }
    }
    return splittedCategoriesToReturn;
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList) ArrayList(java.util.ArrayList) Property(net.fortuna.ical4j.model.Property)

Example 27 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method createKalendarEventRecurringOccurence.

@Override
public KalendarEvent createKalendarEventRecurringOccurence(KalendarRecurEvent recurEvent) {
    KalendarEvent rootEvent = recurEvent.getCalendar().getEvent(recurEvent.getID(), null);
    VEvent vEvent = getVEvent(recurEvent);
    PropertyList vEventProperties = vEvent.getProperties();
    for (Iterator<?> objIt = vEventProperties.iterator(); objIt.hasNext(); ) {
        Object property = objIt.next();
        if (property instanceof RRule || property instanceof ExDate) {
            objIt.remove();
        }
    }
    try {
        Kalendar calendar = recurEvent.getCalendar();
        Date startDate = recurEvent.getOccurenceDate();
        String startString = CalendarUtils.formatRecurrenceDate(startDate, rootEvent.isAllDayEvent());
        RecurrenceId recurId;
        if (rootEvent.isAllDayEvent()) {
            recurId = new RecurrenceId(tz);
            recurId.setDate(CalendarUtils.createDate(startDate));
        } else {
            recurId = new RecurrenceId(startString, tz);
        }
        vEventProperties.add(recurId);
        KalendarEvent kEvent = getKalendarEvent(vEvent);
        kEvent.setKalendar(calendar);
        return kEvent;
    } catch (ParseException e) {
        log.error("", e);
        return null;
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) PropertyList(net.fortuna.ical4j.model.PropertyList) RRule(net.fortuna.ical4j.model.property.RRule) Kalendar(org.olat.commons.calendar.model.Kalendar) ExDate(net.fortuna.ical4j.model.property.ExDate) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) ParseException(java.text.ParseException) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate)

Example 28 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project OpenOLAT by OpenOLAT.

the class ICalServlet method updateUrlProperties.

private void updateUrlProperties(Calendar calendar) {
    for (Iterator<?> eventIter = calendar.getComponents().iterator(); eventIter.hasNext(); ) {
        Object comp = eventIter.next();
        if (comp instanceof VEvent) {
            VEvent event = (VEvent) comp;
            PropertyList ooLinkProperties = event.getProperties(CalendarManager.ICAL_X_OLAT_LINK);
            if (ooLinkProperties.isEmpty()) {
                continue;
            }
            Url currentUrl = event.getUrl();
            if (currentUrl != null) {
                continue;
            }
            for (Iterator<?> iter = ooLinkProperties.iterator(); iter.hasNext(); ) {
                XProperty linkProperty = (XProperty) iter.next();
                if (linkProperty != null) {
                    String encodedLink = linkProperty.getValue();
                    StringTokenizer st = new StringTokenizer(encodedLink, "ยง", false);
                    if (st.countTokens() >= 4) {
                        // provider
                        st.nextToken();
                        // id
                        st.nextToken();
                        // displayname
                        st.nextToken();
                        String uri = st.nextToken();
                        try {
                            Url urlProperty = new Url();
                            urlProperty.setValue(uri);
                            event.getProperties().add(urlProperty);
                            break;
                        } catch (URISyntaxException e) {
                            log.error("Invalid URL:" + uri);
                        }
                    }
                }
            }
        }
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) StringTokenizer(java.util.StringTokenizer) PropertyList(net.fortuna.ical4j.model.PropertyList) XProperty(net.fortuna.ical4j.model.property.XProperty) URISyntaxException(java.net.URISyntaxException) Url(net.fortuna.ical4j.model.property.Url)

Example 29 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project ofbiz-framework by apache.

the class ICalConverter method setWorkEffortServiceMap.

protected static void setWorkEffortServiceMap(Component component, Map<String, Object> serviceMap) {
    PropertyList propertyList = component.getProperties();
    setMapElement(serviceMap, "scopeEnumId", fromClazz(propertyList));
    setMapElement(serviceMap, "description", fromDescription(propertyList));
    setMapElement(serviceMap, "locationDesc", fromLocation(propertyList));
    setMapElement(serviceMap, "priority", fromPriority(propertyList));
    setMapElement(serviceMap, "currentStatusId", fromStatus(propertyList));
    setMapElement(serviceMap, "workEffortName", fromSummary(propertyList));
    setMapElement(serviceMap, "universalId", fromUid(propertyList));
    // Set some fields to null so calendar clients can revert changes
    serviceMap.put("estimatedStartDate", null);
    serviceMap.put("estimatedCompletionDate", null);
    serviceMap.put("estimatedMilliSeconds", null);
    serviceMap.put("lastModifiedDate", null);
    serviceMap.put("actualCompletionDate", null);
    serviceMap.put("percentComplete", null);
    setMapElement(serviceMap, "estimatedStartDate", fromDtStart(propertyList));
    setMapElement(serviceMap, "estimatedMilliSeconds", fromDuration(propertyList));
    setMapElement(serviceMap, "lastModifiedDate", fromLastModified(propertyList));
    if ("VTODO".equals(component.getName())) {
        setMapElement(serviceMap, "actualCompletionDate", fromCompleted(propertyList));
        setMapElement(serviceMap, "percentComplete", fromPercentComplete(propertyList));
    } else {
        setMapElement(serviceMap, "estimatedCompletionDate", fromDtEnd(propertyList));
    }
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList)

Example 30 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project ofbiz-framework by apache.

the class ICalConverter method getAlarms.

protected static void getAlarms(GenericValue workEffort, ComponentList alarms) throws GenericEntityException {
    Description description = null;
    if (workEffort.get("description") != null) {
        description = new Description(workEffort.getString("description"));
    } else {
        description = new Description(workEffort.getString("workEffortName"));
    }
    Summary summary = new Summary(UtilProperties.getMessage("WorkEffortUiLabels", "WorkEffortEventReminder", Locale.getDefault()));
    Delegator delegator = workEffort.getDelegator();
    String workEffortId = workEffort.getString("workEffortId");
    List<GenericValue> reminderList = EntityQuery.use(delegator).from("WorkEffortEventReminder").where("workEffortId", workEffort.get("workEffortId")).queryList();
    for (GenericValue reminder : reminderList) {
        String reminderId = workEffortId + "-" + reminder.getString("sequenceId");
        VAlarm alarm = null;
        PropertyList alarmProps = null;
        boolean newAlarm = true;
        Iterator<VAlarm> i = UtilGenerics.cast(alarms.iterator());
        while (i.hasNext()) {
            alarm = i.next();
            Property xProperty = alarm.getProperty(reminderXPropName);
            if (xProperty != null && reminderId.equals(xProperty.getValue())) {
                newAlarm = false;
                alarmProps = alarm.getProperties();
                // TODO: Write update code. For now, just re-create
                alarmProps.clear();
                break;
            }
        }
        if (newAlarm) {
            alarm = createAlarm(reminder);
            alarms.add(alarm);
            alarmProps = alarm.getProperties();
            alarmProps.add(new XProperty(reminderXPropName, reminderId));
        }
        GenericValue contactMech = reminder.getRelatedOne("ContactMech", false);
        if (contactMech != null && "EMAIL_ADDRESS".equals(contactMech.get("contactMechTypeId"))) {
            try {
                alarmProps.add(new Attendee(contactMech.getString("infoString")));
                alarmProps.add(Action.EMAIL);
                alarmProps.add(summary);
                alarmProps.add(description);
            } catch (URISyntaxException e) {
                alarmProps.add(Action.DISPLAY);
                alarmProps.add(new Description("Error encountered while creating iCalendar: " + e));
            }
        } else {
            alarmProps.add(Action.DISPLAY);
            alarmProps.add(description);
        }
        if (Debug.verboseOn()) {
            try {
                alarm.validate(true);
                Debug.logVerbose("iCalendar alarm passes validation", module);
            } catch (ValidationException e) {
                if (Debug.verboseOn())
                    Debug.logVerbose("iCalendar alarm fails validation: " + e, module);
            }
        }
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Description(net.fortuna.ical4j.model.property.Description) XProperty(net.fortuna.ical4j.model.property.XProperty) ValidationException(net.fortuna.ical4j.model.ValidationException) URISyntaxException(java.net.URISyntaxException) Attendee(net.fortuna.ical4j.model.property.Attendee) PropertyList(net.fortuna.ical4j.model.PropertyList) Delegator(org.apache.ofbiz.entity.Delegator) Summary(net.fortuna.ical4j.model.property.Summary) VAlarm(net.fortuna.ical4j.model.component.VAlarm) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property)

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