List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_ANY
int STATUS_ANY
To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_ANY.
Click Source Link
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public int getCompanyArticlesCount(long companyId, int status) throws SystemException { if (status == WorkflowConstants.STATUS_ANY) { return journalArticlePersistence.countByCompanyId(companyId); } else {//from w ww . j a v a2 s .c o m return journalArticlePersistence.countByC_ST(companyId, status); } }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getLatestArticle(long resourcePrimKey) throws PortalException, SystemException { return getLatestArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY); }
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); }/*from w w w. j a v a 2 s. co 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 getLatestArticle(long groupId, String articleId) throws PortalException, SystemException { return getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getLatestArticle(long groupId, String articleId, int status) throws PortalException, SystemException { List<JournalArticle> articles = null; OrderByComparator orderByComparator = new ArticleVersionComparator(); if (status == WorkflowConstants.STATUS_ANY) { articles = journalArticlePersistence.findByG_A(groupId, articleId, 0, 1, orderByComparator); } else {/*from w w w . jav a 2 s.co m*/ articles = journalArticlePersistence.findByG_A_ST(groupId, articleId, status, 0, 1, orderByComparator); } if (articles.isEmpty()) { throw new NoSuchArticleException("No JournalArticle exists with the key {groupId=" + groupId + ", articleId=" + articleId + ", status=" + status + "}"); } return articles.get(0); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getLatestArticleByUrlTitle(long groupId, String urlTitle, int status) throws PortalException, SystemException { List<JournalArticle> articles = null; OrderByComparator orderByComparator = new ArticleVersionComparator(); if (status == WorkflowConstants.STATUS_ANY) { articles = journalArticlePersistence.findByG_UT(groupId, urlTitle, 0, 1, orderByComparator); } else {//w ww. ja v a2s . c o m articles = journalArticlePersistence.findByG_UT_ST(groupId, urlTitle, status, 0, 1, orderByComparator); } if (articles.isEmpty()) { throw new NoSuchArticleException("No JournalArticle exists with the key {groupId=" + groupId + ", urlTitle=" + urlTitle + ", status=" + status + "}"); } return articles.get(0); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public Hits search(long companyId, long groupId, long classNameId, String structureId, String templateId, String keywords, LinkedHashMap<String, Object> params, int start, int end, Sort sort) throws SystemException { String articleId = null;/*ww w .jav a2 s . c om*/ String title = null; String description = null; String content = null; boolean andOperator = false; if (Validator.isNotNull(keywords)) { articleId = keywords; title = keywords; description = keywords; content = keywords; } else { andOperator = true; } String status = String.valueOf(WorkflowConstants.STATUS_ANY); params.put("keywords", keywords); return search(companyId, groupId, classNameId, articleId, title, description, content, null, status, structureId, templateId, params, andOperator, start, end, sort); }
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 ww w . ja v a 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 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; }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle updateArticleTranslation(long groupId, String articleId, double version, Locale locale, String title, String description, String content, Map<String, byte[]> images) throws PortalException, SystemException { validateContent(content);/* ww w . j a va 2s .c o m*/ JournalArticle oldArticle = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY); double oldVersion = oldArticle.getVersion(); if ((version > 0) && (version != oldVersion)) { throw new ArticleVersionException(); } JournalArticle article = null; User user = userService.getUserById(oldArticle.getUserId()); if (!oldArticle.isDraft()) { 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(oldArticle.getUserId()); article.setUserName(user.getFullName()); article.setCreateDate(new Date()); article.setModifiedDate(new Date()); article.setClassNameId(oldArticle.getClassNameId()); article.setClassPK(oldArticle.getClassPK()); article.setArticleId(articleId); article.setVersion(newVersion); article.setTitleMap(oldArticle.getTitleMap()); article.setUrlTitle(getUniqueUrlTitle(article.getId(), groupId, articleId, title)); article.setDescriptionMap(oldArticle.getDescriptionMap()); article.setType(oldArticle.getType()); article.setStructureId(oldArticle.getStructureId()); article.setTemplateId(oldArticle.getTemplateId()); 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()); } else { article = oldArticle; } Map<Locale, String> titleMap = article.getTitleMap(); titleMap.put(locale, title); article.setTitleMap(titleMap); Map<Locale, String> descriptionMap = article.getDescriptionMap(); descriptionMap.put(locale, description); article.setDescriptionMap(descriptionMap); content = format(user, groupId, articleId, version, !oldArticle.isDraft(), content, oldArticle.getStructureId(), images); article.setContent(content); journalArticlePersistence.update(article, false); return article; }
From source file:com.liferay.portlet.journal.service.persistence.JournalArticleFinderImpl.java
License:Open Source License
public List<JournalArticle> findByExpirationDate(long classNameId, int status, Date expirationDateLT) throws SystemException { Timestamp expirationDateLT_TS = CalendarUtil.getTimestamp(expirationDateLT); Session session = null;/*from www . jav a2 s .c om*/ try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_EXPIRATION_DATE); if (status == WorkflowConstants.STATUS_ANY) { sql = StringUtil.replace(sql, "(status = ?) AND", ""); } SQLQuery q = session.createSQLQuery(sql); q.addEntity("JournalArticle", JournalArticleImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(classNameId); if (status != WorkflowConstants.STATUS_ANY) { qPos.add(status); } qPos.add(expirationDateLT_TS); return q.list(true); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }