Search in sources :

Example 6 with DateTime

use of net.fortuna.ical4j.model.DateTime in project openmeetings by apache.

the class IcalUtils method parseAppointmenttoCalendar.

/**
 * Methods to parse Appointment to iCalendar according RFC 2445
 *
 * @param appointment to be converted to iCalendar
 * @return iCalendar representation of the Appointment
 */
public Calendar parseAppointmenttoCalendar(Appointment appointment) {
    String tzid = parseTimeZone(null, appointment.getOwner()).getID();
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid);
    if (timeZone == null) {
        throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid);
    }
    Calendar icsCalendar = new Calendar();
    icsCalendar.getProperties().add(new ProdId("-//Events Calendar//Apache Openmeetings//EN"));
    icsCalendar.getProperties().add(Version.VERSION_2_0);
    icsCalendar.getProperties().add(CalScale.GREGORIAN);
    icsCalendar.getComponents().add(timeZone.getVTimeZone());
    DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd());
    VEvent meeting = new VEvent(start, end, appointment.getTitle());
    meeting = addVEventpropsfromAppointment(appointment, meeting);
    icsCalendar.getComponents().add(meeting);
    return icsCalendar;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) ProdId(net.fortuna.ical4j.model.property.ProdId) NoSuchElementException(java.util.NoSuchElementException) DateTime(net.fortuna.ical4j.model.DateTime)

Example 7 with DateTime

use of net.fortuna.ical4j.model.DateTime in project openmeetings by apache.

the class IcalHandler method addNewMeeting.

/**
 * @param startDate
 *            use standard TimeZone!!
 * @param endDate
 *            use standard time zone!!
 * @param name
 *            meeting name
 * @param attendees
 *            List of attendees (use getAttendeeData to retrieve valid records)
 * @param description
 *            containing the meeting description
 * @param organizer
 *            organizer
 * @param uid
 *            (maybe null)
 * @param javaTzId ID of owner's java time zone
 * @return UID of Meeting
 */
// ---------------------------------------------------------------------------------------
public String addNewMeeting(Date startDate, Date endDate, String name, List<Map<String, String>> attendees, String description, Map<String, String> organizer, String uid, String javaTzId) {
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timeZone = registry.getTimeZone(javaTzId);
    if (timeZone == null) {
        throw new NoSuchElementException("Unable to get time zone by id provided: " + javaTzId);
    }
    DateTime start = new DateTime(startDate);
    start.setTimeZone(timeZone);
    DateTime end = new DateTime(endDate);
    end.setTimeZone(timeZone);
    VEvent meeting = new VEvent(start, end, name);
    meeting.getProperties().add(new Description(description));
    meeting.getProperties().add(new Sequence(0));
    meeting.getProperties().add(new Location(""));
    meeting.getProperties().add(Transp.OPAQUE);
    // generate unique identifier (if not submitted)
    Uid ui;
    if (Strings.isEmpty(uid)) {
        ui = new Uid(UUID.randomUUID().toString());
        log.debug("Generating Meeting UID : " + ui.getValue());
    } else {
        ui = new Uid(uid);
        log.debug("Using Meeting UID : " + ui.getValue());
    }
    meeting.getProperties().add(ui);
    for (Map<String, String> att : attendees) {
        Attendee uno = new Attendee(URI.create(att.get("uri")));
        String chair = att.get("chair");
        uno.getParameters().add("0".equals(chair) ? Role.REQ_PARTICIPANT : Role.CHAIR);
        uno.getParameters().add(new Cn(att.get("cn")));
        meeting.getProperties().add(uno);
    }
    Organizer orger = new Organizer(URI.create(organizer.get("uri")));
    orger.getParameters().add(new Cn(organizer.get("cn")));
    meeting.getProperties().add(orger);
    icsCalendar.getComponents().add(timeZone.getVTimeZone());
    icsCalendar.getComponents().add(meeting);
    return ui.getValue();
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) Organizer(net.fortuna.ical4j.model.property.Organizer) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) Sequence(net.fortuna.ical4j.model.property.Sequence) Cn(net.fortuna.ical4j.model.parameter.Cn) DateTime(net.fortuna.ical4j.model.DateTime) Attendee(net.fortuna.ical4j.model.property.Attendee) Uid(net.fortuna.ical4j.model.property.Uid) TimeZone(net.fortuna.ical4j.model.TimeZone) NoSuchElementException(java.util.NoSuchElementException) Location(net.fortuna.ical4j.model.property.Location)

