List of usage examples for com.liferay.portal.kernel.uuid PortalUUIDUtil generate
public static String generate(byte[] bytes)
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;//ww w.java 2 s. 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); } }