Foros de discusión

Create a calendar event (calendar booking) on LR 6.2

Ignacio Santos Alonso, modificado hace 9 años.

Create a calendar event (calendar booking) on LR 6.2

Junior Member Mensajes: 50 Fecha de incorporación: 12/02/13 Mensajes recientes
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, modificado hace 9 años.

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

Junior Member Mensajes: 50 Fecha de incorporación: 12/02/13 Mensajes recientes
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, modificado hace 9 años.

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

Expert Mensajes: 329 Fecha de incorporación: 10/02/11 Mensajes recientes
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, modificado hace 9 años.

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

Junior Member Mensajes: 50 Fecha de incorporación: 12/02/13 Mensajes recientes
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, modificado hace 9 años.

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

Junior Member Mensajes: 51 Fecha de incorporación: 28/08/13 Mensajes recientes
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, modificado hace 9 años.

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

Regular Member Mensajes: 166 Fecha de incorporación: 23/07/12 Mensajes recientes
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, modificado hace 8 años.

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

Regular Member Mensajes: 228 Fecha de incorporación: 6/01/14 Mensajes recientes
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, modificado hace 8 años.

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

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
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, modificado hace 8 años.

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

Regular Member Mensajes: 228 Fecha de incorporación: 6/01/14 Mensajes recientes
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, modificado hace 8 años.

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

Regular Member Mensajes: 166 Fecha de incorporación: 23/07/12 Mensajes recientes
Hi Juan,
Hereby attached a sample portlet.

HTH
Arun
juan meza, modificado hace 8 años.

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

Regular Member Mensajes: 228 Fecha de incorporación: 6/01/14 Mensajes recientes
great! thank you!

it works now emoticon!
thumbnail
David H Nebinger, modificado hace 8 años.

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

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
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, modificado hace 7 años.

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

New Member Mensajes: 3 Fecha de incorporación: 28/04/16 Mensajes recientes
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