0001: /**
0002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003: *
0004: * Permission is hereby granted, free of charge, to any person obtaining a copy
0005: * of this software and associated documentation files (the "Software"), to deal
0006: * in the Software without restriction, including without limitation the rights
0007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008: * copies of the Software, and to permit persons to whom the Software is
0009: * furnished to do so, subject to the following conditions:
0010: *
0011: * The above copyright notice and this permission notice shall be included in
0012: * all copies or substantial portions of the Software.
0013: *
0014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020: * SOFTWARE.
0021: */package com.liferay.portlet.calendar.service.impl;
0022:
0023: import com.liferay.portal.NoSuchUserException;
0024: import com.liferay.portal.PortalException;
0025: import com.liferay.portal.SystemException;
0026: import com.liferay.portal.im.AIMConnector;
0027: import com.liferay.portal.im.ICQConnector;
0028: import com.liferay.portal.im.MSNConnector;
0029: import com.liferay.portal.im.YMConnector;
0030: import com.liferay.portal.kernel.cal.DayAndPosition;
0031: import com.liferay.portal.kernel.cal.Recurrence;
0032: import com.liferay.portal.kernel.mail.MailMessage;
0033: import com.liferay.portal.kernel.util.Base64;
0034: import com.liferay.portal.kernel.util.CalendarFactoryUtil;
0035: import com.liferay.portal.kernel.util.LocaleUtil;
0036: import com.liferay.portal.kernel.util.ReleaseInfo;
0037: import com.liferay.portal.kernel.util.StringPool;
0038: import com.liferay.portal.kernel.util.StringUtil;
0039: import com.liferay.portal.kernel.util.TimeZoneUtil;
0040: import com.liferay.portal.kernel.util.Validator;
0041: import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
0042: import com.liferay.portal.model.Company;
0043: import com.liferay.portal.model.Contact;
0044: import com.liferay.portal.model.User;
0045: import com.liferay.portal.model.impl.ResourceImpl;
0046: import com.liferay.portal.util.DateFormats;
0047: import com.liferay.portal.util.PortalUtil;
0048: import com.liferay.portal.util.PortletKeys;
0049: import com.liferay.portlet.calendar.EventDurationException;
0050: import com.liferay.portlet.calendar.EventEndDateException;
0051: import com.liferay.portlet.calendar.EventStartDateException;
0052: import com.liferay.portlet.calendar.EventTitleException;
0053: import com.liferay.portlet.calendar.model.CalEvent;
0054: import com.liferay.portlet.calendar.model.impl.CalEventImpl;
0055: import com.liferay.portlet.calendar.service.base.CalEventLocalServiceBaseImpl;
0056: import com.liferay.portlet.calendar.util.CalUtil;
0057: import com.liferay.util.Time;
0058: import com.liferay.util.cal.CalendarUtil;
0059: import com.liferay.util.servlet.ServletResponseUtil;
0060:
0061: import java.io.BufferedOutputStream;
0062: import java.io.File;
0063: import java.io.FileOutputStream;
0064: import java.io.FileReader;
0065: import java.io.IOException;
0066: import java.io.OutputStream;
0067:
0068: import java.text.DateFormat;
0069:
0070: import java.util.ArrayList;
0071: import java.util.Calendar;
0072: import java.util.Collection;
0073: import java.util.Date;
0074: import java.util.Iterator;
0075: import java.util.List;
0076: import java.util.Locale;
0077: import java.util.Map;
0078: import java.util.TimeZone;
0079:
0080: import javax.mail.internet.InternetAddress;
0081:
0082: import javax.portlet.PortletPreferences;
0083:
0084: import net.fortuna.ical4j.data.CalendarBuilder;
0085: import net.fortuna.ical4j.data.CalendarOutputter;
0086: import net.fortuna.ical4j.data.ParserException;
0087: import net.fortuna.ical4j.model.Component;
0088: import net.fortuna.ical4j.model.DateTime;
0089: import net.fortuna.ical4j.model.Parameter;
0090: import net.fortuna.ical4j.model.Property;
0091: import net.fortuna.ical4j.model.PropertyList;
0092: import net.fortuna.ical4j.model.Recur;
0093: import net.fortuna.ical4j.model.WeekDay;
0094: import net.fortuna.ical4j.model.component.VEvent;
0095: import net.fortuna.ical4j.model.component.VTimeZone;
0096: import net.fortuna.ical4j.model.property.CalScale;
0097: import net.fortuna.ical4j.model.property.Comment;
0098: import net.fortuna.ical4j.model.property.Description;
0099: import net.fortuna.ical4j.model.property.DtStart;
0100: import net.fortuna.ical4j.model.property.Duration;
0101: import net.fortuna.ical4j.model.property.ProdId;
0102: import net.fortuna.ical4j.model.property.RRule;
0103: import net.fortuna.ical4j.model.property.Summary;
0104: import net.fortuna.ical4j.model.property.Uid;
0105: import net.fortuna.ical4j.model.property.Version;
0106:
0107: import org.apache.commons.logging.Log;
0108: import org.apache.commons.logging.LogFactory;
0109:
0110: /**
0111: * <a href="CalEventLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
0112: *
0113: * @author Brian Wing Shun Chan
0114: * @author Bruno Farache
0115: *
0116: */
0117: public class CalEventLocalServiceImpl extends
0118: CalEventLocalServiceBaseImpl {
0119:
0120: public CalEvent addEvent(long userId, long plid, String title,
0121: String description, int startDateMonth, int startDateDay,
0122: int startDateYear, int startDateHour, int startDateMinute,
0123: int endDateMonth, int endDateDay, int endDateYear,
0124: int durationHour, int durationMinute, boolean allDay,
0125: boolean timeZoneSensitive, String type, boolean repeating,
0126: Recurrence recurrence, String remindBy, int firstReminder,
0127: int secondReminder, boolean addCommunityPermissions,
0128: boolean addGuestPermissions) throws PortalException,
0129: SystemException {
0130:
0131: return addEvent(null, userId, plid, title, description,
0132: startDateMonth, startDateDay, startDateYear,
0133: startDateHour, startDateMinute, endDateMonth,
0134: endDateDay, endDateYear, durationHour, durationMinute,
0135: allDay, timeZoneSensitive, type, repeating, recurrence,
0136: remindBy, firstReminder, secondReminder, Boolean
0137: .valueOf(addCommunityPermissions), Boolean
0138: .valueOf(addGuestPermissions), null, null);
0139: }
0140:
0141: public CalEvent addEvent(String uuid, long userId, long plid,
0142: String title, String description, int startDateMonth,
0143: int startDateDay, int startDateYear, int startDateHour,
0144: int startDateMinute, int endDateMonth, int endDateDay,
0145: int endDateYear, int durationHour, int durationMinute,
0146: boolean allDay, boolean timeZoneSensitive, String type,
0147: boolean repeating, Recurrence recurrence, String remindBy,
0148: int firstReminder, int secondReminder,
0149: boolean addCommunityPermissions, boolean addGuestPermissions)
0150: throws PortalException, SystemException {
0151:
0152: return addEvent(uuid, userId, plid, title, description,
0153: startDateMonth, startDateDay, startDateYear,
0154: startDateHour, startDateMinute, endDateMonth,
0155: endDateDay, endDateYear, durationHour, durationMinute,
0156: allDay, timeZoneSensitive, type, repeating, recurrence,
0157: remindBy, firstReminder, secondReminder, new Boolean(
0158: addCommunityPermissions), new Boolean(
0159: addGuestPermissions), null, null);
0160: }
0161:
0162: public CalEvent addEvent(long userId, long plid, String title,
0163: String description, int startDateMonth, int startDateDay,
0164: int startDateYear, int startDateHour, int startDateMinute,
0165: int endDateMonth, int endDateDay, int endDateYear,
0166: int durationHour, int durationMinute, boolean allDay,
0167: boolean timeZoneSensitive, String type, boolean repeating,
0168: Recurrence recurrence, String remindBy, int firstReminder,
0169: int secondReminder, String[] communityPermissions,
0170: String[] guestPermissions) throws PortalException,
0171: SystemException {
0172:
0173: return addEvent(null, userId, plid, title, description,
0174: startDateMonth, startDateDay, startDateYear,
0175: startDateHour, startDateMinute, endDateMonth,
0176: endDateDay, endDateYear, durationHour, durationMinute,
0177: allDay, timeZoneSensitive, type, repeating, recurrence,
0178: remindBy, firstReminder, secondReminder, null, null,
0179: communityPermissions, guestPermissions);
0180: }
0181:
0182: public CalEvent addEvent(String uuid, long userId, long plid,
0183: String title, String description, int startDateMonth,
0184: int startDateDay, int startDateYear, int startDateHour,
0185: int startDateMinute, int endDateMonth, int endDateDay,
0186: int endDateYear, int durationHour, int durationMinute,
0187: boolean allDay, boolean timeZoneSensitive, String type,
0188: boolean repeating, Recurrence recurrence, String remindBy,
0189: int firstReminder, int secondReminder,
0190: Boolean addCommunityPermissions,
0191: Boolean addGuestPermissions, String[] communityPermissions,
0192: String[] guestPermissions) throws PortalException,
0193: SystemException {
0194:
0195: // Event
0196:
0197: User user = userPersistence.findByPrimaryKey(userId);
0198: long groupId = PortalUtil.getPortletGroupId(plid);
0199: Date now = new Date();
0200:
0201: Locale locale = null;
0202: TimeZone timeZone = null;
0203:
0204: if (timeZoneSensitive) {
0205: locale = user.getLocale();
0206: timeZone = user.getTimeZone();
0207: } else {
0208: locale = LocaleUtil.getDefault();
0209: timeZone = TimeZoneUtil.getDefault();
0210: }
0211:
0212: Calendar startDate = CalendarFactoryUtil.getCalendar(timeZone,
0213: locale);
0214:
0215: startDate.set(Calendar.MONTH, startDateMonth);
0216: startDate.set(Calendar.DATE, startDateDay);
0217: startDate.set(Calendar.YEAR, startDateYear);
0218: startDate.set(Calendar.HOUR_OF_DAY, startDateHour);
0219: startDate.set(Calendar.MINUTE, startDateMinute);
0220: startDate.set(Calendar.SECOND, 0);
0221: startDate.set(Calendar.MILLISECOND, 0);
0222:
0223: Calendar endDate = CalendarFactoryUtil.getCalendar(timeZone,
0224: locale);
0225:
0226: endDate.set(Calendar.MONTH, endDateMonth);
0227: endDate.set(Calendar.DATE, endDateDay);
0228: endDate.set(Calendar.YEAR, endDateYear);
0229: endDate.set(Calendar.HOUR_OF_DAY, 23);
0230: endDate.set(Calendar.MINUTE, 59);
0231: endDate.set(Calendar.SECOND, 59);
0232: endDate.set(Calendar.MILLISECOND, 999);
0233:
0234: if (allDay) {
0235: startDate.set(Calendar.HOUR_OF_DAY, 0);
0236: startDate.set(Calendar.MINUTE, 0);
0237:
0238: durationHour = 24;
0239: durationMinute = 0;
0240: }
0241:
0242: validate(title, startDateMonth, startDateDay, startDateYear,
0243: endDateMonth, endDateDay, endDateYear, durationHour,
0244: durationMinute, allDay);
0245:
0246: long eventId = counterLocalService.increment();
0247:
0248: CalEvent event = calEventPersistence.create(eventId);
0249:
0250: event.setUuid(uuid);
0251: event.setGroupId(groupId);
0252: event.setCompanyId(user.getCompanyId());
0253: event.setUserId(user.getUserId());
0254: event.setUserName(user.getFullName());
0255: event.setCreateDate(now);
0256: event.setModifiedDate(now);
0257: event.setTitle(title);
0258: event.setDescription(description);
0259: event.setStartDate(startDate.getTime());
0260: event.setEndDate(endDate.getTime());
0261: event.setDurationHour(durationHour);
0262: event.setDurationMinute(durationMinute);
0263: event.setAllDay(allDay);
0264: event.setTimeZoneSensitive(timeZoneSensitive);
0265: event.setType(type);
0266: event.setRepeating(repeating);
0267: event.setRecurrence(Base64.objectToString(recurrence));
0268: event.setRemindBy(remindBy);
0269: event.setFirstReminder(firstReminder);
0270: event.setSecondReminder(secondReminder);
0271:
0272: calEventPersistence.update(event);
0273:
0274: // Resources
0275:
0276: if ((addCommunityPermissions != null)
0277: && (addGuestPermissions != null)) {
0278:
0279: addEventResources(event, addCommunityPermissions
0280: .booleanValue(), addGuestPermissions.booleanValue());
0281: } else {
0282: addEventResources(event, communityPermissions,
0283: guestPermissions);
0284: }
0285:
0286: // Pool
0287:
0288: CalEventLocalUtil.clearEventsPool(event.getGroupId());
0289:
0290: return event;
0291: }
0292:
0293: public void addEventResources(long eventId,
0294: boolean addCommunityPermissions, boolean addGuestPermissions)
0295: throws PortalException, SystemException {
0296:
0297: CalEvent event = calEventPersistence.findByPrimaryKey(eventId);
0298:
0299: addEventResources(event, addCommunityPermissions,
0300: addGuestPermissions);
0301: }
0302:
0303: public void addEventResources(CalEvent event,
0304: boolean addCommunityPermissions, boolean addGuestPermissions)
0305: throws PortalException, SystemException {
0306:
0307: resourceLocalService.addResources(event.getCompanyId(), event
0308: .getGroupId(), event.getUserId(), CalEvent.class
0309: .getName(), event.getEventId(), false,
0310: addCommunityPermissions, addGuestPermissions);
0311: }
0312:
0313: public void addEventResources(long eventId,
0314: String[] communityPermissions, String[] guestPermissions)
0315: throws PortalException, SystemException {
0316:
0317: CalEvent event = calEventPersistence.findByPrimaryKey(eventId);
0318:
0319: addEventResources(event, communityPermissions, guestPermissions);
0320: }
0321:
0322: public void addEventResources(CalEvent event,
0323: String[] communityPermissions, String[] guestPermissions)
0324: throws PortalException, SystemException {
0325:
0326: resourceLocalService.addModelResources(event.getCompanyId(),
0327: event.getGroupId(), event.getUserId(), CalEvent.class
0328: .getName(), event.getEventId(),
0329: communityPermissions, guestPermissions);
0330: }
0331:
0332: public void checkEvents() throws PortalException, SystemException {
0333: Iterator itr = calEventFinder.findByRemindBy().iterator();
0334:
0335: while (itr.hasNext()) {
0336: CalEvent event = (CalEvent) itr.next();
0337:
0338: User user = userPersistence.findByPrimaryKey(event
0339: .getUserId());
0340:
0341: Calendar now = CalendarFactoryUtil.getCalendar(user
0342: .getTimeZone(), user.getLocale());
0343:
0344: if (!event.isTimeZoneSensitive()) {
0345: Calendar temp = CalendarFactoryUtil.getCalendar();
0346:
0347: temp.setTime(Time.getDate(now));
0348:
0349: now = temp;
0350: }
0351:
0352: Calendar startDate = null;
0353:
0354: if (event.isTimeZoneSensitive()) {
0355: startDate = CalendarFactoryUtil.getCalendar(user
0356: .getTimeZone(), user.getLocale());
0357: } else {
0358: startDate = CalendarFactoryUtil.getCalendar();
0359: }
0360:
0361: startDate.setTime(event.getStartDate());
0362:
0363: long diff = (startDate.getTime().getTime() - now.getTime()
0364: .getTime())
0365: / Time.MINUTE;
0366:
0367: if ((diff == (event.getFirstReminder() / Time.MINUTE))
0368: || (diff == (event.getSecondReminder() / Time.MINUTE))) {
0369:
0370: remindUser(event, user);
0371: }
0372: }
0373: }
0374:
0375: public void deleteEvent(long eventId) throws PortalException,
0376: SystemException {
0377:
0378: CalEvent event = calEventPersistence.findByPrimaryKey(eventId);
0379:
0380: deleteEvent(event);
0381: }
0382:
0383: public void deleteEvent(CalEvent event) throws PortalException,
0384: SystemException {
0385:
0386: // Pool
0387:
0388: CalEventLocalUtil.clearEventsPool(event.getGroupId());
0389:
0390: // Resources
0391:
0392: resourceLocalService.deleteResource(event.getCompanyId(),
0393: CalEvent.class.getName(),
0394: ResourceImpl.SCOPE_INDIVIDUAL, event.getEventId());
0395:
0396: // Event
0397:
0398: calEventPersistence.remove(event.getEventId());
0399: }
0400:
0401: public void deleteEvents(long groupId) throws PortalException,
0402: SystemException {
0403:
0404: Iterator itr = calEventPersistence.findByGroupId(groupId)
0405: .iterator();
0406:
0407: while (itr.hasNext()) {
0408: CalEvent event = (CalEvent) itr.next();
0409:
0410: deleteEvent(event);
0411: }
0412: }
0413:
0414: public File exportEvent(long userId, long eventId)
0415: throws PortalException, SystemException {
0416:
0417: List events = new ArrayList();
0418:
0419: CalEvent event = calEventPersistence.findByPrimaryKey(eventId);
0420:
0421: events.add(event);
0422:
0423: return exportICal4j(toICalCalendar(userId, events), null);
0424: }
0425:
0426: public File exportGroupEvents(long userId, long plid,
0427: String fileName) throws PortalException, SystemException {
0428:
0429: long groupId = PortalUtil.getPortletGroupId(plid);
0430:
0431: List events = calEventPersistence.findByGroupId(groupId);
0432:
0433: return exportICal4j(toICalCalendar(userId, events), fileName);
0434: }
0435:
0436: public CalEvent getEvent(long eventId) throws PortalException,
0437: SystemException {
0438:
0439: return calEventPersistence.findByPrimaryKey(eventId);
0440: }
0441:
0442: public List getEvents(long groupId, String type, int begin, int end)
0443: throws SystemException {
0444:
0445: if (Validator.isNull(type)) {
0446: return calEventPersistence.findByGroupId(groupId, begin,
0447: end);
0448: } else {
0449: return calEventPersistence.findByG_T(groupId, type, begin,
0450: end);
0451: }
0452: }
0453:
0454: public List getEvents(long groupId, Calendar cal)
0455: throws SystemException {
0456: Map eventsPool = CalEventLocalUtil.getEventsPool(groupId);
0457:
0458: String key = CalUtil.toString(cal);
0459:
0460: List events = (List) eventsPool.get(key);
0461:
0462: if (events == null) {
0463:
0464: // Time zone sensitive
0465:
0466: Collection eventsCol1 = calEventFinder.findByG_SD(groupId,
0467: CalendarUtil.getGTDate(cal), CalendarUtil
0468: .getLTDate(cal), true);
0469:
0470: // Time zone insensitive
0471:
0472: Calendar tzICal = CalendarFactoryUtil.getCalendar(cal
0473: .get(Calendar.YEAR), cal.get(Calendar.MONTH), cal
0474: .get(Calendar.DATE));
0475:
0476: Collection eventsCol2 = calEventFinder.findByG_SD(groupId,
0477: CalendarUtil.getGTDate(tzICal), CalendarUtil
0478: .getLTDate(tzICal), false);
0479:
0480: // Create new list
0481:
0482: events = new ArrayList();
0483: events.addAll(eventsCol1);
0484: events.addAll(eventsCol2);
0485:
0486: // Add repeating events
0487:
0488: Iterator itr = getRepeatingEvents(groupId).iterator();
0489:
0490: while (itr.hasNext()) {
0491: CalEvent event = (CalEvent) itr.next();
0492:
0493: Recurrence recurrence = event.getRecurrenceObj();
0494:
0495: try {
0496:
0497: // LEP-3468
0498:
0499: if ((recurrence.getFrequency() == Recurrence.DAILY)
0500: && (recurrence.getInterval() <= 0)) {
0501:
0502: recurrence.setInterval(1);
0503:
0504: event.setRecurrence(Base64
0505: .objectToString(recurrence));
0506:
0507: event = calEventPersistence.update(event);
0508:
0509: recurrence = event.getRecurrenceObj();
0510: }
0511:
0512: if (recurrence.isInRecurrence(getRecurrenceCal(cal,
0513: tzICal, event))) {
0514:
0515: events.add(event);
0516: }
0517: } catch (Exception e) {
0518: _log.error(e.getMessage());
0519: }
0520: }
0521:
0522: eventsPool.put(key, events);
0523: }
0524:
0525: return events;
0526: }
0527:
0528: public List getEvents(long groupId, Calendar cal, String type)
0529: throws SystemException {
0530:
0531: List events = getEvents(groupId, cal);
0532:
0533: if (Validator.isNull(type)) {
0534: return events;
0535: } else {
0536: events = new ArrayList(events);
0537:
0538: Iterator itr = events.iterator();
0539:
0540: while (itr.hasNext()) {
0541: CalEvent event = (CalEvent) itr.next();
0542:
0543: if (!event.getType().equals(type)) {
0544: itr.remove();
0545: }
0546: }
0547:
0548: return events;
0549: }
0550: }
0551:
0552: public int getEventsCount(long groupId, String type)
0553: throws SystemException {
0554:
0555: if (Validator.isNull(type)) {
0556: return calEventPersistence.countByGroupId(groupId);
0557: } else {
0558: return calEventPersistence.countByG_T(groupId, type);
0559: }
0560: }
0561:
0562: public List getRepeatingEvents(long groupId) throws SystemException {
0563: Map eventsPool = CalEventLocalUtil.getEventsPool(groupId);
0564:
0565: String key = "recurrence";
0566:
0567: List events = (List) eventsPool.get(key);
0568:
0569: if (events == null) {
0570: events = calEventPersistence.findByG_R(groupId, true);
0571:
0572: eventsPool.put(key, events);
0573: }
0574:
0575: return events;
0576: }
0577:
0578: public boolean hasEvents(long groupId, Calendar cal)
0579: throws SystemException {
0580:
0581: return hasEvents(groupId, cal, null);
0582: }
0583:
0584: public boolean hasEvents(long groupId, Calendar cal, String type)
0585: throws SystemException {
0586:
0587: if (getEvents(groupId, cal, type).size() > 0) {
0588: return true;
0589: } else {
0590: return false;
0591: }
0592: }
0593:
0594: public void importICal4j(long userId, long plid, File file)
0595: throws PortalException, SystemException {
0596:
0597: try {
0598: CalendarBuilder builder = new CalendarBuilder();
0599:
0600: net.fortuna.ical4j.model.Calendar calendar = builder
0601: .build(new FileReader(file));
0602:
0603: TimeZone timeZone = toTimeZone(userId, (VTimeZone) calendar
0604: .getComponent(Component.VTIMEZONE));
0605:
0606: Iterator itr = calendar.getComponents(Component.VEVENT)
0607: .iterator();
0608:
0609: while (itr.hasNext()) {
0610: VEvent vEvent = (VEvent) itr.next();
0611:
0612: importICal4j(userId, plid, vEvent, timeZone);
0613: }
0614: } catch (IOException ioe) {
0615: throw new SystemException(ioe.getMessage());
0616: } catch (ParserException pe) {
0617: throw new SystemException(pe.getMessage());
0618: }
0619: }
0620:
0621: public CalEvent updateEvent(long userId, long eventId,
0622: String title, String description, int startDateMonth,
0623: int startDateDay, int startDateYear, int startDateHour,
0624: int startDateMinute, int endDateMonth, int endDateDay,
0625: int endDateYear, int durationHour, int durationMinute,
0626: boolean allDay, boolean timeZoneSensitive, String type,
0627: boolean repeating, Recurrence recurrence, String remindBy,
0628: int firstReminder, int secondReminder)
0629: throws PortalException, SystemException {
0630:
0631: User user = userPersistence.findByPrimaryKey(userId);
0632:
0633: Locale locale = null;
0634: TimeZone timeZone = null;
0635:
0636: if (timeZoneSensitive) {
0637: locale = user.getLocale();
0638: timeZone = user.getTimeZone();
0639: } else {
0640: locale = LocaleUtil.getDefault();
0641: timeZone = TimeZoneUtil.getDefault();
0642: }
0643:
0644: Calendar startDate = CalendarFactoryUtil.getCalendar(timeZone,
0645: locale);
0646:
0647: startDate.set(Calendar.MONTH, startDateMonth);
0648: startDate.set(Calendar.DATE, startDateDay);
0649: startDate.set(Calendar.YEAR, startDateYear);
0650: startDate.set(Calendar.HOUR_OF_DAY, startDateHour);
0651: startDate.set(Calendar.MINUTE, startDateMinute);
0652: startDate.set(Calendar.SECOND, 0);
0653: startDate.set(Calendar.MILLISECOND, 0);
0654:
0655: Calendar endDate = CalendarFactoryUtil.getCalendar(timeZone,
0656: locale);
0657:
0658: endDate.set(Calendar.MONTH, endDateMonth);
0659: endDate.set(Calendar.DATE, endDateDay);
0660: endDate.set(Calendar.YEAR, endDateYear);
0661: endDate.set(Calendar.HOUR_OF_DAY, 23);
0662: endDate.set(Calendar.MINUTE, 59);
0663: endDate.set(Calendar.SECOND, 59);
0664: endDate.set(Calendar.MILLISECOND, 999);
0665:
0666: if (allDay) {
0667: startDate.set(Calendar.HOUR_OF_DAY, 0);
0668: startDate.set(Calendar.MINUTE, 0);
0669:
0670: durationHour = 24;
0671: durationMinute = 0;
0672: }
0673:
0674: validate(title, startDateMonth, startDateDay, startDateYear,
0675: endDateMonth, endDateDay, endDateYear, durationHour,
0676: durationMinute, allDay);
0677:
0678: CalEvent event = calEventPersistence.findByPrimaryKey(eventId);
0679:
0680: event.setModifiedDate(new Date());
0681: event.setTitle(title);
0682: event.setDescription(description);
0683: event.setStartDate(startDate.getTime());
0684: event.setEndDate(endDate.getTime());
0685: event.setDurationHour(durationHour);
0686: event.setDurationMinute(durationMinute);
0687: event.setAllDay(allDay);
0688: event.setTimeZoneSensitive(timeZoneSensitive);
0689: event.setType(type);
0690: event.setRepeating(repeating);
0691: event.setRecurrence(Base64.objectToString(recurrence));
0692: event.setRemindBy(remindBy);
0693: event.setFirstReminder(firstReminder);
0694: event.setSecondReminder(secondReminder);
0695:
0696: calEventPersistence.update(event);
0697:
0698: CalEventLocalUtil.clearEventsPool(event.getGroupId());
0699:
0700: return event;
0701: }
0702:
0703: protected File exportICal4j(net.fortuna.ical4j.model.Calendar cal,
0704: String fileName) throws SystemException {
0705:
0706: OutputStream os = null;
0707:
0708: try {
0709: String extension = ".ics";
0710:
0711: if (Validator.isNull(fileName)) {
0712: fileName = "liferay.";
0713: } else {
0714: int pos = fileName.lastIndexOf(StringPool.PERIOD);
0715:
0716: if (pos != -1) {
0717: extension = fileName.substring(pos);
0718: fileName = fileName.substring(0, pos);
0719: }
0720: }
0721:
0722: File file = File.createTempFile(fileName, extension);
0723:
0724: os = new BufferedOutputStream(new FileOutputStream(file
0725: .getPath()));
0726:
0727: CalendarOutputter calOutput = new CalendarOutputter();
0728:
0729: calOutput.output(cal, os);
0730:
0731: return file;
0732: } catch (Exception e) {
0733: _log.error(e, e);
0734:
0735: throw new SystemException(e);
0736: } finally {
0737: ServletResponseUtil.cleanUp(os);
0738: }
0739: }
0740:
0741: protected Calendar getRecurrenceCal(Calendar cal, Calendar tzICal,
0742: CalEvent event) {
0743:
0744: Calendar eventCal = CalendarFactoryUtil.getCalendar();
0745: eventCal.setTime(event.getStartDate());
0746:
0747: Calendar recurrenceCal = (Calendar) tzICal.clone();
0748: recurrenceCal.set(Calendar.HOUR_OF_DAY, eventCal
0749: .get(Calendar.HOUR_OF_DAY));
0750: recurrenceCal.set(Calendar.MINUTE, eventCal
0751: .get(Calendar.MINUTE));
0752: recurrenceCal.set(Calendar.SECOND, 0);
0753: recurrenceCal.set(Calendar.MILLISECOND, 0);
0754:
0755: if (event.isTimeZoneSensitive()) {
0756: int gmtDate = eventCal.get(Calendar.DATE);
0757: long gmtMills = eventCal.getTimeInMillis();
0758:
0759: eventCal.setTimeZone(cal.getTimeZone());
0760:
0761: int tziDate = eventCal.get(Calendar.DATE);
0762: long tziMills = Time.getDate(eventCal).getTime();
0763:
0764: if (gmtDate != tziDate) {
0765: int diffDate = 0;
0766:
0767: if (gmtMills > tziMills) {
0768: diffDate = (int) Math
0769: .ceil((double) (gmtMills - tziMills)
0770: / Time.DAY);
0771: } else {
0772: diffDate = (int) Math
0773: .floor((double) (gmtMills - tziMills)
0774: / Time.DAY);
0775: }
0776:
0777: recurrenceCal.add(Calendar.DATE, diffDate);
0778: }
0779: }
0780:
0781: return recurrenceCal;
0782: }
0783:
0784: protected void importICal4j(long userId, long plid, VEvent event,
0785: TimeZone timeZone) throws PortalException, SystemException {
0786:
0787: String title = StringPool.BLANK;
0788:
0789: if (event.getSummary() != null) {
0790: title = event.getSummary().getValue();
0791: }
0792:
0793: String description = StringPool.BLANK;
0794:
0795: if (event.getDescription() != null) {
0796: description = event.getDescription().getValue();
0797: }
0798:
0799: Calendar startDate = Calendar.getInstance(timeZone);
0800:
0801: startDate.setTime(event.getStartDate().getDate());
0802:
0803: Calendar endDate = Calendar.getInstance(timeZone);
0804:
0805: endDate.setTime(event.getEndDate().getDate());
0806:
0807: long diffMillis = endDate.getTimeInMillis()
0808: - startDate.getTimeInMillis();
0809: long durationHours = diffMillis / (60 * 60 * 1000);
0810: long durationMins = (diffMillis / (60 * 1000))
0811: - (durationHours * 60);
0812: boolean allDay = false;
0813:
0814: if (event.getProperty(Property.DTSTART).getParameter(
0815: Parameter.TZID) == null) {
0816:
0817: Calendar startDateWithoutTimeZone = Calendar.getInstance();
0818:
0819: startDateWithoutTimeZone.setTime(event.getStartDate()
0820: .getDate());
0821:
0822: startDate
0823: .set(Calendar.DAY_OF_MONTH,
0824: startDateWithoutTimeZone
0825: .get(Calendar.DAY_OF_MONTH));
0826: startDate.set(Calendar.HOUR_OF_DAY, 0);
0827: startDate.set(Calendar.MINUTE, 0);
0828: startDate.set(Calendar.SECOND, 0);
0829: startDate.set(Calendar.MILLISECOND, 0);
0830:
0831: durationHours = 24;
0832: durationMins = 0;
0833: allDay = true;
0834: }
0835:
0836: boolean timeZoneSensitive = false;
0837: String type = StringPool.BLANK;
0838: boolean repeating = false;
0839: Recurrence recurrence = null;
0840:
0841: RRule rrule = (RRule) event.getProperty(Property.RRULE);
0842:
0843: if (rrule != null) {
0844: repeating = true;
0845: recurrence = toRecurrence(rrule.getRecur(), timeZone,
0846: startDate);
0847:
0848: if (recurrence.getUntil() != null) {
0849: endDate = recurrence.getUntil();
0850: }
0851: }
0852:
0853: String remindBy = "none";
0854: int firstReminder = 300000;
0855: int secondReminder = 300000;
0856:
0857: boolean addCommunityPermissions = false;
0858: boolean addGuestPermissions = false;
0859:
0860: addEvent(userId, plid, title, description, startDate
0861: .get(Calendar.MONTH), startDate
0862: .get(Calendar.DAY_OF_MONTH), startDate
0863: .get(Calendar.YEAR), startDate
0864: .get(Calendar.HOUR_OF_DAY), startDate
0865: .get(Calendar.MINUTE), endDate.get(Calendar.MONTH),
0866: endDate.get(Calendar.DAY_OF_MONTH), endDate
0867: .get(Calendar.YEAR), (int) durationHours,
0868: (int) durationMins, allDay, timeZoneSensitive, type,
0869: repeating, recurrence, remindBy, firstReminder,
0870: secondReminder, addCommunityPermissions,
0871: addGuestPermissions);
0872:
0873: }
0874:
0875: protected void remindUser(CalEvent event, User user) {
0876: String remindBy = event.getRemindBy();
0877:
0878: if (remindBy.equals(CalEventImpl.REMIND_BY_NONE)) {
0879: return;
0880: }
0881:
0882: try {
0883: long ownerId = event.getGroupId();
0884: int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
0885: long plid = PortletKeys.PREFS_PLID_SHARED;
0886: String portletId = PortletKeys.CALENDAR;
0887:
0888: PortletPreferences prefs = portletPreferencesLocalService
0889: .getPreferences(event.getCompanyId(), ownerId,
0890: ownerType, plid, portletId);
0891:
0892: Company company = companyPersistence.findByPrimaryKey(user
0893: .getCompanyId());
0894:
0895: Contact contact = user.getContact();
0896:
0897: String portletName = PortalUtil.getPortletTitle(
0898: PortletKeys.CALENDAR, user);
0899:
0900: String fromName = CalUtil.getEmailFromName(prefs);
0901: String fromAddress = CalUtil.getEmailFromAddress(prefs);
0902:
0903: String toName = user.getFullName();
0904: String toAddress = user.getEmailAddress();
0905:
0906: if (remindBy.equals(CalEventImpl.REMIND_BY_SMS)) {
0907: toAddress = contact.getSmsSn();
0908: }
0909:
0910: String subject = CalUtil
0911: .getEmailEventReminderSubject(prefs);
0912: String body = CalUtil.getEmailEventReminderBody(prefs);
0913:
0914: DateFormat dateFormatDateTime = DateFormats.getDateTime(
0915: user.getLocale(), user.getTimeZone());
0916:
0917: subject = StringUtil.replace(subject, new String[] {
0918: "[$EVENT_START_DATE$]", "[$EVENT_TITLE$]",
0919: "[$FROM_ADDRESS$]", "[$FROM_NAME$]",
0920: "[$PORTAL_URL$]", "[$PORTLET_NAME$]",
0921: "[$TO_ADDRESS$]", "[$TO_NAME$]" }, new String[] {
0922: dateFormatDateTime.format(event.getStartDate()),
0923: event.getTitle(), fromAddress, fromName,
0924: company.getVirtualHost(), portletName, toAddress,
0925: toName, });
0926:
0927: body = StringUtil.replace(body, new String[] {
0928: "[$EVENT_START_DATE$]", "[$EVENT_TITLE$]",
0929: "[$FROM_ADDRESS$]", "[$FROM_NAME$]",
0930: "[$PORTAL_URL$]", "[$PORTLET_NAME$]",
0931: "[$TO_ADDRESS$]", "[$TO_NAME$]" }, new String[] {
0932: dateFormatDateTime.format(event.getStartDate()),
0933: event.getTitle(), fromAddress, fromName,
0934: company.getVirtualHost(), portletName, toAddress,
0935: toName, });
0936:
0937: if (remindBy.equals(CalEventImpl.REMIND_BY_EMAIL)
0938: || remindBy.equals(CalEventImpl.REMIND_BY_SMS)) {
0939:
0940: InternetAddress from = new InternetAddress(fromAddress,
0941: fromName);
0942:
0943: InternetAddress to = new InternetAddress(toAddress,
0944: toName);
0945:
0946: MailMessage message = new MailMessage(from, to,
0947: subject, body, true);
0948:
0949: mailService.sendEmail(message);
0950: } else if (remindBy.equals(CalEventImpl.REMIND_BY_AIM)
0951: && Validator.isNotNull(contact.getAimSn())) {
0952:
0953: AIMConnector.send(contact.getAimSn(), body);
0954: } else if (remindBy.equals(CalEventImpl.REMIND_BY_ICQ)
0955: && Validator.isNotNull(contact.getIcqSn())) {
0956:
0957: ICQConnector.send(contact.getIcqSn(), body);
0958: } else if (remindBy.equals(CalEventImpl.REMIND_BY_MSN)
0959: && Validator.isNotNull(contact.getMsnSn())) {
0960:
0961: MSNConnector.send(contact.getMsnSn(), body);
0962: } else if (remindBy.equals(CalEventImpl.REMIND_BY_YM)
0963: && Validator.isNotNull(contact.getYmSn())) {
0964:
0965: YMConnector.send(contact.getYmSn(), body);
0966: }
0967: } catch (Exception e) {
0968: _log.error(e);
0969: }
0970: }
0971:
0972: protected int toCalendarWeekDay(WeekDay weekDay) {
0973: int dayOfWeeek = 0;
0974:
0975: if (weekDay.getDay().equals(WeekDay.SU.getDay())) {
0976: dayOfWeeek = Calendar.SUNDAY;
0977: } else if (weekDay.getDay().equals(WeekDay.MO.getDay())) {
0978: dayOfWeeek = Calendar.MONDAY;
0979: } else if (weekDay.getDay().equals(WeekDay.TU.getDay())) {
0980: dayOfWeeek = Calendar.TUESDAY;
0981: } else if (weekDay.getDay().equals(WeekDay.WE.getDay())) {
0982: dayOfWeeek = Calendar.WEDNESDAY;
0983: } else if (weekDay.getDay().equals(WeekDay.TH.getDay())) {
0984: dayOfWeeek = Calendar.THURSDAY;
0985: } else if (weekDay.getDay().equals(WeekDay.FR.getDay())) {
0986: dayOfWeeek = Calendar.FRIDAY;
0987: } else if (weekDay.getDay().equals(WeekDay.SA.getDay())) {
0988: dayOfWeeek = Calendar.SATURDAY;
0989: }
0990:
0991: return dayOfWeeek;
0992: }
0993:
0994: protected net.fortuna.ical4j.model.Calendar toICalCalendar(
0995: long userId, List events) throws PortalException,
0996: SystemException {
0997:
0998: net.fortuna.ical4j.model.Calendar iCal = new net.fortuna.ical4j.model.Calendar();
0999:
1000: ProdId prodId = new ProdId("-//Liferay Inc//Liferay Portal "
1001: + ReleaseInfo.getVersion() + "//EN");
1002:
1003: PropertyList props = iCal.getProperties();
1004:
1005: props.add(prodId);
1006: props.add(Version.VERSION_2_0);
1007: props.add(CalScale.GREGORIAN);
1008:
1009: User user = userPersistence.findByPrimaryKey(userId);
1010: TimeZone timeZone = user.getTimeZone();
1011:
1012: List components = iCal.getComponents();
1013:
1014: Iterator itr = events.iterator();
1015:
1016: while (itr.hasNext()) {
1017: CalEvent event = (CalEvent) itr.next();
1018:
1019: components.add(toICalVEvent(event, timeZone));
1020: }
1021:
1022: return iCal;
1023: }
1024:
1025: protected Recur toICalRecurrence(Recurrence recurrence) {
1026: Recur recur = null;
1027:
1028: int recurrenceType = recurrence.getFrequency();
1029:
1030: int interval = recurrence.getInterval();
1031:
1032: if (recurrenceType == Recurrence.DAILY) {
1033: recur = new Recur(Recur.DAILY, -1);
1034:
1035: if (interval >= 1) {
1036: recur.setInterval(interval);
1037: }
1038:
1039: DayAndPosition[] byDay = recurrence.getByDay();
1040:
1041: if (byDay != null) {
1042: for (int i = 0; i < byDay.length; i++) {
1043: WeekDay weekDay = toICalWeekDay(byDay[i]
1044: .getDayOfWeek());
1045:
1046: recur.getDayList().add(weekDay);
1047: }
1048: }
1049:
1050: } else if (recurrenceType == Recurrence.WEEKLY) {
1051: recur = new Recur(Recur.WEEKLY, -1);
1052:
1053: recur.setInterval(interval);
1054:
1055: DayAndPosition[] byDay = recurrence.getByDay();
1056:
1057: if (byDay != null) {
1058: for (int i = 0; i < byDay.length; i++) {
1059: WeekDay weekDay = toICalWeekDay(byDay[i]
1060: .getDayOfWeek());
1061:
1062: recur.getDayList().add(weekDay);
1063: }
1064: }
1065: } else if (recurrenceType == Recurrence.MONTHLY) {
1066: recur = new Recur(Recur.MONTHLY, -1);
1067:
1068: recur.setInterval(interval);
1069:
1070: int[] byMonthDay = recurrence.getByMonthDay();
1071:
1072: if (byMonthDay != null) {
1073: Integer monthDay = new Integer(byMonthDay[0]);
1074:
1075: recur.getMonthDayList().add(monthDay);
1076: } else if (recurrence.getByDay() != null) {
1077: DayAndPosition[] byDay = recurrence.getByDay();
1078:
1079: WeekDay weekDay = toICalWeekDay(byDay[0].getDayOfWeek());
1080:
1081: recur.getDayList().add(weekDay);
1082:
1083: Integer position = new Integer(byDay[0]
1084: .getDayPosition());
1085:
1086: recur.getSetPosList().add(position);
1087: }
1088: } else if (recurrenceType == Recurrence.YEARLY) {
1089: recur = new Recur(Recur.YEARLY, -1);
1090:
1091: recur.setInterval(interval);
1092: }
1093:
1094: Calendar until = recurrence.getUntil();
1095:
1096: if (until != null) {
1097: DateTime dateTime = new DateTime(until.getTime());
1098:
1099: recur.setUntil(dateTime);
1100: }
1101:
1102: return recur;
1103: }
1104:
1105: protected VEvent toICalVEvent(CalEvent event, TimeZone timeZone) {
1106: VEvent vEvent = new VEvent();
1107:
1108: PropertyList eventProps = vEvent.getProperties();
1109:
1110: // UID
1111:
1112: Uid uid = new Uid(PortalUUIDUtil.generate());
1113:
1114: eventProps.add(uid);
1115:
1116: DtStart dtStart = new DtStart(
1117: new DateTime(event.getStartDate()));
1118:
1119: eventProps.add(dtStart);
1120:
1121: // Duration
1122:
1123: Calendar cal = Calendar.getInstance();
1124:
1125: Date start = cal.getTime();
1126:
1127: cal.add(Calendar.HOUR, event.getDurationHour());
1128: cal.add(Calendar.MINUTE, event.getDurationHour());
1129:
1130: Date end = cal.getTime();
1131:
1132: Duration duration = new Duration(start, end);
1133:
1134: eventProps.add(duration);
1135:
1136: // Summary
1137:
1138: Summary summary = new Summary(event.getTitle());
1139:
1140: eventProps.add(summary);
1141:
1142: // Description
1143:
1144: Description description = new Description(event
1145: .getDescription());
1146:
1147: eventProps.add(description);
1148:
1149: // Comment
1150:
1151: Comment comment = new Comment(event.getType());
1152:
1153: eventProps.add(comment);
1154:
1155: // Recurrence rule
1156:
1157: if (event.isRepeating()) {
1158: Recur recur = toICalRecurrence(event.getRecurrenceObj());
1159:
1160: RRule rRule = new RRule(recur);
1161:
1162: eventProps.add(rRule);
1163: }
1164:
1165: return vEvent;
1166: }
1167:
1168: protected WeekDay toICalWeekDay(int dayOfWeek) {
1169: WeekDay weekDay = null;
1170:
1171: if (dayOfWeek == Calendar.SUNDAY) {
1172: weekDay = WeekDay.SU;
1173: } else if (dayOfWeek == Calendar.MONDAY) {
1174: weekDay = WeekDay.MO;
1175: } else if (dayOfWeek == Calendar.TUESDAY) {
1176: weekDay = WeekDay.TU;
1177: } else if (dayOfWeek == Calendar.WEDNESDAY) {
1178: weekDay = WeekDay.WE;
1179: } else if (dayOfWeek == Calendar.THURSDAY) {
1180: weekDay = WeekDay.TH;
1181: } else if (dayOfWeek == Calendar.FRIDAY) {
1182: weekDay = WeekDay.FR;
1183: } else if (dayOfWeek == Calendar.SATURDAY) {
1184: weekDay = WeekDay.SA;
1185: }
1186:
1187: return weekDay;
1188: }
1189:
1190: protected TimeZone toTimeZone(long userId, VTimeZone vTimeZone)
1191: throws SystemException, NoSuchUserException {
1192:
1193: User user = userPersistence.findByPrimaryKey(userId);
1194:
1195: TimeZone timeZone = user.getTimeZone();
1196:
1197: timeZone = TimeZone.getTimeZone(vTimeZone.getTimeZoneId()
1198: .getValue());
1199:
1200: return timeZone;
1201: }
1202:
1203: protected Recurrence toRecurrence(Recur recur, TimeZone timeZone,
1204: Calendar startDate) {
1205:
1206: Calendar recStartCal = CalendarFactoryUtil
1207: .getCalendar(timeZone);
1208:
1209: recStartCal.setTime(startDate.getTime());
1210:
1211: Recurrence recurrence = new Recurrence(recStartCal,
1212: new com.liferay.portal.kernel.cal.Duration(1, 0, 0, 0));
1213:
1214: recurrence.setWeekStart(Calendar.SUNDAY);
1215:
1216: if (recur.getInterval() > 1) {
1217: recurrence.setInterval(recur.getInterval());
1218: }
1219:
1220: Calendar until = Calendar.getInstance(timeZone);
1221:
1222: if (recur.getUntil() != null) {
1223: until.setTime(recur.getUntil());
1224:
1225: recurrence.setUntil(until);
1226: }
1227:
1228: String frequency = recur.getFrequency();
1229:
1230: if (Recur.DAILY.equals(frequency)) {
1231: recurrence.setFrequency(Recurrence.DAILY);
1232:
1233: List dayPosList = new ArrayList();
1234:
1235: Iterator itr = recur.getDayList().iterator();
1236:
1237: while (itr.hasNext()) {
1238: WeekDay weekDay = (WeekDay) itr.next();
1239:
1240: dayPosList.add(new DayAndPosition(
1241: toCalendarWeekDay(weekDay), 0));
1242: }
1243:
1244: if (!dayPosList.isEmpty()) {
1245: recurrence.setByDay((DayAndPosition[]) dayPosList
1246: .toArray(new DayAndPosition[0]));
1247: }
1248: } else if (Recur.WEEKLY.equals(frequency)) {
1249: recurrence.setFrequency(Recurrence.WEEKLY);
1250:
1251: List dayPosList = new ArrayList();
1252:
1253: Iterator itr = recur.getDayList().iterator();
1254:
1255: while (itr.hasNext()) {
1256: WeekDay weekDay = (WeekDay) itr.next();
1257:
1258: dayPosList.add(new DayAndPosition(
1259: toCalendarWeekDay(weekDay), 0));
1260: }
1261:
1262: if (!dayPosList.isEmpty()) {
1263: recurrence.setByDay((DayAndPosition[]) dayPosList
1264: .toArray(new DayAndPosition[0]));
1265: }
1266: } else if (Recur.MONTHLY.equals(frequency)) {
1267: recurrence.setFrequency(Recurrence.MONTHLY);
1268:
1269: Iterator itr = recur.getMonthDayList().iterator();
1270:
1271: if (itr.hasNext()) {
1272: Integer monthDay = (Integer) itr.next();
1273:
1274: recurrence.setByMonthDay(new int[] { monthDay
1275: .intValue() });
1276: }
1277:
1278: itr = recur.getDayList().iterator();
1279:
1280: if (itr.hasNext()) {
1281: WeekDay weekDay = (WeekDay) itr.next();
1282:
1283: DayAndPosition[] dayPos = { new DayAndPosition(
1284: toCalendarWeekDay(weekDay), weekDay.getOffset()) };
1285:
1286: recurrence.setByDay(dayPos);
1287: }
1288: } else if (Recur.YEARLY.equals(frequency)) {
1289: recurrence.setFrequency(Recurrence.YEARLY);
1290: }
1291:
1292: return recurrence;
1293: }
1294:
1295: protected void validate(String title, int startDateMonth,
1296: int startDateDay, int startDateYear, int endDateMonth,
1297: int endDateDay, int endDateYear, int durationHour,
1298: int durationMinute, boolean allDay) throws PortalException,
1299: SystemException {
1300:
1301: if (Validator.isNull(title)) {
1302: throw new EventTitleException();
1303: } else if (!Validator.isDate(startDateMonth, startDateDay,
1304: startDateYear)) {
1305:
1306: throw new EventStartDateException();
1307: } else if (!Validator.isDate(endDateMonth, endDateDay,
1308: endDateYear)) {
1309: throw new EventEndDateException();
1310: }
1311:
1312: if (!allDay && durationHour <= 0 && durationMinute <= 0) {
1313: throw new EventDurationException();
1314: }
1315:
1316: Calendar startDate = CalendarFactoryUtil.getCalendar(
1317: startDateYear, startDateMonth, startDateDay);
1318:
1319: Calendar endDate = CalendarFactoryUtil.getCalendar(endDateYear,
1320: endDateMonth, endDateDay);
1321:
1322: if (startDate.after(endDate)) {
1323: throw new EventEndDateException();
1324: }
1325: }
1326:
1327: private static Log _log = LogFactory
1328: .getLog(CalEventLocalServiceImpl.class);
1329:
1330: }
|