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
039 public class CalEventServiceImpl extends CalEventServiceBaseImpl {
040
041 public CalEvent addEvent(
042 String title, String description, String location,
043 int startDateMonth, int startDateDay, int startDateYear,
044 int startDateHour, int startDateMinute, int endDateMonth,
045 int endDateDay, int endDateYear, int durationHour,
046 int durationMinute, boolean allDay, boolean timeZoneSensitive,
047 String type, boolean repeating, TZSRecurrence recurrence,
048 int remindBy, int firstReminder, int secondReminder,
049 ServiceContext serviceContext)
050 throws PortalException, SystemException {
051
052 CalendarPermission.check(
053 getPermissionChecker(), serviceContext.getScopeGroupId(),
054 ActionKeys.ADD_EVENT);
055
056 return calEventLocalService.addEvent(
057 getUserId(), title, description, location, startDateMonth,
058 startDateDay, startDateYear, startDateHour, startDateMinute,
059 endDateMonth, endDateDay, endDateYear, durationHour, durationMinute,
060 allDay, timeZoneSensitive, type, repeating, recurrence, remindBy,
061 firstReminder, secondReminder, serviceContext);
062 }
063
064 public void deleteEvent(long eventId)
065 throws PortalException, SystemException {
066
067 CalEventPermission.check(
068 getPermissionChecker(), eventId, ActionKeys.DELETE);
069
070 calEventLocalService.deleteEvent(eventId);
071 }
072
073 public File exportEvent(long eventId)
074 throws PortalException, SystemException {
075
076 CalEventPermission.check(
077 getPermissionChecker(), eventId, ActionKeys.VIEW);
078
079 return calEventLocalService.exportEvent(getGuestOrUserId(), eventId);
080 }
081
082 public File exportGroupEvents(long groupId, String fileName)
083 throws PortalException, SystemException {
084
085 CalendarPermission.check(
086 getPermissionChecker(), groupId, ActionKeys.EXPORT_ALL_EVENTS);
087
088 return calEventLocalService.exportGroupEvents(
089 getGuestOrUserId(), groupId, fileName);
090 }
091
092 public CalEvent getEvent(long eventId)
093 throws PortalException, SystemException {
094
095 CalEventPermission.check(
096 getPermissionChecker(), eventId, ActionKeys.VIEW);
097
098 return calEventLocalService.getEvent(eventId);
099 }
100
101 public List<CalEvent> getEvents(long groupId, Calendar cal, String type)
102 throws PortalException, SystemException {
103
104 return getEvents(groupId, cal, new String[] {type});
105 }
106
107 public List<CalEvent> getEvents(long groupId, Calendar cal, String[] types)
108 throws PortalException, SystemException {
109
110 List<CalEvent> events = calEventLocalService.getEvents(
111 groupId, cal, types);
112
113 events = ListUtil.copy(events);
114
115 Iterator<CalEvent> itr = events.iterator();
116
117 while (itr.hasNext()) {
118 CalEvent event = itr.next();
119
120 if (!CalEventPermission.contains(
121 getPermissionChecker(), event, ActionKeys.VIEW)) {
122
123 itr.remove();
124 }
125 }
126
127 return events;
128 }
129
130 public List<CalEvent> getEvents(
131 long groupId, String type, int start, int end)
132 throws SystemException {
133
134 return getEvents(groupId, new String[] {type}, start, end);
135 }
136
137 public List<CalEvent> getEvents(
138 long groupId, String[] types, int start, int end)
139 throws SystemException {
140
141 if ((types != null) && (types.length > 0) &&
142 ((types.length > 1) || Validator.isNotNull(types[0]))) {
143
144 return calEventPersistence.filterFindByG_T(
145 groupId, types, start, end);
146 }
147 else {
148 return calEventPersistence.filterFindByGroupId(groupId, start, end);
149 }
150 }
151
152 public int getEventsCount(long groupId, String type)
153 throws SystemException {
154
155 return getEventsCount(groupId, new String[] {type});
156 }
157
158 public int getEventsCount(long groupId, String[] types)
159 throws SystemException {
160
161 if ((types != null) && (types.length > 0) &&
162 ((types.length > 1) || Validator.isNotNull(types[0]))) {
163
164 return calEventPersistence.filterCountByG_T(groupId, types);
165 }
166 else {
167 return calEventPersistence.filterCountByGroupId(groupId);
168 }
169 }
170
171 public boolean hasEvents(long groupId, Calendar cal)
172 throws PortalException, SystemException {
173
174 return hasEvents(groupId, cal, new String[0]);
175 }
176
177 public boolean hasEvents(long groupId, Calendar cal, String type)
178 throws PortalException, SystemException {
179
180 return hasEvents(groupId, cal, new String[] {type});
181 }
182
183 public boolean hasEvents(long groupId, Calendar cal, String[] types)
184 throws PortalException, SystemException {
185
186 List<CalEvent> events = getEvents(groupId, cal, types);
187
188 if (events.isEmpty()) {
189 return false;
190 }
191 else {
192 return true;
193 }
194 }
195
196 public void importICal4j(long groupId, InputStream inputStream)
197 throws PortalException, SystemException {
198
199 CalendarPermission.check(
200 getPermissionChecker(), groupId, ActionKeys.ADD_EVENT);
201
202 calEventLocalService.importICal4j(getUserId(), groupId, inputStream);
203 }
204
205 public CalEvent updateEvent(
206 long eventId, String title, String description, String location,
207 int startDateMonth, int startDateDay, int startDateYear,
208 int startDateHour, int startDateMinute, int endDateMonth,
209 int endDateDay, int endDateYear, int durationHour,
210 int durationMinute, boolean allDay, boolean timeZoneSensitive,
211 String type, boolean repeating, TZSRecurrence recurrence,
212 int remindBy, int firstReminder, int secondReminder,
213 ServiceContext serviceContext)
214 throws PortalException, SystemException {
215
216 CalEventPermission.check(
217 getPermissionChecker(), eventId, ActionKeys.UPDATE);
218
219 return calEventLocalService.updateEvent(
220 getUserId(), eventId, title, description, location, startDateMonth,
221 startDateDay, startDateYear, startDateHour, startDateMinute,
222 endDateMonth, endDateDay, endDateYear, durationHour, durationMinute,
223 allDay, timeZoneSensitive, type, repeating, recurrence, remindBy,
224 firstReminder, secondReminder, serviceContext);
225 }
226
227 }