Thomas Ehardt
Thomas Ehardt

Reputation: 155

In Liferay 6.2, how do I get a list of calendars from the calendar portlet?

I'm working on a custom plugin that uses the JSON web service for the calendar portlet to just display events (via, e.g., http://localhost:8080/api/jsonws/calendar-portlet.calendar/get-calendar/calendar-id/11504).

It seems like it should be simple to get a list of calendars that a user has access to, but I cannot figure this out. The plugin uses a combination of Java and JavaScript, so I could get the info either via Java or REST/JSON.

Right now, I'm going into the calendar and getting the ID from the RSS feed URL; I'm sure that this is not the best way to get this info.

Upvotes: 0

Views: 1481

Answers (1)

juanmeza
juanmeza

Reputation: 163

You can get all calendars in a organization like this:

String servletContextName = "calendar-portlet";
    ClassLoader classLoader = (ClassLoader)com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(servletContextName, "portletClassLoader");

    com.liferay.portal.kernel.dao.orm.DynamicQuery dynamicQuery = com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil.forClass(com.liferay.calendar.model.Calendar.class, classLoader);
    dynamicQuery.add(com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil.forName("groupId").eq(groupId));
    java.util.List<com.liferay.calendar.model.Calendar> calendars = com.liferay.calendar.service.CalendarLocalServiceUtil.dynamicQuery(dynamicQuery);
    if(calendars.isEmpty()) {
        throw new Exception("No calendar found for group "+groupId);
    } else {
        for(com.liferay.calendar.model.Calendar c: calendars) {
            System.out.println("Found calendar "+c);
        }
    }

maybe it can help to get you started.. if you want to get them by user, maybe changing the dynamic query to look for userId instead of groupId

Upvotes: 1

Related Questions