Export & auto sync Liferay Calendar events with Outlook & Google Calendar


        Introduction
           If we need to export Liferay calendar events with Outlook & Google calendar then we need to configure .ics file and if requirement is export and auto sync up then we need .ics file to be downloaded from source portal. For example: webcal://abc.com/abcCalendar.ics or http://www.abc.com/abcCalendar.ics etc,  then we can configure the outlook Internet Calendar configuration and Google Calendar configuration or any other calendar applications portals using downloaded URL.


  What is an .ICS file?
                Files that contain the .ics file extension are created by a variety of calendar and scheduling applications. These calendar files allow different users to store calendar information within a text file. That text file can be then stored on the Internet and synchronized with same user as well as other users' calendars. A user can stay updated regarding another user's calendar by "subscribing" to that calendar. This tool often helps administrative assistants to manage their executive schedules and keep project teams stay connected.

  How to create downloadable URL with Liferay Calendar?
    There are many ways to achieve this but we will follow below one.

Create Servlet class into Calendar Portlet.

Steps -
1.  web.xml copy below code <servlet> tag into <web-app> tag.  
     
             <servlet>
                  <servlet-name>outlookCalendar</servlet-name>
                  <servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
                <init-param>
                                <param-name>
                                                servlet-class
                                </param-name>
                                <param-value>
                                                com.sachin.jagtap.outlook.configure.servlet.OutlookExchangeCalendar
                                </param-value>
                  </init-param>
                 <init-param>
                     <param-name>sub-context</param-name>
                    <param-value>corporateCalendar</param-value>
                </init-param>
                <load-on-startup>1</load-on-startup>
             </servlet>

2.  Configure calendar Id into portal-ext.properties or portlet.properties file of calendar-portlet 
    
                ##Configure default or sync calendar Id
                default.twelvecapital.calendarId=20151

3.  Create OutlookExchangeCalendar.java class into mentioned path of web.xml  

public class OutlookExchangeCalendar extends HttpServlet {
                protected void doGet(HttpServletRequest req, HttpServletResponse response)
                                                throws ServletException, IOException {
                                try {
                                                long calendarId = GetterUtil.getLong(PortletProps
                                                                                .get("export.calendarId"));
                                                // long calendarId = 11932;
                                                Calendar calendar = CalendarLocalServiceUtil
                                                                                .getCalendar(calendarId);
                                                String fileName = calendar.getName(LocaleUtil.US) + CharPool.PERIOD
                                                                                + String.valueOf(CalendarDataFormat.ICAL);

                                                CalendarDataHandler calendarDataHandler = CalendarDataHandlerFactory
                                                                                .getCalendarDataHandler(CalendarDataFormat.ICAL);

                                                String data = calendarDataHandler.exportCalendar(calendarId);

                                                PrintWriter out = response.getWriter();
                                                response.setContentType("APPLICATION/OCTET-STREAM");
                                                response.setHeader("Content-Disposition", "attachment; filename=\""
                                                                                + fileName + "\"");

                                                InputStream is = new ByteArrayInputStream(data.getBytes());

                                                int i;
                                                while ((i = is.read()) != -1) {
                                                                out.write(i);
                                                }
                                                is.close();
                                                out.close();

                                } catch (PortalException e) {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                } catch (SystemException e) {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                } catch (Exception e) {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                }

                }


NOTE:
Check the http://hostname/delegate/corporateCalendar.  Now we are very close our target then follow the below configuration produce with Outlook, Google or any other Calendar application. We have succeeded in export and sync up with source and destination calendar application.

A) Liferay Calendar events export and Sync up with Outlook Calendar:

Steps-
1.      GoTo Outlook -->> Tools  -->> Account Settings... 




         2.      GoTo Account Settings... -->>  Internet Calendars 





3.      Click on New... option and Configure with generated  URL




   4.       New Internet Calendar subscription





5. After successful configuration it opens Subscription Options popup window.
·         Folder Name:   Calendar
·         Description: auto sync calendar(optional)
·         Checked Attachment download (optional).





Now you check with your Outlook Calendar it is configured.

B) Liferay Calendar events export and Sync with  Google Calendar:
            For Google Calendar simply download plug-in from Market place and configure it your portal.


Comments

Popular posts from this blog

Configure SOLR with Liferay

Liferay I18N support for Swahili Language