Activies offers a great feature of to-do to help remind the tasks assigned to you. But some uses are already very used to leveraging Notes calendar to track there to-do tasks. It will be very convenient for the user to track their Activities to-dos in their Notes Calendar. This section will show you how to synchronize Activities to-do list with Notes Calendar.
Retrieving Activities to-do list from Activites via Lotus Connections API
Before we start writing code to retrieve the to-do list from Activities, we'd better first make a data model for the Activities to-do in order to hold the data for future use (add those TODOs to Notes Calendar). Here we don't need all of the information retrieved from Activities to-do entry. What we need is the title, startDate, dueDate, and content.
Listing 1. Activities to-do data model
public class ActivitiesTodo {
private String title;
private String startDate;
private String dueDate;
private String content;
public ActivitiesTodo(String title, String author, String assignedTo, String dueDate, String content) {
this.title = title;
this.author = author;
this.assignedTo = assignedTo;
this.dueDate = dueDate;
this.content= content;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
......
}
Following code is used to retrieve all the to-do's which are assigned to you.
For more detail about how to assemble the URL used to retrive Activities to-do list, please refer to the Lotus Connections 2 Information Center.
Listing 2. Retriving the to-do list assigned to you
Abdera abdera = new Abdera();
Parser parser = abdera.getParser();
URL api_url = new URL("http://connections.demoibm.com/activities/service/atom/todos?assignedto=PBrown@demoibm.com");
Using your Activities login ID and password to pass authentication
HttpURLConnection connection = (HttpURLConnection) api_url.openConnection();
String encoding = new sun.misc.BASE64Encoder().encode(("PBrown@demoibm.com" + ":" + "
techw0rks").getBytes());
connection.setRequestProperty("Authorization", "Basic " + encoding);
Document document = parser.parse(connection.getInputStre am());
Feed feed = document.getRoot();
XPath xpath = abdera.getXPath();
List entries = feed.getEntries();
List todoList = new ArrayList();
for (Entry entry : entries) {
String title = xpath.valueOf("a:title", entry);
String startDate = xpath.valueOf("a:published", entry);
String dueDate = xpath.valueOf("snx:duedate", entry, feed.getNamespaces());
String content = xpath.valueOf("a:content", entry);
todoList.add(new ActivitiesTodo(title, startDate, dueDate, content));
}
Adding Activities to-do list to Nodes Calendar via Notes API
xxx
public static void importActivitiesToDos(List todoList) throws NotesException {
NotesThread.sinitThread();
Session s = NotesFactory.createSessionWithFullAccess("Voodoo830702");
DbDirectory dir = s.getDbDirectory(null);
Database db = dir.openMailDatabase();
for (ActivitiesTodo todo : todoList) {
Document doc = db.createDocument();
doc.appendItemValue("Form", "Task");
doc.appendItemValue("Subject", todo.getTitle());
doc.appendItemValue("Chair", s.getUserName());
doc.appendItemValue("StartDate", todo.getStartDate());
doc.appendItemValue("DueDate", todo.getDueDate());
RichTextItem rti = doc.createRichTextItem("Body");
rti.appendText(todo.getContent());
doc.save();
}
}