Search in sources :

Example 1 with NotificationEvent

use of com.liferay.portal.kernel.notifications.NotificationEvent in project liferay-ide by liferay.

the class TasksEntryLocalServiceImpl method sendNotificationEvent.

protected void sendNotificationEvent(TasksEntry tasksEntry, int oldStatus, long oldAssigneeUserId, ServiceContext serviceContext) throws PortalException, SystemException {
    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;
        }
        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);
        NotificationEvent notificationEvent = NotificationEventFactoryUtil.createNotificationEvent(System.currentTimeMillis(), PortletKeys.TASKS, notificationEventJSONObject);
        notificationEvent.setDeliveryRequired(0);
        UserNotificationEventLocalServiceUtil.addUserNotificationEvent(receiverUserId, notificationEvent);
    }
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) NotificationEvent(com.liferay.portal.kernel.notifications.NotificationEvent) HashSet(java.util.HashSet)

Aggregations

JSONObject (com.liferay.portal.kernel.json.JSONObject)1 NotificationEvent (com.liferay.portal.kernel.notifications.NotificationEvent)1 HashSet (java.util.HashSet)1