1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.calendar.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.cal.Recurrence;
28  import com.liferay.portal.kernel.security.permission.ActionKeys;
29  import com.liferay.portal.service.impl.PrincipalBean;
30  import com.liferay.portal.service.permission.PortletPermissionUtil;
31  import com.liferay.portal.util.PortletKeys;
32  import com.liferay.portlet.calendar.model.CalEvent;
33  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
34  import com.liferay.portlet.calendar.service.CalEventService;
35  import com.liferay.portlet.calendar.service.permission.CalEventPermission;
36  
37  import java.io.File;
38  
39  /**
40   * <a href="CalEventServiceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class CalEventServiceImpl
46      extends PrincipalBean implements CalEventService {
47  
48      public CalEvent addEvent(
49              long plid, String title, String description, int startDateMonth,
50              int startDateDay, int startDateYear, int startDateHour,
51              int startDateMinute, int endDateMonth, int endDateDay,
52              int endDateYear, int durationHour, int durationMinute,
53              boolean allDay, boolean timeZoneSensitive, String type,
54              boolean repeating, Recurrence recurrence, String remindBy,
55              int firstReminder, int secondReminder,
56              boolean addCommunityPermissions, boolean addGuestPermissions)
57          throws PortalException, SystemException {
58  
59          PortletPermissionUtil.check(
60              getPermissionChecker(), plid, PortletKeys.CALENDAR,
61              ActionKeys.ADD_EVENT);
62  
63          return CalEventLocalServiceUtil.addEvent(
64              getUserId(), plid, title, description, startDateMonth, startDateDay,
65              startDateYear, startDateHour, startDateMinute, endDateMonth,
66              endDateDay, endDateYear, durationHour, durationMinute, allDay,
67              timeZoneSensitive, type, repeating, recurrence, remindBy,
68              firstReminder, secondReminder, addCommunityPermissions,
69              addGuestPermissions);
70      }
71  
72      public CalEvent addEvent(
73              long plid, String title, String description, int startDateMonth,
74              int startDateDay, int startDateYear, int startDateHour,
75              int startDateMinute, int endDateMonth, int endDateDay,
76              int endDateYear, int durationHour, int durationMinute,
77              boolean allDay, boolean timeZoneSensitive, String type,
78              boolean repeating, Recurrence recurrence, String remindBy,
79              int firstReminder, int secondReminder,
80              String[] communityPermissions, String[] guestPermissions)
81          throws PortalException, SystemException {
82  
83          PortletPermissionUtil.check(
84              getPermissionChecker(), plid, PortletKeys.CALENDAR,
85              ActionKeys.ADD_EVENT);
86  
87          return CalEventLocalServiceUtil.addEvent(
88              getUserId(), plid, title, description, startDateMonth, startDateDay,
89              startDateYear, startDateHour, startDateMinute, endDateMonth,
90              endDateDay, endDateYear, durationHour, durationMinute, allDay,
91              timeZoneSensitive, type, repeating, recurrence, remindBy,
92              firstReminder, secondReminder, communityPermissions,
93              guestPermissions);
94      }
95  
96      public void deleteEvent(long eventId)
97          throws PortalException, SystemException {
98  
99          CalEventPermission.check(
100             getPermissionChecker(), eventId, ActionKeys.DELETE);
101 
102         CalEventLocalServiceUtil.deleteEvent(eventId);
103     }
104 
105     public File exportEvent(long eventId)
106         throws PortalException, SystemException {
107 
108         CalEventPermission.check(
109             getPermissionChecker(), eventId, ActionKeys.VIEW);
110 
111         return CalEventLocalServiceUtil.exportEvent(getUserId(), eventId);
112     }
113 
114     public File exportGroupEvents(long plid, String fileName)
115         throws PortalException, SystemException {
116 
117         PortletPermissionUtil.check(
118             getPermissionChecker(), plid, PortletKeys.CALENDAR,
119             ActionKeys.EXPORT_ALL_EVENTS);
120 
121         return CalEventLocalServiceUtil.exportGroupEvents(
122             getUserId(), plid, fileName);
123     }
124 
125     public CalEvent getEvent(long eventId)
126         throws PortalException, SystemException {
127 
128         CalEventPermission.check(
129             getPermissionChecker(), eventId, ActionKeys.VIEW);
130 
131         return CalEventLocalServiceUtil.getEvent(eventId);
132     }
133 
134     public void importICal4j(long plid, File file)
135         throws PortalException, SystemException {
136 
137         PortletPermissionUtil.check(
138             getPermissionChecker(), plid, PortletKeys.CALENDAR,
139             ActionKeys.ADD_EVENT);
140 
141         CalEventLocalServiceUtil.importICal4j(getUserId(), plid, file);
142     }
143 
144     public CalEvent updateEvent(
145             long eventId, String title, String description,
146             int startDateMonth, int startDateDay, int startDateYear,
147             int startDateHour, int startDateMinute, int endDateMonth,
148             int endDateDay, int endDateYear, int durationHour,
149             int durationMinute, boolean allDay, boolean timeZoneSensitive,
150             String type, boolean repeating, Recurrence recurrence,
151             String remindBy, int firstReminder, int secondReminder)
152         throws PortalException, SystemException {
153 
154         CalEventPermission.check(
155             getPermissionChecker(), eventId, ActionKeys.UPDATE);
156 
157         return CalEventLocalServiceUtil.updateEvent(
158             getUserId(), eventId, title, description, startDateMonth,
159             startDateDay, startDateYear, startDateHour, startDateMinute,
160             endDateMonth, endDateDay, endDateYear, durationHour, durationMinute,
161             allDay, timeZoneSensitive, type, repeating, recurrence, remindBy,
162             firstReminder, secondReminder);
163     }
164 
165 }