List of usage examples for com.liferay.portal.kernel.notifications ChannelHubManagerUtil sendNotificationEvent
public static void sendNotificationEvent(long companyId, long userId, NotificationEvent notificationEvent) throws ChannelException
From source file:com.liferay.so.hook.service.impl.AnnouncementsEntryServiceImpl.java
License:Open Source License
protected void sendNotificationEvent(AnnouncementsEntry announcementEntry) throws PortalException, SystemException { JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); notificationEventJSONObject.put("body", announcementEntry.getTitle()); notificationEventJSONObject.put("entryId", announcementEntry.getEntryId()); notificationEventJSONObject.put("groupId", announcementEntry.getClassPK()); notificationEventJSONObject.put("portletId", PortletKeys.ANNOUNCEMENTS); notificationEventJSONObject.put("title", "x-sent-a-new-announcement"); notificationEventJSONObject.put("userId", announcementEntry.getUserId()); NotificationEvent notificationEvent = NotificationEventFactoryUtil.createNotificationEvent( System.currentTimeMillis(), "6_WAR_soportlet", notificationEventJSONObject); notificationEvent.setDeliveryRequired(0); List<User> users = Collections.emptyList(); if (announcementEntry.getClassNameId() == 0) { users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS); } else {/*from w w w . j a va2 s . co m*/ String className = PortalUtil.getClassName(announcementEntry.getClassNameId()); if (className.equals(Group.class.getName())) { users = UserLocalServiceUtil.getGroupUsers(announcementEntry.getClassPK()); } else if (className.equals(Organization.class.getName())) { users = UserLocalServiceUtil.getOrganizationUsers(announcementEntry.getClassPK()); } else if (className.equals(Role.class.getName())) { users = UserLocalServiceUtil.getRoleUsers(announcementEntry.getClassPK()); } else if (className.equals(UserGroup.class.getName())) { users = UserLocalServiceUtil.getUserGroupUsers(announcementEntry.getClassPK()); } } for (User user : users) { ChannelHubManagerUtil.sendNotificationEvent(user.getCompanyId(), user.getUserId(), notificationEvent); } }
From source file:org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior.java
License:Apache License
protected void sendPortalNotification(TaskEntity task, List<Long> receiverUserIds, Map<String, Object> workflowContext, boolean isGroup) throws ChannelException { String currentUserId = Authentication.getAuthenticatedUserId(); JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject(); long companyId = Long.valueOf((String) workflowContext.get("companyId")); notificationEventJSONObject.put("body", task.getName()); notificationEventJSONObject.put("groupId", (String) workflowContext.get("groupId")); notificationEventJSONObject.put("entryClassName", (String) workflowContext.get("entryClassName")); notificationEventJSONObject.put("entryId", (String) workflowContext.get("entryClassPK")); // workflow tasks portlet id notificationEventJSONObject.put("portletId", WORKFLOW_TASKS_PORTLET_ID); notificationEventJSONObject.put("userId", currentUserId); notificationEventJSONObject.put("taskId", task.getId()); notificationEventJSONObject.put("taskName", task.getName()); notificationEventJSONObject.put("isGroup", isGroup); String title = StringPool.BLANK; if (isGroup) { title = "New workflow task \"" + task.getName() + "\" has been assigned to your role"; } else {/*w ww . j a va 2 s . c o m*/ title = "New workflow task \"" + task.getName() + "\" has been assigned to you"; } // FIXME localize notifications for (Long receiverUserId : receiverUserIds) { if (receiverUserId.toString().equals(currentUserId)) { // do not send notification in case action was performed by same user _log.debug( "User " + receiverUserId + " skipped from sending notification since it is current user"); continue; } _log.debug("Before sending notification receiverUserId = " + receiverUserId); notificationEventJSONObject.put("title", title); NotificationEvent notificationEvent = NotificationEventFactoryUtil.createNotificationEvent( System.currentTimeMillis(), SO_PORTLET_ID, notificationEventJSONObject); notificationEvent.setDeliveryRequired(0); ChannelHubManagerUtil.sendNotificationEvent(companyId, receiverUserId, notificationEvent); _log.debug("Notification for receiverUserId = " + receiverUserId + " sent"); } }