Example usage for com.liferay.portal.kernel.cal Recurrence DAILY

List of usage examples for com.liferay.portal.kernel.cal Recurrence DAILY

Introduction

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

Prototype

int DAILY

To view the source code for com.liferay.portal.kernel.cal Recurrence DAILY.

Click Source Link

Document

Field DAILY

Usage

From source file:com.liferay.portlet.calendar.action.EditEventAction.java

License:Open Source License

protected void updateEvent(ActionRequest actionRequest) throws Exception {
    long eventId = ParamUtil.getLong(actionRequest, "eventId");

    String title = ParamUtil.getString(actionRequest, "title");
    String description = ParamUtil.getString(actionRequest, "description");
    String location = ParamUtil.getString(actionRequest, "location");

    int startDateMonth = ParamUtil.getInteger(actionRequest, "startDateMonth");
    int startDateDay = ParamUtil.getInteger(actionRequest, "startDateDay");
    int startDateYear = ParamUtil.getInteger(actionRequest, "startDateYear");
    int startDateHour = ParamUtil.getInteger(actionRequest, "startDateHour");
    int startDateMinute = ParamUtil.getInteger(actionRequest, "startDateMinute");
    int startDateAmPm = ParamUtil.getInteger(actionRequest, "startDateAmPm");

    if (startDateAmPm == Calendar.PM) {
        startDateHour += 12;//from   w ww . j a v  a 2  s.  co m
    }

    int durationHour = ParamUtil.getInteger(actionRequest, "durationHour");
    int durationMinute = ParamUtil.getInteger(actionRequest, "durationMinute");
    boolean allDay = ParamUtil.getBoolean(actionRequest, "allDay");
    boolean timeZoneSensitive = ParamUtil.getBoolean(actionRequest, "timeZoneSensitive");
    String type = ParamUtil.getString(actionRequest, "type");

    int endDateMonth = ParamUtil.getInteger(actionRequest, "endDateMonth");
    int endDateDay = ParamUtil.getInteger(actionRequest, "endDateDay");
    int endDateYear = ParamUtil.getInteger(actionRequest, "endDateYear");

    boolean repeating = false;

    int recurrenceType = ParamUtil.getInteger(actionRequest, "recurrenceType");

    if (recurrenceType != Recurrence.NO_RECURRENCE) {
        repeating = true;
    }

    Locale locale = null;
    TimeZone timeZone = null;

    if (timeZoneSensitive) {
        User user = PortalUtil.getUser(actionRequest);

        locale = user.getLocale();
        timeZone = user.getTimeZone();
    } else {
        locale = LocaleUtil.getDefault();
        timeZone = TimeZoneUtil.getDefault();
    }

    Calendar startDate = CalendarFactoryUtil.getCalendar(timeZone, locale);

    startDate.set(Calendar.MONTH, startDateMonth);
    startDate.set(Calendar.DATE, startDateDay);
    startDate.set(Calendar.YEAR, startDateYear);
    startDate.set(Calendar.HOUR_OF_DAY, startDateHour);
    startDate.set(Calendar.MINUTE, startDateMinute);
    startDate.set(Calendar.SECOND, 0);
    startDate.set(Calendar.MILLISECOND, 0);

    if (allDay) {
        startDate.set(Calendar.HOUR_OF_DAY, 0);
        startDate.set(Calendar.MINUTE, 0);
        startDate.set(Calendar.SECOND, 0);
        startDate.set(Calendar.MILLISECOND, 0);

        durationHour = 24;
        durationMinute = 0;
    }

    TZSRecurrence recurrence = null;

    if (repeating) {
        Calendar recStartCal = null;

        if (timeZoneSensitive) {
            recStartCal = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC));

            recStartCal.setTime(startDate.getTime());
        } else {
            recStartCal = (Calendar) startDate.clone();
        }

        recurrence = new TZSRecurrence(recStartCal, new Duration(1, 0, 0, 0), recurrenceType);

        recurrence.setTimeZone(timeZone);

        recurrence.setWeekStart(Calendar.SUNDAY);

        if (recurrenceType == Recurrence.DAILY) {
            int dailyType = ParamUtil.getInteger(actionRequest, "dailyType");

            if (dailyType == 0) {
                int dailyInterval = ParamUtil.getInteger(actionRequest, "dailyInterval", 1);

                recurrence.setInterval(dailyInterval);
            } else {
                DayAndPosition[] dayPos = { new DayAndPosition(Calendar.MONDAY, 0),
                        new DayAndPosition(Calendar.TUESDAY, 0), new DayAndPosition(Calendar.WEDNESDAY, 0),
                        new DayAndPosition(Calendar.THURSDAY, 0), new DayAndPosition(Calendar.FRIDAY, 0) };

                recurrence.setByDay(dayPos);
            }
        } else if (recurrenceType == Recurrence.WEEKLY) {
            int weeklyInterval = ParamUtil.getInteger(actionRequest, "weeklyInterval", 1);

            recurrence.setInterval(weeklyInterval);

            List<DayAndPosition> dayPos = new ArrayList<DayAndPosition>();

            addWeeklyDayPos(actionRequest, dayPos, Calendar.SUNDAY);
            addWeeklyDayPos(actionRequest, dayPos, Calendar.MONDAY);
            addWeeklyDayPos(actionRequest, dayPos, Calendar.TUESDAY);
            addWeeklyDayPos(actionRequest, dayPos, Calendar.WEDNESDAY);
            addWeeklyDayPos(actionRequest, dayPos, Calendar.THURSDAY);
            addWeeklyDayPos(actionRequest, dayPos, Calendar.FRIDAY);
            addWeeklyDayPos(actionRequest, dayPos, Calendar.SATURDAY);

            if (dayPos.size() == 0) {
                dayPos.add(new DayAndPosition(Calendar.MONDAY, 0));
            }

            recurrence.setByDay(dayPos.toArray(new DayAndPosition[0]));
        } else if (recurrenceType == Recurrence.MONTHLY) {
            int monthlyType = ParamUtil.getInteger(actionRequest, "monthlyType");

            if (monthlyType == 0) {
                int monthlyDay = ParamUtil.getInteger(actionRequest, "monthlyDay0");

                recurrence.setByMonthDay(new int[] { monthlyDay });

                int monthlyInterval = ParamUtil.getInteger(actionRequest, "monthlyInterval0", 1);

                recurrence.setInterval(monthlyInterval);
            } else {
                int monthlyPos = ParamUtil.getInteger(actionRequest, "monthlyPos");
                int monthlyDay = ParamUtil.getInteger(actionRequest, "monthlyDay1");

                DayAndPosition[] dayPos = { new DayAndPosition(monthlyDay, monthlyPos) };

                recurrence.setByDay(dayPos);

                int monthlyInterval = ParamUtil.getInteger(actionRequest, "monthlyInterval1", 1);

                recurrence.setInterval(monthlyInterval);
            }
        } else if (recurrenceType == Recurrence.YEARLY) {
            int yearlyType = ParamUtil.getInteger(actionRequest, "yearlyType");

            if (yearlyType == 0) {
                int yearlyMonth = ParamUtil.getInteger(actionRequest, "yearlyMonth0");
                int yearlyDay = ParamUtil.getInteger(actionRequest, "yearlyDay0");

                recurrence.setByMonth(new int[] { yearlyMonth });
                recurrence.setByMonthDay(new int[] { yearlyDay });

                int yearlyInterval = ParamUtil.getInteger(actionRequest, "yearlyInterval0", 1);

                recurrence.setInterval(yearlyInterval);
            } else {
                int yearlyPos = ParamUtil.getInteger(actionRequest, "yearlyPos");
                int yearlyDay = ParamUtil.getInteger(actionRequest, "yearlyDay1");
                int yearlyMonth = ParamUtil.getInteger(actionRequest, "yearlyMonth1");

                DayAndPosition[] dayPos = { new DayAndPosition(yearlyDay, yearlyPos) };

                recurrence.setByDay(dayPos);

                recurrence.setByMonth(new int[] { yearlyMonth });

                int yearlyInterval = ParamUtil.getInteger(actionRequest, "yearlyInterval1", 1);

                recurrence.setInterval(yearlyInterval);
            }
        }

        int endDateType = ParamUtil.getInteger(actionRequest, "endDateType");

        if (endDateType == 1) {
            int endDateOccurrence = ParamUtil.getInteger(actionRequest, "endDateOccurrence");

            recurrence.setOccurrence(endDateOccurrence);
        } else if (endDateType == 2) {
            Calendar endDate = CalendarFactoryUtil.getCalendar(timeZone);

            endDate.set(Calendar.MONTH, endDateMonth);
            endDate.set(Calendar.DATE, endDateDay);
            endDate.set(Calendar.YEAR, endDateYear);
            endDate.set(Calendar.HOUR_OF_DAY, startDateHour);
            endDate.set(Calendar.MINUTE, startDateMinute);
            endDate.set(Calendar.SECOND, 0);
            endDate.set(Calendar.MILLISECOND, 0);

            Calendar recEndCal = null;

            if (timeZoneSensitive) {
                recEndCal = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC));

                recEndCal.setTime(endDate.getTime());
            } else {
                recEndCal = (Calendar) endDate.clone();
            }

            recurrence.setUntil(recEndCal);
        }
    }

    int remindBy = ParamUtil.getInteger(actionRequest, "remindBy");
    int firstReminder = ParamUtil.getInteger(actionRequest, "firstReminder");
    int secondReminder = ParamUtil.getInteger(actionRequest, "secondReminder");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(CalEvent.class.getName(), actionRequest);

    if (eventId <= 0) {

        // Add event

        CalEvent event = CalEventServiceUtil.addEvent(title, description, location, startDateMonth,
                startDateDay, startDateYear, startDateHour, startDateMinute, endDateMonth, endDateDay,
                endDateYear, durationHour, durationMinute, allDay, timeZoneSensitive, type, repeating,
                recurrence, remindBy, firstReminder, secondReminder, serviceContext);

        AssetPublisherUtil.addAndStoreSelection(actionRequest, CalEvent.class.getName(), event.getEventId(),
                -1);
    } else {

        // Update event

        CalEventServiceUtil.updateEvent(eventId, 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 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 2s  .  c o  m*/
    }

    // 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;/*from   www.  jav  a  2  s . com*/

    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 TZSRecurrence toRecurrence(RRule rRule, Calendar startDate) {
    Recur recur = rRule.getRecur();/* w ww.j a  v  a  2 s  . c o  m*/

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

    recStartCal.setTime(startDate.getTime());

    TZSRecurrence recurrence = new TZSRecurrence(recStartCal,
            new com.liferay.portal.kernel.cal.Duration(1, 0, 0, 0));

    recurrence.setWeekStart(Calendar.SUNDAY);

    if (recur.getInterval() > 1) {
        recurrence.setInterval(recur.getInterval());
    }

    Calendar until = Calendar.getInstance(TimeZoneUtil.getTimeZone(StringPool.UTC));

    String frequency = recur.getFrequency();

    if (recur.getUntil() != null) {
        until.setTime(recur.getUntil());

        recurrence.setUntil(until);
    } else if (rRule.getValue().indexOf("COUNT") >= 0) {
        until.setTimeInMillis(startDate.getTimeInMillis());

        int addField = 0;

        if (Recur.DAILY.equals(frequency)) {
            addField = Calendar.DAY_OF_YEAR;
        } else if (Recur.WEEKLY.equals(frequency)) {
            addField = Calendar.WEEK_OF_YEAR;
        } else if (Recur.MONTHLY.equals(frequency)) {
            addField = Calendar.MONTH;
        } else if (Recur.YEARLY.equals(frequency)) {
            addField = Calendar.YEAR;
        }

        int addAmount = recurrence.getInterval() * recur.getCount();

        until.add(addField, addAmount);
        until.add(Calendar.DAY_OF_YEAR, -1);

        recurrence.setUntil(until);
    }

    if (Recur.DAILY.equals(frequency)) {
        recurrence.setFrequency(Recurrence.DAILY);

        List<DayAndPosition> dayPosList = new ArrayList<DayAndPosition>();

        Iterator<WeekDay> itr = recur.getDayList().iterator();

        while (itr.hasNext()) {
            WeekDay weekDay = itr.next();

            dayPosList.add(new DayAndPosition(toCalendarWeekDay(weekDay), 0));
        }

        if (!dayPosList.isEmpty()) {
            recurrence.setByDay(dayPosList.toArray(new DayAndPosition[dayPosList.size()]));
        }
    } else if (Recur.WEEKLY.equals(frequency)) {
        recurrence.setFrequency(Recurrence.WEEKLY);

        List<DayAndPosition> dayPosList = new ArrayList<DayAndPosition>();

        Iterator<WeekDay> itr = recur.getDayList().iterator();

        while (itr.hasNext()) {
            WeekDay weekDay = itr.next();

            dayPosList.add(new DayAndPosition(toCalendarWeekDay(weekDay), 0));
        }

        if (!dayPosList.isEmpty()) {
            recurrence.setByDay(dayPosList.toArray(new DayAndPosition[dayPosList.size()]));
        }
    } else if (Recur.MONTHLY.equals(frequency)) {
        recurrence.setFrequency(Recurrence.MONTHLY);

        Iterator<Integer> monthDayListItr = recur.getMonthDayList().iterator();

        if (monthDayListItr.hasNext()) {
            Integer monthDay = monthDayListItr.next();

            recurrence.setByMonthDay(new int[] { monthDay.intValue() });
        }

        Iterator<WeekDay> dayListItr = recur.getDayList().iterator();

        if (dayListItr.hasNext()) {
            WeekDay weekDay = dayListItr.next();

            DayAndPosition[] dayPos = { new DayAndPosition(toCalendarWeekDay(weekDay), weekDay.getOffset()) };

            recurrence.setByDay(dayPos);
        }
    } else if (Recur.YEARLY.equals(frequency)) {
        recurrence.setFrequency(Recurrence.YEARLY);
    }

    return recurrence;
}