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.atom.JournalArticleAtomCollectionProvider.java
License:Open Source License
@Override protected JournalArticle doPostEntry(String title, String summary, String content, Date date, AtomRequestContext atomRequestContext) throws Exception { User user = AtomUtil.getUser(atomRequestContext); long groupId = atomRequestContext.getLongParameter("groupId"); long classNameId = 0; long classPK = 0; String articleId = StringPool.BLANK; boolean autoArticleId = true; Locale locale = LocaleUtil.getDefault(); Map<Locale, String> titleMap = new HashMap<Locale, String>(); titleMap.put(locale, title);/*from w w w .j av a2 s .c o m*/ Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); String type = atomRequestContext.getParameter("type", "general"); String structureId = null; String templateId = null; String layoutUuid = null; Calendar cal = Calendar.getInstance(); cal.setTime(date); int displayDateMonth = cal.get(Calendar.MONTH); int displayDateDay = cal.get(Calendar.DAY_OF_MONTH); int displayDateYear = cal.get(Calendar.YEAR); int displayDateHour = cal.get(Calendar.HOUR_OF_DAY); int displayDateMinute = cal.get(Calendar.MINUTE); int expirationDateMonth = 0; int expirationDateDay = 0; int expirationDateYear = 0; int expirationDateHour = 0; int expirationDateMinute = 0; boolean neverExpire = true; int reviewDateMonth = 0; int reviewDateDay = 0; int reviewDateYear = 0; int reviewDateHour = 0; int reviewDateMinute = 0; boolean neverReview = true; boolean indexable = true; String articleURL = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(false); serviceContext.setAddGuestPermissions(false); serviceContext.setScopeGroupId(groupId); JournalArticle journalArticle = JournalArticleServiceUtil.addArticle(groupId, classNameId, classPK, articleId, autoArticleId, titleMap, descriptionMap, content, type, structureId, templateId, layoutUuid, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, indexable, articleURL, serviceContext); double version = journalArticle.getVersion(); int status = WorkflowConstants.STATUS_APPROVED; journalArticle = JournalArticleLocalServiceUtil.updateStatus(user.getUserId(), groupId, journalArticle.getArticleId(), version, status, articleURL, serviceContext); return journalArticle; }
From source file:com.liferay.portlet.journal.atom.JournalArticleAtomCollectionProvider.java
License:Open Source License
@Override protected void doPutEntry(JournalArticle journalArticle, String title, String summary, String content, Date date, AtomRequestContext atomRequestContext) throws Exception { User user = AtomUtil.getUser(atomRequestContext); long groupId = journalArticle.getGroupId(); String articleId = journalArticle.getArticleId(); double version = journalArticle.getVersion(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setScopeGroupId(groupId); journalArticle = JournalArticleServiceUtil.updateArticle(groupId, articleId, version, content, serviceContext);/*from w w w . jav a 2s.c o m*/ int status = WorkflowConstants.STATUS_APPROVED; String articleURL = StringPool.BLANK; JournalArticleLocalServiceUtil.updateStatus(user.getUserId(), groupId, journalArticle.getArticleId(), journalArticle.getVersion(), status, articleURL, serviceContext); }
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); }//from ww w . ja va2 s . c o m 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 a va2s .co m } 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.lar.JournalPortletDataHandlerImpl.java
License:Open Source License
public static void importArticle(PortletDataContext portletDataContext, Element articleElement) throws Exception { String path = articleElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { return;/* w ww. j a v a 2 s . co m*/ } JournalArticle article = (JournalArticle) portletDataContext.getZipEntryAsObject(path); prepareLanguagesForImport(article); long userId = portletDataContext.getUserId(article.getUserUuid()); JournalCreationStrategy creationStrategy = JournalCreationStrategyFactory.getInstance(); long authorId = creationStrategy.getAuthorUserId(portletDataContext, article); if (authorId != JournalCreationStrategy.USE_DEFAULT_USER_ID_STRATEGY) { userId = authorId; } User user = UserLocalServiceUtil.getUser(userId); String articleId = article.getArticleId(); boolean autoArticleId = false; Map<String, String> articleIds = (Map<String, String>) portletDataContext .getNewPrimaryKeysMap(JournalArticle.class + ".articleId"); String newArticleId = articleIds.get(articleId); // ======= Start of change ============ if (Validator.isNotNull(newArticleId)) { // A sibling of a different version was already assigned a new // article id articleId = newArticleId; } // =======end of change================ String content = article.getContent(); content = importDLFileEntries(portletDataContext, articleElement, content); Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId()); content = StringUtil.replace(content, "@data_handler_group_friendly_url@", group.getFriendlyURL()); content = importLinksToLayout(portletDataContext, content); article.setContent(content); String newContent = creationStrategy.getTransformedContent(portletDataContext, article); if (!StringUtils.equals(JournalCreationStrategy.ARTICLE_CONTENT_UNCHANGED, newContent)) { article.setContent(newContent); } Map<String, String> structureIds = (Map<String, String>) portletDataContext .getNewPrimaryKeysMap(JournalStructure.class); String parentStructureId = MapUtil.getString(structureIds, article.getStructureId(), article.getStructureId()); Map<String, String> templateIds = (Map<String, String>) portletDataContext .getNewPrimaryKeysMap(JournalTemplate.class); String parentTemplateId = MapUtil.getString(templateIds, article.getTemplateId(), article.getTemplateId()); Date displayDate = article.getDisplayDate(); int displayDateMonth = 0; int displayDateDay = 0; int displayDateYear = 0; int displayDateHour = 0; int displayDateMinute = 0; if (displayDate != null) { Calendar displayCal = CalendarFactoryUtil.getCalendar(user.getTimeZone()); displayCal.setTime(displayDate); displayDateMonth = displayCal.get(Calendar.MONTH); displayDateDay = displayCal.get(Calendar.DATE); displayDateYear = displayCal.get(Calendar.YEAR); displayDateHour = displayCal.get(Calendar.HOUR); displayDateMinute = displayCal.get(Calendar.MINUTE); if (displayCal.get(Calendar.AM_PM) == Calendar.PM) { displayDateHour += 12; } } Date expirationDate = article.getExpirationDate(); int expirationDateMonth = 0; int expirationDateDay = 0; int expirationDateYear = 0; int expirationDateHour = 0; int expirationDateMinute = 0; boolean neverExpire = true; if (expirationDate != null) { Calendar expirationCal = CalendarFactoryUtil.getCalendar(user.getTimeZone()); expirationCal.setTime(expirationDate); expirationDateMonth = expirationCal.get(Calendar.MONTH); expirationDateDay = expirationCal.get(Calendar.DATE); expirationDateYear = expirationCal.get(Calendar.YEAR); expirationDateHour = expirationCal.get(Calendar.HOUR); expirationDateMinute = expirationCal.get(Calendar.MINUTE); neverExpire = false; if (expirationCal.get(Calendar.AM_PM) == Calendar.PM) { expirationDateHour += 12; } } Date reviewDate = article.getReviewDate(); int reviewDateMonth = 0; int reviewDateDay = 0; int reviewDateYear = 0; int reviewDateHour = 0; int reviewDateMinute = 0; boolean neverReview = true; if (reviewDate != null) { Calendar reviewCal = CalendarFactoryUtil.getCalendar(user.getTimeZone()); reviewCal.setTime(reviewDate); reviewDateMonth = reviewCal.get(Calendar.MONTH); reviewDateDay = reviewCal.get(Calendar.DATE); reviewDateYear = reviewCal.get(Calendar.YEAR); reviewDateHour = reviewCal.get(Calendar.HOUR); reviewDateMinute = reviewCal.get(Calendar.MINUTE); neverReview = false; if (reviewCal.get(Calendar.AM_PM) == Calendar.PM) { reviewDateHour += 12; } } long structurePrimaryKey = 0; if (Validator.isNotNull(article.getStructureId())) { String structureUuid = articleElement.attributeValue("structure-uuid"); JournalStructure existingStructure = JournalStructureUtil.fetchByUUID_G(structureUuid, portletDataContext.getScopeGroupId()); if (existingStructure == null) { Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId()); long companyGroupId = companyGroup.getGroupId(); existingStructure = JournalStructureUtil.fetchByUUID_G(structureUuid, companyGroupId); } if (existingStructure == null) { String newStructureId = structureIds.get(article.getStructureId()); if (Validator.isNotNull(newStructureId)) { existingStructure = JournalStructureUtil.fetchByG_S(portletDataContext.getScopeGroupId(), String.valueOf(newStructureId)); } if (existingStructure == null) { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(); sb.append("Structure "); sb.append(article.getStructureId()); sb.append(" is missing for article "); sb.append(article.getArticleId()); sb.append(", skipping this article."); _log.warn(sb.toString()); } return; } } structurePrimaryKey = existingStructure.getPrimaryKey(); parentStructureId = existingStructure.getStructureId(); } if (Validator.isNotNull(article.getTemplateId())) { String templateUuid = articleElement.attributeValue("template-uuid"); JournalTemplate existingTemplate = JournalTemplateUtil.fetchByUUID_G(templateUuid, portletDataContext.getScopeGroupId()); if (existingTemplate == null) { Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId()); long companyGroupId = companyGroup.getGroupId(); existingTemplate = JournalTemplateUtil.fetchByUUID_G(templateUuid, companyGroupId); } if (existingTemplate == null) { String newTemplateId = templateIds.get(article.getTemplateId()); if (Validator.isNotNull(newTemplateId)) { existingTemplate = JournalTemplateUtil.fetchByG_T(portletDataContext.getScopeGroupId(), newTemplateId); } if (existingTemplate == null) { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(); sb.append("Template "); sb.append(article.getTemplateId()); sb.append(" is missing for article "); sb.append(article.getArticleId()); sb.append(", skipping this article."); _log.warn(sb.toString()); } return; } } parentTemplateId = existingTemplate.getTemplateId(); } File smallFile = null; String smallImagePath = articleElement.attributeValue("small-image-path"); if (article.isSmallImage() && Validator.isNotNull(smallImagePath)) { byte[] bytes = portletDataContext.getZipEntryAsByteArray(smallImagePath); smallFile = FileUtil.createTempFile(article.getSmallImageType()); FileUtil.write(smallFile, bytes); } Map<String, byte[]> images = new HashMap<String, byte[]>(); String imagePath = articleElement.attributeValue("image-path"); if (portletDataContext.getBooleanParameter(_NAMESPACE, "images") && Validator.isNotNull(imagePath)) { List<String> imageFiles = portletDataContext.getZipFolderEntries(imagePath); for (String imageFile : imageFiles) { String fileName = imageFile; if (fileName.contains(StringPool.SLASH)) { fileName = fileName.substring(fileName.lastIndexOf(CharPool.SLASH) + 1); } if (fileName.endsWith(".xml")) { continue; } int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { fileName = fileName.substring(0, pos); } images.put(fileName, portletDataContext.getZipEntryAsByteArray(imageFile)); } } String articleURL = null; boolean addGroupPermissions = creationStrategy.addGroupPermissions(portletDataContext, article); boolean addGuestPermissions = creationStrategy.addGuestPermissions(portletDataContext, article); ServiceContext serviceContext = portletDataContext.createServiceContext(articleElement, article, _NAMESPACE); serviceContext.setAddGroupPermissions(addGroupPermissions); serviceContext.setAddGuestPermissions(addGuestPermissions); serviceContext.setAttribute("imported", Boolean.TRUE.toString()); if (article.getStatus() != WorkflowConstants.STATUS_APPROVED) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } JournalArticle importedArticle = null; String articleResourceUuid = articleElement.attributeValue("article-resource-uuid"); if (portletDataContext.isDataStrategyMirror()) { JournalArticleResource articleResource = JournalArticleResourceUtil.fetchByUUID_G(articleResourceUuid, portletDataContext.getScopeGroupId()); if (articleResource == null) { Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId()); long companyGroupId = companyGroup.getGroupId(); articleResource = JournalArticleResourceUtil.fetchByUUID_G(articleResourceUuid, companyGroupId); } //Modification start if (articleResource == null) { articleResource = JournalArticleResourceUtil.fetchByG_A(portletDataContext.getScopeGroupId(), articleId); } //Modification end serviceContext.setUuid(articleResourceUuid); JournalArticle existingArticle = null; if (articleResource != null) { try { existingArticle = JournalArticleLocalServiceUtil.getLatestArticle( articleResource.getResourcePrimKey(), WorkflowConstants.STATUS_ANY, false); } catch (NoSuchArticleException nsae) { } } if (existingArticle == null) { existingArticle = JournalArticleUtil.fetchByG_A_V(portletDataContext.getScopeGroupId(), newArticleId, article.getVersion()); } if (existingArticle == null) { importedArticle = JournalArticleLocalServiceUtil.addArticle(userId, portletDataContext.getScopeGroupId(), article.getClassNameId(), structurePrimaryKey, articleId, autoArticleId, article.getVersion(), article.getTitleMap(), article.getDescriptionMap(), article.getContent(), article.getType(), parentStructureId, parentTemplateId, article.getLayoutUuid(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, article.isIndexable(), article.isSmallImage(), article.getSmallImageURL(), smallFile, images, articleURL, serviceContext); } else { importedArticle = JournalArticleLocalServiceUtil.updateArticle(userId, existingArticle.getGroupId(), existingArticle.getArticleId(), existingArticle.getVersion(), article.getTitleMap(), article.getDescriptionMap(), article.getContent(), article.getType(), parentStructureId, parentTemplateId, article.getLayoutUuid(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, article.isIndexable(), article.isSmallImage(), article.getSmallImageURL(), smallFile, images, articleURL, serviceContext); } } else { importedArticle = JournalArticleLocalServiceUtil.addArticle(userId, portletDataContext.getScopeGroupId(), article.getClassNameId(), structurePrimaryKey, articleId, autoArticleId, article.getVersion(), article.getTitleMap(), article.getDescriptionMap(), article.getContent(), article.getType(), parentStructureId, parentTemplateId, article.getLayoutUuid(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, article.isIndexable(), article.isSmallImage(), article.getSmallImageURL(), smallFile, images, articleURL, serviceContext); } if (smallFile != null) { smallFile.delete(); } portletDataContext.importClassedModel(article, importedArticle, _NAMESPACE); if (Validator.isNull(newArticleId)) { articleIds.put(article.getArticleId(), importedArticle.getArticleId()); } Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId()); if (importedArticle.getGroupId() == companyGroup.getGroupId()) { portletDataContext.addCompanyReference(JournalArticle.class, articleId); } if (!articleId.equals(importedArticle.getArticleId())) { if (_log.isWarnEnabled()) { _log.warn("An article with the ID " + articleId + " already " + "exists. The new generated ID is " + importedArticle.getArticleId()); } } }
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 w w. j av a 2 s.c o m 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 ww .j a va 2 s. 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 w ww . j av a 2 s. 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 void deleteArticle(JournalArticle article, String articleURL, ServiceContext serviceContext) throws PortalException, SystemException { if (article.isApproved() && isLatestVersion(article.getGroupId(), article.getArticleId(), article.getVersion(), WorkflowConstants.STATUS_APPROVED)) { updatePreviousApprovedArticle(article); }/* w w w.j av a2s . com*/ // Email PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); if ((preferences != null) && !article.isApproved() && isLatestVersion(article.getGroupId(), article.getArticleId(), article.getVersion())) { sendEmail(article, articleURL, preferences, "denied", serviceContext); } // Images journalArticleImageLocalService.deleteImages(article.getGroupId(), article.getArticleId(), article.getVersion()); // 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) { // Ratings ratingsStatsLocalService.deleteStats(JournalArticle.class.getName(), article.getResourcePrimKey()); // Message boards mbMessageLocalService.deleteDiscussionMessages(JournalArticle.class.getName(), article.getResourcePrimKey()); // Asset assetEntryLocalService.deleteEntry(JournalArticle.class.getName(), article.getResourcePrimKey()); // Content searches journalContentSearchLocalService.deleteArticleContentSearches(article.getGroupId(), article.getArticleId()); // Small image imageLocalService.deleteImage(article.getSmallImageId()); // Expando expandoValueLocalService.deleteValues(JournalArticle.class.getName(), article.getResourcePrimKey()); // Resources resourceLocalService.deleteResource(article.getCompanyId(), JournalArticle.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, article.getResourcePrimKey()); // Resource try { journalArticleResourceLocalService.deleteArticleResource(article.getGroupId(), article.getArticleId()); } catch (NoSuchArticleResourceException nsare) { } } // Article journalArticlePersistence.remove(article); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticle getArticle(long groupId, String articleId) throws PortalException, SystemException { // Get the latest article that is approved, if none are approved, get // the latest unapproved article try {// w w w . j av a 2 s. c o m return getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_APPROVED); } catch (NoSuchArticleException nsae) { return getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY); } }