List of usage examples for com.liferay.portal.kernel.security RandomUtil nextInt
public static int nextInt(int n)
From source file:com.liferay.adaptive.media.AdaptiveMediaAttributeTest.java
License:Open Source License
@Test public void testContentLengthRecognizesIntegers() { AdaptiveMediaAttribute<?, Integer> contentLength = AdaptiveMediaAttribute.contentLength(); Integer value = RandomUtil.nextInt(Integer.MAX_VALUE); Assert.assertEquals(value, contentLength.convert(String.valueOf(value))); }
From source file:com.liferay.adaptive.media.AMAttributeTest.java
License:Open Source License
@Test public void testContentLengthRecognizesIntegers() { AMAttribute<?, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute(); long value = RandomUtil.nextInt(Integer.MAX_VALUE); Assert.assertEquals(value, (long) contentLengthAMAttribute.convert(String.valueOf(value))); }
From source file:com.liferay.asset.test.util.BaseAssetSearchTestCase.java
License:Open Source License
protected Date[] generateRandomDates(Date startDate, int size) { Date[] dates = new Date[size]; for (int i = 0; i < size; i++) { Date date = new Date(startDate.getTime() + (RandomUtil.nextInt(365) + 1) * Time.DAY); Calendar calendar = new GregorianCalendar(); calendar.setTime(date);/*w ww . j a va 2 s . co m*/ calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); dates[i] = calendar.getTime(); } return dates; }
From source file:com.liferay.blogs.demo.data.creator.internal.LoremIpsumBlogsEntryDemoDataCreatorImpl.java
License:Open Source License
private String _getRandomContent() { int count = RandomUtil.nextInt(5) + 3; StringBundler sb = new StringBundler(count * 3); for (int i = 0; i < count; i++) { sb.append("<p>"); sb.append(_getRandomElement(_paragraphs)); sb.append("</p>"); }//from w w w . j a v a 2 s . co m return sb.toString(); }
From source file:com.liferay.blogs.demo.data.creator.internal.LoremIpsumBlogsEntryDemoDataCreatorImpl.java
License:Open Source License
private String _getRandomElement(List<String> list) { return list.get(RandomUtil.nextInt(list.size())); }
From source file:com.liferay.comment.demo.data.creator.internal.CommentDemoDataCreatorImpl.java
License:Open Source License
private String _getRandomBody() { return _bodies.get(RandomUtil.nextInt(_bodies.size())); }
From source file:com.liferay.comment.demo.data.creator.internal.MultipleCommentDemoDataCreatorImpl.java
License:Open Source License
@Override public void create(ClassedModel classedModel) throws PortalException { List<User> users = _userLocalService.getUsers(0, Math.min(_userLocalService.getUsersCount(), _MAX_USERS)); Stream<User> usersStream = users.stream(); usersStream = usersStream.filter(this::_isRegularUser); Stream<Long> userIdsStream = usersStream.map(UserModel::getUserId); List<Long> userIds = userIdsStream.collect(Collectors.toList()); _addComments(userIds, classedModel, _COMMENT_ID, RandomUtil.nextInt(_MAX_COMMENTS), 1); }
From source file:com.liferay.comment.demo.data.creator.internal.MultipleCommentDemoDataCreatorImpl.java
License:Open Source License
private int _addComments(List<Long> userIds, ClassedModel classedModel, long commentId, int maxComments, int level) throws PortalException { int commentsCount = 0; int maxReplies = RandomUtil.nextInt(_MAX_REPLIES / level); int repliesCount = 0; while ((commentsCount < maxComments) && (repliesCount < maxReplies)) { Comment comment = null;/* ww w . j av a2 s .co m*/ long userId = _getRandomElement(userIds); if (commentId == _COMMENT_ID) { comment = _commentDemoDataCreator.create(userId, classedModel); } else { comment = _commentDemoDataCreator.create(userId, commentId); repliesCount++; } commentsCount++; if (level < _MAX_LEVEL) { commentsCount += _addComments(userIds, classedModel, comment.getCommentId(), maxComments - commentsCount, level + 1); } } return commentsCount; }
From source file:com.liferay.comment.demo.data.creator.internal.MultipleCommentDemoDataCreatorImpl.java
License:Open Source License
private <T> T _getRandomElement(List<T> list) { return list.get(RandomUtil.nextInt(list.size())); }
From source file:com.liferay.content.targeting.tools.CTDataFactory.java
License:Open Source License
public PortletPreferencesModel newCampaignContentDisplayPortletPreferenceModels(long groupId, long plid, String portletId) throws Exception { PortletPreferences jxPortletPreferences = new PortletPreferencesImpl(); jxPortletPreferences.setValue("assetEntryIdDefault", String.valueOf(getAssetEntryId())); jxPortletPreferences.setValue("contentDefaultValue", "true"); jxPortletPreferences.setValue("showAssetTitle", "false"); jxPortletPreferences.setValue("contentDefaultValue", "false"); jxPortletPreferences.setValue("enableSocialBookmarks", "false"); jxPortletPreferences.setValue("displayStyleGroupId", String.valueOf(groupId)); jxPortletPreferences.setValue("displayStyle", "full-content"); List<String> queryRuleIndexes = new ArrayList<String>(_maxCampaignContentDisplayQueryRuleCount); if (!_campaignModels.isEmpty()) { for (int i = 0; i < _maxCampaignContentDisplayQueryRuleCount; i++) { jxPortletPreferences.setValue("assetEntryId" + i, String.valueOf(getAssetEntryId())); int pos = RandomUtil.nextInt(_campaignModels.size()); CampaignModel campaignModel = _campaignModels.get(pos); jxPortletPreferences.setValue("campaignId" + i, String.valueOf(campaignModel.getCampaignId())); queryRuleIndexes.add(String.valueOf(i)); }/*from ww w. ja v a 2 s .c om*/ } jxPortletPreferences.setValues("queryLogicIndexes", queryRuleIndexes.toArray(new String[queryRuleIndexes.size()])); return newPortletPreferencesModel(plid, portletId, _portletPreferencesFactory.toXML(jxPortletPreferences)); }