Example usage for com.liferay.portal.kernel.social SocialActivityManagerUtil addActivity

List of usage examples for com.liferay.portal.kernel.social SocialActivityManagerUtil addActivity

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.social SocialActivityManagerUtil addActivity.

Prototype

public static <T extends ClassedModel & GroupedModel> void addActivity(long userId, T classedModel, int type,
            String extraData, long receiverUserId) throws PortalException 

Source Link

Usage

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

/**
 * Moves the blogs entry to the recycle bin. Social activity counters for
 * this entry get disabled./*w w w  .  j a v  a 2s.  c o  m*/
 *
 * @param  userId the primary key of the user moving the blogs entry
 * @param  entry the blogs entry to be moved
 * @return the moved blogs entry
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public BlogsEntry moveEntryToTrash(long userId, BlogsEntry entry) throws PortalException {

    // Entry

    if (entry.isInTrash()) {
        throw new TrashEntryException();
    }

    int oldStatus = entry.getStatus();

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
        entry.setStatus(WorkflowConstants.STATUS_DRAFT);

        blogsEntryPersistence.update(entry);
    }

    entry = updateStatus(userId, entry.getEntryId(), WorkflowConstants.STATUS_IN_TRASH, new ServiceContext());

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", entry.getTitle());

    SocialActivityManagerUtil.addActivity(userId, entry, SocialActivityConstants.TYPE_MOVE_TO_TRASH,
            extraDataJSONObject.toString(), 0);

    // Workflow

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
        workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(entry.getCompanyId(), entry.getGroupId(),
                BlogsEntry.class.getName(), entry.getEntryId());
    }

    return entry;
}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

/**
 * Restores the blogs entry with the ID from the recycle bin. Social
 * activity counters for this entry get activated.
 *
 * @param  userId the primary key of the user restoring the blogs entry
 * @param  entryId the primary key of the blogs entry to be restored
 * @return the restored blogs entry from the recycle bin
 *//*w ww.  ja v  a2  s  . c  om*/
