Fórumok

Programmatically create calendar event on LR 6.2 - which calendarId?

Hiran Chaudhuri, módosítva 9 év-val korábban

Programmatically create calendar event on LR 6.2 - which calendarId?

Regular Member Bejegyzések: 188 Csatlakozás dátuma: 2010.09.01. Legújabb bejegyzések
Hi there.

Through a java portlet I managed to create a calendar booking using the
com.liferay.calendar.service.CalendarBookingLocalServiceUtil.addCalendarBooking(...)
method.

For the calendarId and childCalendarIds I snooped for the value 11815 which works on my test system. But very likely I cannot rely on this id to stay the same. So where would I get the calendarId for a user or an organisation?

Furthermore, I'd like the event to show up for the creator, his own organisation but also for at least one more organisation. How would I accomplish this?
Hiran Chaudhuri, módosítva 9 év-val korábban

RE: Programmatically create calendar event on LR 6.2 - which calendarId? (Válasz)

Regular Member Bejegyzések: 188 Csatlakozás dátuma: 2010.09.01. Legújabb bejegyzések
Meanwhile I found a way to get the calendarId for a user or an organisation, and I'll just post it here so others can find it, or maybe even myself in a distant future...


	private com.liferay.calendar.model.Calendar getCalendar(String customer) throws Exception {
		String servletContextName = "calendar-portlet";
		ClassLoader classLoader = (ClassLoader)com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(servletContextName, "portletClassLoader");

		// find Organisation for the Customer
		// com/liferay/portal/service/OrganizationLocalServiceUtil
		com.liferay.portal.kernel.dao.orm.DynamicQuery dynamicQuery = com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil.forClass(Organization.class, classLoader);
		dynamicQuery.add(com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil.forName("name").eq(customer));
		java.util.List<organization> organizations = com.liferay.portal.service.OrganizationLocalServiceUtil.dynamicQuery(dynamicQuery);
		if(organizations.isEmpty()) {
			throw new Exception("No organization found for '"+customer+"'");
		} else {
			for(Organization o: organizations) {
				log.info("Found organization "+o);
			}
		}
		
		// find groupID for the organisation
		Group group = organizations.get(0).getGroup();
		log.info("Found group "+group);
		
		// find calendarID via GroupID
		// com/liferay/calendar/service/CalendarLocalServiceUtil
		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(group.getGroupId()));
		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 "+group);
		} else {
			for(com.liferay.calendar.model.Calendar c: calendars) {
				log.info("Found calendar "+c);
			}
		}
		
		return calendars.get(0);
	}
</com.liferay.calendar.model.calendar></organization>


For the event to show up for the creator plus users of a specific organisation I just ensure that this organisation has a calendar, and the event will be placed in that calendar. The user is part of that organisation, so he and all others can see the event. This should suffice for my need.