List of usage examples for com.liferay.portal.kernel.util ListUtil toLongArray
public static <T> long[] toLongArray(List<? extends T> list, ToLongFunction<T> toLongFunction)
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
protected void populateServiceContext(ServiceContext serviceContext, FileEntry fileEntry) throws PortalException { serviceContext.setScopeGroupId(fileEntry.getGroupId()); String className = DLFileEntryConstants.getClassName(); long[] assetCategoryIds = _assetCategoryLocalService.getCategoryIds(className, fileEntry.getFileEntryId()); serviceContext.setAssetCategoryIds(assetCategoryIds); AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(className, fileEntry.getFileEntryId()); List<AssetLink> assetLinks = _assetLinkLocalService.getLinks(assetEntry.getEntryId()); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); serviceContext.setAssetLinkEntryIds(assetLinkEntryIds); String[] assetTagNames = _assetTagLocalService.getTagNames(className, fileEntry.getFileEntryId()); serviceContext.setAssetTagNames(assetTagNames); ExpandoBridge expandoBridge = fileEntry.getExpandoBridge(); serviceContext.setExpandoBridgeAttributes(expandoBridge.getAttributes()); DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel(); long fileEntryTypeId = dlFileEntry.getFileEntryTypeId(); if (fileEntryTypeId > 0) { serviceContext.setAttribute("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); DLFileVersion dlFileVersion = _dlFileVersionLocalService .getLatestFileVersion(fileEntry.getFileEntryId(), !dlFileEntry.isCheckedOut()); DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService.getFileEntryType(fileEntryTypeId); List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { DLFileEntryMetadata dlFileEntryMetadata = _dlFileEntryMetadataLocalService .fetchFileEntryMetadata(ddmStructure.getStructureId(), dlFileVersion.getFileVersionId()); if (dlFileEntryMetadata == null) { continue; }//from w ww .j a v a 2 s.c o m DDMFormValues ddmFormValues = StorageEngineManagerUtil .getDDMFormValues(dlFileEntryMetadata.getDDMStorageId()); serviceContext.setAttribute( DDMFormValues.class.getName() + StringPool.POUND + ddmStructure.getStructureId(), ddmFormValues); } } }
From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java
License:Open Source License
protected void populateServiceContext(ServiceContext serviceContext, FileEntry fileEntry) { serviceContext.setScopeGroupId(fileEntry.getGroupId()); String className = DLFileEntryConstants.getClassName(); long[] assetCategoryIds = _assetCategoryLocalService.getCategoryIds(className, fileEntry.getFileEntryId()); serviceContext.setAssetCategoryIds(assetCategoryIds); AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(className, fileEntry.getFileEntryId()); List<AssetLink> assetLinks = _assetLinkLocalService.getLinks(assetEntry.getEntryId()); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); serviceContext.setAssetLinkEntryIds(assetLinkEntryIds); String[] assetTagNames = _assetTagLocalService.getTagNames(className, fileEntry.getFileEntryId()); serviceContext.setAssetTagNames(assetTagNames); ExpandoBridge expandoBridge = fileEntry.getExpandoBridge(); serviceContext.setExpandoBridgeAttributes(expandoBridge.getAttributes()); }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Copies the web content article matching the group, article ID, and * version. This method creates a new article, extracting all the values * from the old one and updating its article ID. * * @param userId the primary key of the web content article's creator/owner * @param groupId the primary key of the web content article's group * @param oldArticleId the primary key of the old web content article * @param newArticleId the primary key of the new web content article * @param autoArticleId whether to auto-generate the web content article ID * @param version the web content article's version * @return the new web content article/*from w ww . j av a 2 s .c o m*/ */ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle copyArticle(long userId, long groupId, String oldArticleId, String newArticleId, boolean autoArticleId, double version) throws PortalException { // Article User user = userLocalService.getUser(userId); oldArticleId = StringUtil.toUpperCase(StringUtil.trim(oldArticleId)); newArticleId = StringUtil.toUpperCase(StringUtil.trim(newArticleId)); JournalArticle oldArticle = journalArticlePersistence.findByG_A_V(groupId, oldArticleId, version); if (autoArticleId) { newArticleId = String.valueOf(counterLocalService.increment()); } else { validate(newArticleId); if (journalArticlePersistence.countByG_A(groupId, newArticleId) > 0) { StringBundler sb = new StringBundler(5); sb.append("{groupId="); sb.append(groupId); sb.append(", articleId="); sb.append(newArticleId); sb.append("}"); throw new DuplicateArticleIdException(sb.toString()); } } long id = counterLocalService.increment(); long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(groupId, newArticleId); JournalArticle newArticle = journalArticlePersistence.create(id); newArticle.setResourcePrimKey(resourcePrimKey); newArticle.setGroupId(groupId); newArticle.setCompanyId(user.getCompanyId()); newArticle.setUserId(user.getUserId()); newArticle.setUserName(user.getFullName()); newArticle.setFolderId(oldArticle.getFolderId()); newArticle.setTreePath(oldArticle.getTreePath()); newArticle.setArticleId(newArticleId); newArticle.setVersion(JournalArticleConstants.VERSION_DEFAULT); newArticle.setUrlTitle(getUniqueUrlTitle(id, groupId, newArticleId, oldArticle.getTitleCurrentValue())); try { copyArticleImages(oldArticle, newArticle); } catch (Exception e) { newArticle.setContent(oldArticle.getContent()); } newArticle.setDDMStructureKey(oldArticle.getDDMStructureKey()); newArticle.setDDMTemplateKey(oldArticle.getDDMTemplateKey()); newArticle.setDefaultLanguageId(oldArticle.getDefaultLanguageId()); newArticle.setLayoutUuid(oldArticle.getLayoutUuid()); newArticle.setDisplayDate(oldArticle.getDisplayDate()); newArticle.setExpirationDate(oldArticle.getExpirationDate()); newArticle.setReviewDate(oldArticle.getReviewDate()); newArticle.setIndexable(oldArticle.isIndexable()); newArticle.setSmallImage(oldArticle.isSmallImage()); newArticle.setSmallImageId(counterLocalService.increment()); newArticle.setSmallImageURL(oldArticle.getSmallImageURL()); WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil .getWorkflowHandler(JournalArticle.class.getName()); WorkflowDefinitionLink workflowDefinitionLink = workflowHandler .getWorkflowDefinitionLink(oldArticle.getCompanyId(), oldArticle.getGroupId(), oldArticle.getId()); if (oldArticle.isPending() || (workflowDefinitionLink != null)) { newArticle.setStatus(WorkflowConstants.STATUS_DRAFT); } else { newArticle.setStatus(oldArticle.getStatus()); } ExpandoBridgeUtil.copyExpandoBridgeAttributes(oldArticle.getExpandoBridge(), newArticle.getExpandoBridge()); journalArticlePersistence.update(newArticle); // Article localization String urlTitle = JournalUtil.getUrlTitle(id, oldArticle.getUrlTitle()); int uniqueUrlTitleCount = _getUniqueUrlTitleCount(groupId, newArticleId, urlTitle); Map<Locale, String> newTitleMap = oldArticle.getTitleMap(); for (Locale locale : newTitleMap.keySet()) { StringBundler sb = new StringBundler(5); sb.append(newTitleMap.get(locale)); sb.append(StringPool.SPACE); sb.append(LanguageUtil.get(locale, "duplicate")); sb.append(StringPool.SPACE); sb.append(uniqueUrlTitleCount); newTitleMap.put(locale, sb.toString()); } _addArticleLocalizedFields(newArticle.getCompanyId(), newArticle.getId(), newTitleMap, oldArticle.getDescriptionMap()); // Resources addArticleResources(newArticle, true, true); // Small image if (oldArticle.isSmallImage()) { Image image = imageLocalService.fetchImage(oldArticle.getSmallImageId()); if (image != null) { byte[] smallImageBytes = image.getTextObj(); imageLocalService.updateImage(newArticle.getSmallImageId(), smallImageBytes); } } // Asset long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(JournalArticle.class.getName(), oldArticle.getResourcePrimKey()); String[] assetTagNames = assetTagLocalService.getTagNames(JournalArticle.class.getName(), oldArticle.getResourcePrimKey()); AssetEntry oldAssetEntry = assetEntryLocalService.getEntry(JournalArticle.class.getName(), oldArticle.getResourcePrimKey()); List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(oldAssetEntry.getEntryId(), false); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); updateAsset(userId, newArticle, assetCategoryIds, assetTagNames, assetLinkEntryIds, oldAssetEntry.getPriority()); // Dynamic data mapping updateDDMLinks(id, groupId, oldArticle.getDDMStructureKey(), oldArticle.getDDMTemplateKey(), true); return newArticle; }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Updates the workflow status of the web content article. * * @param userId the primary key of the user updating the web content * article's status//from w ww . java2s. c om * @param article the web content article * @param status the web content article's workflow status. For more * information see {@link WorkflowConstants} for constants starting * with the "STATUS_" prefix. * @param articleURL the web content article's accessible URL * @param serviceContext the service context to be applied. Can set the * modification date, status date, and portlet preferences. 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. * @param workflowContext the web content article's configured workflow * context * @return the updated web content article */ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle updateStatus(long userId, JournalArticle article, int status, String articleURL, ServiceContext serviceContext, Map<String, Serializable> workflowContext) throws PortalException { // Article User user = userLocalService.getUser(userId); Date now = new Date(); if ((status == WorkflowConstants.STATUS_APPROVED) && (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT) && (article.getDisplayDate() != null) && now.before(article.getDisplayDate())) { status = WorkflowConstants.STATUS_SCHEDULED; } int oldStatus = article.getStatus(); Date modifiedDate = serviceContext.getModifiedDate(now); article.setModifiedDate(modifiedDate); if (status == WorkflowConstants.STATUS_APPROVED) { Date expirationDate = article.getExpirationDate(); if ((expirationDate != null) && expirationDate.before(now)) { article.setExpirationDate(null); } } if (status == WorkflowConstants.STATUS_EXPIRED) { article.setExpirationDate(now); } article.setStatus(status); article.setStatusByUserId(user.getUserId()); article.setStatusByUserName(user.getFullName()); article.setStatusDate(modifiedDate); journalArticlePersistence.update(article); if (isExpireAllArticleVersions(article.getCompanyId())) { setArticlesExpirationDate(article); } if (hasModifiedLatestApprovedVersion(article.getGroupId(), article.getArticleId(), article.getVersion())) { if (status == WorkflowConstants.STATUS_APPROVED) { updateUrlTitles(article.getGroupId(), article.getArticleId(), article.getUrlTitle()); // Asset String title = article.getTitleMapAsXML(); String description = article.getDescriptionMapAsXML(); if ((oldStatus != WorkflowConstants.STATUS_APPROVED) && (article.getVersion() != JournalArticleConstants.VERSION_DEFAULT)) { AssetEntry draftAssetEntry = assetEntryLocalService.fetchEntry(JournalArticle.class.getName(), article.getPrimaryKey()); if (draftAssetEntry != null) { long[] assetCategoryIds = draftAssetEntry.getCategoryIds(); String[] assetTagNames = draftAssetEntry.getTagNames(); List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks( draftAssetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED, false); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, article.getGroupId(), article.getCreateDate(), article.getModifiedDate(), JournalArticle.class.getName(), article.getResourcePrimKey(), article.getUuid(), getClassTypeId(article), assetCategoryIds, assetTagNames, isListable(article), false, null, null, null, null, ContentTypes.TEXT_HTML, title, description, description, null, article.getLayoutUuid(), 0, 0, draftAssetEntry.getPriority()); assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds, AssetLinkConstants.TYPE_RELATED); assetEntryLocalService.deleteEntry(draftAssetEntry); } } if (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { assetEntryLocalService.updateEntry(JournalArticle.class.getName(), article.getResourcePrimKey(), article.getDisplayDate(), article.getExpirationDate(), isListable(article), true); } // Social JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("title", title); if (serviceContext.isCommandUpdate()) { SocialActivityManagerUtil.addActivity(user.getUserId(), article, JournalActivityKeys.UPDATE_ARTICLE, extraDataJSONObject.toString(), 0); } else { SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), article, JournalActivityKeys.ADD_ARTICLE, extraDataJSONObject.toString(), 0); } } else if (oldStatus == WorkflowConstants.STATUS_APPROVED) { updatePreviousApprovedArticle(article); } } if ((article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT) && (oldStatus != WorkflowConstants.STATUS_IN_TRASH) && (status != WorkflowConstants.STATUS_IN_TRASH)) { // 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); articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(), article.getArticleId()); 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 String action = "update"; if (article.getVersion() == 1.0) { action = "add"; } notifySubscribers(user.getUserId(), article, action, serviceContext); } return article; }
From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java
License:Open Source License
@Override public WikiPage updateStatus(long userId, WikiPage page, int status, ServiceContext serviceContext, Map<String, Serializable> workflowContext) throws PortalException { // Page//from www. ja v a 2s .com User user = userPersistence.findByPrimaryKey(userId); int oldStatus = page.getStatus(); page.setStatus(status); page.setStatusByUserId(userId); page.setStatusByUserName(user.getFullName()); page.setStatusDate(new Date()); wikiPagePersistence.update(page); if (status == WorkflowConstants.STATUS_APPROVED) { String cmd = GetterUtil.getString(workflowContext.get(WorkflowConstants.CONTEXT_COMMAND)); if (cmd.equals(Constants.RENAME)) { long resourcePrimKey = page.getResourcePrimKey(); WikiPage oldPage = getPage(resourcePrimKey, true); page = doRenamePage(userId, page.getNodeId(), oldPage.getTitle(), page.getTitle(), serviceContext); } // Asset if ((oldStatus != WorkflowConstants.STATUS_APPROVED) && (page.getVersion() != WikiPageConstants.VERSION_DEFAULT)) { AssetEntry draftAssetEntry = assetEntryLocalService.fetchEntry(WikiPage.class.getName(), page.getPrimaryKey()); if (draftAssetEntry != null) { long[] assetCategoryIds = draftAssetEntry.getCategoryIds(); String[] assetTagNames = draftAssetEntry.getTagNames(); List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(draftAssetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED, false); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, page.getGroupId(), page.getCreateDate(), page.getModifiedDate(), WikiPage.class.getName(), page.getResourcePrimKey(), page.getUuid(), 0, assetCategoryIds, assetTagNames, true, true, null, null, page.getCreateDate(), null, ContentTypes.TEXT_HTML, page.getTitle(), null, null, null, null, 0, 0, null); // Asset Links assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds, AssetLinkConstants.TYPE_RELATED); SystemEventHierarchyEntryThreadLocal.push(WikiPage.class); try { assetEntryLocalService.deleteEntry(draftAssetEntry.getEntryId()); } finally { SystemEventHierarchyEntryThreadLocal.pop(WikiPage.class); } } } assetEntryLocalService.updateVisible(WikiPage.class.getName(), page.getResourcePrimKey(), true); // Social WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = configurationProvider .getConfiguration(WikiGroupServiceOverriddenConfiguration.class, new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME)); if ((oldStatus != WorkflowConstants.STATUS_IN_TRASH) && (!page.isMinorEdit() || wikiGroupServiceOverriddenConfiguration.pageMinorEditAddSocialActivity())) { JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("title", page.getTitle()); extraDataJSONObject.put("version", page.getVersion()); int type = WikiActivityKeys.UPDATE_PAGE; if (serviceContext.isCommandAdd()) { type = WikiActivityKeys.ADD_PAGE; } SocialActivityManagerUtil.addActivity(userId, page, type, extraDataJSONObject.toString(), 0); } // Subscriptions if (NotificationThreadLocal.isEnabled() && (!page.isMinorEdit() || wikiGroupServiceOverriddenConfiguration.pageMinorEditSendEmail())) { notifySubscribers(userId, page, (String) workflowContext.get(WorkflowConstants.CONTEXT_URL), serviceContext); } // Cache clearPageCache(page); } // Head if (status == WorkflowConstants.STATUS_APPROVED) { page.setHead(true); List<WikiPage> pages = wikiPagePersistence.findByN_T_H(page.getNodeId(), page.getTitle(), true); for (WikiPage curPage : pages) { if (!curPage.equals(page)) { curPage.setHead(false); wikiPagePersistence.update(curPage); } } } else if (status != WorkflowConstants.STATUS_IN_TRASH) { page.setHead(false); List<WikiPage> pages = wikiPagePersistence.findByN_T_S(page.getNodeId(), page.getTitle(), WorkflowConstants.STATUS_APPROVED); for (WikiPage curPage : pages) { if (!curPage.equals(page)) { curPage.setHead(true); wikiPagePersistence.update(curPage); break; } } } // Indexer Indexer<WikiPage> indexer = IndexerRegistryUtil.nullSafeGetIndexer(WikiPage.class); indexer.reindex(page); return wikiPagePersistence.update(page); }
From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java
License:Open Source License
protected void populateServiceContext(ServiceContext serviceContext, WikiPage page) throws PortalException { long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(WikiPage.class.getName(), page.getResourcePrimKey());// w ww . j a v a 2 s. c om serviceContext.setAssetCategoryIds(assetCategoryIds); AssetEntry assetEntry = assetEntryLocalService.getEntry(WikiPage.class.getName(), page.getResourcePrimKey()); List<AssetLink> assetLinks = assetLinkLocalService.getLinks(assetEntry.getEntryId()); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); serviceContext.setAssetLinkEntryIds(assetLinkEntryIds); String[] assetTagNames = assetTagLocalService.getTagNames(WikiPage.class.getName(), page.getResourcePrimKey()); serviceContext.setAssetTagNames(assetTagNames); ExpandoBridge expandoBridge = page.getExpandoBridge(); serviceContext.setExpandoBridgeAttributes(expandoBridge.getAttributes()); }
From source file:com.liferay.wiki.service.test.WikiPageLocalServiceTest.java
License:Open Source License
protected void checkPopulatedServiceContext(ServiceContext serviceContext, WikiPage page, boolean hasExpandoValues) throws Exception { long[] assetCategoryIds = AssetCategoryLocalServiceUtil.getCategoryIds(WikiPage.class.getName(), page.getResourcePrimKey());// w ww. j ava 2 s. c o m Assert.assertArrayEquals(serviceContext.getAssetCategoryIds(), assetCategoryIds); AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(WikiPage.class.getName(), page.getResourcePrimKey()); List<AssetLink> assetLinks = AssetLinkLocalServiceUtil.getLinks(assetEntry.getEntryId()); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); Assert.assertArrayEquals(serviceContext.getAssetLinkEntryIds(), assetLinkEntryIds); String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(WikiPage.class.getName(), page.getResourcePrimKey()); Assert.assertArrayEquals(serviceContext.getAssetTagNames(), assetTagNames); if (hasExpandoValues) { ExpandoBridge expandoBridge = page.getExpandoBridge(); AssertUtils.assertEquals(expandoBridge.getAttributes(), serviceContext.getExpandoBridgeAttributes()); } }