Example usage for com.liferay.portal.kernel.service IdentityServiceContextFunction IdentityServiceContextFunction

List of usage examples for com.liferay.portal.kernel.service IdentityServiceContextFunction IdentityServiceContextFunction

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service IdentityServiceContextFunction IdentityServiceContextFunction.

Prototype

public IdentityServiceContextFunction(ServiceContext serviceContext) 

Source Link

Usage

From source file:com.liferay.blogs.internal.util.PingbackMethodImpl.java

License:Open Source License

protected long addPingback(long companyId) throws Exception {
    if (!PropsValues.BLOGS_PINGBACK_ENABLED) {
        throw new DisabledPingbackException("Pingbacks are disabled");
    }//from  w w  w  .ja  v  a  2 s  . c o  m

    validateSource();

    BlogsEntry entry = getBlogsEntry(companyId);

    if (!entry.isAllowPingbacks() || Validator.isNull(entry.getUrlTitle())) {

        throw new DisabledPingbackException("Pingbacks are disabled");
    }

    long userId = _userLocalService.getDefaultUserId(companyId);
    long groupId = entry.getGroupId();
    String className = BlogsEntry.class.getName();
    long classPK = entry.getEntryId();

    String body = "[...] " + getExcerpt() + " [...] [url=" + _sourceURI + "]"
            + LanguageUtil.get(LocaleUtil.getSiteDefault(), "read-more") + "[/url]";

    ServiceContext serviceContext = buildServiceContext(companyId, groupId, entry.getUrlTitle());

    return _commentManager.addComment(userId, groupId, className, classPK, body,
            new IdentityServiceContextFunction(serviceContext));
}

From source file:com.liferay.blogs.service.impl.test.BlogsEntryLocalServiceImplTest.java

License:Open Source License

@Test
public void testAddDiscussion() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    BlogsEntry blogsEntry = BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(),
            StringUtil.randomString(), StringUtil.randomString(), new Date(), serviceContext);

    _blogsEntries.add(blogsEntry);/*from ww w.java2 s . c  o  m*/

    long initialCommentsCount = CommentManagerUtil.getCommentsCount(BlogsEntry.class.getName(),
            blogsEntry.getEntryId());

    CommentManagerUtil.addComment(TestPropsValues.getUserId(), TestPropsValues.getGroupId(),
            BlogsEntry.class.getName(), blogsEntry.getEntryId(), StringUtil.randomString(),
            new IdentityServiceContextFunction(serviceContext));

    Assert.assertEquals(initialCommentsCount + 1,
            CommentManagerUtil.getCommentsCount(BlogsEntry.class.getName(), blogsEntry.getEntryId()));
}

From source file:com.liferay.blogs.service.impl.test.BlogsEntryLocalServiceImplTest.java

License:Open Source License

@Test
public void testDeleteDiscussion() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    BlogsEntry blogsEntry = BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(),
            StringUtil.randomString(), StringUtil.randomString(), new Date(), serviceContext);

    _blogsEntries.add(blogsEntry);/*from w w  w. j  a v  a 2s  .  co  m*/

    CommentManagerUtil.addComment(TestPropsValues.getUserId(), TestPropsValues.getGroupId(),
            BlogsEntry.class.getName(), blogsEntry.getEntryId(), StringUtil.randomString(),
            new IdentityServiceContextFunction(serviceContext));

    Assert.assertTrue(CommentManagerUtil.hasDiscussion(BlogsEntry.class.getName(), blogsEntry.getEntryId()));

    CommentManagerUtil.deleteDiscussion(BlogsEntry.class.getName(), blogsEntry.getEntryId());

    Assert.assertFalse(CommentManagerUtil.hasDiscussion(BlogsEntry.class.getName(), blogsEntry.getEntryId()));
}

From source file:com.liferay.blogs.trackback.test.TrackbackImplTest.java

License:Open Source License

@Test
public void testAddTrackback() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    _blogsEntry = BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), StringUtil.randomString(),
            StringUtil.randomString(), new Date(), serviceContext);

    IdentityServiceContextFunction serviceContextFunction = new IdentityServiceContextFunction(serviceContext);

    CommentManagerUtil.addComment(TestPropsValues.getUserId(), TestPropsValues.getGroupId(),
            BlogsEntry.class.getName(), _blogsEntry.getEntryId(), StringUtil.randomString(),
            serviceContextFunction);//from  ww w .j  a v a  2 s.co  m

    int initialCommentsCount = CommentManagerUtil.getCommentsCount(BlogsEntry.class.getName(),
            _blogsEntry.getEntryId());

    Trackback trackback = new TrackbackImpl();

    ThemeDisplay themeDisplay = new ThemeDisplay();

    Company company = CompanyLocalServiceUtil.getCompany(TestPropsValues.getCompanyId());

    themeDisplay.setCompany(company);

    trackback.addTrackback(_blogsEntry, themeDisplay, StringUtil.randomString(), StringUtil.randomString(),
            StringUtil.randomString(), StringUtil.randomString(), serviceContextFunction);

    Assert.assertEquals(initialCommentsCount + 1,
            CommentManagerUtil.getCommentsCount(BlogsEntry.class.getName(), _blogsEntry.getEntryId()));

    LinkbackConsumerUtil.verifyNewTrackbacks();
}

