Search in sources :

Example 11 with Description

use of net.fortuna.ical4j.model.property.Description 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 12 with Description

use of net.fortuna.ical4j.model.property.Description in project opencast by opencast.

the class CalendarGenerator method addEvent.

/**
 * Adds an SchedulerEvent as a new entry to this iCalendar
 *
 * @param mp
 *          {@link MediaPackage} of event
 * @param agentId
 *          the agent identifier
 * @param start
 *          the start date
 * @param end
 *          the end date
 * @param captureAgentMetadata
 *          properties for capture agent metadata
 *
 * @return true if the event could be added.
 */
public boolean addEvent(MediaPackage mp, DublinCoreCatalog catalog, String agentId, Date start, Date end, Date lastModified, String captureAgentMetadata) {
    String eventId = mp.getIdentifier().compact();
    logger.debug("Creating iCaleandar VEvent from scheduled event '{}'", eventId);
    DateTime startDate = new DateTime(start);
    DateTime endDate = new DateTime(end);
    Date marginEndDate = new org.joda.time.DateTime(endDate.getTime()).plusHours(1).toDate();
    if (marginEndDate.before(new Date())) {
        logger.debug("Event has already passed more than an hour, skipping!");
        return false;
    }
    startDate.setUtc(true);
    endDate.setUtc(true);
    String seriesID = null;
    VEvent event = new VEvent(startDate, endDate, catalog.getFirst(DublinCore.PROPERTY_TITLE));
    try {
        ParameterList pl = new ParameterList();
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            pl.add(new Cn(catalog.getFirst(DublinCore.PROPERTY_CREATOR)));
        }
        event.getProperties().add(new Uid(eventId));
        DateTime lastModifiedDate = new DateTime(lastModified);
        lastModifiedDate.setUtc(true);
        event.getProperties().add(new LastModified(lastModifiedDate));
        // TODO Organizer should be URI (email-address?) created fake address
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            URI organizer = new URI("mailto", catalog.getFirst(DublinCore.PROPERTY_CREATOR) + "@opencast.tld", null);
            event.getProperties().add(new Organizer(pl, organizer));
        }
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION))) {
            event.getProperties().add(new Description(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION)));
        }
        event.getProperties().add(new Location(agentId));
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF))) {
            seriesID = catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF);
            event.getProperties().add(new RelatedTo(seriesID));
        }
        ParameterList dcParameters = new ParameterList();
        dcParameters.add(new FmtType("application/xml"));
        dcParameters.add(Value.BINARY);
        dcParameters.add(Encoding.BASE64);
        dcParameters.add(new XParameter("X-APPLE-FILENAME", "episode.xml"));
        Attach metadataAttachment = new Attach(dcParameters, catalog.toXmlString().getBytes("UTF-8"));
        event.getProperties().add(metadataAttachment);
        String seriesDC = getSeriesDublinCoreAsString(seriesID);
        if (seriesDC != null) {
            logger.debug("Attaching series {} information to event {}", seriesID, eventId);
            ParameterList sDcParameters = new ParameterList();
            sDcParameters.add(new FmtType("application/xml"));
            sDcParameters.add(Value.BINARY);
            sDcParameters.add(Encoding.BASE64);
            sDcParameters.add(new XParameter("X-APPLE-FILENAME", "series.xml"));
            Attach seriesAttachment = new Attach(sDcParameters, seriesDC.getBytes("UTF-8"));
            event.getProperties().add(seriesAttachment);
        } else {
            logger.debug("No series provided for event {}.", eventId);
        }
        ParameterList caParameters = new ParameterList();
        caParameters.add(new FmtType("application/text"));
        caParameters.add(Value.BINARY);
        caParameters.add(Encoding.BASE64);
        caParameters.add(new XParameter("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties"));
        Attach agentsAttachment = new Attach(caParameters, captureAgentMetadata.getBytes("UTF-8"));
        event.getProperties().add(agentsAttachment);
    } catch (Exception e) {
        logger.error("Unable to add event '{}' to recording calendar: {}", eventId, ExceptionUtils.getStackTrace(e));
        return false;
    }
    cal.getComponents().add(event);
    logger.debug("new VEvent = {} ", event.toString());
    return true;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) Organizer(net.fortuna.ical4j.model.property.Organizer) Attach(net.fortuna.ical4j.model.property.Attach) Cn(net.fortuna.ical4j.model.parameter.Cn) URI(java.net.URI) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) LastModified(net.fortuna.ical4j.model.property.LastModified) Uid(net.fortuna.ical4j.model.property.Uid) FmtType(net.fortuna.ical4j.model.parameter.FmtType) ParameterList(net.fortuna.ical4j.model.ParameterList) RelatedTo(net.fortuna.ical4j.model.property.RelatedTo) XParameter(net.fortuna.ical4j.model.parameter.XParameter) Location(net.fortuna.ical4j.model.property.Location)

