Updating Google Calendar with MS Project Tasks – 2 – Revisited

This is the 2nd part in the series. Please refer to Updating Google Calendar with MS Project Tasks - Revisited for Part 1, including how to build the code.

In the previous post we saw, how to list all the Calendar's. In this post we shall build upon the code to list all the calendar's for a given user account, and update the MS Project tasks to the selected calendar.

We shall need to following three steps:

  • List Calendars and select one
  • Parse MS Project tasks and convert them to Calendar events
  • Update Google Calendar with Events

Step 1: List All calendar's

We have already seen the code for this in previous post

Step 2: Parse MS Project task and convert to Calendar Event

Lets look at the code for the conversion

protected CalendarEventEntry convertTaskToCalenderEntry(Task task) {
    System.out.println("Task "+task);
    CalendarEventEntry eventEntry = new CalendarEventEntry();
    eventEntry.setTitle(new PlainTextConstruct(task.getName()));

    When date = new When();
    date.setStartTime(new DateTime(task.getStart()));
    eventEntry.addTime(date);
    return eventEntry;
}

The code takes Start and End date of task, as well as title, and creates an CalendarEventEntry for the same. There can be additional logic built into this, like filtering events based on some rules etc.

Step 3: Updating entries into Google Calendar

public void updateCalenderWithEntry(List<Task> tasks, CalendarService calendarService, URL url) {
    for (Task task : tasks) {
        CalendarEventEntry entry = convertTaskToCalenderEntry(task);
        try {
            calendarService.insert(url, entry);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
}

Here we just iterate through the tasks and update the events using CalendarService. The Calendar URL can be retrieved from the CalendarEntry class.

A complete working example is part of com.ashishpaliwal.mpputils.examples.MppToGoogleCalendar

Using the sample program

>com.ashishpaliwal.mpputils.examples.MppToGoogleCalendar [MPP File] [Google User Name] [password]

What's Next?

Eager to hear from user, what they would like to see. Adding a UI and out-of-box working package is something that would be good. However, please do try using this and I shall try my best to improve this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.