@Indexable(type = IndexableType.REINDEX)
@Override
public BlogsEntry restoreEntryFromTrash(long userId, long entryId) throws PortalException {

    // Entry

    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);

    if (!entry.isInTrash()) {
        throw new RestoreEntryException(RestoreEntryException.INVALID_STATUS);
    }

    TrashEntry trashEntry = trashEntryLocalService.getEntry(BlogsEntry.class.getName(), entryId);

    entry = updateStatus(userId, entryId, trashEntry.getStatus(), new ServiceContext());

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", entry.getTitle());

    SocialActivityManagerUtil.addActivity(userId, entry, SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
            extraDataJSONObject.toString(), 0);

    return entry;
}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override/*  w w w  .  j a  v a2  s.c  om*/
public BlogsEntry updateStatus(long userId, long entryId, int status, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    // Entry

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);

    int oldStatus = entry.getStatus();

    if ((status == WorkflowConstants.STATUS_APPROVED) && now.before(entry.getDisplayDate())) {

        status = WorkflowConstants.STATUS_SCHEDULED;
    }

    entry.setStatus(status);
    entry.setStatusByUserId(user.getUserId());
    entry.setStatusByUserName(user.getFullName());
    entry.setStatusDate(serviceContext.getModifiedDate(now));

    if ((status == WorkflowConstants.STATUS_APPROVED) && Validator.isNull(entry.getUrlTitle())) {

        entry.setUrlTitle(getUniqueUrlTitle(entryId, entry.getGroupId(), entry.getTitle()));
    }

    blogsEntryPersistence.update(entry);

    // Statistics

    blogsStatsUserLocalService.updateStatsUser(entry.getGroupId(), entry.getUserId(), entry.getDisplayDate());

    AssetEntry assetEntry = assetEntryLocalService.fetchEntry(BlogsEntry.class.getName(), entryId);

    if ((assetEntry == null) || (assetEntry.getPublishDate() == null)) {
        serviceContext.setCommand(Constants.ADD);
    }

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", entry.getTitle());

    if (status == WorkflowConstants.STATUS_APPROVED) {

        // Asset

        assetEntryLocalService.updateEntry(BlogsEntry.class.getName(), entryId, entry.getDisplayDate(), null,
                true, true);

        // Social

        if ((oldStatus != WorkflowConstants.STATUS_IN_TRASH)
                && (oldStatus != WorkflowConstants.STATUS_SCHEDULED)) {

            if (serviceContext.isCommandUpdate()) {
                SocialActivityManagerUtil.addActivity(user.getUserId(), entry, BlogsActivityKeys.UPDATE_ENTRY,
                        extraDataJSONObject.toString(), 0);
            } else {
                SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), entry,
                        BlogsActivityKeys.ADD_ENTRY, extraDataJSONObject.toString(), 0);
            }
        }

        // Trash

        if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) {
            if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
                CommentManagerUtil.restoreDiscussionFromTrash(BlogsEntry.class.getName(), entryId);
            }

            trashEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entryId);
        }

        if (oldStatus != WorkflowConstants.STATUS_IN_TRASH) {

            // Subscriptions

            notifySubscribers(userId, entry, serviceContext, workflowContext);

            // Ping

            String[] trackbacks = (String[]) serviceContext.getAttribute("trackbacks");
            Boolean pingOldTrackbacks = ParamUtil.getBoolean(serviceContext, "pingOldTrackbacks");

            pingGoogle(entry, serviceContext);
            pingPingback(entry, serviceContext);
            pingTrackbacks(entry, trackbacks, pingOldTrackbacks, serviceContext);
        }
    } else {

        // Asset

        assetEntryLocalService.updateVisible(BlogsEntry.class.getName(), entryId, false);

        // Social

        if ((status == WorkflowConstants.STATUS_SCHEDULED)
                && (oldStatus != WorkflowConstants.STATUS_IN_TRASH)) {

            if (serviceContext.isCommandUpdate()) {
                SocialActivityManagerUtil.addActivity(user.getUserId(), entry, BlogsActivityKeys.UPDATE_ENTRY,
                        extraDataJSONObject.toString(), 0);
            } else {
                SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), entry,
                        BlogsActivityKeys.ADD_ENTRY, extraDataJSONObject.toString(), 0);
            }
        }

        // Trash

        if (status == WorkflowConstants.STATUS_IN_TRASH) {
            if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
                CommentManagerUtil.moveDiscussionToTrash(BlogsEntry.class.getName(), entryId);
            }

            trashEntryLocalService.addTrashEntry(userId, entry.getGroupId(), BlogsEntry.class.getName(),
                    entry.getEntryId(), entry.getUuid(), null, oldStatus, null, null);
        } else if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) {
            if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
                CommentManagerUtil.restoreDiscussionFromTrash(BlogsEntry.class.getName(), entryId);
            }

            trashEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entryId);
        }
    }

    return entry;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Moves the latest version of the web content article matching the group
 * and article ID to the recycle bin./*from w w w .java  2 s .c  om*/
 *
 * @param  userId the primary key of the user updating the web content
 *         article
 * @param  article the web content article
 * @return the updated web content article, which was moved to the Recycle
 *         Bin
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle moveArticleToTrash(long userId, JournalArticle article) throws PortalException {

    // Article

    if (article.isInTrash()) {
        throw new TrashEntryException();
    }

    int oldStatus = article.getStatus();

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
        article.setStatus(WorkflowConstants.STATUS_DRAFT);
    }

    journalArticlePersistence.update(article);

    List<JournalArticle> articleVersions = journalArticlePersistence.findByG_A(article.getGroupId(),
            article.getArticleId());

    articleVersions = ListUtil.sort(articleVersions, new ArticleVersionComparator());

    List<ObjectValuePair<Long, Integer>> articleVersionStatusOVPs = new ArrayList<>();

    if ((articleVersions != null) && !articleVersions.isEmpty()) {
        articleVersionStatusOVPs = getArticleVersionStatuses(articleVersions);
    }

    article = updateStatus(userId, article.getId(), WorkflowConstants.STATUS_IN_TRASH,
            new HashMap<String, Serializable>(), new ServiceContext());

    // Trash

    JournalArticleResource articleResource = journalArticleResourceLocalService
            .getArticleResource(article.getResourcePrimKey());

    UnicodeProperties typeSettingsProperties = new UnicodeProperties();

    typeSettingsProperties.put("title", article.getArticleId());

    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, article.getGroupId(),
            JournalArticle.class.getName(), article.getResourcePrimKey(), articleResource.getUuid(), null,
            oldStatus, articleVersionStatusOVPs, typeSettingsProperties);

    String trashArticleId = TrashUtil.getTrashTitle(trashEntry.getEntryId());

    for (JournalArticle articleVersion : articleVersions) {
        articleVersion.setArticleId(trashArticleId);
        articleVersion.setStatus(WorkflowConstants.STATUS_IN_TRASH);

        journalArticlePersistence.update(articleVersion);
    }

    articleResource.setArticleId(trashArticleId);

    journalArticleResourcePersistence.update(articleResource);

    article.setArticleId(trashArticleId);

    article = journalArticlePersistence.update(article);

    // Asset

    assetEntryLocalService.updateVisible(JournalArticle.class.getName(), article.getResourcePrimKey(), false);

    // Attachments

    for (FileEntry fileEntry : article.getImagesFileEntries()) {
        PortletFileRepositoryUtil.movePortletFileEntryToTrash(userId, fileEntry.getFileEntryId());
    }

    // Comment

    if (isArticleCommentsEnabled(article.getCompanyId())) {
        CommentManagerUtil.moveDiscussionToTrash(JournalArticle.class.getName(), article.getResourcePrimKey());
    }

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", article.getTitleMapAsXML());

    SocialActivityManagerUtil.addActivity(userId, article, SocialActivityConstants.TYPE_MOVE_TO_TRASH,
            extraDataJSONObject.toString(), 0);

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
        workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(article.getCompanyId(),
                article.getGroupId(), JournalArticle.class.getName(), article.getId());
    }

    return article;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Restores the web content article from the Recycle Bin.
 *
 * @param  userId the primary key of the user restoring the web content
 *         article//from  w  w  w. j ava  2s.c  o  m
 * @param  article the web content article
 * @return the restored web content article from the Recycle Bin
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle restoreArticleFromTrash(long userId, JournalArticle article) throws PortalException {

    // Article

    if (!article.isInTrash()) {
        throw new RestoreEntryException(RestoreEntryException.INVALID_STATUS);
    }

    String trashArticleId = TrashUtil.getOriginalTitle(article.getArticleId());

    List<JournalArticle> articleVersions = journalArticlePersistence.findByG_A(article.getGroupId(),
            article.getArticleId());

    for (JournalArticle articleVersion : articleVersions) {
        articleVersion.setArticleId(trashArticleId);

        journalArticlePersistence.update(articleVersion);
    }

    article.setArticleId(trashArticleId);

    journalArticlePersistence.update(article);

    JournalArticleResource articleResource = journalArticleResourcePersistence
            .fetchByPrimaryKey(article.getResourcePrimKey());

    articleResource.setArticleId(trashArticleId);

    journalArticleResourcePersistence.update(articleResource);

    TrashEntry trashEntry = trashEntryLocalService.getEntry(JournalArticle.class.getName(),
            article.getResourcePrimKey());

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setScopeGroupId(article.getGroupId());

    updateStatus(userId, article, trashEntry.getStatus(), null, serviceContext,
            new HashMap<String, Serializable>());

    // Trash

    List<TrashVersion> trashVersions = trashVersionLocalService.getVersions(trashEntry.getEntryId());

    boolean visible = false;

    for (TrashVersion trashVersion : trashVersions) {
        JournalArticle trashArticleVersion = journalArticlePersistence
                .findByPrimaryKey(trashVersion.getClassPK());

        trashArticleVersion.setStatus(trashVersion.getStatus());

        if (trashVersion.getStatus() == WorkflowConstants.STATUS_APPROVED) {
            visible = true;
        }

        journalArticlePersistence.update(trashArticleVersion);
    }

    trashEntryLocalService.deleteEntry(JournalArticle.class.getName(), article.getResourcePrimKey());

    if (visible) {
        assetEntryLocalService.updateVisible(JournalArticle.class.getName(), article.getResourcePrimKey(),
                true);
    }

    // Comment

    if (isArticleCommentsEnabled(article.getCompanyId())) {
        CommentManagerUtil.restoreDiscussionFromTrash(JournalArticle.class.getName(),
                article.getResourcePrimKey());
    }

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", article.getTitleMapAsXML());

    SocialActivityManagerUtil.addActivity(userId, article, SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
            extraDataJSONObject.toString(), 0);

    return article;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Updates the workflow status of the web content article.
 *
 * @param  userId the primary key of the user updating the web content
 *         article's status/*from   ww  w  .  jav  a  2  s .c om*/
 * @param  article the web content article
 * @param  status the web content article's workflow status. For more
 *         information see {@link WorkflowConstants} for constants starting
 *         with the "STATUS_" prefix.
 * @param  articleURL the web content article's accessible URL
 * @param  serviceContext the service context to be applied. Can set the
 *         modification date, status date, and portlet preferences. With
 *         respect to social activities, by setting the service context's
 *         command to {@link Constants#UPDATE}, the invocation is considered
 *         a web content update activity; otherwise it is considered a web
 *         content add activity.
 * @param  workflowContext the web content article's configured workflow
 *         context
 * @return the updated web content article
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle updateStatus(long userId, JournalArticle article, int status, String articleURL,
        ServiceContext serviceContext, Map<String, Serializable> workflowContext) throws PortalException {

    // Article

    User user = userLocalService.getUser(userId);
    Date now = new Date();

    if ((status == WorkflowConstants.STATUS_APPROVED)
            && (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT)
            && (article.getDisplayDate() != null) && now.before(article.getDisplayDate())) {

        status = WorkflowConstants.STATUS_SCHEDULED;
    }

    int oldStatus = article.getStatus();

    Date modifiedDate = serviceContext.getModifiedDate(now);

    article.setModifiedDate(modifiedDate);

    if (status == WorkflowConstants.STATUS_APPROVED) {
        Date expirationDate = article.getExpirationDate();

        if ((expirationDate != null) && expirationDate.before(now)) {
            article.setExpirationDate(null);
        }
    }

    if (status == WorkflowConstants.STATUS_EXPIRED) {
        article.setExpirationDate(now);
    }

    article.setStatus(status);
    article.setStatusByUserId(user.getUserId());
    article.setStatusByUserName(user.getFullName());
    article.setStatusDate(modifiedDate);

    journalArticlePersistence.update(article);

    if (isExpireAllArticleVersions(article.getCompanyId())) {
        setArticlesExpirationDate(article);
    }

    if (hasModifiedLatestApprovedVersion(article.getGroupId(), article.getArticleId(), article.getVersion())) {

        if (status == WorkflowConstants.STATUS_APPROVED) {
            updateUrlTitles(article.getGroupId(), article.getArticleId(), article.getUrlTitle());

            // Asset

            String title = article.getTitleMapAsXML();
            String description = article.getDescriptionMapAsXML();

            if ((oldStatus != WorkflowConstants.STATUS_APPROVED)
                    && (article.getVersion() != JournalArticleConstants.VERSION_DEFAULT)) {

                AssetEntry draftAssetEntry = assetEntryLocalService.fetchEntry(JournalArticle.class.getName(),
                        article.getPrimaryKey());

                if (draftAssetEntry != null) {
                    long[] assetCategoryIds = draftAssetEntry.getCategoryIds();
                    String[] assetTagNames = draftAssetEntry.getTagNames();

                    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(
                            draftAssetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED, false);

                    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

                    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, article.getGroupId(),
                            article.getCreateDate(), article.getModifiedDate(), JournalArticle.class.getName(),
                            article.getResourcePrimKey(), article.getUuid(), getClassTypeId(article),
                            assetCategoryIds, assetTagNames, isListable(article), false, null, null, null, null,
                            ContentTypes.TEXT_HTML, title, description, description, null,
                            article.getLayoutUuid(), 0, 0, draftAssetEntry.getPriority());

                    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
                            AssetLinkConstants.TYPE_RELATED);

                    assetEntryLocalService.deleteEntry(draftAssetEntry);
                }
            }

            if (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT) {

                assetEntryLocalService.updateEntry(JournalArticle.class.getName(), article.getResourcePrimKey(),
                        article.getDisplayDate(), article.getExpirationDate(), isListable(article), true);
            }

            // Social

            JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

            extraDataJSONObject.put("title", title);

            if (serviceContext.isCommandUpdate()) {
                SocialActivityManagerUtil.addActivity(user.getUserId(), article,
                        JournalActivityKeys.UPDATE_ARTICLE, extraDataJSONObject.toString(), 0);
            } else {
                SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), article,
                        JournalActivityKeys.ADD_ARTICLE, extraDataJSONObject.toString(), 0);
            }
        } else if (oldStatus == WorkflowConstants.STATUS_APPROVED) {
            updatePreviousApprovedArticle(article);
        }
    }

    if ((article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT)
            && (oldStatus != WorkflowConstants.STATUS_IN_TRASH)
            && (status != WorkflowConstants.STATUS_IN_TRASH)) {

        // Email

        if ((oldStatus == WorkflowConstants.STATUS_PENDING) && ((status == WorkflowConstants.STATUS_APPROVED)
                || (status == WorkflowConstants.STATUS_DENIED))) {

            String msg = "granted";

            if (status == WorkflowConstants.STATUS_DENIED) {
                msg = "denied";
            }

            try {
                PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

                articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(),
                        article.getArticleId());

                sendEmail(article, articleURL, preferences, msg, serviceContext);
            } catch (Exception e) {
                _log.error("Unable to send email to notify the change of status " + "to " + msg
                        + " for article " + article.getId() + ": " + e.getMessage());
            }
        }

        // Subscriptions

        String action = "update";

        if (article.getVersion() == 1.0) {
            action = "add";
        }

        notifySubscribers(user.getUserId(), article, action, serviceContext);
    }

    return article;
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override//from   w  w  w. ja v a2s  . c o m
public JournalFolder moveFolderToTrash(long userId, long folderId) throws PortalException {

    // Folder

    JournalFolder folder = journalFolderPersistence.findByPrimaryKey(folderId);

    if (folder.isInTrash()) {
        throw new TrashEntryException();
    }

    String title = folder.getName();

    folder = updateStatus(userId, folder, WorkflowConstants.STATUS_IN_TRASH);

    // Trash

    UnicodeProperties typeSettingsProperties = new UnicodeProperties();

    typeSettingsProperties.put("title", folder.getName());

    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, folder.getGroupId(),
            JournalFolder.class.getName(), folder.getFolderId(), folder.getUuid(), null,
            WorkflowConstants.STATUS_APPROVED, null, typeSettingsProperties);

    folder.setName(TrashUtil.getTrashTitle(trashEntry.getEntryId()));

    journalFolderPersistence.update(folder);

    // Folders and articles

    List<Object> foldersAndArticles = journalFolderLocalService.getFoldersAndArticles(folder.getGroupId(),
            folder.getFolderId());

    moveDependentsToTrash(foldersAndArticles, trashEntry.getEntryId());

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", title);

    SocialActivityManagerUtil.addActivity(userId, folder, SocialActivityConstants.TYPE_MOVE_TO_TRASH,
            extraDataJSONObject.toString(), 0);

    return folder;
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

