Search in sources :

Example 31 with PropertyList

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

the class ICalConverter method toCalendarComponent.

protected static ResponseProperties toCalendarComponent(ComponentList components, GenericValue workEffort, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = workEffort.getDelegator();
    String workEffortId = workEffort.getString("workEffortId");
    String workEffortUid = workEffort.getString("universalId");
    String workEffortTypeId = workEffort.getString("workEffortTypeId");
    GenericValue typeValue = EntityQuery.use(delegator).from("WorkEffortType").where("workEffortTypeId", workEffortTypeId).cache().queryOne();
    boolean isTask = false;
    boolean newComponent = true;
    ComponentList resultList = null;
    ComponentList alarms = null;
    Component result = null;
    if ("TASK".equals(workEffortTypeId) || (typeValue != null && "TASK".equals(typeValue.get("parentTypeId")))) {
        isTask = true;
        resultList = components.getComponents("VTODO");
    } else if ("EVENT".equals(workEffortTypeId) || (typeValue != null && "EVENT".equals(typeValue.get("parentTypeId")))) {
        resultList = components.getComponents("VEVENT");
    } else {
        return null;
    }
    Iterator<Component> i = UtilGenerics.cast(resultList.iterator());
    while (i.hasNext()) {
        result = i.next();
        Property xProperty = result.getProperty(workEffortIdXPropName);
        if (xProperty != null && workEffortId.equals(xProperty.getValue())) {
            newComponent = false;
            break;
        }
        Property uid = result.getProperty(Uid.UID);
        if (uid != null && uid.getValue().equals(workEffortUid)) {
            newComponent = false;
            break;
        }
    }
    if (isTask) {
        VToDo toDo = null;
        if (newComponent) {
            toDo = new VToDo();
            result = toDo;
        } else {
            toDo = (VToDo) result;
        }
        alarms = toDo.getAlarms();
    } else {
        VEvent event = null;
        if (newComponent) {
            event = new VEvent();
            result = event;
        } else {
            event = (VEvent) result;
        }
        alarms = event.getAlarms();
    }
    if (newComponent) {
        components.add(result);
    }
    PropertyList componentProps = result.getProperties();
    loadWorkEffort(componentProps, workEffort);
    if (isTask) {
        replaceProperty(componentProps, toCompleted(workEffort.getTimestamp("actualCompletionDate")));
        replaceProperty(componentProps, toPercentComplete(workEffort.getLong("percentComplete")));
    } else {
        replaceProperty(componentProps, toDtEnd(workEffort.getTimestamp("estimatedCompletionDate")));
    }
    if (workEffort.get("estimatedCompletionDate") == null) {
        replaceProperty(componentProps, toDuration(workEffort.getDouble("estimatedMilliSeconds")));
    }
    List<GenericValue> relatedParties = EntityQuery.use(delegator).from("WorkEffortPartyAssignView").where("workEffortId", workEffortId).cache(true).filterByDate().queryList();
    if (relatedParties.size() > 0) {
        loadRelatedParties(relatedParties, componentProps, context);
    }
    if (newComponent) {
        if (UtilValidate.isNotEmpty(workEffort.getString("tempExprId"))) {
            TemporalExpression tempExpr = TemporalExpressionWorker.getTemporalExpression(delegator, workEffort.getString("tempExprId"));
            if (tempExpr != null) {
                try {
                    ICalRecurConverter.convert(tempExpr, componentProps);
                } catch (Exception e) {
                    replaceProperty(componentProps, new Description("Error while converting recurrence: " + e));
                }
            }
        }
        getAlarms(workEffort, alarms);
    }
    if (Debug.verboseOn()) {
        try {
            result.validate(true);
            Debug.logVerbose("iCalendar component passes validation", module);
        } catch (ValidationException e) {
            Debug.logVerbose(e, "iCalendar component fails validation: ", module);
        }
    }
    return null;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) GenericValue(org.apache.ofbiz.entity.GenericValue) TemporalExpression(org.apache.ofbiz.service.calendar.TemporalExpression) Description(net.fortuna.ical4j.model.property.Description) ValidationException(net.fortuna.ical4j.model.ValidationException) ComponentList(net.fortuna.ical4j.model.ComponentList) 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) Delegator(org.apache.ofbiz.entity.Delegator) Component(net.fortuna.ical4j.model.Component) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property) VToDo(net.fortuna.ical4j.model.component.VToDo)

Example 32 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method toObservanceComp.

