Example usage for com.liferay.portal.kernel.cal TZSRecurrence isInRecurrence

List of usage examples for com.liferay.portal.kernel.cal TZSRecurrence isInRecurrence

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.cal TZSRecurrence isInRecurrence.

Prototype

public boolean isInRecurrence(Calendar current) 

Source Link

Document

Method isInRecurrence

Usage

From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java

License:Open Source License

public List<CalEvent> getRepeatingEvents(long groupId, Calendar cal, String[] types) throws SystemException {

    Map<String, List<CalEvent>> eventsPool = CalEventLocalUtil.getEventsPool(groupId);

    String key = "recurrence".concat(CalUtil.toString(null, types));

    List<CalEvent> events = eventsPool.get(key);

    if (events == null) {
        if ((types != null) && (types.length > 0) && ((types.length > 1) || Validator.isNotNull(types[0]))) {

            events = calEventPersistence.findByG_T_R(groupId, types, true);
        } else {/* www .  ja  v  a 2s  . c o m*/
            events = calEventPersistence.findByG_R(groupId, true);
        }

        events = new UnmodifiableList<CalEvent>(events);

        eventsPool.put(key, events);
    }

    if (cal != null) {

        // Time zone insensitive

        Calendar tzICal = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC));

        tzICal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));

        Iterator<CalEvent> itr = events.iterator();

        List<CalEvent> repeatingEvents = new ArrayList<CalEvent>();

        while (itr.hasNext()) {
            CalEvent event = itr.next();

            TZSRecurrence recurrence = event.getRecurrenceObj();

            try {

                // LEP-3468

                if ((recurrence.getFrequency() != Recurrence.NO_RECURRENCE)
                        && (recurrence.getInterval() <= 0)) {

                    recurrence.setInterval(1);

                    event.setRecurrenceObj(recurrence);

                    event = calEventPersistence.update(event, false);

                    recurrence = event.getRecurrenceObj();
                }

                if (recurrence.isInRecurrence(getRecurrenceCal(cal, tzICal, event))) {

                    repeatingEvents.add(event);
                }
            } catch (Exception e) {
                _log.error(e, e);
            }
        }

        events = new UnmodifiableList<CalEvent>(repeatingEvents);
    }

    return events;
}