Fetch upcoming events

In this tutorial, we will explain how to fetch the upcoming events for a user using Blue Mind client APIs.

Overview

To fetch the upcoming events, the steps are:

Code sample

		// login with the API key
		AccessToken token = cal.login("admin0@global.virt", key, "junit-"
				+ getName());

		// login as the other user
		AccessToken asUser = cal.sudo(token, "admin@willow.vmw");
		assertNotNull(asUser);
		assertNotNull(asUser.getSessionId());
		User theOtherUser = cal.findMe(asUser);
		System.out.println("I am user " + theOtherUser.getBoxName());

		// compute now and now + 1 day
		Calendar gc = new GregorianCalendar(
				TimeZone.getTimeZone("Europe/Paris"), Locale.FRENCH);
		Date now = gc.getTime();
		gc.add(Calendar.DAY_OF_MONTH, 1);
		Date nowPlusOneDay = gc.getTime();

		// Query for occurences between those dates
		CalendarQuery cq = new CalendarQuery();
		cq.setFrom(now);
		cq.setTo(nowPlusOneDay);
		OccurrenceFactory of = cal.find(asUser, cq);

		// And print them
		System.out.println("Found " + of.getOccurrences().size()
				+ " occurences between " + now + " and " + nowPlusOneDay);
		for (Occurrence oc : of.getOccurrences()) {
			Event e = oc.getEvent();
			gc.setTimeInMillis(oc.getBegin());
			Date begin = gc.getTime();
			gc.setTimeInMillis(oc.getEnd());
			Date end = gc.getTime();
			System.out.println("Event " + e.getTitle() + " occurs at " + begin
					+ " (ends at " + end + ")");
		}