private static Observance toObservanceComp(int hintYear, RuleLine rline, boolean isStandard, Time standardOffset, Time daylightOffset, String tznameFormat) {
    PropertyList props = new PropertyList();
    String tzname = getObservanceName(tznameFormat, rline);
    if (tzname != null) {
        props.add(new TzName(tzname));
    }
    Time at = rline.getAt();
    Time onset;
    switch(at.getType()) {
        case STANDARD_TIME:
            if (isStandard) {
                // We're moving from daylight time to standard time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's daylight time.
                // daylight = utc + daylight offset = (standard - standard offset) + daylight offset
                onset = addTimes(subtractTimes(at, standardOffset), daylightOffset);
            } else {
                // We're moving from standard time to daylight time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's standard time.  at is already in
                // standard time.
                onset = at;
            }
            break;
        case UTC_TIME:
            if (isStandard) {
                // We're moving from daylight time to standard time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's daylight time.
                // daylight = utc + daylightOffset.
                onset = addTimes(at, daylightOffset);
            } else {
                // We're moving from standard time to daylight time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's standard time.
                // standard = utc + standard offset.
                onset = addTimes(at, standardOffset);
            }
            break;
        default:
            // WALL_TIME
            // at is already in the iCalendar style.
            onset = at;
            break;
    }
    int hh = onset.getHour();
    int mm = onset.getMinute();
    int ss = onset.getSecond();
    if (hh >= 24) {
        // Hour should be between 0 and 23, but sometimes we can get 24:00:00 from the zoneinfo source.
        // Since hour part in iCalendar only allows 0-23, let's approximate any time with hour >= 24 to
        // 23:59:59.
        hh = 23;
        mm = 59;
        ss = 59;
    }
    // YYYYMMDD fixed to 16010101 (MS Outlook style)
    props.add(getDtStart(String.format("16010101T%02d%02d%02d", hh, mm, ss)));
    Time toOffset, fromOffset;
    if (isStandard) {
        toOffset = standardOffset;
        fromOffset = daylightOffset;
    } else {
        toOffset = daylightOffset;
        fromOffset = standardOffset;
    }
    props.add(new TzOffsetTo(new UtcOffset(getUtcOffset(toOffset))));
    props.add(new TzOffsetFrom(new UtcOffset(getUtcOffset(fromOffset))));
    int month = rline.getIn();
    StringBuilder rruleVal = new StringBuilder();
    rruleVal.append("FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=").append(month).append(";");
    rruleVal.append(dayToICalRRulePart(hintYear, month, rline.getOn()));
    try {
        RRule rrule = new RRule(new ParameterList(), rruleVal.toString());
        props.add(rrule);
    } catch (ParseException e) {
    }
    if (isStandard) {
        return new Standard(props);
    } else {
        return new Daylight(props);
    }
}
Also used : TzName(net.fortuna.ical4j.model.property.TzName) RRule(net.fortuna.ical4j.model.property.RRule) DateTime(net.fortuna.ical4j.model.DateTime) Time(com.zimbra.common.calendar.ZoneInfoParser.Time) Standard(net.fortuna.ical4j.model.component.Standard) UtcOffset(net.fortuna.ical4j.model.UtcOffset) PropertyList(net.fortuna.ical4j.model.PropertyList) Daylight(net.fortuna.ical4j.model.component.Daylight) TzOffsetTo(net.fortuna.ical4j.model.property.TzOffsetTo) TzOffsetFrom(net.fortuna.ical4j.model.property.TzOffsetFrom) ParameterList(net.fortuna.ical4j.model.ParameterList) ParseException(java.text.ParseException) TZDataParseException(com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException)

Example 33 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method toVTimeZoneComp.

/**
 * @param zoneLines - Only the zoneLines related to a time zone that might be relevant from the reference date.
 */