@Override
public void restoreFolderFromTrash(long userId, long folderId) throws PortalException {

    // Folder/*from w ww .j  a  va 2 s . c o  m*/

    JournalFolder folder = journalFolderPersistence.findByPrimaryKey(folderId);

    if (!folder.isInTrash()) {
        throw new RestoreEntryException(RestoreEntryException.INVALID_STATUS);
    }

    folder.setName(TrashUtil.getOriginalTitle(folder.getName()));

    journalFolderPersistence.update(folder);

    TrashEntry trashEntry = trashEntryLocalService.getEntry(JournalFolder.class.getName(), folderId);

    updateStatus(userId, folder, trashEntry.getStatus());

    // Folders and articles

    List<Object> foldersAndArticles = journalFolderLocalService.getFoldersAndArticles(folder.getGroupId(),
            folder.getFolderId(), WorkflowConstants.STATUS_IN_TRASH);

    restoreDependentsFromTrash(foldersAndArticles);

    // Trash

    trashEntryLocalService.deleteEntry(JournalFolder.class.getName(), folder.getFolderId());

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", folder.getName());

    SocialActivityManagerUtil.addActivity(userId, folder, SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
            extraDataJSONObject.toString(), 0);
}

From source file:com.liferay.subscription.service.impl.SubscriptionLocalServiceImpl.java

