Forums de discussion

Create a calendar event (calendar booking) on LR 6.2

Ignacio Santos Alonso, modifié il y a 9 années.

Create a calendar event (calendar booking) on LR 6.2

Junior Member Publications: 50 Date d'inscription: 12/02/13 Publications récentes
I'm trying to create a simple calendar event for the calendar portlet. I achieved this easily on previous versions of the portal (5.2 and 6.0) using the method
CalEventLocalServiceUtil.addEvent(...)


I just found out that in version 6.2 the DB model for calendar events is way more complex, involving several entities: CalEvent, CalendarBooking,CalendarResource and Calendar. I found out that there's a jar with services to deal with these new entities (calendar-portlet-service.jar) and I think that I should be able to create the event using:
CalendarBookingLocalServiceUtil.addCalendarBooking(...)


-What parameters does it take? Any examples? I don't know how to set calendarId and others.
-Does that mean that I also have to create a Calendar object? Should I use CalendarLocalServiceUtil.addCalendar(...)? Some of the parameters that I need to call that method are also unclear.
-Is it necessary to create a CalendarResource (CalendarResourceLocalServiceUtil.addCalendarResource(...))? It seems that an instance of CalendarResource it's needed by the previous method. Anyways, there is no clear way to call this and I can't find any good examples in Liferay's source code.
-In addition to all the previous methods, is it still necessary to add a CalEvent as I did on previous versions of the portal?

Any sample code for all of this? As I said I have a lot of doubts about the parameters needed in each and every one of those methods.

PS. At the moment of writing this message I'm having a look at
https://github.com/liferay/liferay-plugins/blob/6.2.x/portlets/calendar-portlet/docroot/WEB-INF/src/com/liferay/calendar/portlet/CalendarPortlet.java
but still don't have a clear idea of what's necessary and what's not and how to get some of the parameters. I'll post any new findings, but still would be glad to get some help from someone that has already worked with Calendar Events and Bookings.
Ignacio Santos Alonso, modifié il y a 9 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Junior Member Publications: 50 Date d'inscription: 12/02/13 Publications récentes
I'm actually:
1. Adding a CalendarResource.
2. Adding a Calendar (which is instantiated twice in the database!).
3. Adding a CalendarEvent for each of my events.
4. Adding a CalendarBooking for each of my events.
(in that order)

and all I get are the events marked in the month calendar as dots but I can't see the detail in the day (I mean, the actual title and description of the event and the start and end times)

Why did this become so complicated?? Please help!!
thumbnail
Prakash Khanchandani, modifié il y a 9 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Expert Publications: 329 Date d'inscription: 10/02/11 Publications récentes
If I understand correctly you need to add a event for a particular date and time.

So you just need to look at the updateCalendarBooking() method for CalendarPortlet.java.

You will have all that you need for your event to appear from this method and also how the parameters are passed to the method to add/update a CalendarBooking.

So now some little enlightenment:
  • CalEvent is a DB table but it is not used in the new portlet. So forget about this.
  • CalendarBooking is the actual table which stores the individual Events. So need to care only about this
  • Calendar entity is easy to understand if you have used Google Calendars, its a lot similar to those. You don't have to create it everytime, just fetch the already created Site or User specific calendars and you are good to create an event (CalendarBooking) for the Calendar. This is for added flexibility.
  • CalendarResource, again you don't have to add this everytime just fetch the already added ones. For each User using the Calendar and for every group on which it is added a default CalendarResource is created (i presume).


So there you are. Certainly a little more code but not that complex emoticon ... though I agree where you need more flexibility, maintainability and functionality there might be more complexity emoticon

Hope this helps

-
Prakash K
(Fulcrum Worldwide)
Ignacio Santos Alonso, modifié il y a 9 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Junior Member Publications: 50 Date d'inscription: 12/02/13 Publications récentes
Thank you so much for your time Prakash, I haven't been around in the forums for the last couple of months... I solved this issue by myself but I am very grateful for your kind help. Cheers mate!
Diogo Salazar, modifié il y a 9 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Junior Member Publications: 51 Date d'inscription: 28/08/13 Publications récentes
Ignacio Santos Alonso:
Thank you so much for your time Prakash, I haven't been around in the forums for the last couple of months... I solved this issue by myself but I am very grateful for your kind help. Cheers mate!