private static VTimeZone toVTimeZoneComp(Calendar referenceDate, List<ZoneLine> zoneLines, LastModified lastModified, Set<String> tzAliases, boolean isPrimary, Integer matchScore) {
    int hintYear = referenceDate.get(Calendar.YEAR);
    ZoneLine zline1 = zoneLines.get(0);
    PropertyList vtzProps = toVTimeZonePropertyList(zline1, lastModified, tzAliases, isPrimary, matchScore);
    if (zoneLines.size() == 1) {
        return toVTimeZoneComp(hintYear, toObservances(hintYear, zline1), vtzProps);
    }
    boolean suppressWarning = false;
    // Rare to get here - generally happens for some new timezone changes in the near future.
    ZoneLine zline2 = zoneLines.get(1);
    Observances obs1 = toObservances(hintYear, zline1);
    if (zline1.hasRule()) {
        if ((null != obs1.std) && (null != obs1.daylight)) {
            VTimeZone vtz = null;
            vtz = toVTimeZoneComp(referenceDate, zline1, zline2, obs1, vtzProps, obs1.inDaylightTimeOnDate(referenceDate));
            if (vtz != null) {
                return vtz;
            }
        }
    } else {
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        String fmtRefDate = format1.format(referenceDate.getTime());
        if ((null != obs1.std) && (null == obs1.daylight)) {
            // At reference date, only using STANDARD time
            Observances obs2 = toObservances(hintYear, zline2);
            if ((null != obs2.std) && (null != obs2.daylight)) {
                if (obs2.inDaylightTimeOnDate(referenceDate)) {
                    System.err.println(String.format("1st zoneLine '%s' for '%s' only has STANDARD time.", zline1.toString(), zline1.getName()));
                    System.err.println(String.format("Reference date %s would be in DAYLIGHT time by rules of 2nd zoneLine '%s'", fmtRefDate, zline2.toString()));
                    System.err.println("Therefore, Ignoring 2nd zoneLine.");
                    suppressWarning = true;
                } else {
                    TzOffsetTo oldOffsetTo = (TzOffsetTo) obs1.std.getProperties().getProperty(Property.TZOFFSETTO);
                    TzOffsetTo newOffsetTo = (TzOffsetTo) obs2.std.getProperties().getProperty(Property.TZOFFSETTO);
                    if (oldOffsetTo.equals(newOffsetTo)) {
                        // Standard time same by current rules and new rules - can ignore 1st zoneLine going forward
                        return toVTimeZoneComp(hintYear, toObservances(hintYear, zline2), vtzProps);
                    }
                    System.err.println(String.format("1st zoneLine '%s' for '%s' only has STANDARD time.", zline1.toString(), zline1.getName()));
                    System.err.println(String.format("Reference date %s would also be in STANDARD time by rules of 2nd zoneLine '%s'", fmtRefDate, zline2.toString()));
                    System.err.println(String.format("BUT OLD STANDARD has TZOFFSETTO=%s which differs from new TZOFFSETTO=%s.", oldOffsetTo.toString(), newOffsetTo.toString()));
                    System.err.println("Therefore, Ignoring 2nd zoneLine.");
                    suppressWarning = true;
                }
            }
        }
    }
    if (!suppressWarning) {
        System.err.println(String.format("More than 1 zoneLine for zone '%s' but unknown scenario.  Using only zoneLine:\n    %s", zline1.getName(), zline1.toString()));
    }
    return toVTimeZoneComp(hintYear, toObservances(hintYear, zline1), vtzProps);
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList) TzOffsetTo(net.fortuna.ical4j.model.property.TzOffsetTo) ZoneLine(com.zimbra.common.calendar.ZoneInfoParser.ZoneLine) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) SimpleDateFormat(java.text.SimpleDateFormat)

Example 34 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project bw-calendar-engine by Bedework.

the class IcalTranslator method makeIc.

private Icalendar makeIc(final BwCalendar col, final Icalendar ic, final Calendar cal, final boolean diff, final boolean mergeAttendees) throws CalFacadeException {
    try {
        if (cal == null) {
            return ic;
        }
        PropertyList pl = cal.getProperties();
        Property prop = pl.getProperty(Property.PRODID);
        if (prop != null) {
            ic.setProdid(prop.getValue());
        }
        prop = pl.getProperty(Property.VERSION);
        if (prop != null) {
            ic.setVersion(prop.getValue());
        }
        ic.setMethod(getMethod(cal));
        prop = pl.getProperty(Property.CALSCALE);
        if (prop != null) {
            ic.setCalscale(prop.getValue());
        }
        Collection<CalendarComponent> clist = orderedComponents(cal.getComponents());
        for (CalendarComponent comp : clist) {
            if (comp instanceof VFreeBusy) {
                EventInfo ei = BwEventUtil.toEvent(cb, col, ic, comp, diff, mergeAttendees);
                if (ei != null) {
                    ic.addComponent(ei);
                }
            } else if (comp instanceof VTimeZone) {
                ic.addTimeZone(doTimeZone((VTimeZone) comp));
            } else if ((comp instanceof VEvent) || (comp instanceof VToDo) || (comp instanceof VPoll) || (comp instanceof VAvailability)) {
                EventInfo ei = BwEventUtil.toEvent(cb, col, ic, comp, diff, mergeAttendees);
                if (ei != null) {
                    ic.addComponent(ei);
                }
            }
        }
        return ic;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) EventInfo(org.bedework.calfacade.svc.EventInfo) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) VAvailability(net.fortuna.ical4j.model.component.VAvailability) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) VPoll(net.fortuna.ical4j.model.component.VPoll) Property(net.fortuna.ical4j.model.Property) VToDo(net.fortuna.ical4j.model.component.VToDo)

Example 35 with PropertyList

use of net.fortuna.ical4j.model.PropertyList in project bw-calendar-engine by Bedework.

the class IcalUtil method addProperty.

/**
 * @param comp
 * @param val
 */
public static void addProperty(final Component comp, final Property val) {
    PropertyList props = comp.getProperties();
    props.add(val);
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList)

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