List of usage examples for com.liferay.portal.kernel.service ServiceContext validateModifiedDate
public void validateModifiedDate(AuditedModel auditedModel, Class<? extends PortalException> clazz) throws PortalException
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 w ww. ja v a 2 s .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 translation of the web content article. * * @param groupId the primary key of the web content article's group * @param articleId the primary key of the web content article * @param version the web content article's version * @param locale the locale of the web content article's display template * @param title the translated web content article title * @param description the translated web content article description * @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 images the web content's images * @param serviceContext the service context to be applied. Can set the * modification date and URL title for the web content article. * @return the updated web content article *//* w w w.j av a 2 s .c o m*/ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle updateArticleTranslation(long groupId, String articleId, double version, Locale locale, String title, String description, String content, Map<String, byte[]> images, ServiceContext serviceContext) throws PortalException { validateContent(content); JournalArticle oldArticle = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY); double oldVersion = oldArticle.getVersion(); if ((version > 0) && (version != oldVersion)) { StringBundler sb = new StringBundler(4); sb.append("Version "); sb.append(version); sb.append(" is not the same as "); sb.append(oldVersion); throw new ArticleVersionException(sb.toString()); } boolean incrementVersion = false; if (oldArticle.isApproved() || oldArticle.isExpired()) { incrementVersion = true; } if (serviceContext != null) { serviceContext.validateModifiedDate(oldArticle, ArticleVersionException.class); } JournalArticle article = null; User user = userLocalService.fetchUser(oldArticle.getUserId()); if (user == null) { user = userLocalService.getDefaultUser(oldArticle.getCompanyId()); } Locale defaultLocale = getArticleDefaultLocale(content); if (incrementVersion) { double newVersion = getNextVersion(oldArticle); long id = counterLocalService.increment(); article = journalArticlePersistence.create(id); article.setResourcePrimKey(oldArticle.getResourcePrimKey()); article.setGroupId(oldArticle.getGroupId()); article.setCompanyId(oldArticle.getCompanyId()); article.setUserId(oldArticle.getUserId()); article.setUserName(user.getFullName()); article.setCreateDate(oldArticle.getCreateDate()); article.setFolderId(oldArticle.getFolderId()); article.setClassNameId(oldArticle.getClassNameId()); article.setClassPK(oldArticle.getClassPK()); article.setArticleId(articleId); article.setVersion(newVersion); article.setUrlTitle( getUniqueUrlTitle(id, groupId, articleId, title, oldArticle.getUrlTitle(), serviceContext)); article.setDDMStructureKey(oldArticle.getDDMStructureKey()); article.setDDMTemplateKey(oldArticle.getDDMTemplateKey()); article.setDefaultLanguageId(LocaleUtil.toLanguageId(defaultLocale)); article.setLayoutUuid(oldArticle.getLayoutUuid()); article.setDisplayDate(oldArticle.getDisplayDate()); article.setExpirationDate(oldArticle.getExpirationDate()); article.setReviewDate(oldArticle.getReviewDate()); article.setIndexable(oldArticle.getIndexable()); article.setSmallImage(oldArticle.getSmallImage()); article.setSmallImageId(oldArticle.getSmallImageId()); if (article.getSmallImageId() == 0) { article.setSmallImageId(counterLocalService.increment()); } article.setSmallImageURL(oldArticle.getSmallImageURL()); article.setStatus(WorkflowConstants.STATUS_DRAFT); article.setStatusDate(new Date()); ExpandoBridgeUtil.copyExpandoBridgeAttributes(oldArticle.getExpandoBridge(), article.getExpandoBridge()); // Article localization _addArticleLocalizedFields(article.getCompanyId(), article.getId(), oldArticle.getTitleMap(), oldArticle.getDescriptionMap()); // Dynamic data mapping updateDDMLinks(id, groupId, oldArticle.getDDMStructureKey(), oldArticle.getDDMTemplateKey(), true); } else { article = oldArticle; } _updateArticleLocalizedFields(article.getCompanyId(), article.getId(), title, description, LocaleUtil.toLanguageId(locale)); content = format(user, groupId, article, content); article.setContent(content); journalArticlePersistence.update(article); return article; }
From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java
License:Open Source License
protected WikiPage updatePage(long userId, WikiPage oldPage, long newNodeId, String newTitle, String content, String summary, boolean minorEdit, String format, String parentTitle, String redirectTitle, ServiceContext serviceContext) throws PortalException { User user = userPersistence.findByPrimaryKey(userId); long pageId = 0; if (oldPage.isApproved()) { pageId = counterLocalService.increment(); } else {//from w ww . ja v a2 s . co m pageId = oldPage.getPageId(); } content = SanitizerUtil.sanitize(user.getCompanyId(), oldPage.getGroupId(), userId, WikiPage.class.getName(), pageId, "text/" + format, content); long nodeId = oldPage.getNodeId(); if (newNodeId != 0) { nodeId = newNodeId; } if (!format.equals(oldPage.getFormat())) { validate(nodeId, content, format); } serviceContext.validateModifiedDate(oldPage, PageVersionException.class); long resourcePrimKey = wikiPageResourceLocalService.getPageResourcePrimKey(oldPage.getGroupId(), oldPage.getNodeId(), oldPage.getTitle()); Date now = new Date(); WikiPage page = oldPage; double newVersion = oldPage.getVersion(); if (oldPage.isApproved()) { newVersion = MathUtil.format(oldPage.getVersion() + 0.1, 1, 1); page = wikiPagePersistence.create(pageId); page.setUuid(serviceContext.getUuid()); } page.setResourcePrimKey(resourcePrimKey); page.setGroupId(oldPage.getGroupId()); page.setCompanyId(user.getCompanyId()); page.setUserId(user.getUserId()); page.setUserName(user.getFullName()); page.setCreateDate(oldPage.getCreateDate()); page.setNodeId(nodeId); page.setTitle(Validator.isNull(newTitle) ? oldPage.getTitle() : newTitle); page.setVersion(newVersion); page.setMinorEdit(minorEdit); page.setContent(content); if (oldPage.isPending()) { page.setStatus(oldPage.getStatus()); } else { page.setStatus(WorkflowConstants.STATUS_DRAFT); } page.setSummary(summary); page.setFormat(format); if (Validator.isNotNull(parentTitle)) { page.setParentTitle(parentTitle); } if (Validator.isNotNull(redirectTitle)) { page.setRedirectTitle(redirectTitle); } ExpandoBridgeUtil.setExpandoBridgeAttributes(oldPage.getExpandoBridge(), page.getExpandoBridge(), serviceContext); wikiPagePersistence.update(page); // Node WikiNode node = wikiNodePersistence.findByPrimaryKey(nodeId); node.setLastPostDate(serviceContext.getModifiedDate(now)); wikiNodePersistence.update(node); // Asset updateAsset(userId, page, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); // Workflow page = startWorkflowInstance(userId, page, serviceContext); return page; }