0

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.

Thomas Ehardt
  • 155
  • 4
  • 11

1 Answers1

1

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

juanmeza
  • 163
  • 1
  • 12
  • I actually ended up going in a different direction. The people responsible for the calendar are non-technical people, and we are an Exchange shop, so they are already familiar with that. I ended up using Microsoft's excellent (yes, really) Exchange library for java [link](https://github.com/OfficeDev/ews-java-api) and wrote a Liferay web service to consume it. It's ended up being a solution that the end users prefer because it requires no additional learning for new team members. – Thomas Ehardt Aug 26 '15 at 14:57