Hi there Ignacio, good afternoon.

If you managed to come up with a solution that is indeed different from the above suggestion, could you please post it to the forum?

Thanks!
thumbnail
Arun D, modifié il y a 9 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Regular Member Publications: 166 Date d'inscription: 23/07/12 Publications récentes
Hello,
Try the following piece of code
// Start
try {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long scopeGroupId = themeDisplay.getScopeGroupId();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(scopeGroupId);

//Create a Calendar Event
CalEvent calEvent = CalEventLocalServiceUtil.addEvent(
PrincipalThreadLocal.getUserId(), //userId
"new meeting", //title
"new meeting description", //description
"office", //location
2, //int startDateMonth || 0 > Jan || 1 > Feb || 2 > Mar || 3 > Apr||.....|| 11 > Dec||
23, //int startDateDay,
2015, //int startDateYear,
15, //int startDateHour,
0, //int startDateMinute,
1, //int durationHour,
0, //int durationMinute,
false, //boolean allDay,
true, //boolean timeZoneSensitive,
"Meeting", //String type,
false, //boolean repeating,
null, //TZSRecurrence recurrence,
0, //int remindBy,
0, //int firstReminder,
0, // int secondReminder,
serviceContext);

//Import the event to Calendar Booking - Requires calendar-portlet-service.jar(tomcat-7.0.42\webapps\calendar-portlet\WEB-INF\lib)
CalendarImporterLocalServiceUtil.importCalEvent(calEvent);

} catch (com.liferay.portal.kernel.exception.PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (com.liferay.portal.kernel.exception.SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// End

HTH
Arun
juan meza, modifié il y a 8 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Regular Member Publications: 228 Date d'inscription: 06/01/14 Publications récentes
hi Arun!

im having trouble with the last part of your code:
//Import the event to Calendar Booking - Requires calendar-portlet-service.jar(tomcat-7.0.42\webapps\calendar-portlet\WEB-INF\lib)
CalendarImporterLocalServiceUtil.importCalEvent(calEvent);


the jar is in Calendar Portlet, that means i cant import it in my own portlet... so how do i achieve this?

move the jar to the liferay libs so the portlet can see it?
add the jar to the portlet?

is there a more elegant way?

thank you
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
In order to consume the calendar service you need to copy the service jar into your plugin's WEB-INF/lib directory.

You should also declare the calendar as a required deployment context in liferay-plugin-package.properties.

Moving to Liferay libs is unnecessary as Liferay won't ever use it. If you're talking about making it a global jar, that too is a bad idea.

Just copy the jar and include it in the war and be done with it.
juan meza, modifié il y a 8 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Regular Member Publications: 228 Date d'inscription: 06/01/14 Publications récentes
hi David!

amateur question! :$

I add the jar to WEB-INF/lib folder, but i dont see it when i try to add it in the portlet dependency jars...
what can i do so i can see it there too? to add it as a required library?
thumbnail
Arun Das, modifié il y a 8 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Regular Member Publications: 166 Date d'inscription: 23/07/12 Publications récentes
Hi Juan,
Hereby attached a sample portlet.

HTH
Arun
juan meza, modifié il y a 8 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Regular Member Publications: 228 Date d'inscription: 06/01/14 Publications récentes
great! thank you!

it works now emoticon!
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: Create a calendar event (calendar booking) on LR 6.2

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
Portal dependency jars is used to identify jars from the Liferay ROOT/WEB-INF/lib dir that your plugin is dependent upon. You won't see jars that you don't get from there, i.e. any service jars not part of root, custom implementation jars, third party jars, updated jars of the portal jars you'd rather use instead...
Smira davar, modifié il y a 7 années.

RE: Create a calendar event (calendar booking) on LR 6.2

New Member Publications: 3 Date d'inscription: 28/04/16 Publications récentes
Hello,
I used your solution and it's fine. But is there some possibility to get the CalEvent and CalendarBookings in sync? What I'm especially searching for is how to retrieve the CalendarBooking object after creating it with the CalendarImporterLocalServiceUtil.importCalEvent(calEvent). I did not find any data/id that I could used for retrieving the CalendarBooking object.
Would be nice if anyone got solution or hint emoticon