List of usage examples for com.liferay.portal.kernel.service ServiceContextUtil getPortletPreferences
public static PortletPreferences getPortletPreferences(ServiceContext serviceContext)
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Adds a web content article with additional parameters. * * <p>/*w w w. j a v a 2 s . c o m*/ * The web content articles hold HTML content wrapped in XML. The XML lets * you specify the article's default locale and available locales. Here is a * content example: * </p> * * <p> * <pre> * <code> * <?xml version='1.0' encoding='UTF-8'?> * <root default-locale="en_US" available-locales="en_US"> * <static-content language-id="en_US"> * <![CDATA[<p><b><i>test<i> content<b></p>]]> * </static-content> * </root> * </code> * </pre> * </p> * * @param userId the primary key of the web content article's creator/owner * @param groupId the primary key of the web content article's group * @param folderId the primary key of the web content article folder * @param classNameId the primary key of the DDMStructure class if the web * content article is related to a DDM structure, the primary key of * the class name associated with the article, or * JournalArticleConstants.CLASSNAME_ID_DEFAULT in the journal-api * module otherwise * @param classPK the primary key of the DDM structure, if the primary key * of the DDMStructure class is given as the * <code>classNameId</code> parameter, the primary key of the class * associated with the web content article, or <code>0</code> * otherwise * @param articleId the primary key of the web content article * @param autoArticleId whether to auto generate the web content article ID * @param version the web content article's version * @param titleMap the web content article's locales and localized titles * @param descriptionMap the web content article's locales and localized * descriptions * @param content the HTML content wrapped in XML * @param ddmStructureKey the primary key of the web content article's DDM * structure, if the article is related to a DDM structure, or * <code>null</code> otherwise * @param ddmTemplateKey the primary key of the web content article's DDM * template * @param layoutUuid the unique string identifying the web content * article's display page * @param displayDateMonth the month the web content article is set to * display * @param displayDateDay the calendar day the web content article is set to * display * @param displayDateYear the year the web content article is set to * display * @param displayDateHour the hour the web content article is set to * display * @param displayDateMinute the minute the web content article is set to * display * @param expirationDateMonth the month the web content article is set to * expire * @param expirationDateDay the calendar day the web content article is set * to expire * @param expirationDateYear the year the web content article is set to * expire * @param expirationDateHour the hour the web content article is set to * expire * @param expirationDateMinute the minute the web content article is set to * expire * @param neverExpire whether the web content article is not set to auto * expire * @param reviewDateMonth the month the web content article is set for * review * @param reviewDateDay the calendar day the web content article is set for * review * @param reviewDateYear the year the web content article is set for review * @param reviewDateHour the hour the web content article is set for review * @param reviewDateMinute the minute the web content article is set for * review * @param neverReview whether the web content article is not set for review * @param indexable whether the web content article is searchable * @param smallImage whether the web content article has a small image * @param smallImageURL the web content article's small image URL * @param smallImageFile the web content article's small image file * @param images the web content's images * @param articleURL the web content article's accessible URL * @param serviceContext the service context to be applied. Can set the * UUID, creation date, modification date, expando bridge * attributes, guest permissions, group permissions, asset category * IDs, asset tag names, asset link entry IDs, URL title, and * workflow actions for the web content article. Can also set * whether to add the default guest and group permissions. * @return the web content article */ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle addArticle(long userId, long groupId, long folderId, long classNameId, long classPK, String articleId, boolean autoArticleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile, Map<String, byte[]> images, String articleURL, ServiceContext serviceContext) throws PortalException { // Article User user = userLocalService.getUser(userId); articleId = StringUtil.toUpperCase(StringUtil.trim(articleId)); Date displayDate = null; Date expirationDate = null; Date reviewDate = null; if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), null); if (!neverExpire) { expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, user.getTimeZone(), ArticleExpirationDateException.class); } if (!neverReview) { reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, user.getTimeZone(), ArticleReviewDateException.class); } } byte[] smallImageBytes = null; try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } Date now = new Date(); validateDDMStructureId(groupId, folderId, ddmStructureKey); if (autoArticleId) { articleId = String.valueOf(counterLocalService.increment()); } validate(user.getCompanyId(), groupId, classNameId, articleId, autoArticleId, version, titleMap, content, ddmStructureKey, ddmTemplateKey, displayDate, expirationDate, smallImage, smallImageURL, smallImageFile, smallImageBytes, serviceContext); validateReferences(groupId, ddmStructureKey, ddmTemplateKey, layoutUuid, smallImage, smallImageURL, smallImageBytes, 0, content); serviceContext.setAttribute("articleId", articleId); long id = counterLocalService.increment(); String articleResourceUuid = GetterUtil.getString(serviceContext.getAttribute("articleResourceUuid")); long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(articleResourceUuid, groupId, articleId); JournalArticle article = journalArticlePersistence.create(id); Locale locale = getArticleDefaultLocale(content); String title = titleMap.get(locale); article.setUuid(serviceContext.getUuid()); article.setResourcePrimKey(resourcePrimKey); article.setGroupId(groupId); article.setCompanyId(user.getCompanyId()); article.setUserId(user.getUserId()); article.setUserName(user.getFullName()); article.setFolderId(folderId); article.setClassNameId(classNameId); article.setClassPK(classPK); article.setTreePath(article.buildTreePath()); article.setArticleId(articleId); article.setVersion(version); article.setUrlTitle(getUniqueUrlTitle(id, groupId, articleId, title, null, serviceContext)); content = format(user, groupId, article, content); article.setContent(content); article.setDDMStructureKey(ddmStructureKey); article.setDDMTemplateKey(ddmTemplateKey); article.setDefaultLanguageId(LocaleUtil.toLanguageId(locale)); article.setLayoutUuid(layoutUuid); article.setDisplayDate(displayDate); article.setExpirationDate(expirationDate); article.setReviewDate(reviewDate); article.setIndexable(indexable); article.setSmallImage(smallImage); article.setSmallImageId(counterLocalService.increment()); article.setSmallImageURL(smallImageURL); if ((expirationDate == null) || expirationDate.after(now)) { article.setStatus(WorkflowConstants.STATUS_DRAFT); } else { article.setStatus(WorkflowConstants.STATUS_EXPIRED); } article.setStatusByUserId(userId); article.setStatusDate(serviceContext.getModifiedDate(now)); article.setExpandoBridgeAttributes(serviceContext); journalArticlePersistence.update(article); // Article localization _addArticleLocalizedFields(user.getCompanyId(), article.getId(), titleMap, descriptionMap); // Resources if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) { addArticleResources(article, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions()); } else { addArticleResources(article, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions()); } // Small image saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes); // Asset updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); // Dynamic data mapping if (classNameLocalService.getClassNameId(DDMStructure.class) == classNameId) { updateDDMStructurePredefinedValues(classPK, content, serviceContext); } else { updateDDMLinks(id, groupId, ddmStructureKey, ddmTemplateKey, true); } // Email PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); articleURL = buildArticleURL(articleURL, groupId, folderId, articleId); serviceContext.setAttribute("articleURL", articleURL); sendEmail(article, articleURL, preferences, "requested", serviceContext); // Workflow if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { startWorkflowInstance(userId, article, serviceContext); } else { updateStatus(userId, article, WorkflowConstants.STATUS_APPROVED, null, serviceContext, new HashMap<String, Serializable>()); } return journalArticlePersistence.findByPrimaryKey(article.getId()); }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Deletes the web content article and its resources, optionally sending * email notifying denial of the article if it had not yet been approved. * * @param article the web content article * @param articleURL the web content article's accessible URL to include in * email notifications (optionally <code>null</code>) * @param serviceContext the service context to be applied (optionally * <code>null</code>). Can set the portlet preferences that include * email information to notify recipients of the unapproved web * content's denial./*ww w . j a v a 2 s . c om*/ * @return the deleted web content article */ @Indexable(type = IndexableType.DELETE) @Override @SystemEvent(action = SystemEventConstants.ACTION_SKIP, send = false, type = SystemEventConstants.TYPE_DELETE) public JournalArticle deleteArticle(JournalArticle article, String articleURL, ServiceContext serviceContext) throws PortalException { JournalArticleResource articleResource = journalArticleResourceLocalService .fetchArticleResource(article.getGroupId(), article.getArticleId()); if (article.isApproved() && isLatestVersion(article.getGroupId(), article.getArticleId(), article.getVersion(), WorkflowConstants.STATUS_APPROVED)) { updatePreviousApprovedArticle(article); } // Article localization journalArticleLocalizationPersistence.removeByArticlePK(article.getId()); // Email if ((serviceContext != null) && Validator.isNotNull(articleURL)) { PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); if ((preferences != null) && !article.isApproved() && isLatestVersion(article.getGroupId(), article.getArticleId(), article.getVersion())) { articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(), article.getArticleId()); sendEmail(article, articleURL, preferences, "denied", serviceContext); } } // Dynamic data mapping if (article.getClassNameId() != classNameLocalService.getClassNameId(DDMStructure.class)) { ddmStorageLinkLocalService.deleteClassStorageLink(article.getId()); ddmTemplateLinkLocalService.deleteTemplateLink( classNameLocalService.getClassNameId(JournalArticle.class), article.getId()); } // Expando expandoRowLocalService.deleteRows(article.getId()); // Trash if (article.isInTrash()) { TrashEntry trashEntry = article.getTrashEntry(); if (trashEntry != null) { trashVersionLocalService.deleteTrashVersion(JournalArticle.class.getName(), article.getId()); } } // Workflow if (!article.isDraft()) { workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(article.getCompanyId(), article.getGroupId(), JournalArticle.class.getName(), article.getId()); } int articlesCount = journalArticlePersistence.countByG_A(article.getGroupId(), article.getArticleId()); if (articlesCount == 1) { // Asset assetEntryLocalService.deleteEntry(JournalArticle.class.getName(), article.getResourcePrimKey()); // Comment CommentManagerUtil.deleteDiscussion(JournalArticle.class.getName(), article.getResourcePrimKey()); // Content searches journalContentSearchLocalService.deleteArticleContentSearches(article.getGroupId(), article.getArticleId()); // Images long folderId = article.getImagesFolderId(); if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { PortletFileRepositoryUtil.deletePortletFolder(folderId); } // Ratings ratingsStatsLocalService.deleteStats(JournalArticle.class.getName(), article.getResourcePrimKey()); // Small image imageLocalService.deleteImage(article.getSmallImageId()); // Trash trashEntryLocalService.deleteEntry(JournalArticle.class.getName(), article.getResourcePrimKey()); // Resources resourceLocalService.deleteResource(article.getCompanyId(), JournalArticle.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, article.getResourcePrimKey()); // Resource if (articleResource != null) { journalArticleResourceLocalService.deleteJournalArticleResource(articleResource); } } // Article journalArticlePersistence.remove(article); // System event if (articleResource != null) { JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("uuid", article.getUuid()); extraDataJSONObject.put("version", article.getVersion()); systemEventLocalService.addSystemEvent(0, article.getGroupId(), article.getModelClassName(), article.getPrimaryKey(), articleResource.getUuid(), null, SystemEventConstants.TYPE_DELETE, extraDataJSONObject.toString()); } return article; }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Updates the web content article with additional parameters. * * @param userId the primary key of the user updating the web content * article//from www . j a va 2s. co m * @param groupId the primary key of the web content article's group * @param folderId the primary key of the web content article folder * @param articleId the primary key of the web content article * @param version the web content article's version * @param titleMap the web content article's locales and localized titles * @param descriptionMap the web content article's locales and localized * descriptions * @param content the HTML content wrapped in XML. For more information, * see the content example in the {@link #addArticle(long, long, * long, long, long, String, boolean, double, Map, Map, String, * String, String, String, int, int, int, int, int, int, int, int, * int, int, boolean, int, int, int, int, int, boolean, boolean, * boolean, String, File, Map, String, ServiceContext)} description. * @param ddmStructureKey the primary key of the web content article's DDM * structure, if the article is related to a DDM structure, or * <code>null</code> otherwise * @param ddmTemplateKey the primary key of the web content article's DDM * template * @param layoutUuid the unique string identifying the web content * article's display page * @param displayDateMonth the month the web content article is set to * display * @param displayDateDay the calendar day the web content article is set to * display * @param displayDateYear the year the web content article is set to * display * @param displayDateHour the hour the web content article is set to * display * @param displayDateMinute the minute the web content article is set to * display * @param expirationDateMonth the month the web content article is set to * expire * @param expirationDateDay the calendar day the web content article is set * to expire * @param expirationDateYear the year the web content article is set to * expire * @param expirationDateHour the hour the web content article is set to * expire * @param expirationDateMinute the minute the web content article is set to * expire * @param neverExpire whether the web content article is not set to auto * expire * @param reviewDateMonth the month the web content article is set for * review * @param reviewDateDay the calendar day the web content article is set for * review * @param reviewDateYear the year the web content article is set for review * @param reviewDateHour the hour the web content article is set for review * @param reviewDateMinute the minute the web content article is set for * review * @param neverReview whether the web content article is not set for review * @param indexable whether the web content is searchable * @param smallImage whether to update web content article's a small image. * A file must be passed in as <code>smallImageFile</code> value, * otherwise the current small image is deleted. * @param smallImageURL the web content article's small image URL * (optionally <code>null</code>) * @param smallImageFile the web content article's new small image file * (optionally <code>null</code>). Must pass in * <code>smallImage</code> value of <code>true</code> to replace the * article's small image file. * @param images the web content's images (optionally <code>null</code>) * @param articleURL the web content article's accessible URL (optionally * <code>null</code>) * @param serviceContext the service context to be applied. Can set the * modification date, expando bridge attributes, asset category IDs, * asset tag names, asset link entry IDs, asset priority, workflow * actions, URL title , and can set whether to add the default * command update for the web content article. 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. * @return the updated web content article */ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle updateArticle(long userId, long groupId, long folderId, String articleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile, Map<String, byte[]> images, String articleURL, ServiceContext serviceContext) throws PortalException { // Article User user = userLocalService.getUser(userId); articleId = StringUtil.toUpperCase(StringUtil.trim(articleId)); byte[] smallImageBytes = null; try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } JournalArticle latestArticle = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY); JournalArticle article = latestArticle; boolean imported = ExportImportThreadLocal.isImportInProcess(); double latestVersion = latestArticle.getVersion(); boolean addNewVersion = false; if (imported) { article = getArticle(groupId, articleId, version); } else { if ((version > 0) && (version != latestVersion)) { StringBundler sb = new StringBundler(4); sb.append("Version "); sb.append(version); sb.append(" is not the same as "); sb.append(latestVersion); throw new ArticleVersionException(sb.toString()); } serviceContext.validateModifiedDate(latestArticle, ArticleVersionException.class); if (latestArticle.isApproved() || latestArticle.isExpired() || latestArticle.isScheduled()) { addNewVersion = true; version = getNextVersion(article); } } Date displayDate = null; Date expirationDate = null; Date reviewDate = null; if (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), null); if (!neverExpire) { expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, user.getTimeZone(), ArticleExpirationDateException.class); } if (!neverReview) { reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, user.getTimeZone(), ArticleReviewDateException.class); } } Date now = new Date(); boolean expired = false; if ((expirationDate != null) && expirationDate.before(now)) { expired = true; } validate(user.getCompanyId(), groupId, latestArticle.getClassNameId(), titleMap, content, ddmStructureKey, ddmTemplateKey, displayDate, expirationDate, smallImage, smallImageURL, smallImageFile, smallImageBytes, serviceContext); validateReferences(groupId, ddmStructureKey, ddmTemplateKey, layoutUuid, smallImage, smallImageURL, smallImageBytes, latestArticle.getSmallImageId(), content); if (addNewVersion) { long id = counterLocalService.increment(); article = journalArticlePersistence.create(id); article.setResourcePrimKey(latestArticle.getResourcePrimKey()); article.setGroupId(latestArticle.getGroupId()); article.setCompanyId(latestArticle.getCompanyId()); article.setUserId(user.getUserId()); article.setUserName(user.getFullName()); article.setCreateDate(latestArticle.getCreateDate()); article.setClassNameId(latestArticle.getClassNameId()); article.setClassPK(latestArticle.getClassPK()); article.setArticleId(articleId); article.setVersion(version); article.setSmallImageId(latestArticle.getSmallImageId()); _addArticleLocalizedFields(article.getCompanyId(), article.getId(), titleMap, descriptionMap); } else { _updateArticleLocalizedFields(article.getCompanyId(), article.getId(), titleMap, descriptionMap); } Locale locale = getArticleDefaultLocale(content); String title = titleMap.get(locale); content = format(user, groupId, article, content); article.setFolderId(folderId); article.setTreePath(article.buildTreePath()); article.setUrlTitle(getUniqueUrlTitle(article.getId(), groupId, article.getArticleId(), title, latestArticle.getUrlTitle(), serviceContext)); article.setContent(content); article.setDDMStructureKey(ddmStructureKey); article.setDDMTemplateKey(ddmTemplateKey); article.setDefaultLanguageId(LocaleUtil.toLanguageId(locale)); article.setLayoutUuid(layoutUuid); article.setDisplayDate(displayDate); article.setExpirationDate(expirationDate); article.setReviewDate(reviewDate); article.setIndexable(indexable); article.setSmallImage(smallImage); if (smallImage) { if ((smallImageFile != null) && (smallImageBytes != null)) { article.setSmallImageId(counterLocalService.increment()); } } else { article.setSmallImageId(0); } article.setSmallImageURL(smallImageURL); if (latestArticle.isPending()) { article.setStatus(latestArticle.getStatus()); } else if (!expired) { article.setStatus(WorkflowConstants.STATUS_DRAFT); } else { article.setStatus(WorkflowConstants.STATUS_EXPIRED); } ExpandoBridgeUtil.setExpandoBridgeAttributes(latestArticle.getExpandoBridge(), article.getExpandoBridge(), serviceContext); journalArticlePersistence.update(article); // Asset if (hasModifiedLatestApprovedVersion(groupId, articleId, version)) { updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); } // Dynamic data mapping if (classNameLocalService.getClassNameId(DDMStructure.class) == article.getClassNameId()) { updateDDMStructurePredefinedValues(article.getClassPK(), content, serviceContext); } else { updateDDMLinks(article.getId(), groupId, ddmStructureKey, ddmTemplateKey, addNewVersion); } // Small image saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes); // Email PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); // Workflow if (expired && imported) { updateStatus(userId, article, article.getStatus(), articleURL, serviceContext, new HashMap<String, Serializable>()); } if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_PUBLISH) { articleURL = buildArticleURL(articleURL, groupId, folderId, articleId); serviceContext.setAttribute("articleURL", articleURL); sendEmail(article, articleURL, preferences, "requested", serviceContext); startWorkflowInstance(userId, article, serviceContext); } return journalArticlePersistence.findByPrimaryKey(article.getId()); }
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//w w w . j a va 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; }