Example 8 with DateTime

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

the class BwEvent method updateStag.

/**
 * Set the stag for this event.
 * @param val
 */
@NoProxy
public void updateStag(final Timestamp val) {
    DateTime dt = new DateTime(val);
    // dt.setUtc(true);
    setStag(new LastModified(dt).getValue() + "-" + hex4FromNanos(val.getNanos()));
}
Also used : LastModified(net.fortuna.ical4j.model.property.LastModified) DateTime(net.fortuna.ical4j.model.DateTime) NoProxy(org.bedework.calfacade.annotations.ical.NoProxy)

Example 9 with DateTime

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

the class BwEvent method setDtstamps.

/**
 * Set the dtstamp, lastmod and created if created is not set already.
 * @param val
 */
@NoProxy
public void setDtstamps(final Timestamp val) {
    DateTime dt = new DateTime(val);
    setDtstamp(new DtStamp(dt).getValue());
    setLastmod(new LastModified(dt).getValue());
    setCtoken(getLastmod() + "-" + hex4FromNanos(val.getNanos()));
    if (getCreated() == null) {
        setCreated(new Created(dt).getValue());
    }
}
Also used : LastModified(net.fortuna.ical4j.model.property.LastModified) DtStamp(net.fortuna.ical4j.model.property.DtStamp) DateTime(net.fortuna.ical4j.model.DateTime) Created(net.fortuna.ical4j.model.property.Created) NoProxy(org.bedework.calfacade.annotations.ical.NoProxy)

Example 10 with DateTime

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

the class BwDateTime method addDuration.

private BwDateTime addDuration(final Dur val) throws CalFacadeException {
    DtEnd dtEnd;
    java.util.Date endDt = val.getTime(makeDate());
    DtStart dtStart = makeDtStart(Timezones.getTzRegistry());
    if (getDateType()) {
        dtEnd = new DtEnd(new Date(endDt));
        addIcalParameter(dtEnd, Value.DATE);
    } else {
        DateTime d = new DateTime(endDt);
        Parameter tzid = getIcalParameter(dtStart, "TZID");
        if (tzid != null) {
            DateTime sd = (DateTime) dtStart.getDate();
            d.setTimeZone(sd.getTimeZone());
        }
        // dtEnd = new DtEnd(d, dtStart.isUtc());
        dtEnd = new DtEnd(d);
        if (tzid != null) {
            addIcalParameter(dtEnd, tzid);
        } else if (dtStart.isUtc()) {
            dtEnd.setUtc(true);
        }
    }
    return makeBwDateTime(dtEnd);
}
Also used : DtStart(net.fortuna.ical4j.model.property.DtStart) Parameter(net.fortuna.ical4j.model.Parameter) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Aggregations

DateTime (net.fortuna.ical4j.model.DateTime)70 Period (net.fortuna.ical4j.model.Period)20 VEvent (net.fortuna.ical4j.model.component.VEvent)18 BwDateTime (org.bedework.calfacade.BwDateTime)15 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)15 Date (java.util.Date)13 TimeZone (net.fortuna.ical4j.model.TimeZone)13 ParseException (java.text.ParseException)12 DtStart (net.fortuna.ical4j.model.property.DtStart)11 Date (net.fortuna.ical4j.model.Date)10 Dur (net.fortuna.ical4j.model.Dur)10 PeriodList (net.fortuna.ical4j.model.PeriodList)10 PropertyList (net.fortuna.ical4j.model.PropertyList)9 DtStamp (net.fortuna.ical4j.model.property.DtStamp)9 LastModified (net.fortuna.ical4j.model.property.LastModified)9 Uid (net.fortuna.ical4j.model.property.Uid)9 Calendar (net.fortuna.ical4j.model.Calendar)8 Recur (net.fortuna.ical4j.model.Recur)8 ExDate (net.fortuna.ical4j.model.property.ExDate)8 GregorianCalendar (java.util.GregorianCalendar)7