List of usage examples for com.liferay.portal.kernel.util EscapableLocalizableFunction EscapableLocalizableFunction
public EscapableLocalizableFunction(Function<Locale, String> function)
From source file:com.liferay.document.library.internal.service.SubscriptionDLAppHelperLocalServiceWrapper.java
License:Open Source License
protected void notifySubscribers(long userId, FileVersion fileVersion, String entryURL, ServiceContext serviceContext) throws PortalException { if (!fileVersion.isApproved() || Validator.isNull(entryURL)) { return;// ww w. j av a2 s . co m } DLGroupServiceSettings dlGroupServiceSettings = DLGroupServiceSettings .getInstance(fileVersion.getGroupId()); boolean commandUpdate = false; if (serviceContext.isCommandUpdate() || Constants.CHECKIN.equals(serviceContext.getCommand())) { commandUpdate = true; } if (serviceContext.isCommandAdd() && dlGroupServiceSettings.isEmailFileEntryAddedEnabled()) { } else if (commandUpdate && dlGroupServiceSettings.isEmailFileEntryUpdatedEnabled()) { } else { return; } String entryTitle = fileVersion.getTitle(); String fromName = dlGroupServiceSettings.getEmailFromName(); String fromAddress = dlGroupServiceSettings.getEmailFromAddress(); LocalizedValuesMap subjectLocalizedValuesMap = null; LocalizedValuesMap bodyLocalizedValuesMap = null; if (commandUpdate) { subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedSubject(); bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedBody(); } else { subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedSubject(); bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedBody(); } FileEntry fileEntry = fileVersion.getFileEntry(); Folder folder = null; long folderId = fileEntry.getFolderId(); if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { folder = _dlAppLocalService.getFolder(folderId); } SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender( DLPermission.RESOURCE_NAME); DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel(); DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService .getDLFileEntryType(dlFileEntry.getFileEntryTypeId()); subscriptionSender.setClassPK(fileVersion.getFileEntryId()); subscriptionSender.setClassName(DLFileEntryConstants.getClassName()); subscriptionSender.setCompanyId(fileVersion.getCompanyId()); if (folder != null) { subscriptionSender.setContextAttribute("[$FOLDER_NAME$]", folder.getName(), true); } else { subscriptionSender.setLocalizedContextAttribute("[$FOLDER_NAME$]", new EscapableLocalizableFunction(locale -> LanguageUtil.get(locale, "home"))); } subscriptionSender.setContextAttributes("[$DOCUMENT_STATUS_BY_USER_NAME$]", fileVersion.getStatusByUserName(), "[$DOCUMENT_TITLE$]", entryTitle, "[$DOCUMENT_URL$]", entryURL); subscriptionSender.setContextCreatorUserPrefix("DOCUMENT"); subscriptionSender.setCreatorUserId(fileVersion.getUserId()); subscriptionSender.setCurrentUserId(userId); subscriptionSender.setEntryTitle(entryTitle); subscriptionSender.setEntryURL(entryURL); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setHtmlFormat(true); subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap)); subscriptionSender.setLocalizedContextAttribute("[$DOCUMENT_TYPE$]", new EscapableLocalizableFunction(locale -> dlFileEntryType.getName(locale))); subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap)); subscriptionSender.setMailId("file_entry", fileVersion.getFileEntryId()); int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY; if (commandUpdate) { notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY; } subscriptionSender.setNotificationType(notificationType); String portletId = PortletProviderUtil.getPortletId(FileEntry.class.getName(), PortletProvider.Action.VIEW); subscriptionSender.setPortletId(portletId); subscriptionSender.setReplyToAddress(fromAddress); subscriptionSender.setScopeGroupId(fileVersion.getGroupId()); subscriptionSender.setServiceContext(serviceContext); subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), fileVersion.getGroupId()); if (folder != null) { subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), folder.getFolderId()); for (Long ancestorFolderId : folder.getAncestorFolderIds()) { subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), ancestorFolderId); } } if (dlFileEntryType.getFileEntryTypeId() == DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) { subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(), fileVersion.getGroupId()); } else { subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(), dlFileEntryType.getFileEntryTypeId()); } subscriptionSender.addPersistedSubscribers(DLFileEntry.class.getName(), fileEntry.getFileEntryId()); subscriptionSender.flushNotificationsAsync(); }
From source file:com.liferay.message.boards.internal.service.SubscriptionMBMessageLocalServiceWrapper.java
License:Open Source License
protected MBSubscriptionSender getSubscriptionSender(long userId, MBCategory category, MBMessage message, String messageURL, String entryTitle, boolean htmlFormat, String messageBody, String messageSubject, String messageSubjectPrefix, String inReplyTo, String fromName, String fromAddress, String replyToAddress, String emailAddress, String fullName, LocalizedValuesMap subjectLocalizedValuesMap, LocalizedValuesMap bodyLocalizedValuesMap, ServiceContext serviceContext) { MBSubscriptionSender subscriptionSender = new MBSubscriptionSender(MBPermission.RESOURCE_NAME); subscriptionSender.setAnonymous(message.isAnonymous()); subscriptionSender.setBulk(PropsValues.MESSAGE_BOARDS_EMAIL_BULK); subscriptionSender.setClassName(message.getModelClassName()); subscriptionSender.setClassPK(message.getMessageId()); subscriptionSender.setCompanyId(message.getCompanyId()); subscriptionSender.setContextAttribute("[$MESSAGE_BODY$]", messageBody, false); long groupId = message.getGroupId(); if (category.getCategoryId() != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) { subscriptionSender.setContextAttribute("[$CATEGORY_NAME$]", category.getName(), true); } else {//w w w. ja va2 s .co m try { Group group = _groupLocalService.getGroup(groupId); subscriptionSender.setLocalizedContextAttribute("[$CATEGORY_NAME$]", new EscapableLocalizableFunction(locale -> _getLocalizedRootCategoryName(group, locale))); } catch (PortalException pe) { ReflectionUtil.throwException(pe); } } subscriptionSender.setContextAttributes("[$MAILING_LIST_ADDRESS$]", replyToAddress, "[$MESSAGE_ID$]", message.getMessageId(), "[$MESSAGE_SUBJECT$]", messageSubject, "[$MESSAGE_SUBJECT_PREFIX$]", messageSubjectPrefix, "[$MESSAGE_URL$]", messageURL, "[$MESSAGE_USER_ADDRESS$]", emailAddress, "[$MESSAGE_USER_NAME$]", fullName); subscriptionSender.setCurrentUserId(userId); subscriptionSender.setEntryTitle(entryTitle); subscriptionSender.setEntryURL(messageURL); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setFullName(fullName); subscriptionSender.setHtmlFormat(htmlFormat); subscriptionSender.setInReplyTo(inReplyTo); if (bodyLocalizedValuesMap != null) { subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap)); } if (subjectLocalizedValuesMap != null) { subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap)); } Date modifiedDate = message.getModifiedDate(); subscriptionSender.setMailId(MBUtil.MESSAGE_POP_PORTLET_PREFIX, message.getCategoryId(), message.getMessageId(), modifiedDate.getTime()); int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY; if (serviceContext.isCommandUpdate()) { notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY; } subscriptionSender.setNotificationType(notificationType); String portletId = PortletProviderUtil.getPortletId(MBMessage.class.getName(), PortletProvider.Action.VIEW); subscriptionSender.setPortletId(portletId); subscriptionSender.setReplyToAddress(replyToAddress); subscriptionSender.setScopeGroupId(groupId); subscriptionSender.setServiceContext(serviceContext); subscriptionSender.setUniqueMailId(false); return subscriptionSender; }
From source file:com.liferay.petra.mail.template.internal.DefaultMailTemplateTest.java
License:Open Source License
@Before public void setUp() { MailTemplateContextBuilder mailTemplateContextBuilder = new DefaultMailTemplateContextBuilder(); mailTemplateContextBuilder.put("[$PLACEHOLDER$]", "replacement"); mailTemplateContextBuilder.put("[$ESCAPED_VALUE$]", new EscapableObject<>("<>", true)); mailTemplateContextBuilder.put("[$LOCALIZED_VALUE$]", new EscapableLocalizableFunction(Locale::getLanguage)); mailTemplateContextBuilder.put("[$PORTAL_URL$]", "http://liferay.com"); _mailTemplateContext = mailTemplateContextBuilder.build(); }