Home : J-Integra for Exchange : HOWTO : Working With Recurring Calendar Items
Q183246 - HOWTO: Working With Recurring Calendar Items

Working With Recurring Calendar Items

This article demonstrates how to work with recurring Calendar items, such as Appointments and Meetings. The code snippets that follow use a basic Appointment for illustration, however, they can easily be adapted to Meeting Requests (see here for more details). For more information on the RecurrencePattern object, please refer to the Microsoft CDO reference.

Creating a recurring Appointment:

import com.intrinsyc.cdo.*;
import java.util.Date;
import java.text.SimpleDateFormat;

public class RecurrenceTesting {
    public static void main(String[] args) {
		
        String domain           = "";
        String username         = "";
        String password         = "";
        String CDOmachine       = "";
        String exchangeServer   = "";
        String mailbox          = "";

        try {
            // Authenticate to Windows
            com.linar.jintegra.AuthInfo.setDefault(domain, username, password);

            // Create Session and Logon
            Session session = new Session(CDOmachine);
            session.logon(
                null,
                null,
                Boolean.valueOf(false),
                Boolean.valueOf(true),
                Boolean.valueOf(false),
                Boolean.valueOf(false),
                exchangeServer + "\n" + mailbox
            );

            // Retrieve Messages collection from Calendar and add new AppointmentItem
            Integer defaultCalendar = Integer.valueOf(CdoDefaultFolderTypes.CdoDefaultFolderCalendar);
            Folder calendar = new FolderProxy(session.getDefaultFolder(defaultCalendar));
            Messages appointments = new MessagesProxy(calendar.getMessages());
            AppointmentItem appointment = new AppointmentItemProxy(appointments.add(null, null, null, null));

            // Set AppointmentItem details
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss aa");
            Date startTime = sdf.parse("2008/12/01 3:00:00 PM");
            Date endTime = sdf.parse("2008/12/01 3:30:00 PM");

            appointment.setSubject("My Recurring Test Appointment.");
            appointment.setLocation("The office.");
            appointment.setText("Bi-weekly.");
            appointment.setStartTime(startTime);
            appointment.setEndTime(endTime);


            // Set RecurrencePattern details            
            // ***** Create Appointment that recurs every 2 weeks *****
            RecurrencePattern recurrence = new RecurrencePatternProxy(appointment.getRecurrencePattern());
            recurrence.setRecurrenceType(Integer.valueOf(CdoRecurTypes.CdoRecurTypeWeekly));
            recurrence.setInterval(Integer.valueOf(2));
            // ***** Create Appointment that recurs every 2 weeks *****
            /*
            // ***** Create Appointment that recurs every year on the 1st Monday in December *****
            RecurrencePattern recurrence = new RecurrencePatternProxy(appointment.getRecurrencePattern());
            recurrence.setRecurrenceType(Integer.valueOf(CdoRecurTypes.CdoRecurTypeYearlyNth));
            recurrence.setMonthOfYear(Integer.valueOf(12));
            recurrence.setDayOfWeekMask(Integer.valueOf(CdoDaysOfWeek.CdoMonday)); 
            recurrence.setInstance(Integer.valueOf(1));			
            // ***** Create Appointment that recurs every year on the 1st Monday in December *****
            */
            /*
            // ***** Create Appointment that recurs every weekday *****
            RecurrencePattern recurrence = new RecurrencePatternProxy(appointment.getRecurrencePattern());
            recurrence.setRecurrenceType(Integer.valueOf(CdoRecurTypes.CdoRecurTypeWeekly));			
            recurrence.setDayOfWeekMask(Integer.valueOf(
                CdoDaysOfWeek.CdoMonday + 
                CdoDaysOfWeek.CdoTuesday + 
                CdoDaysOfWeek.CdoWednesday + 
                CdoDaysOfWeek.CdoThursday + 
                CdoDaysOfWeek.CdoFriday
            )); 
            // ***** Create Appointment that recurs every weekday *****
            */

            // Update/Save AppointmentItem in Calendar
            appointment.update(Boolean.valueOf(true), Boolean.valueOf(true));

            // Logoff
            session.logoff();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // Release all objects
            com.linar.jintegra.Cleaner.releaseAll();
        }
    }
}

Modifying the recurrence of a recurring Appointment:

The following code snippet assumes there already exists a valid reference to a desired Appointment. Note: a reference to an existing AppointmentItem can be obtained using a MessageFilter or the AppointmentItem's unique ID.

// apptUpdate is a reference to the appointment that is to be updated

// Clear the old RecurrencePattern
// THIS MUST BE DONE FIRST
apptUpdate.clearRecurrencePattern();

// Change AppointmentItem and RecurrencePattern details
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss aa");
Date startTime = sdf.parse("2008/12/03 01:00:00 PM");
Date endTime = sdf.parse("2008/12/03 01:30:00 PM");
apptUpdate.setStartTime(startTime);
apptUpdate.setEndTime(endTime);

RecurrencePattern recurrence = new RecurrencePatternProxy(apptUpdate.getRecurrencePattern());
recurrence.setRecurrenceType(Integer.valueOf(CdoRecurTypes.CdoRecurTypeWeekly));
recurrence.setInterval(Integer.valueOf(3));  // Recurs every 3 weeks

// Update the Appointment
apptUpdate.update(Boolean.valueOf(true), Boolean.valueOf(true));

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 12/1/2008.
Last Modified on 12/1/2008.
Last Modified by J-Integra KB Admin.
Article has been viewed 8379 times.
Rated 0 out of 10 based on 0 votes.
Print Article
Email Article