List of usage examples for com.liferay.portal.kernel.service ServiceContext getLayoutFullURL
public String getLayoutFullURL()
From source file:com.liferay.blogs.internal.util.PingbackMethodImplTest.java
License:Open Source License
@Test public void testBuildServiceContext() throws Exception { PingbackMethodImpl pingbackMethodImpl = getPingbackMethodImpl(); ServiceContext serviceContext = pingbackMethodImpl.buildServiceContext(_COMPANY_ID, _GROUP_ID, _URL_TITLE); Assert.assertEquals(_PINGBACK_USER_NAME, serviceContext.getAttribute("pingbackUserName")); Assert.assertEquals(_LAYOUT_FULL_URL + "/-/" + _FRIENDLY_URL_MAPPING + "/" + _URL_TITLE, serviceContext.getAttribute("redirect")); Assert.assertEquals(_LAYOUT_FULL_URL, serviceContext.getLayoutFullURL()); }
From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java
License:Open Source License
protected void notifySubscribers(long userId, BookmarksEntry entry, ServiceContext serviceContext) throws PortalException { String layoutFullURL = serviceContext.getLayoutFullURL(); if (!entry.isApproved() || Validator.isNull(layoutFullURL)) { return;/*w ww . j ava 2s. com*/ } BookmarksGroupServiceOverriddenConfiguration bookmarksGroupServiceOverriddenConfiguration = configurationProvider .getConfiguration(BookmarksGroupServiceOverriddenConfiguration.class, new GroupServiceSettingsLocator(entry.getGroupId(), BookmarksConstants.SERVICE_NAME)); if ((serviceContext.isCommandAdd() && !bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedEnabled()) || (serviceContext.isCommandUpdate() && !bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedEnabled())) { return; } String statusByUserName = StringPool.BLANK; try { User user = userLocalService.getUserById(serviceContext.getGuestOrUserId()); statusByUserName = user.getFullName(); } catch (Exception e) { _log.error(e, e); } String entryTitle = entry.getName(); StringBundler sb = new StringBundler(7); sb.append(layoutFullURL); sb.append(Portal.FRIENDLY_URL_SEPARATOR); sb.append("bookmarks"); sb.append(StringPool.SLASH); sb.append("folder"); sb.append(StringPool.SLASH); sb.append(entry.getFolderId()); String entryURL = sb.toString(); String fromName = bookmarksGroupServiceOverriddenConfiguration.emailFromName(); String fromAddress = bookmarksGroupServiceOverriddenConfiguration.emailFromAddress(); LocalizedValuesMap subjectLocalizedValuesMap = null; LocalizedValuesMap bodyLocalizedValuesMap = null; if (serviceContext.isCommandUpdate()) { subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedSubject(); bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedBody(); } else { subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedSubject(); bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedBody(); } SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender( BookmarksResourcePermissionChecker.RESOURCE_NAME); subscriptionSender.setClassName(entry.getModelClassName()); subscriptionSender.setClassPK(entry.getEntryId()); subscriptionSender.setCompanyId(entry.getCompanyId()); subscriptionSender.setContextAttributes("[$BOOKMARKS_ENTRY_STATUS_BY_USER_NAME$]", statusByUserName, "[$BOOKMARKS_ENTRY_URL$]", entryURL); subscriptionSender.setContextCreatorUserPrefix("BOOKMARKS_ENTRY"); subscriptionSender.setCreatorUserId(entry.getUserId()); subscriptionSender.setCurrentUserId(userId); subscriptionSender.setEntryTitle(entryTitle); subscriptionSender.setEntryURL(entryURL); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setHtmlFormat(true); if (bodyLocalizedValuesMap != null) { subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap)); } if (subjectLocalizedValuesMap != null) { subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap)); } subscriptionSender.setMailId("bookmarks_entry", entry.getEntryId()); int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY; if (serviceContext.isCommandUpdate()) { notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY; } subscriptionSender.setNotificationType(notificationType); subscriptionSender.setPortletId(BookmarksPortletKeys.BOOKMARKS); subscriptionSender.setReplyToAddress(fromAddress); subscriptionSender.setScopeGroupId(entry.getGroupId()); subscriptionSender.setServiceContext(serviceContext); BookmarksFolder folder = entry.getFolder(); if (folder != null) { subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), folder.getFolderId()); for (Long ancestorFolderId : folder.getAncestorFolderIds()) { subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), ancestorFolderId); } } subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), entry.getGroupId()); subscriptionSender.addPersistedSubscribers(BookmarksEntry.class.getName(), entry.getEntryId()); subscriptionSender.flushNotificationsAsync(); }
From source file:com.liferay.contacts.web.internal.notifications.ContactsCenterUserNotificationHandler.java
License:Open Source License
@Override protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext) throws Exception { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload()); long socialRequestId = jsonObject.getLong("classPK"); SocialRequest socialRequest = _socialRequestLocalService.fetchSocialRequest(socialRequestId); if (socialRequest == null) { _userNotificationEventLocalService .deleteUserNotificationEvent(userNotificationEvent.getUserNotificationEventId()); return null; }//from w w w. ja v a 2s. c o m String creatorUserName = getUserNameLink(socialRequest.getUserId(), serviceContext); ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(serviceContext.getLocale()); String title = StringPool.BLANK; if (socialRequest.getType() == SocialRelationConstants.TYPE_BI_CONNECTION) { title = ResourceBundleUtil.getString(resourceBundle, serviceContext.getLocale(), "request-social-networking-summary-add-connection", new Object[] { creatorUserName }); } else { title = ResourceBundleUtil.getString(resourceBundle, serviceContext.getLocale(), "x-sends-you-a-social-relationship-request", new Object[] { creatorUserName }); } if ((socialRequest.getStatus() != SocialRequestConstants.STATUS_PENDING) || (socialRequest.getModifiedDate() > userNotificationEvent.getTimestamp())) { return StringUtil.replace(_BODY, new String[] { "[$BODY$]", "[$TITLE$]" }, new String[] { StringPool.BLANK, title }); } LiferayPortletResponse liferayPortletResponse = serviceContext.getLiferayPortletResponse(); PortletURL confirmURL = liferayPortletResponse.createActionURL(ContactsPortletKeys.CONTACTS_CENTER); confirmURL.setParameter(ActionRequest.ACTION_NAME, "updateSocialRequest"); confirmURL.setParameter("redirect", serviceContext.getLayoutFullURL()); confirmURL.setParameter("socialRequestId", String.valueOf(socialRequestId)); confirmURL.setParameter("status", String.valueOf(SocialRequestConstants.STATUS_CONFIRM)); confirmURL.setParameter("userNotificationEventId", String.valueOf(userNotificationEvent.getUserNotificationEventId())); confirmURL.setWindowState(WindowState.NORMAL); PortletURL ignoreURL = liferayPortletResponse.createActionURL(ContactsPortletKeys.CONTACTS_CENTER); ignoreURL.setParameter(ActionRequest.ACTION_NAME, "updateSocialRequest"); ignoreURL.setParameter("redirect", serviceContext.getLayoutFullURL()); ignoreURL.setParameter("socialRequestId", String.valueOf(socialRequestId)); ignoreURL.setParameter("status", String.valueOf(SocialRequestConstants.STATUS_IGNORE)); ignoreURL.setParameter("userNotificationEventId", String.valueOf(userNotificationEvent.getUserNotificationEventId())); ignoreURL.setWindowState(WindowState.NORMAL); return StringUtil.replace(getBodyTemplate(), new String[] { "[$CONFIRM$]", "[$CONFIRM_URL$]", "[$IGNORE$]", "[$IGNORE_URL$]", "[$TITLE$]" }, new String[] { serviceContext.translate("confirm"), confirmURL.toString(), serviceContext.translate("ignore"), ignoreURL.toString(), title }); }