License:Open Source License

/**
 * Subscribes the user to the entity, notifying him at the given frequency.
 *
 * <p>/*from  w  w  w  . ja va 2  s.  c  om*/
 * If there is no asset entry with the class name and class PK a new asset
 * entry is created.
 * </p>
 *
 * <p>
 * A social activity for the subscription is created using the asset entry
 * associated with the class name and class PK, or the newly created asset
 * entry.
 * </p>
 *
 * @param  userId the primary key of the user
 * @param  groupId the primary key of the entity's group
 * @param  className the entity's class name
 * @param  classPK the primary key of the entity's instance
 * @param  frequency the frequency for notifications
 * @return the subscription
 */
@Override
public Subscription addSubscription(long userId, long groupId, String className, long classPK, String frequency)
        throws PortalException {

    // Subscription

    User user = userLocalService.getUser(userId);
    long classNameId = classNameLocalService.getClassNameId(className);

    Subscription subscription = subscriptionPersistence.fetchByC_U_C_C(user.getCompanyId(), userId, classNameId,
            classPK);

    if (subscription == null) {
        long subscriptionId = counterLocalService.increment();

        subscription = subscriptionPersistence.create(subscriptionId);

        subscription.setGroupId(groupId);
        subscription.setCompanyId(user.getCompanyId());
        subscription.setUserId(user.getUserId());
        subscription.setUserName(user.getFullName());
        subscription.setClassNameId(classNameId);
        subscription.setClassPK(classPK);
        subscription.setFrequency(frequency);

        subscriptionPersistence.update(subscription);
    }

    if (groupId > 0) {

        // Asset

        AssetEntry assetEntry = null;

        try {
            assetEntry = assetEntryLocalService.getEntry(className, classPK);
        } catch (Exception e) {
            assetEntry = assetEntryLocalService.updateEntry(userId, groupId, subscription.getCreateDate(),
                    subscription.getModifiedDate(), className, classPK, null, 0, null, null, true, false, null,
                    null, null, null, null, String.valueOf(groupId), null, null, null, null, 0, 0, null);
        }

        // Social

        JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

        extraDataJSONObject.put("title", assetEntry.getTitle());

        SocialActivityManagerUtil.addActivity(userId, assetEntry, SocialActivityConstants.TYPE_SUBSCRIBE,
                extraDataJSONObject.toString(), 0);
    }

    return subscription;
}

From source file:com.liferay.subscription.service.impl.SubscriptionLocalServiceImpl.java

License:Open Source License

/**
 * Deletes the subscription. A social activity with the unsubscribe action
 * is created.//from   w  w  w  .  ja  va2 s .  c om
 *
 * @param  subscription the subscription
 * @return the subscription that was removed
 */
@Override
public Subscription deleteSubscription(Subscription subscription) throws PortalException {

    // Subscription

    subscriptionPersistence.remove(subscription);

    // Social

    ClassName className = classNameLocalService.getClassName(subscription.getClassNameId());

    AssetEntry assetEntry = assetEntryLocalService.fetchEntry(className.getClassName(),
            subscription.getClassPK());

    if (assetEntry != null) {
        JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

        extraDataJSONObject.put("title", assetEntry.getTitle());

        SocialActivityManagerUtil.addActivity(subscription.getUserId(), subscription,
                SocialActivityConstants.TYPE_UNSUBSCRIBE, extraDataJSONObject.toString(), 0);
    }

    return subscription;
}