Example usage for com.liferay.portal.kernel.util StringPool UTC

List of usage examples for com.liferay.portal.kernel.util StringPool UTC

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool UTC.

Prototype

String UTC

To view the source code for com.liferay.portal.kernel.util StringPool UTC.

Click Source Link

Usage

From source file:com.liferay.calendar.portlet.CalendarPortlet.java

License:Open Source License

protected TimeZone getTimeZone(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    boolean allDay = ParamUtil.getBoolean(portletRequest, "allDay");

    if (allDay) {
        return TimeZoneUtil.getTimeZone(StringPool.UTC);
    }//  www.j  a  v a  2  s .  c  o  m

    PortletPreferences preferences = portletRequest.getPreferences();

    User user = themeDisplay.getUser();

    String timeZoneId = preferences.getValue("timeZoneId", user.getTimeZoneId());

    if (Validator.isNull(timeZoneId)) {
        timeZoneId = user.getTimeZoneId();
    }

    return TimeZone.getTimeZone(timeZoneId);
}

From source file:com.liferay.calendar.recurrence.RecurrenceSerializer.java

License:Open Source License

public static Recurrence deserialize(String data) {
    try {// w  w  w . j a va2 s. c o  m
        Recurrence recurrence = new Recurrence();

        int index = data.indexOf(StringPool.NEW_LINE);

        if (index != -1) {
            String exceptionDates = data.substring(index + 1, data.length());

            RDateList rDateList = new RDateList(exceptionDates, TimeZone.getTimeZone(StringPool.UTC));

            for (DateValue dateValue : rDateList.getDatesUtc()) {
                Calendar jCalendar = _toJCalendar(dateValue);

                recurrence.addExceptionDate(jCalendar);
            }

            data = data.substring(0, index);
        }

        RRule rRule = new RRule(data);

        recurrence.setCount(rRule.getCount());
        recurrence.setFrequency(Frequency.parse(String.valueOf(rRule.getFreq())));
        recurrence.setInterval(rRule.getInterval());

        DateValue dateValue = rRule.getUntil();

        if (dateValue != null) {
            Calendar jCalendar = _toJCalendar(dateValue);

            recurrence.setUntilJCalendar(jCalendar);
        }

        List<PositionalWeekday> positionalWeekdays = new ArrayList<PositionalWeekday>();

        for (WeekdayNum weekdayNum : rRule.getByDay()) {
            Weekday weekday = Weekday.parse(weekdayNum.wday.toString());

            PositionalWeekday positionalWeekday = new PositionalWeekday(weekday, weekdayNum.num);

            positionalWeekdays.add(positionalWeekday);
        }

        recurrence.setPositionalWeekdays(positionalWeekdays);

        recurrence.setMonths(ListUtil.toList(rRule.getByMonth()));

        return recurrence;
    } catch (ParseException pe) {
        _log.error("Unable to parse data " + data, pe);
    }

    return null;
}

From source file:com.liferay.calendar.recurrence.RecurrenceSerializer.java

License:Open Source License

public static String serialize(Recurrence recurrence) {
    RRule rRule = new RRule();

    List<WeekdayNum> weekdayNums = new ArrayList<WeekdayNum>();

    for (PositionalWeekday positionalWeekday : recurrence.getPositionalWeekdays()) {

        com.google.ical.values.Weekday wday = _weekdaysMap.get(positionalWeekday.getWeekday());

        WeekdayNum weekdayNum = new WeekdayNum(positionalWeekday.getPosition(), wday);

        weekdayNums.add(weekdayNum);/* ww w  .j a  v  a2s  .  co m*/
    }

    rRule.setByDay(weekdayNums);

    List<Integer> months = recurrence.getMonths();

    if (months != null) {
        rRule.setByMonth(ArrayUtil.toIntArray(months));
    }

    rRule.setCount(recurrence.getCount());

    com.google.ical.values.Frequency frequency = com.google.ical.values.Frequency
            .valueOf(String.valueOf(recurrence.getFrequency()));

    rRule.setFreq(frequency);

    rRule.setInterval(recurrence.getInterval());

    Calendar jCalendar = recurrence.getUntilJCalendar();

    if (jCalendar != null) {
        DateValue dateValue = _toDateValue(jCalendar);

        rRule.setUntil(dateValue);
    }

    String data = rRule.toIcal();

    List<Calendar> exceptionJCalendars = recurrence.getExceptionJCalendars();

    if (!exceptionJCalendars.isEmpty()) {
        DateValue[] dateValues = new DateValue[exceptionJCalendars.size()];

        for (int i = 0; i < exceptionJCalendars.size(); i++) {
            dateValues[i] = _toDateValue(exceptionJCalendars.get(i));
        }

        RDateList rDateList = new RDateList(TimeZone.getTimeZone(StringPool.UTC));

        rDateList.setDatesUtc(dateValues);
        rDateList.setName(_EXDATE);

        data = data.concat(StringPool.NEW_LINE).concat(rDateList.toIcal());
    }

    return data;
}

