List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_EXPIRED
int STATUS_EXPIRED
To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_EXPIRED.
Click Source Link
From source file:com.liferay.journal.service.test.JournalArticleServiceTest.java
License:Open Source License
@Test public void testFetchLatestArticleExpiredWithStatusExpired() throws Exception { updateAndExpireLatestArticle("Version 2"); _latestArticle = fetchLatestArticle(WorkflowConstants.STATUS_EXPIRED, false); Assert.assertTrue(_latestArticle.isExpired()); Assert.assertEquals("Version 2", _latestArticle.getTitle(LocaleUtil.getDefault())); Assert.assertEquals(1.1, _latestArticle.getVersion(), 0); }
From source file:com.liferay.journal.service.test.JournalArticleServiceTest.java
License:Open Source License
@Test public void testFetchLatestArticleNotExpiredWithStatusExpired() throws Exception { _article = JournalTestUtil.updateArticle(_article, "Version 2"); _latestArticle = fetchLatestArticle(WorkflowConstants.STATUS_EXPIRED, false); Assert.assertNull(_latestArticle);//from w w w .j a v a 2s . co m }
From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java
License:Open Source License
public List<ManagementBarFilterItem> getManagementBarStatusFilterItems() throws PortalException, PortletException { List<ManagementBarFilterItem> managementBarFilterItems = new ArrayList<>(); managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_ANY)); managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DRAFT)); ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); int workflowDefinitionLinksCount = WorkflowDefinitionLinkLocalServiceUtil.getWorkflowDefinitionLinksCount( themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), JournalFolder.class.getName()); if (workflowDefinitionLinksCount > 0) { managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_PENDING)); managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DENIED)); }//from w ww. ja v a 2s. c o m managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_SCHEDULED)); managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_APPROVED)); managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_EXPIRED)); return managementBarFilterItems; }
From source file:com.liferay.portlet.journal.lar.JournalContentPortletDataHandlerImpl.java
License:Open Source License
@Override protected String doExportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { portletDataContext.addPermissions("com.liferay.portlet.journal", portletDataContext.getScopeGroupId()); String articleId = portletPreferences.getValue("articleId", null); if (articleId == null) { if (_log.isWarnEnabled()) { _log.warn("No article id found in preferences of portlet " + portletId); }//w w w. j a v a2s . com return StringPool.BLANK; } long articleGroupId = GetterUtil.getLong(portletPreferences.getValue("groupId", StringPool.BLANK)); if (articleGroupId <= 0) { if (_log.isWarnEnabled()) { _log.warn("No group id found in preferences of portlet " + portletId); } return StringPool.BLANK; } long previousScopeGroupId = portletDataContext.getScopeGroupId(); if (articleGroupId != portletDataContext.getScopeGroupId()) { portletDataContext.setScopeGroupId(articleGroupId); } JournalArticle article = null; try { article = JournalArticleLocalServiceUtil.getLatestArticle(articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED); } catch (NoSuchArticleException nsae) { } if (article == null) { try { article = JournalArticleLocalServiceUtil.getLatestArticle(articleGroupId, articleId, WorkflowConstants.STATUS_EXPIRED); } catch (NoSuchArticleException nsae) { } } Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("journal-content-data"); if (article == null) { portletDataContext.setScopeGroupId(previousScopeGroupId); return document.formattedString(); } String path = JournalPortletDataHandlerImpl.getArticlePath(portletDataContext, article); Element articleElement = rootElement.addElement("article"); articleElement.addAttribute("path", path); Element dlFileEntryTypesElement = rootElement.addElement("dl-file-entry-types"); Element dlFoldersElement = rootElement.addElement("dl-folders"); Element dlFilesElement = rootElement.addElement("dl-file-entries"); Element dlFileRanksElement = rootElement.addElement("dl-file-ranks"); JournalPortletDataHandlerImpl.exportArticle(portletDataContext, rootElement, rootElement, rootElement, dlFileEntryTypesElement, dlFoldersElement, dlFilesElement, dlFileRanksElement, article, false); portletDataContext.setScopeGroupId(previousScopeGroupId); return document.formattedString(); }
From source file:com.liferay.portlet.journal.lar.JournalPortletDataHandlerImpl.java
License:Open Source License
public static void exportArticle(PortletDataContext portletDataContext, Element articlesElement, Element structuresElement, Element templatesElement, Element dlFileEntryTypesElement, Element dlFoldersElement, Element dlFileEntriesElement, Element dlFileRanksElement, Element dlRepositoriesElement, Element dlRepositoryEntriesElement, JournalArticle article, String preferenceTemplateId, boolean checkDateRange) throws Exception { if (checkDateRange && !portletDataContext.isWithinDateRange(article.getModifiedDate())) { return;/*from w w w .j ava 2 s .c om*/ } if ((article.getStatus() != WorkflowConstants.STATUS_APPROVED) && (article.getStatus() != WorkflowConstants.STATUS_EXPIRED)) { return; } String path = getArticlePath(portletDataContext, article); if (!portletDataContext.isPathNotProcessed(path)) { return; } // Clone this article to make sure changes to its content are never // persisted article = (JournalArticle) article.clone(); Element articleElement = (Element) articlesElement .selectSingleNode("//article[@path='".concat(path).concat("']")); if (articleElement == null) { articleElement = articlesElement.addElement("article"); } articleElement.addAttribute("article-resource-uuid", article.getArticleResourceUuid()); if (Validator.isNotNull(article.getStructureId())) { JournalStructure structure = JournalStructureLocalServiceUtil.getStructure(article.getGroupId(), article.getStructureId(), true); articleElement.addAttribute("structure-uuid", structure.getUuid()); exportStructure(portletDataContext, structuresElement, structure); } String templateId = article.getTemplateId(); if (Validator.isNotNull(preferenceTemplateId)) { templateId = preferenceTemplateId; } if (Validator.isNotNull(templateId)) { JournalTemplate template = JournalTemplateLocalServiceUtil.getTemplate(article.getGroupId(), templateId, true); articleElement.addAttribute("template-uuid", template.getUuid()); exportTemplate(portletDataContext, templatesElement, dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement, dlRepositoryEntriesElement, template); } Image smallImage = ImageUtil.fetchByPrimaryKey(article.getSmallImageId()); if (article.isSmallImage() && (smallImage != null)) { String smallImagePath = getArticleSmallImagePath(portletDataContext, article); articleElement.addAttribute("small-image-path", smallImagePath); article.setSmallImageType(smallImage.getType()); portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj()); } if (portletDataContext.getBooleanParameter(_NAMESPACE, "images")) { String imagePath = getArticleImagePath(portletDataContext, article); articleElement.addAttribute("image-path", imagePath); List<JournalArticleImage> articleImages = JournalArticleImageUtil.findByG_A_V(article.getGroupId(), article.getArticleId(), article.getVersion()); for (JournalArticleImage articleImage : articleImages) { Image image = null; try { image = ImageUtil.findByPrimaryKey(articleImage.getArticleImageId()); } catch (NoSuchImageException nsie) { continue; } if (image.getTextObj() == null) { continue; } String articleImagePath = getArticleImagePath(portletDataContext, article, articleImage, image); if (!portletDataContext.isPathNotProcessed(articleImagePath)) { continue; } portletDataContext.addZipEntry(articleImagePath, image.getTextObj()); } } article.setStatusByUserUuid(article.getStatusByUserUuid()); if (portletDataContext.getBooleanParameter(_NAMESPACE, "embedded-assets")) { String content = exportReferencedContent(portletDataContext, dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement, dlRepositoryEntriesElement, articleElement, article.getContent()); article.setContent(content); } portletDataContext.addClassedModel(articleElement, path, article, _NAMESPACE); }
From source file:com.liferay.portlet.journal.search.ArticleSearchTerms.java
License:Open Source License
public int getStatusCode() { if (status.equals("approved")) { return WorkflowConstants.STATUS_APPROVED; } else if (status.equals("draft")) { return WorkflowConstants.STATUS_DRAFT; } else if (status.equals("expired")) { return WorkflowConstants.STATUS_EXPIRED; } else if (status.equals("pending")) { return WorkflowConstants.STATUS_PENDING; } else {//from w ww . ja v a2s . com return WorkflowConstants.STATUS_ANY; } }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle addArticle(long userId, long groupId, long classNameId, long classPK, String articleId, boolean autoArticleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String type, String structureId, String templateId, 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, SystemException { // Article//from w w w .ja va 2s .c o m User user = userPersistence.findByPrimaryKey(userId); articleId = articleId.trim().toUpperCase(); Date displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), new ArticleDisplayDateException()); Date expirationDate = null; if (!neverExpire) { expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, user.getTimeZone(), new ArticleExpirationDateException()); } Date reviewDate = null; if (!neverReview) { reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, user.getTimeZone(), new ArticleReviewDateException()); } byte[] smallImageBytes = null; try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } Date now = new Date(); validate(user.getCompanyId(), groupId, classNameId, articleId, autoArticleId, version, titleMap, content, type, structureId, templateId, smallImage, smallImageURL, smallImageFile, smallImageBytes); if (autoArticleId) { articleId = String.valueOf(counterLocalService.increment()); } long id = counterLocalService.increment(); long resourcePrimKey = journalArticleResourceLocalService .getArticleResourcePrimKey(serviceContext.getUuid(), groupId, articleId); JournalArticle article = journalArticlePersistence.create(id); Locale locale = LocaleUtil.getDefault(); String defaultLanguageId = GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId")); if (Validator.isNotNull(defaultLanguageId)) { locale = LocaleUtil.fromLanguageId(defaultLanguageId); } String title = titleMap.get(locale); content = format(user, groupId, articleId, version, false, content, structureId, images); article.setResourcePrimKey(resourcePrimKey); article.setGroupId(groupId); article.setCompanyId(user.getCompanyId()); article.setUserId(user.getUserId()); article.setUserName(user.getFullName()); article.setCreateDate(serviceContext.getCreateDate(now)); article.setModifiedDate(serviceContext.getModifiedDate(now)); article.setClassNameId(classNameId); article.setClassPK(classPK); article.setArticleId(articleId); article.setVersion(version); article.setTitleMap(titleMap, locale); article.setUrlTitle(getUniqueUrlTitle(id, groupId, articleId, title)); article.setDescriptionMap(descriptionMap, locale); article.setContent(content); article.setType(type); article.setStructureId(structureId); article.setTemplateId(templateId); 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); } journalArticlePersistence.update(article, false); // Resources if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) { addArticleResources(article, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions()); } else { addArticleResources(article, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions()); } // Expando ExpandoBridge expandoBridge = article.getExpandoBridge(); expandoBridge.setAttributes(serviceContext); // Small image saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes); // Asset updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds()); // Message boards if (PropsValues.JOURNAL_ARTICLE_COMMENTS_ENABLED) { mbMessageLocalService.addDiscussionMessage(userId, article.getUserName(), groupId, JournalArticle.class.getName(), resourcePrimKey, WorkflowConstants.ACTION_PUBLISH); } // Email PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); sendEmail(article, articleURL, preferences, "requested", serviceContext); // Workflow if (classNameId == 0) { WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId, JournalArticle.class.getName(), article.getId(), article, serviceContext); if (serviceContext.getWorkflowAction() != WorkflowConstants.ACTION_PUBLISH) { // Indexer Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); indexer.reindex(article); } } else { updateStatus(userId, article, WorkflowConstants.STATUS_APPROVED, null, serviceContext); } return article; }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public void checkArticles() throws PortalException, SystemException { Date now = new Date(); List<JournalArticle> articles = journalArticleFinder.findByExpirationDate(0, WorkflowConstants.STATUS_APPROVED, now); if (_log.isDebugEnabled()) { _log.debug("Expiring " + articles.size() + " articles"); }//from ww w. j av a 2s .c o m Set<Long> companyIds = new HashSet<Long>(); for (JournalArticle article : articles) { article.setStatus(WorkflowConstants.STATUS_EXPIRED); journalArticlePersistence.update(article, false); if (article.isIndexable()) { Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); indexer.delete(article); } updatePreviousApprovedArticle(article); JournalContentUtil.clearCache(article.getGroupId(), article.getArticleId(), article.getTemplateId()); companyIds.add(article.getCompanyId()); } for (long companyId : companyIds) { CacheUtil.clearCache(companyId); } articles = journalArticleFinder.findByReviewDate(0, now, new Date(now.getTime() - _JOURNAL_ARTICLE_CHECK_INTERVAL)); if (_log.isDebugEnabled()) { _log.debug("Sending review notifications for " + articles.size() + " articles"); } for (JournalArticle article : articles) { String articleURL = StringPool.BLANK; long ownerId = article.getGroupId(); int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP; long plid = PortletKeys.PREFS_PLID_SHARED; String portletId = PortletKeys.JOURNAL; PortletPreferences preferences = portletPreferencesLocalService.getPreferences(article.getCompanyId(), ownerId, ownerType, plid, portletId); sendEmail(article, articleURL, preferences, "review", new ServiceContext()); } }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle expireArticle(long userId, long groupId, String articleId, double version, String articleURL, ServiceContext serviceContext) throws PortalException, SystemException { return updateStatus(userId, groupId, articleId, version, WorkflowConstants.STATUS_EXPIRED, articleURL, serviceContext);//from w ww. j a va 2 s. c o m }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle updateArticle(long userId, long groupId, String articleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String type, String structureId, String templateId, 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, SystemException { // Article//from w ww . j a v a 2 s.co m User user = userPersistence.findByPrimaryKey(userId); articleId = articleId.trim().toUpperCase(); Date displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), new ArticleDisplayDateException()); Date expirationDate = null; if (!neverExpire) { expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, user.getTimeZone(), new ArticleExpirationDateException()); } Date now = new Date(); boolean expired = false; if ((expirationDate != null) && expirationDate.before(now)) { expired = true; } Date reviewDate = null; if (!neverReview) { reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, user.getTimeZone(), new ArticleReviewDateException()); } byte[] smallImageBytes = null; try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } JournalArticle oldArticle = null; double oldVersion = 0; boolean incrementVersion = false; boolean imported = GetterUtil.getBoolean(serviceContext.getAttribute("imported")); if (imported) { oldArticle = getArticle(groupId, articleId, version); oldVersion = version; if (!expired) { incrementVersion = true; } else { return expireArticle(userId, groupId, articleId, version, articleURL, serviceContext); } } else { oldArticle = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY); oldVersion = oldArticle.getVersion(); if ((version > 0) && (version != oldVersion)) { throw new ArticleVersionException(); } if (oldArticle.isApproved() || oldArticle.isExpired()) { incrementVersion = true; } } validate(user.getCompanyId(), groupId, oldArticle.getClassNameId(), titleMap, content, type, structureId, templateId, smallImage, smallImageURL, smallImageFile, smallImageBytes); JournalArticle article = null; if (incrementVersion) { double newVersion = MathUtil.format(oldVersion + 0.1, 1, 1); long id = counterLocalService.increment(); article = journalArticlePersistence.create(id); article.setResourcePrimKey(oldArticle.getResourcePrimKey()); article.setGroupId(oldArticle.getGroupId()); article.setCompanyId(oldArticle.getCompanyId()); article.setUserId(user.getUserId()); article.setUserName(user.getFullName()); article.setCreateDate(serviceContext.getModifiedDate(now)); article.setClassNameId(oldArticle.getClassNameId()); article.setClassPK(oldArticle.getClassPK()); article.setArticleId(articleId); article.setVersion(newVersion); article.setSmallImageId(oldArticle.getSmallImageId()); } else { article = oldArticle; } Locale locale = LocaleUtil.getDefault(); String defaultLanguageId = GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId")); if (Validator.isNotNull(defaultLanguageId)) { locale = LocaleUtil.fromLanguageId(defaultLanguageId); } String title = titleMap.get(locale); content = format(user, groupId, articleId, article.getVersion(), incrementVersion, content, structureId, images); article.setModifiedDate(serviceContext.getModifiedDate(now)); article.setTitleMap(titleMap, locale); article.setUrlTitle(getUniqueUrlTitle(article.getId(), groupId, articleId, title)); article.setDescriptionMap(descriptionMap, locale); article.setContent(content); article.setType(type); article.setStructureId(structureId); article.setTemplateId(templateId); article.setLayoutUuid(layoutUuid); article.setDisplayDate(displayDate); article.setExpirationDate(expirationDate); article.setReviewDate(reviewDate); article.setIndexable(indexable); article.setSmallImage(smallImage); if (article.getSmallImageId() == 0) { article.setSmallImageId(counterLocalService.increment()); } article.setSmallImageURL(smallImageURL); if (oldArticle.isPending()) { article.setStatus(oldArticle.getStatus()); } else if (!expired) { article.setStatus(WorkflowConstants.STATUS_DRAFT); } else { article.setStatus(WorkflowConstants.STATUS_EXPIRED); } journalArticlePersistence.update(article, false); // Asset updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds()); // Expando ExpandoBridge expandoBridge = article.getExpandoBridge(); expandoBridge.setAttributes(serviceContext); // Small image saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes); // Email PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); // Workflow if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_PUBLISH) { sendEmail(article, articleURL, preferences, "requested", serviceContext); WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId, JournalArticle.class.getName(), article.getId(), article, serviceContext); } else if (article.getVersion() == JournalArticleConstants.VERSION_DEFAULT) { // Indexer Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); indexer.reindex(article); } return article; }