001
014
015 package com.liferay.portlet.calendar.service.impl;
016
017 import com.liferay.portal.kernel.cal.TZSRecurrence;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.kernel.util.ListUtil;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.security.permission.ActionKeys;
023 import com.liferay.portal.service.ServiceContext;
024 import com.liferay.portlet.calendar.model.CalEvent;
025 import com.liferay.portlet.calendar.service.base.CalEventServiceBaseImpl;
026 import com.liferay.portlet.calendar.service.permission.CalEventPermission;
027 import com.liferay.portlet.calendar.service.permission.CalendarPermission;
028
029 import java.io.File;
030 import java.io.InputStream;
031
032 import java.util.Calendar;
033 import java.util.Iterator;
034 import java.util.List;
035
036
040 public class CalEventServiceImpl extends CalEventServiceBaseImpl {
041
042 @Override
043 public CalEvent addEvent(
044 String title, String description, String location,
045 int startDateMonth, int startDateDay, int startDateYear,
046 int startDateHour, int startDateMinute, int durationHour,
047 int durationMinute, boolean allDay, boolean timeZoneSensitive,
048 String type, boolean repeating, TZSRecurrence recurrence,
049 int remindBy, int firstReminder, int secondReminder,
050 ServiceContext serviceContext)
051 throws PortalException, SystemException {
052
053 CalendarPermission.check(
054 getPermissionChecker(), serviceContext.getScopeGroupId(),
055 ActionKeys.ADD_EVENT);
056
057 return calEventLocalService.addEvent(
058 getUserId(), title, description, location, startDateMonth,
059 startDateDay, startDateYear, startDateHour, startDateMinute,
060 durationHour, durationMinute, allDay, timeZoneSensitive, type,
061 repeating, recurrence, remindBy, firstReminder, secondReminder,
062 serviceContext);
063 }
064
065
070 @Override
071 public CalEvent addEvent(
072 String title, String description, String location,
073 int startDateMonth, int startDateDay, int startDateYear,
074 int startDateHour, int startDateMinute, int endDateMonth,
075 int endDateDay, int endDateYear, int durationHour,
076 int durationMinute, boolean allDay, boolean timeZoneSensitive,
077 String type, boolean repeating, TZSRecurrence recurrence,
078 int remindBy, int firstReminder, int secondReminder,
079 ServiceContext serviceContext)
080 throws PortalException, SystemException {
081
082 CalendarPermission.check(
083 getPermissionChecker(), serviceContext.getScopeGroupId(),
084 ActionKeys.ADD_EVENT);
085
086 return calEventLocalService.addEvent(
087 getUserId(), title, description, location, startDateMonth,
088 startDateDay, startDateYear, startDateHour, startDateMinute,
089 endDateMonth, endDateDay, endDateYear, durationHour, durationMinute,
090 allDay, timeZoneSensitive, type, repeating, recurrence, remindBy,
091 firstReminder, secondReminder, serviceContext);
092 }
093
094 @Override
095 public void deleteEvent(long eventId)
096 throws PortalException, SystemException {
097
098 CalEventPermission.check(
099 getPermissionChecker(), eventId, ActionKeys.DELETE);
100
101 calEventLocalService.deleteEvent(eventId);
102 }
103
104 @Override
105 public File exportEvent(long eventId)
106 throws PortalException, SystemException {
107
108 CalEventPermission.check(
109 getPermissionChecker(), eventId, ActionKeys.VIEW);
110
111 return calEventLocalService.exportEvent(getGuestOrUserId(), eventId);
112 }
113
114 @Override
115 public File exportGroupEvents(long groupId, String fileName)
116 throws PortalException, SystemException {
117
118 CalendarPermission.check(
119 getPermissionChecker(), groupId, ActionKeys.EXPORT_ALL_EVENTS);
120
121 return calEventLocalService.exportGroupEvents(
122 getGuestOrUserId(), groupId, fileName);
123 }
124
125 @Override
126 public CalEvent getEvent(long eventId)
127 throws PortalException, SystemException {
128
129 CalEventPermission.check(
130 getPermissionChecker(), eventId, ActionKeys.VIEW);
131
132 return calEventLocalService.getEvent(eventId);
133 }
134
135 @Override
136 public List<CalEvent> getEvents(long groupId, Calendar cal, String type)
137 throws PortalException, SystemException {
138
139 return getEvents(groupId, cal, new String[] {type});
140 }
141
142 @Override
143 public List<CalEvent> getEvents(long groupId, Calendar cal, String[] types)
144 throws PortalException, SystemException {
145
146 List<CalEvent> events = calEventLocalService.getEvents(
147 groupId, cal, types);
148
149 events = ListUtil.copy(events);
150
151 Iterator<CalEvent> itr = events.iterator();
152
153 while (itr.hasNext()) {
154 CalEvent event = itr.next();
155
156 if (!CalEventPermission.contains(
157 getPermissionChecker(), event, ActionKeys.VIEW)) {
158
159 itr.remove();
160 }
161 }
162
163 return events;
164 }
165
166 @Override
167 public List<CalEvent> getEvents(
168 long groupId, String type, int start, int end)
169 throws SystemException {
170
171 return getEvents(groupId, new String[] {type}, start, end);
172 }
173
174 @Override
175 public List<CalEvent> getEvents(
176 long groupId, String[] types, int start, int end)
177 throws SystemException {
178
179 if ((types != null) && (types.length > 0) &&
180 ((types.length > 1) || Validator.isNotNull(types[0]))) {
181
182 return calEventPersistence.filterFindByG_T(
183 groupId, types, start, end);
184 }
185 else {
186 return calEventPersistence.filterFindByGroupId(groupId, start, end);
187 }
188 }
189
190 @Override
191 public int getEventsCount(long groupId, String type)
192 throws SystemException {
193
194 return getEventsCount(groupId, new String[] {type});
195 }
196
197 @Override
198 public int getEventsCount(long groupId, String[] types)
199 throws SystemException {
200
201 if ((types != null) && (types.length > 0) &&
202 ((types.length > 1) || Validator.isNotNull(types[0]))) {
203
204 return calEventPersistence.filterCountByG_T(groupId, types);
205 }
206 else {
207 return calEventPersistence.filterCountByGroupId(groupId);
208 }
209 }
210
211 @Override
212 public boolean hasEvents(long groupId, Calendar cal)
213 throws PortalException, SystemException {
214
215 return hasEvents(groupId, cal, new String[0]);
216 }
217
218 @Override
219 public boolean hasEvents(long groupId, Calendar cal, String type)
220 throws PortalException, SystemException {
221
222 return hasEvents(groupId, cal, new String[] {type});
223 }
224
225 @Override
226 public boolean hasEvents(long groupId, Calendar cal, String[] types)
227 throws PortalException, SystemException {
228
229 List<CalEvent> events = getEvents(groupId, cal, types);
230
231 if (events.isEmpty()) {
232 return false;
233 }
234 else {
235 return true;
236 }
237 }
238
239 @Override
240 public void importICal4j(long groupId, InputStream inputStream)
241 throws PortalException, SystemException {
242
243 CalendarPermission.check(
244 getPermissionChecker(), groupId, ActionKeys.ADD_EVENT);
245
246 calEventLocalService.importICal4j(getUserId(), groupId, inputStream);
247 }
248
249 @Override
250 public CalEvent updateEvent(
251 long eventId, String title, String description, String location,
252 int startDateMonth, int startDateDay, int startDateYear,
253 int startDateHour, int startDateMinute, int durationHour,
254 int durationMinute, boolean allDay, boolean timeZoneSensitive,
255 String type, boolean repeating, TZSRecurrence recurrence,
256 int remindBy, int firstReminder, int secondReminder,
257 ServiceContext serviceContext)
258 throws PortalException, SystemException {
259
260 CalEventPermission.check(
261 getPermissionChecker(), eventId, ActionKeys.UPDATE);
262
263 return calEventLocalService.updateEvent(
264 getUserId(), eventId, title, description, location, startDateMonth,
265 startDateDay, startDateYear, startDateHour, startDateMinute,
266 durationHour, durationMinute, allDay, timeZoneSensitive, type,
267 repeating, recurrence, remindBy, firstReminder, secondReminder,
268 serviceContext);
269 }
270
271
276 @Override
277 public CalEvent updateEvent(
278 long eventId, String title, String description, String location,
279 int startDateMonth, int startDateDay, int startDateYear,
280 int startDateHour, int startDateMinute, int endDateMonth,
281 int endDateDay, int endDateYear, int durationHour,
282 int durationMinute, boolean allDay, boolean timeZoneSensitive,
283 String type, boolean repeating, TZSRecurrence recurrence,
284 int remindBy, int firstReminder, int secondReminder,
285 ServiceContext serviceContext)
286 throws PortalException, SystemException {
287
288 CalEventPermission.check(
289 getPermissionChecker(), eventId, ActionKeys.UPDATE);
290
291 return calEventLocalService.updateEvent(
292 getUserId(), eventId, title, description, location, startDateMonth,
293 startDateDay, startDateYear, startDateHour, startDateMinute,
294 endDateMonth, endDateDay, endDateYear, durationHour, durationMinute,
295 allDay, timeZoneSensitive, type, repeating, recurrence, remindBy,
296 firstReminder, secondReminder, serviceContext);
297 }
298
299 }