List of usage examples for com.liferay.portal.kernel.comment CommentManagerUtil restoreDiscussionFromTrash
public static void restoreDiscussionFromTrash(String className, long classPK)
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
@Indexable(type = IndexableType.REINDEX) @Override/*www. jav a 2s .co m*/ 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
/** * Restores the web content article from the Recycle Bin. * * @param userId the primary key of the user restoring the web content * article//from www .j a v a 2s. co 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.wiki.service.impl.WikiPageLocalServiceImpl.java
License:Open Source License
protected void movePageFromTrash(long userId, WikiPage page, long newNodeId, String newParentTitle) throws PortalException { // Page//from ww w .j a v a 2 s.c o m String trashTitle = page.getTitle(); String originalTitle = TrashUtil.getOriginalTitle(trashTitle); long oldNodeId = page.getNodeId(); if (newNodeId == 0) { newNodeId = oldNodeId; } List<WikiPage> pageVersions = wikiPagePersistence.findByR_N_H(page.getResourcePrimKey(), oldNodeId, false); for (WikiPage pageVersion : pageVersions) { pageVersion.setParentTitle(newParentTitle); pageVersion.setNodeId(newNodeId); pageVersion.setTitle(originalTitle); wikiPagePersistence.update(pageVersion); } WikiPageResource pageResource = wikiPageResourcePersistence.fetchByPrimaryKey(page.getResourcePrimKey()); pageResource.setNodeId(newNodeId); pageResource.setTitle(originalTitle); wikiPageResourcePersistence.update(pageResource); page.setNodeId(newNodeId); page.setTitle(originalTitle); WikiPage parentPage = page.getParentPage(); if ((parentPage != null) && parentPage.isInTrash()) { page.setParentTitle(StringPool.BLANK); } if (Validator.isNotNull(newParentTitle)) { WikiPage newParentPage = getPage(newNodeId, newParentTitle); if (!newParentPage.isInTrash()) { page.setParentTitle(newParentTitle); } } WikiPage redirectPage = page.getRedirectPage(); if ((redirectPage != null) && redirectPage.isInTrash()) { page.setRedirectTitle(StringPool.BLANK); } wikiPagePersistence.update(page); TrashEntry trashEntry = trashEntryLocalService.getEntry(WikiPage.class.getName(), page.getResourcePrimKey()); updateStatus(userId, page, trashEntry.getStatus(), new ServiceContext(), new HashMap<String, Serializable>()); // Attachments for (FileEntry fileEntry : page.getAttachmentsFileEntries()) { PortletFileRepositoryUtil.restorePortletFileEntryFromTrash(userId, fileEntry.getFileEntryId()); } // Child pages moveDependentChildPagesFromTrash(page, oldNodeId, trashTitle); // Redirect pages moveDependentRedirectorPagesFromTrash(page, oldNodeId, trashTitle); // Trash List<TrashVersion> trashVersions = trashVersionLocalService.getVersions(trashEntry.getEntryId()); for (TrashVersion trashVersion : trashVersions) { WikiPage trashArticleVersion = wikiPagePersistence.findByPrimaryKey(trashVersion.getClassPK()); trashArticleVersion.setStatus(trashVersion.getStatus()); wikiPagePersistence.update(trashArticleVersion); } trashEntryLocalService.deleteEntry(WikiPage.class.getName(), page.getResourcePrimKey()); // Comment CommentManagerUtil.restoreDiscussionFromTrash(WikiPage.class.getName(), page.getResourcePrimKey()); // Social JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("title", page.getTitle()); extraDataJSONObject.put("version", page.getVersion()); SocialActivityManagerUtil.addActivity(userId, page, SocialActivityConstants.TYPE_RESTORE_FROM_TRASH, extraDataJSONObject.toString(), 0); Indexer<WikiPage> indexer = IndexerRegistryUtil.nullSafeGetIndexer(WikiPage.class); indexer.reindex(page); }