From source file:com.liferay.comment.demo.data.creator.internal.CommentDemoDataCreatorImpl.java

License:Open Source License

@Override
public Comment create(long userId, ClassedModel classedModel) throws PortalException {

    User user = _userLocalService.fetchUser(userId);

    String className = classedModel.getModelClassName();
    Long classPK = (long) classedModel.getPrimaryKeyObj();

    AssetEntry assetEntry = _assetEntryLocalService.getEntry(className, classPK);

    Group group = _groupLocalService.getGroup(assetEntry.getGroupId());

    IdentityServiceContextFunction identityServiceContextFunction = new IdentityServiceContextFunction(
            new ServiceContext());

    long commentId = _commentManager.addComment(user.getUserId(), group.getGroupId(), className, classPK,
            user.getFullName(), StringPool.BLANK, _getRandomBody(), identityServiceContextFunction);

    return _getComment(commentId);
}

From source file:com.liferay.comment.demo.data.creator.internal.CommentDemoDataCreatorImpl.java

License:Open Source License

@Override
public Comment create(long userId, long parentCommentId) throws PortalException {

    User user = _userLocalService.fetchUser(userId);
    Comment parentComment = _commentManager.fetchComment(parentCommentId);

    IdentityServiceContextFunction identityServiceContextFunction = new IdentityServiceContextFunction(
            new ServiceContext());

    long commentId = _commentManager.addComment(userId, parentComment.getClassName(),
            parentComment.getClassPK(), user.getFullName(), parentCommentId, StringPool.BLANK, _getRandomBody(),
            identityServiceContextFunction);

    return _getComment(commentId);
}

From source file:com.liferay.exportimport.test.util.lar.BaseStagedModelDataHandlerTestCase.java

License:Open Source License

protected void addComments(StagedModel stagedModel) throws Exception {
    if (!isCommentableStagedModel()) {
        return;/*from   w  w w.ja va  2  s .  com*/
    }

    User user = TestPropsValues.getUser();
    String className = ExportImportClassedModelUtil.getClassName(stagedModel);
    long classPK = ExportImportClassedModelUtil.getClassPK(stagedModel);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(stagingGroup.getGroupId(),
            user.getUserId());

    CommentManagerUtil.addComment(user.getUserId(), stagingGroup.getGroupId(), className, classPK,
            user.getFullName(), RandomTestUtil.randomString(), RandomTestUtil.randomString(50),
            new IdentityServiceContextFunction(serviceContext));
}

From source file:com.liferay.message.boards.comment.internal.test.MBCommentManagerImplTest.java

License:Open Source License

private long _addComment() throws Exception {
    User user = TestPropsValues.getUser();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, user.getUserId());

    IdentityServiceContextFunction serviceContextFunction = new IdentityServiceContextFunction(serviceContext);

    return _commentManager.addComment(user.getUserId(), _group.getGroupId(),
            DLFileEntryConstants.getClassName(), _fileEntry.getFileEntryId(), StringUtil.randomString(),
            serviceContextFunction);//from  w  w w  . j av  a 2  s. c  o m
}

From source file:com.liferay.message.boards.comment.internal.test.MBCommentManagerImplTest.java

License:Open Source License

private long _addComment(long parentCommentId) throws Exception {
    User user = TestPropsValues.getUser();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, user.getUserId());

    IdentityServiceContextFunction serviceContextFunction = new IdentityServiceContextFunction(serviceContext);

    return _commentManager.addComment(user.getUserId(), User.class.getName(), user.getUserId(),
            user.getFullName(), parentCommentId, StringUtil.randomString(), StringUtil.randomString(),
            serviceContextFunction);/*from   www.  j  a  v a2 s.com*/
}

From source file:com.liferay.message.boards.comment.internal.test.MBCommentManagerImplTest.java

License:Open Source License

private Function<String, ServiceContext> _createServiceContextFunction() {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, _user.getUserId());

    return new IdentityServiceContextFunction(serviceContext);
}