List of usage examples for com.liferay.portal.kernel.util Time MINUTE
long MINUTE
To view the source code for com.liferay.portal.kernel.util Time MINUTE.
Click Source Link
From source file:com.liferay.calendar.service.impl.CalendarImporterLocalServiceImpl.java
License:Open Source License
@Override public void importCalEvent(CalEvent calEvent) throws PortalException { // Calendar event CalendarBooking calendarBooking = fetchCalendarBooking(calEvent); if (calendarBooking != null) { verifyCalendarBooking(calendarBooking, calEvent); return;/*from www .j a va2s . c o m*/ } long calendarBookingId = counterLocalService.increment(); CalendarResource calendarResource = getCalendarResource(calEvent.getCompanyId(), calEvent.getGroupId()); Date startDate = calEvent.getStartDate(); long startTime = startDate.getTime(); long endTime = startTime + calEvent.getDurationHour() * Time.HOUR + calEvent.getDurationMinute() * Time.MINUTE; if (calEvent.isAllDay()) { endTime = endTime - 1; } String recurrence = getRecurrence(calEvent.getRecurrenceObj()); addCalendarBooking(calEvent.getUuid(), calendarBookingId, calEvent.getCompanyId(), calendarResource.getGroupId(), calEvent.getUserId(), calEvent.getUserName(), calEvent.getCreateDate(), calEvent.getModifiedDate(), calendarResource.getDefaultCalendarId(), calendarResource.getCalendarResourceId(), calEvent.getTitle(), calEvent.getDescription(), calEvent.getLocation(), startTime, endTime, calEvent.getAllDay(), recurrence, calEvent.getFirstReminder(), NotificationType.EMAIL, calEvent.getSecondReminder(), NotificationType.EMAIL); // Resources importCalendarBookingResourcePermissions(calEvent, calendarBookingId); // Subscriptions importSubscriptions(calEvent, calendarBookingId); // Asset importAssets(calEvent, calendarBookingId); // Message boards importMBDiscussion(calEvent, calendarBookingId); // Social importSocialActivities(calEvent, calendarBookingId); // Ratings importRatings(classNameLocalService.getClassNameId(CalEvent.class.getName()), calEvent.getEventId(), classNameLocalService.getClassNameId(CalendarBooking.class.getName()), calendarBookingId); }
From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java
License:Open Source License
@Test public void testAddCalendarBookingDoesNotNotifyCreatorTwice() throws Exception { ServiceContext serviceContext = createServiceContext(); _invitingUser = UserTestUtil.addUser(); Calendar calendar = CalendarTestUtil.addCalendar(_invitingUser, serviceContext); Calendar invitedCalendar = CalendarTestUtil.addCalendar(_user, serviceContext); long startTime = System.currentTimeMillis() + Time.MINUTE; long endTime = startTime + Time.HOUR; long firstReminder = Time.MINUTE; serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); CalendarBooking calendarBooking = CalendarBookingTestUtil.addCalendarBooking(_invitingUser, calendar, new long[] { invitedCalendar.getCalendarId() }, RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(), startTime, endTime, null, (int) firstReminder, NotificationType.EMAIL, 0, NotificationType.EMAIL, serviceContext); CalendarBooking childCalendarBooking = getChildCalendarBooking(calendarBooking); CalendarBookingLocalServiceUtil.updateStatus(_user.getUserId(), childCalendarBooking, CalendarBookingWorkflowConstants.STATUS_APPROVED, serviceContext); CalendarBookingLocalServiceUtil.checkCalendarBookings(); String mailMessageSubject = "Calendar: Event Reminder for " + StringPool.QUOTE + calendarBooking.getTitle(LocaleUtil.getDefault()) + StringPool.QUOTE; List<com.dumbster.smtp.MailMessage> mailMessages = MailServiceTestUtil.getMailMessages("Subject", mailMessageSubject);/*from w w w . ja va2s. co m*/ Assert.assertEquals(mailMessages.toString(), 2, mailMessages.size()); }
From source file:com.liferay.calendar.util.CalendarICalDataHandler.java
License:Open Source License
protected void importICalEvent(long calendarId, VEvent vEvent) throws Exception { Calendar calendar = CalendarLocalServiceUtil.getCalendar(calendarId); // Title// w ww . j av a2 s .com User user = UserLocalServiceUtil.getUser(calendar.getUserId()); Map<Locale, String> titleMap = new HashMap<Locale, String>(); Summary summary = vEvent.getSummary(); if (summary != null) { String title = ModelHintsUtil.trimString(CalendarBooking.class.getName(), "title", summary.getValue()); titleMap.put(user.getLocale(), title); } // Description Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); Description description = vEvent.getDescription(); if (description != null) { descriptionMap.put(user.getLocale(), description.getValue()); } // Location String locationString = StringPool.BLANK; Location location = vEvent.getLocation(); if (location != null) { locationString = location.getValue(); } // Dates DtStart dtStart = vEvent.getStartDate(); Date startDate = dtStart.getDate(); DtEnd dtEnd = vEvent.getEndDate(); Date endDate = dtEnd.getDate(); // All day boolean allDay = false; if (isICalDateOnly(dtStart)) { allDay = true; long time = endDate.getTime(); endDate.setTime(time - 1); } // Recurrence RRule rrule = (RRule) vEvent.getProperty(Property.RRULE); String recurrence = StringPool.BLANK; if (rrule != null) { recurrence = StringUtil.trim(rrule.toString()); PropertyList propertyList = vEvent.getProperties(Property.EXDATE); if (!propertyList.isEmpty()) { StringBundler sb = new StringBundler(); Iterator<ExDate> iterator = propertyList.iterator(); while (iterator.hasNext()) { ExDate exDate = iterator.next(); DateList dateList = exDate.getDates(); ListIterator<Date> listIterator = dateList.listIterator(); while (listIterator.hasNext()) { Date date = listIterator.next(); java.util.Calendar jCalendar = JCalendarUtil.getJCalendar(date.getTime()); int year = jCalendar.get(java.util.Calendar.YEAR); int month = jCalendar.get(java.util.Calendar.MONTH) + 1; int day = jCalendar.get(java.util.Calendar.DATE); int hour = jCalendar.get(java.util.Calendar.HOUR_OF_DAY); int minute = jCalendar.get(java.util.Calendar.MINUTE); int second = jCalendar.get(java.util.Calendar.SECOND); sb.append(String.format(_EXDATE_FORMAT, year, month, day, hour, minute, second)); if (listIterator.hasNext()) { sb.append(StringPool.COMMA); } } if (iterator.hasNext()) { sb.append(StringPool.COMMA); } } recurrence = recurrence.concat(StringPool.NEW_LINE).concat(_EXDATE).concat(sb.toString()); } } // Reminders ComponentList componentList = vEvent.getAlarms(); long[] reminders = new long[componentList.size()]; String[] reminderTypes = new String[componentList.size()]; int i = 0; for (Iterator<VAlarm> iterator = componentList.iterator(); iterator.hasNext();) { VAlarm vAlarm = iterator.next(); Action action = vAlarm.getAction(); String value = StringUtil.lowerCase(action.getValue()); if (!isActionSupported(value)) { continue; } reminderTypes[i] = value; Trigger trigger = vAlarm.getTrigger(); long time = 0; DateTime dateTime = trigger.getDateTime(); Dur dur = trigger.getDuration(); if ((dateTime == null) && (dur == null)) { continue; } if (dateTime != null) { time = startDate.getTime() - dateTime.getTime(); if (time < 0) { continue; } } else { if (!dur.isNegative()) { continue; } time += dur.getWeeks() * Time.WEEK; time += dur.getDays() * Time.DAY; time += dur.getHours() * Time.HOUR; time += dur.getMinutes() * Time.MINUTE; time += dur.getSeconds() * Time.SECOND; } reminders[i] = time; i++; } long firstReminder = 0; String firstReminderType = null; long secondReminder = 0; String secondReminderType = null; if (i > 0) { firstReminder = reminders[0]; firstReminderType = reminderTypes[0]; } if (i > 1) { secondReminder = reminders[1]; secondReminderType = reminderTypes[1]; } // Attendees PropertyList propertyList = vEvent.getProperties(Property.ATTENDEE); List<Long> childCalendarIds = new ArrayList<Long>(); for (Iterator<Attendee> iterator = propertyList.iterator(); iterator.hasNext();) { Attendee attendee = iterator.next(); URI uri = attendee.getCalAddress(); if (uri == null) { continue; } User attendeeUser = UserLocalServiceUtil.fetchUserByEmailAddress(calendar.getCompanyId(), uri.getSchemeSpecificPart()); if ((attendeeUser == null) || (calendar.getUserId() == attendeeUser.getUserId())) { continue; } ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(calendar.getCompanyId()); serviceContext.setScopeGroupId(calendar.getGroupId()); CalendarResource calendarResource = CalendarResourceUtil .getUserCalendarResource(attendeeUser.getUserId(), serviceContext); if (calendarResource == null) { continue; } childCalendarIds.add(calendarResource.getDefaultCalendarId()); } long[] childCalendarIdsArray = ArrayUtil .toArray(childCalendarIds.toArray(new Long[childCalendarIds.size()])); // Merge calendar booking CalendarBooking calendarBooking = null; String uuid = null; Uid uid = vEvent.getUid(); if (uid != null) { uuid = uid.getValue(); calendarBooking = CalendarBookingLocalServiceUtil.fetchCalendarBooking(uuid, calendar.getGroupId()); } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setAttribute("sendNotification", Boolean.FALSE); serviceContext.setScopeGroupId(calendar.getGroupId()); if (calendarBooking == null) { serviceContext.setUuid(uuid); CalendarBookingServiceUtil.addCalendarBooking(calendarId, childCalendarIdsArray, CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, titleMap, descriptionMap, locationString, startDate.getTime(), endDate.getTime(), allDay, recurrence, firstReminder, firstReminderType, secondReminder, secondReminderType, serviceContext); } else { CalendarBookingServiceUtil.updateCalendarBooking(calendarBooking.getCalendarBookingId(), calendarId, childCalendarIdsArray, titleMap, descriptionMap, locationString, startDate.getTime(), endDate.getTime(), allDay, recurrence, firstReminder, firstReminderType, secondReminder, secondReminderType, calendarBooking.getStatus(), serviceContext); } }
From source file:com.liferay.calendar.util.CalendarICalDataHandler.java
License:Open Source License
protected Dur toICalDur(long reminder) { int weeks = (int) (reminder / Time.WEEK); if (weeks > 0) { return new Dur(weeks); }/*from w w w.ja va2 s . com*/ int days = (int) (reminder / Time.DAY); if (days > 0) { return new Dur(days, 0, 0, 0); } int hours = (int) (reminder / Time.HOUR); if (hours > 0) { return new Dur(0, hours, 0, 0); } int minutes = (int) (reminder / Time.MINUTE); if (minutes > 0) { return new Dur(0, 0, minutes, 0); } int seconds = (int) (reminder / Time.SECOND); if (seconds > 0) { return new Dur(0, 0, 0, seconds); } return null; }
From source file:com.liferay.exportimport.test.BasePrototypePropagationTestCase.java
License:Open Source License
protected void doTestLayoutTypePropagation(boolean linkEnabled) throws Exception { setLinkEnabled(linkEnabled);//from www. j a v a 2 s .c om int initialPortletCount = LayoutTestUtil.getPortlets(layout).size(); prototypeLayout = LayoutTestUtil.updateLayoutTemplateId(prototypeLayout, "1_column"); LayoutTestUtil.updateLayoutColumnCustomizable(prototypeLayout, "column-1", true); addPortletToLayout(TestPropsValues.getUserId(), prototypeLayout, globalJournalArticle, "column-1"); if (linkEnabled) { Assert.assertEquals(initialLayoutTemplateId, LayoutTestUtil.getLayoutTemplateId(layout)); Assert.assertFalse(LayoutTestUtil.isLayoutColumnCustomizable(layout, "column-1")); Assert.assertEquals(initialPortletCount, LayoutTestUtil.getPortlets(layout).size()); } prototypeLayout = updateModifiedDate(prototypeLayout, new Date(System.currentTimeMillis() + Time.MINUTE)); layout = propagateChanges(layout); if (linkEnabled) { Assert.assertEquals("1_column", LayoutTestUtil.getLayoutTemplateId(layout)); Assert.assertTrue(LayoutTestUtil.isLayoutColumnCustomizable(layout, "column-1")); Assert.assertEquals(initialPortletCount + 1, LayoutTestUtil.getPortlets(layout).size()); } else { Assert.assertEquals(initialLayoutTemplateId, LayoutTestUtil.getLayoutTemplateId(layout)); Assert.assertFalse(LayoutTestUtil.isLayoutColumnCustomizable(layout, "column-1")); Assert.assertEquals(initialPortletCount, LayoutTestUtil.getPortlets(layout).size()); } }
From source file:com.liferay.exportimport.test.LayoutSetPrototypePropagationTest.java
License:Open Source License
@Ignore @Test//w w w . j a v a 2 s . c o m public void testLayoutPermissionPropagationWithLinkEnabled() throws Exception { setLinkEnabled(true); Role role = RoleLocalServiceUtil.getRole(TestPropsValues.getCompanyId(), RoleConstants.POWER_USER); ResourcePermissionServiceUtil.setIndividualResourcePermissions(prototypeLayout.getGroupId(), prototypeLayout.getCompanyId(), Layout.class.getName(), String.valueOf(prototypeLayout.getPrimaryKey()), role.getRoleId(), new String[] { ActionKeys.CUSTOMIZE }); prototypeLayout = updateModifiedDate(prototypeLayout, new Date(System.currentTimeMillis() + Time.MINUTE)); CacheUtil.clearCache(prototypeLayout.getCompanyId()); propagateChanges(group); Assert.assertTrue(ResourcePermissionLocalServiceUtil.hasResourcePermission(layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPrimaryKey()), role.getRoleId(), ActionKeys.CUSTOMIZE)); }
From source file:com.liferay.exportimport.test.util.lar.BasePortletExportImportTestCase.java
License:Open Source License
@Test public void testUpdateLastPublishDate() throws Exception { Date lastPublishDate = new Date(System.currentTimeMillis() - Time.HOUR); Date stagedModelCreationDate = new Date(lastPublishDate.getTime() + Time.MINUTE); StagedModel stagedModel = addStagedModel(group.getGroupId(), stagedModelCreationDate); if (stagedModel == null) { return;/*from w ww.java 2s . c o m*/ } LayoutTestUtil.addPortletToLayout(TestPropsValues.getUserId(), layout, getPortletId(), "column-1", new HashMap<String, String[]>()); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, getPortletId()); portletPreferences.setValue("last-publish-date", String.valueOf(lastPublishDate.getTime())); portletPreferences.store(); Map<String, String[]> exportParameterMap = new LinkedHashMap<>(); exportParameterMap.put(PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE, new String[] { String.valueOf(true) }); exportParameterMap.put("range", new String[] { ExportImportDateUtil.RANGE_FROM_LAST_PUBLISH_DATE }); Map<String, String[]> importParameterMap = new LinkedHashMap<>(); portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, getPortletId()); Date oldLastPublishDate = ExportImportDateUtil.getLastPublishDate(portletPreferences); exportImportPortlet(getPortletId(), exportParameterMap, importParameterMap); portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, getPortletId()); Date newLastPublishDate = ExportImportDateUtil.getLastPublishDate(portletPreferences); Assert.assertTrue(newLastPublishDate.after(oldLastPublishDate)); StagedModel importedStagedModel = getStagedModel(getStagedModelUuid(stagedModel), importedGroup.getGroupId()); Assert.assertNotNull(importedStagedModel); }
From source file:com.liferay.frontend.js.spa.web.internal.servlet.taglib.util.SPAUtil.java
License:Open Source License
private long _getCacheExpirationTime(SPAConfiguration spaConfiguration) { long cacheExpirationTime = spaConfiguration.cacheExpirationTime(); if (cacheExpirationTime > 0) { cacheExpirationTime *= Time.MINUTE; }// w w w. ja v a 2 s .c om return cacheExpirationTime; }
From source file:com.liferay.journal.internal.upgrade.v1_1_2.UpgradeCheckIntervalConfiguration.java
License:Open Source License
protected void upgradeCheckIntervalConfiguration() throws Exception { Configuration configuration = _configurationAdmin .getConfiguration(JournalServiceConfiguration.class.getName(), StringPool.QUESTION); Dictionary<String, Object> properties = configuration.getProperties(); if (properties == null) { return;//from w w w . j a v a2 s . c om } long checkIntervalMilliseconds = GetterUtil.getLong(properties.get("checkInterval")); long checkIntervalMinutes = checkIntervalMilliseconds / Time.MINUTE; int checkInterval = Integer.MAX_VALUE; if (checkIntervalMinutes <= Integer.MAX_VALUE) { checkInterval = (int) checkIntervalMinutes; } properties.put("checkInterval", checkInterval); configuration.update(properties); }
From source file:com.liferay.journal.service.test.JournalArticleScheduledTest.java
License:Open Source License
protected Calendar getCalendar(Date date, int when) { Calendar calendar = new GregorianCalendar(); calendar.setTime(new Date(date.getTime() + Time.MINUTE * when * 5)); return calendar; }