From source file:com.liferay.calendar.recurrence.RecurrenceSerializer.java

License:Open Source License

private static Calendar _toJCalendar(DateValue dateValue) {
    Calendar jCalendar = CalendarFactoryUtil.getCalendar(TimeZone.getTimeZone(StringPool.UTC));

    jCalendar.set(Calendar.DATE, dateValue.day());
    jCalendar.set(Calendar.MONTH, dateValue.month() - 1);
    jCalendar.set(Calendar.YEAR, dateValue.year());

    if (dateValue instanceof DateTimeValue) {
        DateTimeValue dateTimeValue = (DateTimeValue) dateValue;

        jCalendar.set(Calendar.HOUR_OF_DAY, dateTimeValue.hour());
        jCalendar.set(Calendar.MINUTE, dateTimeValue.minute());
        jCalendar.set(Calendar.SECOND, dateTimeValue.second());
    }/*from   ww  w  . ja  v a2 s .  c  o m*/

    return jCalendar;
}

From source file:com.liferay.calendar.search.test.CalendarBookingIndexerTest.java

License:Open Source License

protected void addCalendarBooking(LocalizedValuesMap titleMap) {
    try {/*from w  w w.j  av a 2s  . c  o m*/
        ServiceContext serviceContext = new ServiceContext();

        CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
                serviceContext);

        Calendar calendar = CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
                calendarResource.getCalendarResourceId(), RandomTestUtil.randomLocaleStringMap(),
                RandomTestUtil.randomLocaleStringMap(), StringPool.UTC, RandomTestUtil.randomInt(0, 255), false,
                false, false, serviceContext);

        long startTime = DateUtil.newTime() + RandomTestUtil.randomInt();

        long endTime = startTime + Time.HOUR;

        HashMap<Locale, String> hashMap = new HashMap<>();

        CalendarBookingLocalServiceUtil.addCalendarBooking(_user.getUserId(), calendar.getCalendarId(),
                new long[0], CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, 0,
                titleMap.getValues(), hashMap, null, startTime, endTime, false, null, 0, "email", 0, "email",
                serviceContext);
    } catch (PortalException pe) {
        throw new RuntimeException(pe);
    }
}

From source file:com.liferay.calendar.search.test.CalendarFixture.java

License:Open Source License

public Calendar addCalendar(LocalizedValuesMap nameLocalizedValuesMap,
        LocalizedValuesMap descriptionLocalizedValuesMap, ServiceContext serviceContext)
        throws PortalException {

    CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
            serviceContext);/*from  ww w  . j  a va2  s  .  com*/

    Calendar calendar = _calendarLocalService.addCalendar(serviceContext.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), nameLocalizedValuesMap.getValues(),
            descriptionLocalizedValuesMap.getValues(), StringPool.UTC, RandomTestUtil.randomInt(0, 255), false,
            false, false, serviceContext);

    _calendars.add(calendar);

    return calendar;
}

From source file:com.liferay.calendar.search.test.CalendarSearcherTest.java

License:Open Source License

protected void addCalendar(String name, String description) throws PortalException {

    ServiceContext serviceContext = new ServiceContext();

    CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
            serviceContext);/*from  w w  w  .j  a va2s.c  o m*/

    Map<Locale, String> nameMap = new HashMap<>();

    nameMap.put(LocaleUtil.getDefault(), name);

    Map<Locale, String> descriptionMap = new HashMap<>();

    descriptionMap.put(LocaleUtil.getDefault(), description);

    CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), nameMap, descriptionMap, StringPool.UTC,
            RandomTestUtil.randomInt(0, 255), false, false, false, serviceContext);
}

From source file:com.liferay.calendar.service.impl.CalendarBookingServiceImpl.java

License:Open Source License

