List of usage examples for com.liferay.portal.kernel.notifications UserNotificationManagerUtil isDeliver
public static boolean isDeliver(long userId, String portletId, long classNameId, int notificationType, int deliveryType) throws PortalException
From source file:com.liferay.alloy.mvc.AlloyNotificationEventHelper.java
License:Open Source License
protected void addUserNotificationEvent(String portletKey, long userId, int notificationType, int deliveryType, Object... attributes) throws Exception { if ((attributes.length == 0) || ((attributes.length % 2) != 0)) { throw new IllegalArgumentException("Attributes length is not an even number"); }//from www . jav a2 s .c o m if (UserNotificationManagerUtil.isDeliver(userId, portletKey, 0, notificationType, deliveryType)) { JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); for (int i = 0; i < attributes.length; i += 2) { String key = String.valueOf(attributes[i]); String value = String.valueOf(attributes[i + 1]); notificationEventJSONObject.put(key, value); } NotificationEvent notificationEvent = NotificationEventFactoryUtil .createNotificationEvent(System.currentTimeMillis(), portletKey, notificationEventJSONObject); notificationEvent.setDeliveryRequired(0); UserNotificationEventLocalServiceUtil.addUserNotificationEvent(userId, notificationEvent); } }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void sendNotificationEvent(SocialRequest socialRequest) throws Exception { if (UserNotificationManagerUtil.isDeliver(socialRequest.getReceiverUserId(), PortletKeys.CONTACTS_CENTER, 0, SocialRelationConstants.SOCIAL_RELATION_REQUEST, UserNotificationDeliveryConstants.TYPE_WEBSITE)) { JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); notificationEventJSONObject.put("classPK", socialRequest.getRequestId()); notificationEventJSONObject.put("userId", socialRequest.getUserId()); UserNotificationEventLocalServiceUtil.sendUserNotificationEvents(socialRequest.getReceiverUserId(), PortletKeys.CONTACTS_CENTER, UserNotificationDeliveryConstants.TYPE_WEBSITE, true, notificationEventJSONObject); }//from w ww. j a v a2 s . com }
From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void sendNotificationEvent(SocialRequest socialRequest) throws Exception { if (UserNotificationManagerUtil.isDeliver(socialRequest.getReceiverUserId(), ContactsPortletKeys.CONTACTS_CENTER, 0, SocialRelationConstants.SOCIAL_RELATION_REQUEST, UserNotificationDeliveryConstants.TYPE_WEBSITE)) { JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); notificationEventJSONObject.put("classPK", socialRequest.getRequestId()); notificationEventJSONObject.put("userId", socialRequest.getUserId()); userNotificationEventLocalService.sendUserNotificationEvents(socialRequest.getReceiverUserId(), ContactsPortletKeys.CONTACTS_CENTER, UserNotificationDeliveryConstants.TYPE_WEBSITE, true, notificationEventJSONObject); }//w w w .jav a 2 s . c o m }
From source file:com.liferay.invitation.invite.members.service.impl.MemberRequestLocalServiceImpl.java
License:Open Source License
protected void sendNotificationEvent(MemberRequest memberRequest) throws PortalException { String portletId = PortletProviderUtil.getPortletId(MemberRequest.class.getName(), PortletProvider.Action.EDIT); if (UserNotificationManagerUtil.isDeliver(memberRequest.getReceiverUserId(), portletId, 0, MembershipRequestConstants.STATUS_PENDING, UserNotificationDeliveryConstants.TYPE_WEBSITE)) { JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); notificationEventJSONObject.put("classPK", memberRequest.getMemberRequestId()); notificationEventJSONObject.put("userId", memberRequest.getUserId()); NotificationEvent notificationEvent = NotificationEventFactoryUtil .createNotificationEvent(System.currentTimeMillis(), portletId, notificationEventJSONObject); notificationEvent.setDeliveryRequired(0); notificationEvent.setDeliveryType(UserNotificationDeliveryConstants.TYPE_WEBSITE); userNotificationEventLocalService.addUserNotificationEvent(memberRequest.getReceiverUserId(), true, notificationEvent);//from w w w .ja va 2s. co m } }
From source file:com.liferay.microblogs.util.MicroblogsUtil.java
License:Open Source License
public static int getNotificationType(MicroblogsEntry microblogsEntry, long userId, int deliveryType) throws PortalException { if (isTaggedUser(microblogsEntry.getMicroblogsEntryId(), false, userId) && UserNotificationManagerUtil.isDeliver(userId, PortletKeys.MICROBLOGS, 0, MicroblogsEntryConstants.NOTIFICATION_TYPE_TAG, deliveryType)) { return MicroblogsEntryConstants.NOTIFICATION_TYPE_TAG; } else if (microblogsEntry.getType() == MicroblogsEntryConstants.TYPE_REPLY) { long rootMicroblogsEntryId = getRootMicroblogsEntryId(microblogsEntry); if ((getRootMicroblogsUserId(microblogsEntry) == userId) && UserNotificationManagerUtil.isDeliver(userId, PortletKeys.MICROBLOGS, 0, MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY, deliveryType)) { return MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY; } else if (hasReplied(rootMicroblogsEntryId, userId) && UserNotificationManagerUtil.isDeliver(userId, PortletKeys.MICROBLOGS, 0, MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_REPLIED, deliveryType)) { return MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_REPLIED; } else if (MicroblogsUtil.isTaggedUser(rootMicroblogsEntryId, true, userId) && UserNotificationManagerUtil.isDeliver(userId, PortletKeys.MICROBLOGS, 0, MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_TAGGED, deliveryType)) { return MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_TAGGED; }/*from w w w . j ava2 s . c o m*/ } return MicroblogsEntryConstants.NOTIFICATION_TYPE_UNKNOWN; }
From source file:com.liferay.privatemessaging.service.impl.UserThreadLocalServiceImpl.java
License:Open Source License
protected void sendEmail(long mbMessageId, ThemeDisplay themeDisplay) throws Exception { MBMessage mbMessage = MBMessageLocalServiceUtil.getMBMessage(mbMessageId); User sender = UserLocalServiceUtil.getUser(mbMessage.getUserId()); Company company = CompanyLocalServiceUtil.getCompany(sender.getCompanyId()); InternetAddress from = new InternetAddress(company.getEmailAddress()); String subject = StringUtil.read(PrivateMessagingPortlet.class .getResourceAsStream("dependencies/notification_message_subject.tmpl")); subject = StringUtil.replace(subject, new String[] { "[$COMPANY_NAME$]", "[$FROM_NAME$]" }, new String[] { company.getName(), sender.getFullName() }); String body = StringUtil.read( PrivateMessagingPortlet.class.getResourceAsStream("dependencies/notification_message_body.tmpl")); long portraitId = sender.getPortraitId(); String tokenId = WebServerServletTokenUtil.getToken(sender.getPortraitId()); String portraitURL = themeDisplay.getPortalURL() + themeDisplay.getPathImage() + "/user_" + (sender.isFemale() ? "female" : "male") + "_portrait?img_id=" + portraitId + "&t=" + tokenId; body = StringUtil.replace(body,/*from ww w . ja v a 2s .c om*/ new String[] { "[$BODY$]", "[$COMPANY_NAME$]", "[$FROM_AVATAR$]", "[$FROM_NAME$]", "[$FROM_PROFILE_URL$]", "[$SUBJECT$]" }, new String[] { mbMessage.getBody(), company.getName(), portraitURL, sender.getFullName(), sender.getDisplayURL(themeDisplay), mbMessage.getSubject() }); List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbMessage.getThreadId()); for (UserThread userThread : userThreads) { if ((userThread.getUserId() == mbMessage.getUserId()) && UserNotificationManagerUtil.isDeliver( userThread.getUserId(), PortletKeys.PRIVATE_MESSAGING, PrivateMessagingConstants.NEW_MESSAGE, 0, UserNotificationDeliveryConstants.TYPE_EMAIL)) { continue; } User recipient = UserLocalServiceUtil.getUser(userThread.getUserId()); String threadURL = getThreadURL(recipient, mbMessage.getThreadId(), themeDisplay); if (Validator.isNull(threadURL)) { continue; } InternetAddress to = new InternetAddress(recipient.getEmailAddress()); Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime(FastDateFormatConstants.LONG, FastDateFormatConstants.SHORT, recipient.getLocale(), recipient.getTimeZone()); String userThreadBody = StringUtil.replace(body, new String[] { "[$SENT_DATE$]", "[$THREAD_URL$]" }, new String[] { dateFormatDateTime.format(mbMessage.getCreateDate()), threadURL }); MailMessage mailMessage = new MailMessage(from, to, subject, userThreadBody, true); MailServiceUtil.sendEmail(mailMessage); } }
From source file:com.liferay.privatemessaging.service.impl.UserThreadLocalServiceImpl.java
License:Open Source License
protected void sendNotificationEvent(MBMessage mbMessage) throws PortalException { JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); notificationEventJSONObject.put("classPK", mbMessage.getMessageId()); notificationEventJSONObject.put("userId", mbMessage.getUserId()); List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbMessage.getThreadId()); for (UserThread userThread : userThreads) { if ((userThread.getUserId() == mbMessage.getUserId()) || ((userThread.getUserId() != mbMessage.getUserId()) && !UserNotificationManagerUtil.isDeliver(userThread.getUserId(), PortletKeys.PRIVATE_MESSAGING, 0, PrivateMessagingConstants.NEW_MESSAGE, UserNotificationDeliveryConstants.TYPE_WEBSITE))) { continue; }//from www .java 2 s . com UserNotificationEventLocalServiceUtil.sendUserNotificationEvents(userThread.getUserId(), PortletKeys.PRIVATE_MESSAGING, UserNotificationDeliveryConstants.TYPE_WEBSITE, notificationEventJSONObject); } }
From source file:com.liferay.tasks.service.impl.TasksEntryLocalServiceImpl.java
License:Open Source License
protected void sendNotificationEvent(TasksEntry tasksEntry, int oldStatus, long oldAssigneeUserId, ServiceContext serviceContext) throws PortalException { HashSet<Long> receiverUserIds = new HashSet<Long>(3); receiverUserIds.add(oldAssigneeUserId); receiverUserIds.add(tasksEntry.getUserId()); receiverUserIds.add(tasksEntry.getAssigneeUserId()); receiverUserIds.remove(serviceContext.getUserId()); JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); notificationEventJSONObject.put("classPK", tasksEntry.getTasksEntryId()); notificationEventJSONObject.put("userId", serviceContext.getUserId()); for (long receiverUserId : receiverUserIds) { if ((receiverUserId == 0) || !UserNotificationManagerUtil.isDeliver(receiverUserId, PortletKeys.TASKS, 0, TasksEntryConstants.STATUS_ALL, UserNotificationDeliveryConstants.TYPE_WEBSITE)) { continue; }/*w ww . j av a2 s .co m*/ String title = StringPool.BLANK; if (oldStatus == TasksEntryConstants.STATUS_ALL) { title = "x-assigned-you-a-task"; } else if (tasksEntry.getAssigneeUserId() != oldAssigneeUserId) { if (receiverUserId == oldAssigneeUserId) { title = "x-reassigned-your-task"; } else { title = "x-assigned-you-a-task"; } } else if (tasksEntry.getStatus() != oldStatus) { if ((tasksEntry.getStatus() != TasksEntryConstants.STATUS_OPEN) && (tasksEntry.getStatus() != TasksEntryConstants.STATUS_REOPENED) && (tasksEntry.getStatus() != TasksEntryConstants.STATUS_RESOLVED)) { return; } String statusLabel = TasksEntryConstants.getStatusLabel(tasksEntry.getStatus()); title = "x-" + statusLabel + "-the-task"; } else { title = "x-modified-the-task"; } notificationEventJSONObject.put("title", title); UserNotificationEventLocalServiceUtil.sendUserNotificationEvents(receiverUserId, PortletKeys.TASKS, UserNotificationDeliveryConstants.TYPE_WEBSITE, notificationEventJSONObject); } }