Example usage for com.liferay.portal.kernel.notifications NotificationEventFactoryUtil createNotificationEvent

List of usage examples for com.liferay.portal.kernel.notifications NotificationEventFactoryUtil createNotificationEvent

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.notifications NotificationEventFactoryUtil createNotificationEvent.

Prototype

public static NotificationEvent createNotificationEvent(long timestamp, String type,
            JSONObject payloadJSONObject) 

Source Link

Usage

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 w  w  w  .ja v  a  2 s  .  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);/*from  w  w  w. j av  a  2 s  . c  om*/
    }
}

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 {/*  w  ww.  j  a va2 s  .  c  om*/
        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 .ja  va2s. 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");
    }
}

From source file:se.vgregion.hook.MBMessageListener.java

License:Open Source License

@Override
public void onAfterUpdate(MBMessage message) throws ModelListenerException {

    try {//from w w  w  .j a  v  a2 s  .c  o m

        // Only for new messages that are discussions
        if (!message.isDiscussion() || !message.isReply()) {
            return;
        }

        long companyId = message.getCompanyId();
        long groupId = message.getGroupId();
        long classPK = message.getClassPK();
        String className = message.getClassName();

        boolean createDiscussionNotification = ExpandoValueLocalServiceUtil.getData(companyId,
                Group.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME,
                EXP_COL_NAME_CREATE_DISCUSSION_NOTIFICATION, groupId, false);

        // Only continue if group (site) has been setup to create notifications for discussions
        if (!createDiscussionNotification) {
            return;
        }

        if (className.equals(JournalArticle.class.getName())) {
            System.out.println("Article comment");

            JournalArticle article = JournalArticleLocalServiceUtil.fetchLatestIndexableArticle(classPK);

            String articleLayoutUuid = article.getLayoutUuid();

            // Only continue if there is a display page
            if (articleLayoutUuid.equals("")) {
                return;
            }

            Group group = GroupLocalServiceUtil.getGroup(groupId);

            Company company = CompanyLocalServiceUtil.getCompany(companyId);

            JSONObject json = JSONFactoryUtil.createJSONObject();

            String notificationTitle = message.getUserName() + " postade en kommentar p artikeln "
                    + article.getTitle(DEFAULT_LOCALE_STRING);

            String siteURL = "";

            LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, false);
            String virtualHostName = layoutSet.getVirtualHostname();

            if (virtualHostName.equals("")) {
                siteURL = "/web" + group.getFriendlyURL();
            }

            String articleURL = siteURL + JournalArticleConstants.CANONICAL_URL_SEPARATOR
                    + article.getUrlTitle();

            json.put("title", notificationTitle);
            json.put("userId", article.getUserId());
            json.put("url", articleURL);

            NotificationEvent event = NotificationEventFactoryUtil
                    .createNotificationEvent(System.currentTimeMillis(), PortletKeys.MESSAGE_BOARDS, json);

            UserNotificationEventLocalServiceUtil.addUserNotificationEvent(article.getUserId(), event);
        }

    } catch (Exception e) {
        throw new ModelListenerException(e);
    }

}