@Override
public CalendarBooking addCalendarBooking(long calendarId, long[] childCalendarIds,
        long parentCalendarBookingId, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
        String location, int startTimeYear, int startTimeMonth, int startTimeDay, int startTimeHour,
        int startTimeMinute, int endTimeYear, int endTimeMonth, int endTimeDay, int endTimeHour,
        int endTimeMinute, String timeZoneId, boolean allDay, String recurrence, long firstReminder,
        String firstReminderType, long secondReminder, String secondReminderType, ServiceContext serviceContext)
        throws PortalException {

    TimeZone timeZone = TimeZoneUtil.getTimeZone(timeZoneId);

    if (allDay) {
        timeZone = TimeZone.getTimeZone(StringPool.UTC);
    }//from  w w  w  .  j ava2  s  .c o  m

    java.util.Calendar startTimeJCalendar = JCalendarUtil.getJCalendar(startTimeYear, startTimeMonth,
            startTimeDay, startTimeHour, startTimeMinute, 0, 0, timeZone);
    java.util.Calendar endTimeJCalendar = JCalendarUtil.getJCalendar(endTimeYear, endTimeMonth, endTimeDay,
            endTimeHour, endTimeMinute, 0, 0, timeZone);

    return calendarBookingService.addCalendarBooking(calendarId, childCalendarIds, parentCalendarBookingId,
            titleMap, descriptionMap, location, startTimeJCalendar.getTimeInMillis(),
            endTimeJCalendar.getTimeInMillis(), allDay, recurrence, firstReminder, firstReminderType,
            secondReminder, secondReminderType, serviceContext);
}

From source file:com.liferay.calendar.service.impl.CalendarBookingServiceImpl.java

License:Open Source License

@Override
public CalendarBooking updateCalendarBookingInstance(long calendarBookingId, int instanceIndex, long calendarId,
        Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String location, int startTimeYear,
        int startTimeMonth, int startTimeDay, int startTimeHour, int startTimeMinute, int endTimeYear,
        int endTimeMonth, int endTimeDay, int endTimeHour, int endTimeMinute, String timeZoneId, boolean allDay,
        String recurrence, boolean allFollowing, long firstReminder, String firstReminderType,
        long secondReminder, String secondReminderType, int status, ServiceContext serviceContext)
        throws PortalException {

    TimeZone timeZone = TimeZoneUtil.getTimeZone(timeZoneId);

    if (allDay) {
        timeZone = TimeZone.getTimeZone(StringPool.UTC);
    }/* ww  w  .ja  v a 2 s.c  o  m*/

    java.util.Calendar startTimeJCalendar = JCalendarUtil.getJCalendar(startTimeYear, startTimeMonth,
            startTimeDay, startTimeHour, startTimeMinute, 0, 0, timeZone);

    java.util.Calendar endTimeJCalendar = JCalendarUtil.getJCalendar(endTimeYear, endTimeMonth, endTimeDay,
            endTimeHour, endTimeMinute, 0, 0, timeZone);

    return calendarBookingService.updateCalendarBookingInstance(calendarBookingId, instanceIndex, calendarId,
            titleMap, descriptionMap, location, startTimeJCalendar.getTimeInMillis(),
            endTimeJCalendar.getTimeInMillis(), allDay, recurrence, allFollowing, firstReminder,
            firstReminderType, secondReminder, secondReminderType, status, serviceContext);
}

From source file:com.liferay.calendar.service.test.CalendarLocalServiceTest.java

License:Open Source License

@Test
public void testSearch() throws Exception {
    ServiceContext serviceContext = new ServiceContext();

    CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
            serviceContext);/*from   w w w.j a va 2s  .c  o  m*/

    Locale locale = LocaleUtil.getDefault();

    Map<Locale, String> nameMap = RandomTestUtil.randomLocaleStringMap(locale);

    Calendar expectedCalendar = CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), nameMap, RandomTestUtil.randomLocaleStringMap(),
            StringPool.UTC, RandomTestUtil.randomInt(0, 255), false, false, false, serviceContext);

    CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), RandomTestUtil.randomLocaleStringMap(),
            RandomTestUtil.randomLocaleStringMap(), StringPool.UTC, RandomTestUtil.randomInt(0, 255), false,
            false, false, serviceContext);

    List<Calendar> actualCalendars = CalendarLocalServiceUtil.search(_group.getCompanyId(),
            new long[] { _group.getGroupId() }, new long[] { calendarResource.getCalendarResourceId() },
            nameMap.get(locale), true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new CalendarNameComparator());

    Assert.assertEquals(actualCalendars.toString(), 1, actualCalendars.size());

    Calendar actualCalendar = actualCalendars.get(0);

    Assert.assertEquals(expectedCalendar.getCalendarId(), actualCalendar.getCalendarId());
    Assert.assertEquals(expectedCalendar.getNameMap(), actualCalendar.getNameMap());
}