List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED
int STATUS_APPROVED
To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED.
Click Source Link
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle) throws PortalException, SystemException { // Get the latest article that is approved, if none are approved, get // the latest unapproved article try {// ww w. j a va2 s .c om return getLatestArticleByUrlTitle(groupId, urlTitle, WorkflowConstants.STATUS_APPROVED); } catch (NoSuchArticleException nsae) { return getLatestArticleByUrlTitle(groupId, urlTitle, WorkflowConstants.STATUS_PENDING); } }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getDisplayArticle(long groupId, String articleId) throws PortalException, SystemException { List<JournalArticle> articles = journalArticlePersistence.findByG_A_ST(groupId, articleId, WorkflowConstants.STATUS_APPROVED); if (articles.isEmpty()) { throw new NoSuchArticleException("No approved JournalArticle exists with the key {groupId=" + groupId + ", " + "articleId=" + articleId + "}"); }//from w ww.j a va 2s.c o m Date now = new Date(); for (int i = 0; i < articles.size(); i++) { JournalArticle article = articles.get(i); Date expirationDate = article.getExpirationDate(); if (article.getDisplayDate().before(now) && ((expirationDate == null) || expirationDate.after(now))) { return article; } } return articles.get(0); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getDisplayArticleByUrlTitle(long groupId, String urlTitle) throws PortalException, SystemException { List<JournalArticle> articles = null; OrderByComparator orderByComparator = new ArticleVersionComparator(); articles = journalArticlePersistence.findByG_UT_ST(groupId, urlTitle, WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator); if (articles.isEmpty()) { throw new NoSuchArticleException( "No JournalArticle exists with the key {groupId=" + groupId + ", urlTitle=" + urlTitle + "}"); }// ww w .ja v a2 s. c om Date now = new Date(); for (JournalArticle article : articles) { Date expirationDate = article.getExpirationDate(); if (article.getDisplayDate().before(now) && ((expirationDate == null) || expirationDate.after(now))) { return article; } } return articles.get(0); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getLatestArticle(long resourcePrimKey, int status, boolean preferApproved) throws PortalException, SystemException { List<JournalArticle> articles = null; OrderByComparator orderByComparator = new ArticleVersionComparator(); if (status == WorkflowConstants.STATUS_ANY) { if (preferApproved) { articles = journalArticlePersistence.findByR_ST(resourcePrimKey, WorkflowConstants.STATUS_APPROVED, 0, 1, orderByComparator); }// w ww . ja v a 2s . c o m if ((articles == null) || (articles.size() == 0)) { articles = journalArticlePersistence.findByResourcePrimKey(resourcePrimKey, 0, 1, orderByComparator); } } else { articles = journalArticlePersistence.findByR_ST(resourcePrimKey, status, 0, 1, orderByComparator); } if (articles.isEmpty()) { throw new NoSuchArticleException( "No JournalArticle exists with the key {resourcePrimKey=" + resourcePrimKey + "}"); } return articles.get(0); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle updateStatus(long userId, JournalArticle article, int status, String articleURL, ServiceContext serviceContext) throws PortalException, SystemException { // Article//from ww w . j a va2 s.c o m User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); int oldStatus = article.getStatus(); article.setModifiedDate(serviceContext.getModifiedDate(now)); boolean neverExpire = false; if (status == WorkflowConstants.STATUS_APPROVED) { Date expirationDate = article.getExpirationDate(); if ((expirationDate != null) && expirationDate.before(now)) { neverExpire = true; article.setExpirationDate(null); } } if (status == WorkflowConstants.STATUS_EXPIRED) { article.setExpirationDate(now); } article.setStatus(status); article.setStatusByUserId(user.getUserId()); article.setStatusByUserName(user.getFullName()); article.setStatusDate(serviceContext.getModifiedDate(now)); journalArticlePersistence.update(article, false); if (isLatestVersion(article.getGroupId(), article.getArticleId(), article.getVersion())) { if (status == WorkflowConstants.STATUS_APPROVED) { updateUrlTitles(article.getGroupId(), article.getArticleId(), article.getUrlTitle()); // Asset if ((oldStatus != WorkflowConstants.STATUS_APPROVED) && (article.getVersion() != JournalArticleConstants.VERSION_DEFAULT)) { AssetEntry draftAssetEntry = null; try { draftAssetEntry = assetEntryLocalService.getEntry(JournalArticle.class.getName(), article.getPrimaryKey()); Date[] dateInterval = getDateInterval(article.getGroupId(), article.getArticleId(), article.getDisplayDate(), article.getExpirationDate()); Date displayDate = dateInterval[0]; Date expirationDate = dateInterval[1]; long[] assetCategoryIds = draftAssetEntry.getCategoryIds(); String[] assetTagNames = draftAssetEntry.getTagNames(); List<AssetLink> assetLinks = assetLinkLocalService .getDirectLinks(draftAssetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED); long[] assetLinkEntryIds = StringUtil .split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L); boolean visible = true; if (article.getClassNameId() > 0) { visible = false; } AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, article.getGroupId(), JournalArticle.class.getName(), article.getResourcePrimKey(), article.getUuid(), getClassTypeId(article), assetCategoryIds, assetTagNames, visible, null, null, displayDate, expirationDate, ContentTypes.TEXT_HTML, article.getTitle(), article.getDescription(), article.getDescription(), null, article.getLayoutUuid(), 0, 0, null, false); assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds, AssetLinkConstants.TYPE_RELATED); assetEntryLocalService.deleteEntry(JournalArticle.class.getName(), article.getPrimaryKey()); } catch (NoSuchEntryException nsee) { } } if (article.getClassNameId() == 0) { AssetEntry assetEntry = assetEntryLocalService.updateVisible(JournalArticle.class.getName(), article.getResourcePrimKey(), true); if (neverExpire) { assetEntry.setExpirationDate(null); assetEntryLocalService.updateAssetEntry(assetEntry, false); } } // Expando ExpandoBridge expandoBridge = article.getExpandoBridge(); expandoBridge.setAttributes(serviceContext); // Indexer Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); indexer.reindex(article); } else if (oldStatus == WorkflowConstants.STATUS_APPROVED) { updatePreviousApprovedArticle(article); } } if (article.getClassNameId() == 0) { // 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); 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 notifySubscribers(article, serviceContext); } return article; }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected Date[] getDateInterval(long groupId, String articleId, Date earliestDisplayDate, Date latestExpirationDate) throws SystemException { Date[] dateInterval = new Date[2]; List<JournalArticle> articles = journalArticlePersistence.findByG_A_ST(groupId, articleId, WorkflowConstants.STATUS_APPROVED); boolean expiringArticle = true; if (latestExpirationDate == null) { expiringArticle = false;/*from w ww . j a va 2 s . co m*/ } for (JournalArticle article : articles) { if ((earliestDisplayDate == null) || ((article.getDisplayDate() != null) && earliestDisplayDate.after(article.getDisplayDate()))) { earliestDisplayDate = article.getDisplayDate(); } if (expiringArticle && ((latestExpirationDate == null) || ((article.getExpirationDate() != null) && latestExpirationDate.before(article.getExpirationDate())))) { latestExpirationDate = article.getExpirationDate(); } if (expiringArticle && (article.getExpirationDate() == null) && (latestExpirationDate != null)) { expiringArticle = false; } } dateInterval[0] = earliestDisplayDate; dateInterval[1] = latestExpirationDate; return dateInterval; }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void updatePreviousApprovedArticle(JournalArticle article) throws PortalException, SystemException { List<JournalArticle> approvedArticles = journalArticlePersistence.findByG_A_ST(article.getGroupId(), article.getArticleId(), WorkflowConstants.STATUS_APPROVED, 0, 2); if (approvedArticles.isEmpty() || ((approvedArticles.size() == 1) && (article.getStatus() == WorkflowConstants.STATUS_APPROVED))) { if (article.isIndexable()) { Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); indexer.delete(article);//w w w.j a v a2 s . c om } assetEntryLocalService.updateVisible(JournalArticle.class.getName(), article.getResourcePrimKey(), false); } else { JournalArticle previousApprovedArticle = approvedArticles.get(0); if (article.getStatus() == WorkflowConstants.STATUS_APPROVED) { previousApprovedArticle = approvedArticles.get(1); } if (article.isIndexable()) { Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); indexer.reindex(previousApprovedArticle); } } }
From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java
License:Open Source License
@Override protected void addStatus(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params"); boolean includeScheduledArticles = false; if (params != null) { includeScheduledArticles = GetterUtil.getBoolean(params.get("includeScheduledArticles")); }// w w w . ja v a 2 s . c om if (includeScheduledArticles) { BooleanQuery statusQuery = BooleanQueryFactoryUtil.create(searchContext); BooleanQuery statusHeadQuery = BooleanQueryFactoryUtil.create(searchContext); statusHeadQuery.addRequiredTerm("head", Boolean.TRUE); statusHeadQuery.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_APPROVED); statusQuery.add(statusHeadQuery, BooleanClauseOccur.SHOULD); BooleanQuery statusScheduledHeadQuery = BooleanQueryFactoryUtil.create(searchContext); statusScheduledHeadQuery.addRequiredTerm("scheduledHead", Boolean.TRUE); statusScheduledHeadQuery.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_SCHEDULED); statusQuery.add(statusScheduledHeadQuery, BooleanClauseOccur.SHOULD); contextQuery.add(statusQuery, BooleanClauseOccur.MUST); } else { super.addStatus(contextQuery, searchContext); boolean head = GetterUtil.getBoolean(searchContext.getAttribute("head"), Boolean.TRUE); boolean relatedClassName = GetterUtil.getBoolean(searchContext.getAttribute("relatedClassName")); if (head && !relatedClassName) { contextQuery.addRequiredTerm("head", Boolean.TRUE); } } }
From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java
License:Open Source License
protected void addStatusHeads(Document document, JournalArticle article) throws SystemException { boolean head = false; boolean scheduledHead = false; int[] statuses = new int[] { WorkflowConstants.STATUS_APPROVED, WorkflowConstants.STATUS_IN_TRASH }; JournalArticle latestArticle = JournalArticleLocalServiceUtil .fetchLatestArticle(article.getResourcePrimKey(), statuses); if (latestArticle == null) { statuses = new int[] { WorkflowConstants.STATUS_SCHEDULED }; latestArticle = JournalArticleLocalServiceUtil.fetchLatestArticle(article.getResourcePrimKey(), statuses);//from w w w .j a v a 2 s. c om } if ((latestArticle != null) && latestArticle.isIndexable() && (article.getId() == latestArticle.getId())) { if (latestArticle.getStatus() == WorkflowConstants.STATUS_SCHEDULED) { scheduledHead = true; } else { head = true; } } document.addKeyword("head", head); document.addKeyword("scheduledHead", scheduledHead); }
From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java
License:Open Source License
@Override protected void doReindex(Object obj) throws Exception { JournalArticle article = (JournalArticle) obj; if (PortalUtil.getClassNameId(DDMStructure.class) == article.getClassNameId()) { Document document = getDocument(article); SearchEngineUtil.deleteDocument(getSearchEngineId(), article.getCompanyId(), document.get(Field.UID)); return;/*from ww w . j ava 2 s. co m*/ } if (!PropsValues.JOURNAL_ARTICLE_INDEX_ALL_VERSIONS) { int status = article.getStatus(); if ((status != WorkflowConstants.STATUS_APPROVED) && (status != WorkflowConstants.STATUS_IN_TRASH) && (status != WorkflowConstants.STATUS_SCHEDULED)) { deleteDocument(article.getCompanyId(), article.getResourcePrimKey()); } } reindexArticleVersions(article); }