List of usage examples for com.liferay.portal.kernel.notifications NotificationEvent setDeliveryRequired
public void setDeliveryRequired(long deliverBy) throws IllegalArgumentException
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"); }/* www . j av a2s. co 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.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);//w w w .j a v a2 s . c o m } }
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 ww.ja va 2s . c o 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 {//from w ww . j a va2 s . c om 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"); } }