List of usage examples for com.liferay.portal.kernel.cal TZSRecurrence getUntil
public Calendar getUntil()
From source file:com.liferay.calendar.service.impl.CalendarImporterLocalServiceImpl.java
License:Open Source License
protected String getRecurrence(TZSRecurrence tzsRecurrence) { if (tzsRecurrence == null) { return null; }/*from w w w . j av a 2 s . co m*/ Recurrence recurrence = new Recurrence(); Frequency frequency = _frequencyMap.get(tzsRecurrence.getFrequency()); int interval = tzsRecurrence.getInterval(); List<PositionalWeekday> positionalWeekdays = new ArrayList<PositionalWeekday>(); if ((frequency == Frequency.DAILY) && (interval == 0)) { frequency = Frequency.WEEKLY; interval = 1; positionalWeekdays.add(new PositionalWeekday(Weekday.MONDAY, 0)); positionalWeekdays.add(new PositionalWeekday(Weekday.TUESDAY, 0)); positionalWeekdays.add(new PositionalWeekday(Weekday.WEDNESDAY, 0)); positionalWeekdays.add(new PositionalWeekday(Weekday.THURSDAY, 0)); positionalWeekdays.add(new PositionalWeekday(Weekday.FRIDAY, 0)); } else { DayAndPosition[] dayAndPositions = tzsRecurrence.getByDay(); if (dayAndPositions != null) { for (DayAndPosition dayAndPosition : dayAndPositions) { Weekday weekday = _weekdayMap.get(dayAndPosition.getDayOfWeek()); PositionalWeekday positionalWeekday = new PositionalWeekday(weekday, dayAndPosition.getDayPosition()); positionalWeekdays.add(positionalWeekday); } } int[] months = tzsRecurrence.getByMonth(); if (ArrayUtil.isNotEmpty(months)) { List<Integer> monthsList = new ArrayList<Integer>(); for (int month : months) { monthsList.add(month + 1); } recurrence.setMonths(monthsList); } } recurrence.setInterval(interval); recurrence.setFrequency(frequency); recurrence.setPositionalWeekdays(positionalWeekdays); Calendar untilJCalendar = tzsRecurrence.getUntil(); int ocurrence = tzsRecurrence.getOccurrence(); if (untilJCalendar != null) { recurrence.setUntilJCalendar(untilJCalendar); } else if (ocurrence > 0) { recurrence.setCount(ocurrence); } return RecurrenceSerializer.serialize(recurrence); }
From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java
License:Open Source License
protected void importICal4j(long userId, long groupId, VEvent event) throws PortalException, SystemException { User user = userPersistence.findByPrimaryKey(userId); TimeZone timeZone = user.getTimeZone(); // X iCal property Property timeZoneXProperty = event.getProperty(TimeZoneSensitive.PROPERTY_NAME); boolean timeZoneXPropertyValue = true; if ((timeZoneXProperty != null) && timeZoneXProperty.getValue().equals("FALSE")) { timeZoneXPropertyValue = false;/*from ww w. ja v a 2 s . c om*/ } // Title String title = StringPool.BLANK; if (event.getSummary() != null) { title = ModelHintsUtil.trimString(CalEvent.class.getName(), "title", event.getSummary().getValue()); } // Description String description = StringPool.BLANK; if (event.getDescription() != null) { description = event.getDescription().getValue(); } // Location String location = StringPool.BLANK; if (event.getLocation() != null) { location = event.getLocation().getValue(); } // Start date DtStart dtStart = event.getStartDate(); Calendar startDate = toCalendar(dtStart, timeZone, timeZoneXPropertyValue); startDate.setTime(dtStart.getDate()); // End date Calendar endDate = null; DtEnd dtEnd = event.getEndDate(true); RRule rrule = (RRule) event.getProperty(Property.RRULE); if (dtEnd != null) { endDate = toCalendar(dtEnd, timeZone, timeZoneXPropertyValue); endDate.setTime(dtEnd.getDate()); } else { endDate = (Calendar) startDate.clone(); endDate.add(Calendar.DATE, 1); } // Duration long diffMillis = 0; long durationHours = 24; long durationMins = 0; boolean multiDayEvent = false; if (dtEnd != null) { diffMillis = dtEnd.getDate().getTime() - startDate.getTimeInMillis(); durationHours = diffMillis / Time.HOUR; durationMins = (diffMillis / Time.MINUTE) - (durationHours * 60); if ((durationHours > 24) || ((durationHours == 24) && (durationMins > 0))) { durationHours = 24; durationMins = 0; multiDayEvent = true; } } // All day boolean allDay = false; if (isICal4jDateOnly(event.getStartDate()) || multiDayEvent) { allDay = true; } // Time zone sensitive boolean timeZoneSensitive = true; if (allDay || !timeZoneXPropertyValue) { timeZoneSensitive = false; } // Type String type = StringPool.BLANK; Property comment = event.getProperty(Property.COMMENT); if ((comment != null) && ArrayUtil.contains(CalEventConstants.TYPES, comment.getValue())) { type = comment.getValue(); } // Recurrence boolean repeating = false; TZSRecurrence recurrence = null; if (multiDayEvent) { repeating = true; Calendar recStartCal = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC)); recStartCal.setTime(startDate.getTime()); com.liferay.portal.kernel.cal.Duration duration = new com.liferay.portal.kernel.cal.Duration(1, 0, 0, 0); recurrence = new TZSRecurrence(recStartCal, duration, Recurrence.DAILY); Calendar until = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC)); until.setTimeInMillis(until.getTimeInMillis() + diffMillis); recurrence.setUntil(until); endDate.setTime(recurrence.getUntil().getTime()); } else if (rrule != null) { repeating = true; recurrence = toRecurrence(rrule, startDate); if (recurrence.getUntil() != null) { endDate.setTime(recurrence.getUntil().getTime()); } } // Reminder int remindBy = CalEventConstants.REMIND_BY_NONE; int firstReminder = 300000; int secondReminder = 300000; // Permissions ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(groupId); // Merge event String uuid = null; CalEvent existingEvent = null; if (event.getUid() != null) { Uid uid = event.getUid(); if (existingEvent == null) { // VEvent exported by Liferay portal uuid = uid.getValue(); existingEvent = calEventPersistence.fetchByUUID_G(uuid, groupId); } if (existingEvent == null) { // VEvent exported by external application uuid = PortalUUIDUtil.generate(uid.getValue().getBytes()); existingEvent = calEventPersistence.fetchByUUID_G(uuid, groupId); } } int startDateMonth = startDate.get(Calendar.MONTH); int startDateDay = startDate.get(Calendar.DAY_OF_MONTH); int startDateYear = startDate.get(Calendar.YEAR); int startDateHour = startDate.get(Calendar.HOUR_OF_DAY); int startDateMinute = startDate.get(Calendar.MINUTE); int endDateMonth = endDate.get(Calendar.MONTH); int endDateDay = endDate.get(Calendar.DAY_OF_MONTH); int endDateYear = endDate.get(Calendar.YEAR); int durationHour = (int) durationHours; int durationMinute = (int) durationMins; if (existingEvent == null) { serviceContext.setUuid(uuid); addEvent(userId, title, description, location, startDateMonth, startDateDay, startDateYear, startDateHour, startDateMinute, endDateMonth, endDateDay, endDateYear, durationHour, durationMinute, allDay, timeZoneSensitive, type, repeating, recurrence, remindBy, firstReminder, secondReminder, serviceContext); } else { updateEvent(userId, existingEvent.getEventId(), title, description, location, startDateMonth, startDateDay, startDateYear, startDateHour, startDateMinute, endDateMonth, endDateDay, endDateYear, durationHour, durationMinute, allDay, timeZoneSensitive, type, repeating, recurrence, remindBy, firstReminder, secondReminder, serviceContext); } }
From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java
License:Open Source License
protected Recur toICalRecurrence(TZSRecurrence recurrence) { Recur recur = null;// w w w. j av a 2 s . c o m int recurrenceType = recurrence.getFrequency(); int interval = recurrence.getInterval(); if (recurrenceType == Recurrence.DAILY) { recur = new Recur(Recur.DAILY, -1); if (interval >= 1) { recur.setInterval(interval); } DayAndPosition[] byDay = recurrence.getByDay(); if (byDay != null) { for (int i = 0; i < byDay.length; i++) { WeekDay weekDay = toICalWeekDay(byDay[i].getDayOfWeek()); recur.getDayList().add(weekDay); } } } else if (recurrenceType == Recurrence.WEEKLY) { recur = new Recur(Recur.WEEKLY, -1); recur.setInterval(interval); DayAndPosition[] byDay = recurrence.getByDay(); if (byDay != null) { for (int i = 0; i < byDay.length; i++) { WeekDay weekDay = toICalWeekDay(byDay[i].getDayOfWeek()); recur.getDayList().add(weekDay); } } } else if (recurrenceType == Recurrence.MONTHLY) { recur = new Recur(Recur.MONTHLY, -1); recur.setInterval(interval); int[] byMonthDay = recurrence.getByMonthDay(); if (byMonthDay != null) { Integer monthDay = new Integer(byMonthDay[0]); recur.getMonthDayList().add(monthDay); } else if (recurrence.getByDay() != null) { DayAndPosition[] byDay = recurrence.getByDay(); WeekDay weekDay = toICalWeekDay(byDay[0].getDayOfWeek()); recur.getDayList().add(weekDay); Integer position = new Integer(byDay[0].getDayPosition()); recur.getSetPosList().add(position); } } else if (recurrenceType == Recurrence.YEARLY) { recur = new Recur(Recur.YEARLY, -1); recur.setInterval(interval); } Calendar until = recurrence.getUntil(); if (until != null) { DateTime dateTime = new DateTime(until.getTime()); recur.setUntil(dateTime); } return recur; }
From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java
License:Open Source License
protected void validate(String title, int startDateMonth, int startDateDay, int startDateYear, int endDateMonth, int endDateDay, int endDateYear, int durationHour, int durationMinute, boolean allDay, boolean repeating, TZSRecurrence recurrence) throws PortalException { if (Validator.isNull(title)) { throw new EventTitleException(); } else if (!Validator.isDate(startDateMonth, startDateDay, startDateYear)) { throw new EventStartDateException(); } else if (!Validator.isDate(endDateMonth, endDateDay, endDateYear)) { throw new EventEndDateException(); }/*from w w w. j a v a2s . c o m*/ if (!allDay && durationHour <= 0 && durationMinute <= 0) { throw new EventDurationException(); } Calendar startDate = CalendarFactoryUtil.getCalendar(startDateYear, startDateMonth, startDateDay); if (repeating) { Calendar until = recurrence.getUntil(); if (startDate.after(until)) { throw new EventEndDateException(); } } }