/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.calendar.service.impl;
import com.liferay.calendar.constants.CalendarActionKeys;
import com.liferay.calendar.model.Calendar;
import com.liferay.calendar.model.CalendarBooking;
import com.liferay.calendar.model.CalendarBookingConstants;
import com.liferay.calendar.service.base.CalendarBookingServiceBaseImpl;
import com.liferay.calendar.service.permission.CalendarPermission;
import com.liferay.calendar.util.CalendarUtil;
import com.liferay.calendar.util.JCalendarUtil;
import com.liferay.calendar.util.RSSUtil;
import com.liferay.calendar.workflow.CalendarBookingWorkflowConstants;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.security.access.control.AccessControlled;
import com.liferay.portal.kernel.security.auth.PrincipalException;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.TimeZoneUtil;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.feed.synd.SyndLink;
import com.sun.syndication.feed.synd.SyndLinkImpl;
import com.sun.syndication.io.FeedException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
/**
* @author Eduardo Lundgren
* @author Fabio Pezzutto
* @author Bruno Basto
* @author Pier Paolo Ramon
*/
public class CalendarBookingServiceImpl extends CalendarBookingServiceBaseImpl {
@Override
public CalendarBooking addCalendarBooking(
long calendarId, long[] childCalendarIds,
long parentCalendarBookingId, long recurringCalendarBookingId,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, int startTimeYear, int startTimeMonth,
int startTimeDay, int startTimeHour, int startTimeMinute,
int endTimeYear, int endTimeMonth, int endTimeDay, int endTimeHour,
int endTimeMinute, String timeZoneId, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
TimeZone timeZone = TimeZoneUtil.getTimeZone(timeZoneId);
if (allDay) {
timeZone = TimeZone.getTimeZone(StringPool.UTC);
}
java.util.Calendar startTimeJCalendar = JCalendarUtil.getJCalendar(
startTimeYear, startTimeMonth, startTimeDay, startTimeHour,
startTimeMinute, 0, 0, timeZone);
java.util.Calendar endTimeJCalendar = JCalendarUtil.getJCalendar(
endTimeYear, endTimeMonth, endTimeDay, endTimeHour, endTimeMinute,
0, 0, timeZone);
return calendarBookingService.addCalendarBooking(
calendarId, childCalendarIds, parentCalendarBookingId,
recurringCalendarBookingId, titleMap, descriptionMap, location,
startTimeJCalendar.getTimeInMillis(),
endTimeJCalendar.getTimeInMillis(), allDay, recurrence,
firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking addCalendarBooking(
long calendarId, long[] childCalendarIds,
long parentCalendarBookingId, long recurringCalendarBookingId,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, long startTime, long endTime, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
CalendarPermission.check(
getPermissionChecker(), calendarId,
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.addCalendarBooking(
getUserId(), calendarId, childCalendarIds, parentCalendarBookingId,
recurringCalendarBookingId, titleMap, descriptionMap, location,
startTime, endTime, allDay, recurrence, firstReminder,
firstReminderType, secondReminder, secondReminderType,
serviceContext);
}
/**
* @deprecated As of 2.2.0, replaced by {@link #addCalendarBooking(long,
* long[], long, long, Map, Map, String, long, long, boolean,
* String, long, String, long, String, ServiceContext)}
*/
@Deprecated
@Override
public CalendarBooking addCalendarBooking(
long calendarId, long[] childCalendarIds,
long parentCalendarBookingId, Map<Locale, String> titleMap,
Map<Locale, String> descriptionMap, String location,
int startTimeYear, int startTimeMonth, int startTimeDay,
int startTimeHour, int startTimeMinute, int endTimeYear,
int endTimeMonth, int endTimeDay, int endTimeHour,
int endTimeMinute, String timeZoneId, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
return calendarBookingService.addCalendarBooking(
calendarId, childCalendarIds, parentCalendarBookingId,
CalendarBookingConstants.RECURRING_CALENDAR_BOOKING_ID_DEFAULT,
titleMap, descriptionMap, location, startTimeYear, startTimeMonth,
startTimeDay, startTimeHour, startTimeMinute, endTimeYear,
endTimeMonth, endTimeDay, endTimeHour, endTimeMinute, timeZoneId,
allDay, recurrence, firstReminder, firstReminderType,
secondReminder, secondReminderType, serviceContext);
}
/**
* @deprecated As of 2.2.0
*/
@Deprecated
@Override
public CalendarBooking addCalendarBooking(
long calendarId, long[] childCalendarIds,
long parentCalendarBookingId, Map<Locale, String> titleMap,
Map<Locale, String> descriptionMap, String location, long startTime,
long endTime, boolean allDay, String recurrence, long firstReminder,
String firstReminderType, long secondReminder,
String secondReminderType, ServiceContext serviceContext)
throws PortalException {
return calendarBookingService.addCalendarBooking(
calendarId, childCalendarIds, parentCalendarBookingId,
CalendarBookingConstants.RECURRING_CALENDAR_BOOKING_ID_DEFAULT,
titleMap, descriptionMap, location, startTime, endTime, allDay,
recurrence, firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking deleteCalendarBooking(long calendarBookingId)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.deleteCalendarBooking(
calendarBookingId);
}
@Override
public void deleteCalendarBookingInstance(
long calendarBookingId, int instanceIndex, boolean allFollowing)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
calendarBookingLocalService.deleteCalendarBookingInstance(
calendarBooking, instanceIndex, allFollowing);
}
@Override
public void deleteCalendarBookingInstance(
long calendarBookingId, int instanceIndex, boolean allFollowing,
boolean deleteRecurringCalendarBookings)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
calendarBookingLocalService.deleteCalendarBookingInstance(
calendarBooking, instanceIndex, allFollowing,
deleteRecurringCalendarBookings);
}
@Override
public void deleteCalendarBookingInstance(
long calendarBookingId, long startTime, boolean allFollowing)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
calendarBookingLocalService.deleteCalendarBookingInstance(
calendarBookingId, startTime, allFollowing);
}
@Override
public String exportCalendarBooking(long calendarBookingId, String type)
throws Exception {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendar(),
CalendarActionKeys.VIEW_BOOKING_DETAILS);
return calendarBookingLocalService.exportCalendarBooking(
calendarBookingId, type);
}
@Override
public CalendarBooking fetchCalendarBooking(long calendarBookingId)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.fetchByPrimaryKey(calendarBookingId);
if (calendarBooking == null) {
return null;
}
return filterCalendarBooking(calendarBooking);
}
@Override
public CalendarBooking getCalendarBooking(long calendarBookingId)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
return filterCalendarBooking(calendarBooking);
}
@Override
public CalendarBooking getCalendarBooking(
long calendarId, long parentCalendarBookingId)
throws PortalException {
CalendarPermission.check(
getPermissionChecker(), calendarId,
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.getCalendarBooking(
calendarId, parentCalendarBookingId);
}
@Override
public CalendarBooking getCalendarBookingInstance(
long calendarBookingId, int instanceIndex)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingLocalService.getCalendarBookingInstance(
calendarBookingId, instanceIndex);
return filterCalendarBooking(calendarBooking);
}
@Override
public List<CalendarBooking> getCalendarBookings(
long calendarId, int[] statuses)
throws PortalException {
List<CalendarBooking> calendarBookings =
calendarBookingLocalService.getCalendarBookings(
calendarId, statuses);
return filterCalendarBookings(calendarBookings, ActionKeys.VIEW);
}
@Override
public List<CalendarBooking> getCalendarBookings(
long calendarId, long startTime, long endTime)
throws PortalException {
return getCalendarBookings(
calendarId, startTime, endTime, QueryUtil.ALL_POS);
}
@Override
public List<CalendarBooking> getCalendarBookings(
long calendarId, long startTime, long endTime, int max)
throws PortalException {
List<CalendarBooking> calendarBookings =
calendarBookingLocalService.getCalendarBookings(
calendarId, startTime, endTime, max);
for (CalendarBooking calendarBooking : calendarBookings) {
filterCalendarBooking(calendarBooking);
}
return calendarBookings;
}
@Override
public String getCalendarBookingsRSS(
long calendarId, long startTime, long endTime, int max, String type,
double version, String displayStyle, ThemeDisplay themeDisplay)
throws PortalException {
Calendar calendar = calendarService.getCalendar(calendarId);
int[] statuses = {
CalendarBookingWorkflowConstants.STATUS_APPROVED,
CalendarBookingWorkflowConstants.STATUS_MAYBE
};
List<CalendarBooking> calendarBookings = search(
themeDisplay.getCompanyId(), new long[0], new long[] {calendarId},
new long[0], -1, null, startTime, endTime, true, statuses, 0, max,
null);
return exportToRSS(
calendar.getName(themeDisplay.getLocale()),
calendar.getDescription(themeDisplay.getLocale()), type, version,
displayStyle, PortalUtil.getLayoutFullURL(themeDisplay),
calendarBookings, themeDisplay);
}
@Override
public List<CalendarBooking> getChildCalendarBookings(
long parentCalendarBookingId)
throws PortalException {
List<CalendarBooking> calendarBookings =
calendarBookingLocalService.getChildCalendarBookings(
parentCalendarBookingId);
for (CalendarBooking calendarBooking : calendarBookings) {
filterCalendarBooking(calendarBooking);
}
return calendarBookings;
}
@Override
public List<CalendarBooking> getChildCalendarBookings(
long parentCalendarBookingId, int status)
throws PortalException {
List<CalendarBooking> calendarBookings =
calendarBookingLocalService.getChildCalendarBookings(
parentCalendarBookingId, status);
for (CalendarBooking calendarBooking : calendarBookings) {
filterCalendarBooking(calendarBooking);
}
return calendarBookings;
}
@Override
public CalendarBooking getNewStartTimeAndDurationCalendarBooking(
long calendarBookingId, long offset, long duration)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
calendarBooking = CalendarUtil.getNewStartTimeCalendarBooking(
calendarBooking, offset);
calendarBooking = CalendarUtil.getNewDurationCalendarBooking(
calendarBooking, duration);
return calendarBooking;
}
@Override
public boolean hasChildCalendarBookings(long parentCalendarBookingId) {
int total = calendarBookingPersistence.countByParentCalendarBookingId(
parentCalendarBookingId);
if (total > 1) {
return true;
}
return false;
}
@Override
public CalendarBooking invokeTransition(
long calendarBookingId, int instanceIndex, int status,
boolean updateInstance, boolean allFollowing,
ServiceContext serviceContext)
throws PortalException {
CalendarBooking calendarBookingInstance = getCalendarBookingInstance(
calendarBookingId, instanceIndex);
return invokeTransition(
calendarBookingId, calendarBookingInstance.getStartTime(), status,
updateInstance, allFollowing, serviceContext);
}
/**
* @deprecated As of 2.2.0, replaced by {@link #invokeTransition(long, int,
* long, boolean, boolean, ServiceContext)}
*/
@Deprecated
@Override
public void invokeTransition(
long calendarBookingId, int status, ServiceContext serviceContext)
throws PortalException {
invokeTransition(
calendarBookingId, 0, status, false, false, serviceContext);
}
@Override
public CalendarBooking invokeTransition(
long calendarBookingId, long startTime, int status,
boolean updateInstance, boolean allFollowing,
ServiceContext serviceContext)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.invokeTransition(
getUserId(), calendarBooking, startTime, status, updateInstance,
allFollowing, serviceContext);
}
@Override
public CalendarBooking moveCalendarBookingToTrash(long calendarBookingId)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.moveCalendarBookingToTrash(
getUserId(), calendarBooking.getCalendarBookingId());
}
@Override
public CalendarBooking restoreCalendarBookingFromTrash(
long calendarBookingId)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.findByPrimaryKey(calendarBookingId);
CalendarPermission.check(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.restoreCalendarBookingFromTrash(
getUserId(), calendarBooking.getCalendarBookingId());
}
@AccessControlled(guestAccessEnabled = true)
@Override
public List<CalendarBooking> search(
long companyId, long[] groupIds, long[] calendarIds,
long[] calendarResourceIds, long parentCalendarBookingId,
String keywords, long startTime, long endTime, boolean recurring,
int[] statuses, int start, int end,
OrderByComparator<CalendarBooking> orderByComparator)
throws PortalException {
List<CalendarBooking> calendarBookings =
calendarBookingLocalService.search(
companyId, groupIds, calendarIds, calendarResourceIds,
parentCalendarBookingId, keywords, startTime, endTime,
recurring, statuses, start, end, orderByComparator);
return filterCalendarBookings(calendarBookings, ActionKeys.VIEW);
}
@Override
public List<CalendarBooking> search(
long companyId, long[] groupIds, long[] calendarIds,
long[] calendarResourceIds, long parentCalendarBookingId,
String title, String description, String location, long startTime,
long endTime, boolean recurring, int[] statuses,
boolean andOperator, int start, int end,
OrderByComparator<CalendarBooking> orderByComparator)
throws PortalException {
List<CalendarBooking> calendarBookings =
calendarBookingLocalService.search(
companyId, groupIds, calendarIds, calendarResourceIds,
parentCalendarBookingId, title, description, location,
startTime, endTime, recurring, statuses, andOperator, start,
end, orderByComparator);
return filterCalendarBookings(calendarBookings, ActionKeys.VIEW);
}
@AccessControlled(guestAccessEnabled = true)
@Override
public int searchCount(
long companyId, long[] groupIds, long[] calendarIds,
long[] calendarResourceIds, long parentCalendarBookingId,
String keywords, long startTime, long endTime, boolean recurring,
int[] statuses)
throws PortalException {
List<CalendarBooking> calendarBookings = search(
companyId, groupIds, calendarIds, calendarResourceIds,
parentCalendarBookingId, keywords, startTime, endTime, recurring,
statuses, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
return calendarBookings.size();
}
@Override
public int searchCount(
long companyId, long[] groupIds, long[] calendarIds,
long[] calendarResourceIds, long parentCalendarBookingId,
String title, String description, String location, long startTime,
long endTime, boolean recurring, int[] statuses,
boolean andOperator)
throws PortalException {
List<CalendarBooking> calendarBookings = search(
companyId, groupIds, calendarIds, calendarResourceIds,
parentCalendarBookingId, title, description, location, startTime,
endTime, recurring, statuses, andOperator, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null);
return calendarBookings.size();
}
@Override
public CalendarBooking updateCalendarBooking(
long calendarBookingId, long calendarId, long[] childCalendarIds,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, long startTime, long endTime, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
CalendarPermission.check(
getPermissionChecker(), calendarId,
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.updateCalendarBooking(
getUserId(), calendarBookingId, calendarId, childCalendarIds,
titleMap, descriptionMap, location, startTime, endTime, allDay,
recurrence, firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking updateCalendarBooking(
long calendarBookingId, long calendarId,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, long startTime, long endTime, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
CalendarPermission.check(
getPermissionChecker(), calendarId,
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.updateCalendarBooking(
getUserId(), calendarBookingId, calendarId, titleMap,
descriptionMap, location, startTime, endTime, allDay, recurrence,
firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking updateCalendarBookingInstance(
long calendarBookingId, int instanceIndex, long calendarId,
long[] childCalendarIds, Map<Locale, String> titleMap,
Map<Locale, String> descriptionMap, String location, long startTime,
long endTime, boolean allDay, String recurrence,
boolean allFollowing, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
CalendarPermission.check(
getPermissionChecker(), calendarId,
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.updateCalendarBookingInstance(
getUserId(), calendarBookingId, instanceIndex, calendarId,
childCalendarIds, titleMap, descriptionMap, location, startTime,
endTime, allDay, recurrence, allFollowing, firstReminder,
firstReminderType, secondReminder, secondReminderType,
serviceContext);
}
@Override
public CalendarBooking updateCalendarBookingInstance(
long calendarBookingId, int instanceIndex, long calendarId,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, int startTimeYear, int startTimeMonth,
int startTimeDay, int startTimeHour, int startTimeMinute,
int endTimeYear, int endTimeMonth, int endTimeDay, int endTimeHour,
int endTimeMinute, String timeZoneId, boolean allDay,
String recurrence, boolean allFollowing, long firstReminder,
String firstReminderType, long secondReminder,
String secondReminderType, ServiceContext serviceContext)
throws PortalException {
TimeZone timeZone = TimeZoneUtil.getTimeZone(timeZoneId);
if (allDay) {
timeZone = TimeZone.getTimeZone(StringPool.UTC);
}
java.util.Calendar startTimeJCalendar = JCalendarUtil.getJCalendar(
startTimeYear, startTimeMonth, startTimeDay, startTimeHour,
startTimeMinute, 0, 0, timeZone);
java.util.Calendar endTimeJCalendar = JCalendarUtil.getJCalendar(
endTimeYear, endTimeMonth, endTimeDay, endTimeHour, endTimeMinute,
0, 0, timeZone);
return calendarBookingService.updateCalendarBookingInstance(
calendarBookingId, instanceIndex, calendarId, titleMap,
descriptionMap, location, startTimeJCalendar.getTimeInMillis(),
endTimeJCalendar.getTimeInMillis(), allDay, recurrence,
allFollowing, firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking updateCalendarBookingInstance(
long calendarBookingId, int instanceIndex, long calendarId,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, long startTime, long endTime, boolean allDay,
String recurrence, boolean allFollowing, long firstReminder,
String firstReminderType, long secondReminder,
String secondReminderType, ServiceContext serviceContext)
throws PortalException {
CalendarPermission.check(
getPermissionChecker(), calendarId,
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.updateCalendarBookingInstance(
getUserId(), calendarBookingId, instanceIndex, calendarId, titleMap,
descriptionMap, location, startTime, endTime, allDay, recurrence,
allFollowing, firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking updateOffsetAndDuration(
long calendarBookingId, long calendarId, long[] childCalendarIds,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, long offset, long duration, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
CalendarBooking calendarBooking =
calendarBookingPersistence.fetchByPrimaryKey(calendarBookingId);
java.util.Calendar startTimeJCalendar = JCalendarUtil.getJCalendar(
calendarBooking.getStartTime() + offset);
java.util.Calendar endTimeJCalendar = JCalendarUtil.getJCalendar(
startTimeJCalendar.getTimeInMillis() + duration);
return calendarBookingService.updateCalendarBooking(
calendarBookingId, calendarId, childCalendarIds, titleMap,
descriptionMap, location, startTimeJCalendar.getTimeInMillis(),
endTimeJCalendar.getTimeInMillis(), allDay, recurrence,
firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking updateOffsetAndDuration(
long calendarBookingId, long calendarId,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, long offset, long duration, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
long[] childCalendarIds =
calendarBookingLocalService.getChildCalendarIds(
calendarBookingId, calendarId);
return updateOffsetAndDuration(
calendarBookingId, calendarId, childCalendarIds, titleMap,
descriptionMap, location, offset, duration, allDay, recurrence,
firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
@Override
public CalendarBooking updateRecurringCalendarBooking(
long calendarBookingId, long calendarId, long[] childCalendarIds,
Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
String location, long startTime, long endTime, boolean allDay,
String recurrence, long firstReminder, String firstReminderType,
long secondReminder, String secondReminderType,
ServiceContext serviceContext)
throws PortalException {
CalendarPermission.check(
getPermissionChecker(), calendarId,
CalendarActionKeys.MANAGE_BOOKINGS);
return calendarBookingLocalService.updateRecurringCalendarBooking(
getUserId(), calendarBookingId, calendarId, childCalendarIds,
titleMap, descriptionMap, location, startTime, endTime, allDay,
firstReminder, firstReminderType, secondReminder,
secondReminderType, serviceContext);
}
protected String exportToRSS(
String name, String description, String type, double version,
String displayStyle, String feedURL,
List<CalendarBooking> calendarBookings, ThemeDisplay themeDisplay) {
SyndFeed syndFeed = new SyndFeedImpl();
syndFeed.setDescription(description);
List<SyndEntry> syndEntries = new ArrayList<>();
syndFeed.setEntries(syndEntries);
Locale locale = themeDisplay.getLocale();
for (CalendarBooking calendarBooking : calendarBookings) {
SyndEntry syndEntry = new SyndEntryImpl();
String author = PortalUtil.getUserName(calendarBooking);
syndEntry.setAuthor(author);
SyndContent syndContent = new SyndContentImpl();
syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
String value = RSSUtil.getContent(
calendarBooking, displayStyle, themeDisplay);
syndContent.setValue(value);
syndEntry.setDescription(syndContent);
String link = StringPool.BLANK;
syndEntry.setLink(link);
syndEntry.setPublishedDate(calendarBooking.getCreateDate());
syndEntry.setTitle(calendarBooking.getTitle(locale));
syndEntry.setUpdatedDate(calendarBooking.getModifiedDate());
syndEntry.setUri(link);
syndEntries.add(syndEntry);
}
syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
List<SyndLink> syndLinks = new ArrayList<>();
syndFeed.setLinks(syndLinks);
SyndLink syndLink = new SyndLinkImpl();
syndLinks.add(syndLink);
syndLink.setHref(feedURL);
syndLink.setRel("self");
syndFeed.setPublishedDate(new Date());
syndFeed.setTitle(name);
syndFeed.setUri(feedURL);
try {
return RSSUtil.export(syndFeed);
}
catch (FeedException fe) {
throw new SystemException(fe);
}
}
protected CalendarBooking filterCalendarBooking(
CalendarBooking calendarBooking)
throws PortalException {
if (!CalendarPermission.contains(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.VIEW_BOOKING_DETAILS)) {
calendarBooking.setTitle(StringPool.BLANK);
calendarBooking.setDescription(StringPool.BLANK);
calendarBooking.setLocation(StringPool.BLANK);
}
return calendarBooking;
}
protected List<CalendarBooking> filterCalendarBookings(
List<CalendarBooking> calendarBookings, String actionId)
throws PortalException {
calendarBookings = ListUtil.copy(calendarBookings);
Iterator<CalendarBooking> itr = calendarBookings.iterator();
while (itr.hasNext()) {
CalendarBooking calendarBooking = itr.next();
if (!CalendarPermission.contains(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.VIEW_BOOKING_DETAILS)) {
if (!CalendarPermission.contains(
getPermissionChecker(), calendarBooking.getCalendarId(),
actionId) ||
isPendingInWorkflow(calendarBooking)) {
itr.remove();
}
else {
filterCalendarBooking(calendarBooking);
}
}
}
return calendarBookings;
}
protected boolean isPendingInWorkflow(CalendarBooking calendarBooking)
throws PortalException, PrincipalException {
if (calendarBooking.isPending() &&
!CalendarPermission.contains(
getPermissionChecker(), calendarBooking.getCalendarId(),
CalendarActionKeys.MANAGE_BOOKINGS)) {
return true;
}
return false;
}
}