List of usage examples for com.liferay.portal.kernel.util ArrayUtil toArray
@Deprecated public static String[] toArray(String[] array)
From source file:com.hrportal.service.impl.WebArticleHelperLocalServiceImpl.java
License:Open Source License
public List<JournalArticle> getJournalArticlesByCategoryIds(List<Long> cIds) { //ServiceContext sc = ServiceContextThreadLocal.getServiceContext(); ArrayList<JournalArticle> jaList = new ArrayList<JournalArticle>(); if (cIds != null && cIds.size() > 0) { AssetEntryQuery q = new AssetEntryQuery(); q.setAllCategoryIds(ArrayUtil.toArray(cIds.toArray(new Long[cIds.size()]))); q.setClassName(JournalArticle.class.getName()); try {//from w w w .j a va2s . c o m List<AssetEntry> assets = AssetEntryLocalServiceUtil.getEntries(q); for (AssetEntry asset : assets) { JournalArticle ja = JournalArticleLocalServiceUtil.getLatestArticle(asset.getClassPK()); if (!jaList.contains(ja)) { jaList.add(ja); } } } catch (Exception e) { _log.error("", e); } } return jaList; }
From source file:com.liferay.asset.internal.util.AssetServiceUtil.java
License:Open Source License
public static long[] filterCategoryIds(PermissionChecker permissionChecker, long[] categoryIds) throws PortalException { List<Long> viewableCategoryIds = new ArrayList<>(); for (long categoryId : categoryIds) { AssetCategory category = AssetCategoryLocalServiceUtil.fetchCategory(categoryId); if ((category != null) && AssetCategoryPermission.contains(permissionChecker, category, ActionKeys.VIEW)) { viewableCategoryIds.add(categoryId); }/* ww w . j a v a 2 s . c o m*/ } return ArrayUtil.toArray(viewableCategoryIds.toArray(new Long[viewableCategoryIds.size()])); }
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
private long[] _filterAssetCategoryIds(long[] assetCategoryIds) { List<Long> assetCategoryIdsList = new ArrayList<>(); for (long assetCategoryId : assetCategoryIds) { AssetCategory category = _assetCategoryLocalService.fetchAssetCategory(assetCategoryId); if (category == null) { continue; }/*from w ww . j ava 2 s . com*/ assetCategoryIdsList.add(assetCategoryId); } return ArrayUtil.toArray(assetCategoryIdsList.toArray(new Long[assetCategoryIdsList.size()])); }
From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java
License:Open Source License
private Long[] _getClassTypeIds(PortletPreferences portletPreferences, String className, Long[] availableClassTypeIds) { boolean anyAssetType = GetterUtil .getBoolean(portletPreferences.getValue("anyClassType" + className, Boolean.TRUE.toString())); if (anyAssetType) { return availableClassTypeIds; }/*w w w .j a va 2 s . c om*/ long defaultClassTypeId = GetterUtil.getLong(portletPreferences.getValue("anyClassType" + className, null), -1); if (defaultClassTypeId > -1) { return new Long[] { defaultClassTypeId }; } Long[] classTypeIds = ArrayUtil .toArray(StringUtil.split(portletPreferences.getValue("classTypeIds" + className, null), 0L)); if (classTypeIds != null) { return classTypeIds; } else { return availableClassTypeIds; } }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
public static Long[] getClassTypeIds(PortletPreferences portletPreferences, String className, Long[] availableClassTypeIds) { boolean anyAssetType = GetterUtil .getBoolean(portletPreferences.getValue("anyClassType" + className, Boolean.TRUE.toString())); if (anyAssetType) { return availableClassTypeIds; }// ww w . ja v a 2 s . c om long defaultClassTypeId = GetterUtil.getLong(portletPreferences.getValue("anyClassType" + className, null), -1); if (defaultClassTypeId > -1) { return new Long[] { defaultClassTypeId }; } Long[] classTypeIds = ArrayUtil .toArray(StringUtil.split(portletPreferences.getValue("classTypeIds" + className, null), 0L)); if (classTypeIds != null) { return classTypeIds; } else { return availableClassTypeIds; } }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
private static long[] _filterAssetCategoryIds(long[] assetCategoryIds) { List<Long> assetCategoryIdsList = new ArrayList<>(); for (long assetCategoryId : assetCategoryIds) { AssetCategory category = _assetCategoryLocalService.fetchAssetCategory(assetCategoryId); if (category == null) { continue; }//from w ww. j av a 2s. co m assetCategoryIdsList.add(assetCategoryId); } return ArrayUtil.toArray(assetCategoryIdsList.toArray(new Long[assetCategoryIdsList.size()])); }
From source file:com.liferay.asset.taglib.internal.util.AssetCategoryUtil.java
License:Open Source License
public static long[] filterCategoryIds(long vocabularyId, long[] categoryIds) { List<Long> filteredCategoryIds = new ArrayList<>(); for (long categoryId : categoryIds) { AssetCategory category = AssetCategoryLocalServiceUtil.fetchCategory(categoryId); if (category == null) { continue; }/*w w w.j a v a 2 s.com*/ if (category.getVocabularyId() == vocabularyId) { filteredCategoryIds.add(category.getCategoryId()); } } return ArrayUtil.toArray(filteredCategoryIds.toArray(new Long[filteredCategoryIds.size()])); }
From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java
License:Open Source License
@Override public int getFoldersEntriesCount(long groupId, List<Long> folderIds) { return bookmarksEntryPersistence.countByG_F_S(groupId, ArrayUtil.toArray(folderIds.toArray(new Long[folderIds.size()])), WorkflowConstants.STATUS_APPROVED); }
From source file:com.liferay.bookmarks.service.impl.BookmarksEntryServiceImpl.java
License:Open Source License
@Override public int getFoldersEntriesCount(long groupId, List<Long> folderIds) { return bookmarksEntryPersistence.filterCountByG_F_S(groupId, ArrayUtil.toArray(folderIds.toArray(new Long[folderIds.size()])), WorkflowConstants.STATUS_APPROVED); }
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//from w w w . j a v a2s . c om 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); } }