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

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

Introduction

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

Prototype

public int getOccurrence() 

Source Link

Document

Method getOccurrence

Usage

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.  ja  v a 2 s .c o 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);
}