List of usage examples for com.liferay.portal.kernel.service ServiceContext setAttribute
public void setAttribute(String name, Serializable value)
From source file:com.bemis.portal.fileuploader.service.impl.FileUploaderLocalServiceImpl.java
License:Open Source License
/** * Uploads the file into the destination folder * If the file does not exist, adds the file. If exists, updates the existing file * Adds tags and categories to documents * * @param companyId/*ww w . j a va 2 s . c o m*/ * @param groupId * @param userId * @param file * @param fileDescription * @param title * @param folderId * @param changeLog * @param assetTagNames * @return FileEntry * @throws PortalException */ public FileEntry uploadFile(long companyId, long groupId, long userId, File file, String fileDescription, String title, long folderId, String changeLog, String[] assetTagNames) throws PortalException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setScopeGroupId(groupId); serviceContext.setUserId(userId); serviceContext.setAssetTagNames(assetTagNames); serviceContext.setAttribute(FileUploaderConstants.DESTINATION_FOLDER_ID, folderId); return uploadFile(file, fileDescription, title, changeLog, serviceContext); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
protected void testExportImportAssetEntries(List<Group> scopeGroups) throws Exception { List<AssetEntry> assetEntries = new ArrayList<>(); String[] scopeIds = new String[0]; for (Group scopeGroup : scopeGroups) { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); if (scopeGroup.isLayout()) { // Creating structures and templates in layout scope group is // not possible Company company = CompanyLocalServiceUtil.getCompany(layout.getCompanyId()); serviceContext.setAttribute("ddmGroupId", company.getGroupId()); }// ww w. j a v a 2 s .c o m assetEntries = addAssetEntries(scopeGroup, 3, assetEntries, serviceContext); String scopeId = _assetPublisherHelper.getScopeId(scopeGroup, group.getGroupId()); scopeIds = ArrayUtil.append(scopeIds, scopeId); } Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("assetEntryXml", getAssetEntriesXmls(assetEntries)); preferenceMap.put("scopeIds", scopeIds); PortletPreferences importedPortletPreferences = getImportedPortletPreferences(preferenceMap); String[] importedScopeIds = importedPortletPreferences.getValues("scopeIds", null); long[] selectedGroupIds = getGroupIdsFromScopeIds(importedScopeIds, importedLayout); List<AssetEntry> actualAssetEntries = _assetPublisherHelper.getAssetEntries(new MockPortletRequest(), importedPortletPreferences, _permissionChecker, selectedGroupIds, false, false); assertAssetEntries(assetEntries, actualAssetEntries); }
From source file:com.liferay.blogs.internal.util.PingbackMethodImpl.java
License:Open Source License
protected ServiceContext buildServiceContext(long companyId, long groupId, String urlTitle) throws Exception { ServiceContext serviceContext = new ServiceContext(); String pingbackUserName = LanguageUtil.get(LocaleUtil.getSiteDefault(), "pingback"); serviceContext.setAttribute("pingbackUserName", pingbackUserName); StringBundler sb = new StringBundler(5); String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(), PortletProvider.Action.VIEW); if (Validator.isNull(portletId)) { return serviceContext; }// w ww. j a v a 2 s . c o m String layoutFullURL = PortalUtil.getLayoutFullURL(groupId, portletId); sb.append(layoutFullURL); sb.append(Portal.FRIENDLY_URL_SEPARATOR); Portlet portlet = _portletLocalService.getPortletById(companyId, portletId); sb.append(portlet.getFriendlyURLMapping()); sb.append(StringPool.SLASH); sb.append(urlTitle); serviceContext.setAttribute("redirect", sb.toString()); serviceContext.setLayoutFullURL(layoutFullURL); return serviceContext; }
From source file:com.liferay.blogs.notifications.test.BlogsUserNotificationTest.java
License:Open Source License
@Override protected BaseModel<?> updateBaseModel(BaseModel<?> baseModel) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(), TestPropsValues.getUserId()); BlogsTestUtil.populateNotificationsServiceContext(serviceContext, Constants.UPDATE); serviceContext.setAttribute("sendEmailEntryUpdated", true); return BlogsEntryLocalServiceUtil.updateEntry(TestPropsValues.getUserId(), ((BlogsEntry) baseModel).getEntryId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext);/* ww w . j a v a2s.c o m*/ }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
@Indexable(type = IndexableType.REINDEX) @Override/* w w w .ja v a2 s . c o m*/ public BlogsEntry addEntry(long userId, String title, String subtitle, String urlTitle, String description, String content, Date displayDate, boolean allowPingbacks, boolean allowTrackbacks, String[] trackbacks, String coverImageCaption, ImageSelector coverImageImageSelector, ImageSelector smallImageImageSelector, ServiceContext serviceContext) throws PortalException { // Entry User user = userPersistence.findByPrimaryKey(userId); long groupId = serviceContext.getScopeGroupId(); long entryId = counterLocalService.increment(); validate(title, urlTitle, content); BlogsEntry entry = blogsEntryPersistence.create(entryId); entry.setUuid(serviceContext.getUuid()); entry.setGroupId(groupId); entry.setCompanyId(user.getCompanyId()); entry.setUserId(user.getUserId()); entry.setUserName(user.getFullName()); entry.setTitle(title); entry.setSubtitle(subtitle); if (Validator.isNotNull(urlTitle)) { entry.setUrlTitle(getUniqueUrlTitle(entryId, groupId, urlTitle)); } entry.setDescription(description); entry.setContent(content); entry.setDisplayDate(displayDate); entry.setAllowPingbacks(allowPingbacks); entry.setAllowTrackbacks(allowTrackbacks); entry.setStatus(WorkflowConstants.STATUS_DRAFT); entry.setStatusByUserId(userId); entry.setStatusDate(serviceContext.getModifiedDate(null)); entry.setExpandoBridgeAttributes(serviceContext); blogsEntryPersistence.update(entry); // Resources if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) { addEntryResources(entry, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions()); } else { addEntryResources(entry, serviceContext.getModelPermissions()); } // Asset updateAsset(userId, entry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); // Images long coverImageFileEntryId = 0; String coverImageURL = null; if (coverImageImageSelector != null) { coverImageURL = coverImageImageSelector.getImageURL(); if (coverImageImageSelector.getImageBytes() != null) { coverImageFileEntryId = addCoverImageFileEntry(userId, groupId, entryId, coverImageImageSelector); } } long smallImageFileEntryId = 0; String smallImageURL = null; if (smallImageImageSelector != null) { smallImageURL = smallImageImageSelector.getImageURL(); if (smallImageImageSelector.getImageBytes() != null) { smallImageFileEntryId = addSmallImageFileEntry(userId, groupId, entryId, smallImageImageSelector); } } validate(smallImageFileEntryId); entry.setCoverImageCaption(coverImageCaption); entry.setCoverImageFileEntryId(coverImageFileEntryId); entry.setCoverImageURL(coverImageURL); if ((smallImageFileEntryId != 0) || Validator.isNotNull(smallImageURL)) { entry.setSmallImage(true); } entry.setSmallImageFileEntryId(smallImageFileEntryId); entry.setSmallImageURL(smallImageURL); blogsEntryPersistence.update(entry); // Workflow if (ArrayUtil.isNotEmpty(trackbacks)) { serviceContext.setAttribute("trackbacks", trackbacks); } else { serviceContext.setAttribute("trackbacks", null); } return startWorkflowInstance(userId, entry, serviceContext); }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
@Override public void checkEntries() throws PortalException { Date now = new Date(); int count = blogsEntryPersistence.countByLtD_S(now, WorkflowConstants.STATUS_SCHEDULED); if (count == 0) { return;/* w w w. j a v a 2 s . c o m*/ } List<BlogsEntry> entries = blogsEntryPersistence.findByLtD_S(now, WorkflowConstants.STATUS_SCHEDULED); for (BlogsEntry entry : entries) { ServiceContext serviceContext = new ServiceContext(); String[] trackbacks = StringUtil.split(entry.getTrackbacks()); serviceContext.setAttribute("trackbacks", trackbacks); serviceContext.setCommand(Constants.UPDATE); String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(), PortletProvider.Action.VIEW); if (Validator.isNotNull(portletId)) { String layoutFullURL = PortalUtil.getLayoutFullURL(entry.getGroupId(), portletId); serviceContext.setLayoutFullURL(layoutFullURL); } serviceContext.setScopeGroupId(entry.getGroupId()); blogsEntryLocalService.updateStatus(entry.getStatusByUserId(), entry.getEntryId(), WorkflowConstants.STATUS_APPROVED, serviceContext, new HashMap<String, Serializable>()); } }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
@Indexable(type = IndexableType.REINDEX) @Override// w ww .ja va2 s. c om public BlogsEntry updateEntry(long userId, long entryId, String title, String subtitle, String urlTitle, String description, String content, Date displayDate, boolean allowPingbacks, boolean allowTrackbacks, String[] trackbacks, String coverImageCaption, ImageSelector coverImageImageSelector, ImageSelector smallImageImageSelector, ServiceContext serviceContext) throws PortalException { // Entry BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId); validate(title, urlTitle, content); String oldUrlTitle = entry.getUrlTitle(); entry.setTitle(title); entry.setSubtitle(subtitle); if (Validator.isNotNull(urlTitle)) { entry.setUrlTitle(getUniqueUrlTitle(entryId, entry.getGroupId(), urlTitle)); } entry.setDescription(description); entry.setContent(content); entry.setDisplayDate(displayDate); entry.setAllowPingbacks(allowPingbacks); entry.setAllowTrackbacks(allowTrackbacks); if (entry.isPending() || entry.isDraft()) { } else { entry.setStatus(WorkflowConstants.STATUS_DRAFT); } entry.setExpandoBridgeAttributes(serviceContext); blogsEntryPersistence.update(entry); // Asset updateAsset(userId, entry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); // Images long coverImageFileEntryId = entry.getCoverImageFileEntryId(); String coverImageURL = entry.getCoverImageURL(); long deletePreviousCoverImageFileEntryId = 0; if (coverImageImageSelector != null) { coverImageURL = coverImageImageSelector.getImageURL(); if (coverImageImageSelector.getImageBytes() != null) { coverImageFileEntryId = addCoverImageFileEntry(userId, entry.getGroupId(), entryId, coverImageImageSelector); } else { coverImageFileEntryId = 0; } deletePreviousCoverImageFileEntryId = entry.getCoverImageFileEntryId(); } long smallImageFileEntryId = entry.getSmallImageFileEntryId(); String smallImageURL = entry.getSmallImageURL(); long deletePreviousSmallImageFileEntryId = 0; if (smallImageImageSelector != null) { smallImageURL = smallImageImageSelector.getImageURL(); if (smallImageImageSelector.getImageBytes() != null) { smallImageFileEntryId = addSmallImageFileEntry(userId, entry.getGroupId(), entryId, smallImageImageSelector); } else { smallImageFileEntryId = 0; } deletePreviousSmallImageFileEntryId = entry.getSmallImageFileEntryId(); } validate(smallImageFileEntryId); entry.setCoverImageCaption(coverImageCaption); entry.setCoverImageFileEntryId(coverImageFileEntryId); entry.setCoverImageURL(coverImageURL); if ((smallImageFileEntryId != 0) || Validator.isNotNull(smallImageURL)) { entry.setSmallImage(true); } entry.setSmallImageFileEntryId(smallImageFileEntryId); entry.setSmallImageURL(smallImageURL); blogsEntryPersistence.update(entry); // Workflow boolean pingOldTrackbacks = false; if (!oldUrlTitle.equals(entry.getUrlTitle())) { pingOldTrackbacks = true; } serviceContext.setAttribute("pingOldTrackbacks", String.valueOf(pingOldTrackbacks)); if (ArrayUtil.isNotEmpty(trackbacks)) { serviceContext.setAttribute("trackbacks", trackbacks); } else { serviceContext.setAttribute("trackbacks", null); } entry = startWorkflowInstance(userId, entry, serviceContext); if (deletePreviousCoverImageFileEntryId != 0) { PortletFileRepositoryUtil.deletePortletFileEntry(deletePreviousCoverImageFileEntryId); } if (deletePreviousSmallImageFileEntryId != 0) { PortletFileRepositoryUtil.deletePortletFileEntry(deletePreviousSmallImageFileEntryId); } return entry; }
From source file:com.liferay.blogs.service.test.BlogsEntryStatusTransitionTest.java
License:Open Source License
protected ServiceContext getServiceContext(BlogsEntry entry) throws Exception { ServiceContext serviceContext = new ServiceContext(); String[] trackbacks = StringUtil.split(entry.getTrackbacks()); serviceContext.setAttribute("trackbacks", trackbacks); serviceContext.setCommand(Constants.UPDATE); String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(), PortletProvider.Action.VIEW); String layoutFullURL = PortalUtil.getLayoutFullURL(entry.getGroupId(), portletId); serviceContext.setLayoutFullURL(layoutFullURL); serviceContext.setScopeGroupId(entry.getGroupId()); return serviceContext; }
From source file:com.liferay.blogs.subscription.test.BlogsSubscriptionAuthorTest.java
License:Open Source License
@Override protected void updateBaseModel(long userId, long baseModelId) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(), userId); BlogsTestUtil.populateNotificationsServiceContext(serviceContext, Constants.UPDATE); serviceContext.setAttribute("sendEmailEntryUpdated", true); BlogsEntryLocalServiceUtil.updateEntry(userId, baseModelId, RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext); }
From source file:com.liferay.blogs.test.util.BlogsTestUtil.java
License:Open Source License
public static void populateNotificationsServiceContext(ServiceContext serviceContext, String command) throws Exception { serviceContext.setAttribute("entryURL", "http://localhost"); if (Validator.isNotNull(command)) { serviceContext.setCommand(command); }// w ww .jav a2 s. co m serviceContext.setLayoutFullURL("http://localhost"); }