Example 13 with Description

use of net.fortuna.ical4j.model.property.Description in project openolat by klemens.

the class ICalFileCalendarManager method getKalendarEvent.

/**
 * Build a KalendarEvent out of a source VEvent.
 * @param event
 * @return
 */
private KalendarEvent getKalendarEvent(VEvent event) {
    // subject
    Summary eventsummary = event.getSummary();
    String subject = "";
    if (eventsummary != null)
        subject = eventsummary.getValue();
    // start
    DtStart dtStart = event.getStartDate();
    Date start = dtStart.getDate();
    Duration dur = event.getDuration();
    // end
    Date end = null;
    if (dur != null) {
        end = dur.getDuration().getTime(start);
    } else if (event.getEndDate() != null) {
        end = event.getEndDate().getDate();
    }
    // check all day event first
    boolean isAllDay = false;
    Parameter dateParameter = event.getProperties().getProperty(Property.DTSTART).getParameters().getParameter(Value.DATE.getName());
    if (dateParameter != null) {
        isAllDay = true;
        // Make sure the time of the dates are 00:00 localtime because DATE fields in iCal are GMT 00:00
        // Note that start date and end date can have different offset because of daylight saving switch
        java.util.TimeZone timezone = java.util.GregorianCalendar.getInstance().getTimeZone();
        start = new Date(start.getTime() - timezone.getOffset(start.getTime()));
        end = new Date(end.getTime() - timezone.getOffset(end.getTime()));
        // adjust end date: ICal sets end dates to the next day
        end = new Date(end.getTime() - (1000 * 60 * 60 * 24));
    } else if (start != null && end != null && (end.getTime() - start.getTime()) == (24 * 60 * 60 * 1000)) {
        // check that start has no hour, no minute and no second
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.setTime(start);
        isAllDay = cal.get(java.util.Calendar.HOUR_OF_DAY) == 0 && cal.get(java.util.Calendar.MINUTE) == 0 && cal.get(java.util.Calendar.SECOND) == 0 && cal.get(java.util.Calendar.MILLISECOND) == 0;
        // adjust end date: ICal sets end dates to the next day
        end = new Date(end.getTime() - (1000 * 60 * 60 * 24));
    }
    Uid eventuid = event.getUid();
    String uid;
    if (eventuid != null) {
        uid = eventuid.getValue();
    } else {
        uid = CodeHelper.getGlobalForeverUniqueID();
    }
    RecurrenceId eventRecurenceId = event.getRecurrenceId();
    String recurrenceId = null;
    if (eventRecurenceId != null) {
        recurrenceId = eventRecurenceId.getValue();
    }
    KalendarEvent calEvent = new KalendarEvent(uid, recurrenceId, subject, start, end);
    calEvent.setAllDayEvent(isAllDay);
    // classification
    Clazz classification = event.getClassification();
    if (classification != null) {
        String sClass = classification.getValue();
        int iClassification = KalendarEvent.CLASS_PRIVATE;
        if (sClass.equals(ICAL_CLASS_PRIVATE.getValue()))
            iClassification = KalendarEvent.CLASS_PRIVATE;
        else if (sClass.equals(ICAL_CLASS_X_FREEBUSY.getValue()))
            iClassification = KalendarEvent.CLASS_X_FREEBUSY;
        else if (sClass.equals(ICAL_CLASS_PUBLIC.getValue()))
            iClassification = KalendarEvent.CLASS_PUBLIC;
        calEvent.setClassification(iClassification);
    }
    // created/last modified
    Created created = event.getCreated();
    if (created != null) {
        calEvent.setCreated(created.getDate().getTime());
    }
    // created/last modified
    Contact contact = (Contact) event.getProperty(Property.CONTACT);
    if (contact != null) {
        calEvent.setCreatedBy(contact.getValue());
    }
    LastModified lastModified = event.getLastModified();
    if (lastModified != null) {
        calEvent.setLastModified(lastModified.getDate().getTime());
    }
    Description description = event.getDescription();
    if (description != null) {
        calEvent.setDescription(description.getValue());
    }
    // location
    Location location = event.getLocation();
    if (location != null) {
        calEvent.setLocation(location.getValue());
    }
    // links if any
    PropertyList linkProperties = event.getProperties(ICAL_X_OLAT_LINK);
    List<KalendarEventLink> kalendarEventLinks = new ArrayList<KalendarEventLink>();
    for (Iterator<?> iter = linkProperties.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) {
                String provider = st.nextToken();
                String id = st.nextToken();
                String displayName = st.nextToken();
                String uri = st.nextToken();
                String iconCss = "";
                // migration: iconCss has been added later, check if available first
                if (st.hasMoreElements()) {
                    iconCss = st.nextToken();
                }
                KalendarEventLink eventLink = new KalendarEventLink(provider, id, displayName, uri, iconCss);
                kalendarEventLinks.add(eventLink);
            }
        }
    }
    calEvent.setKalendarEventLinks(kalendarEventLinks);
    Property comment = event.getProperty(ICAL_X_OLAT_COMMENT);
    if (comment != null)
        calEvent.setComment(comment.getValue());
    Property numParticipants = event.getProperty(ICAL_X_OLAT_NUMPARTICIPANTS);
    if (numParticipants != null)
        calEvent.setNumParticipants(Integer.parseInt(numParticipants.getValue()));
    Property participants = event.getProperty(ICAL_X_OLAT_PARTICIPANTS);
    if (participants != null) {
        StringTokenizer strTok = new StringTokenizer(participants.getValue(), "§", false);
        String[] parts = new String[strTok.countTokens()];
        for (int i = 0; strTok.hasMoreTokens(); i++) {
            parts[i] = strTok.nextToken();
        }
        calEvent.setParticipants(parts);
    }
    Property sourceNodId = event.getProperty(ICAL_X_OLAT_SOURCENODEID);
    if (sourceNodId != null) {
        calEvent.setSourceNodeId(sourceNodId.getValue());
    }
    // managed properties
    Property managed = event.getProperty(ICAL_X_OLAT_MANAGED);
    if (managed != null) {
        String value = managed.getValue();
        if ("true".equals(value)) {
            value = "all";
        }
        CalendarManagedFlag[] values = CalendarManagedFlag.toEnum(value);
        calEvent.setManagedFlags(values);
    }
    Property externalId = event.getProperty(ICAL_X_OLAT_EXTERNAL_ID);
    if (externalId != null) {
        calEvent.setExternalId(externalId.getValue());
    }
    Property externalSource = event.getProperty(ICAL_X_OLAT_EXTERNAL_SOURCE);
    if (externalSource != null) {
        calEvent.setExternalSource(externalSource.getValue());
    }
    // recurrence
    if (event.getProperty(ICAL_RRULE) != null) {
        calEvent.setRecurrenceRule(event.getProperty(ICAL_RRULE).getValue());
    }
    // recurrence exclusions
    if (event.getProperty(ICAL_EXDATE) != null) {
        calEvent.setRecurrenceExc(event.getProperty(ICAL_EXDATE).getValue());
    }
    return calEvent;
}
Also used : Description(net.fortuna.ical4j.model.property.Description) ArrayList(java.util.ArrayList) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) Created(net.fortuna.ical4j.model.property.Created) LastModified(net.fortuna.ical4j.model.property.LastModified) CalendarManagedFlag(org.olat.commons.calendar.CalendarManagedFlag) Clazz(net.fortuna.ical4j.model.property.Clazz) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property) XProperty(net.fortuna.ical4j.model.property.XProperty) Calendar(net.fortuna.ical4j.model.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Duration(net.fortuna.ical4j.model.property.Duration) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) Contact(net.fortuna.ical4j.model.property.Contact) Uid(net.fortuna.ical4j.model.property.Uid) StringTokenizer(java.util.StringTokenizer) DtStart(net.fortuna.ical4j.model.property.DtStart) PropertyList(net.fortuna.ical4j.model.PropertyList) Summary(net.fortuna.ical4j.model.property.Summary) Parameter(net.fortuna.ical4j.model.Parameter) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) Location(net.fortuna.ical4j.model.property.Location)

Aggregations

Description (net.fortuna.ical4j.model.property.Description)13 Uid (net.fortuna.ical4j.model.property.Uid)9 VEvent (net.fortuna.ical4j.model.component.VEvent)8 Location (net.fortuna.ical4j.model.property.Location)8 PropertyList (net.fortuna.ical4j.model.PropertyList)7 LastModified (net.fortuna.ical4j.model.property.LastModified)7 DateTime (net.fortuna.ical4j.model.DateTime)6 Summary (net.fortuna.ical4j.model.property.Summary)6 XProperty (net.fortuna.ical4j.model.property.XProperty)6 URISyntaxException (java.net.URISyntaxException)5 Date (java.util.Date)5 Property (net.fortuna.ical4j.model.Property)5 Contact (net.fortuna.ical4j.model.property.Contact)5 Created (net.fortuna.ical4j.model.property.Created)5 URI (java.net.URI)4 Calendar (net.fortuna.ical4j.model.Calendar)4 DtStart (net.fortuna.ical4j.model.property.DtStart)4 Duration (net.fortuna.ical4j.model.property.Duration)4 RecurrenceId (net.fortuna.ical4j.model.property.RecurrenceId)4 IOException (java.io.IOException)3