Example usage for com.liferay.portal.kernel.poller PollerResponse setParameter

List of usage examples for com.liferay.portal.kernel.poller PollerResponse setParameter

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.poller PollerResponse setParameter.

Prototype

public void setParameter(String name, String value) throws PollerResponseClosedException;

Source Link

Usage

From source file:blade.portlet.BladePollProcessor.java

License:Open Source License

@Override
protected PollerResponse doReceive(PollerRequest pollerRequest) throws Exception {
    _log.debug("Recevied the poller request" + pollerRequest);
    JSONObject responseJSON = JSONFactoryUtil.createJSONObject();
    PollerResponse pollerResponse = new DefaultPollerResponse();
    responseJSON.put("message", "Hello from BLADE Poller, time now is:" + new Date());
    pollerResponse.setParameter("content", responseJSON);
    return pollerResponse;
}

From source file:com.liferay.blade.samples.pollprocessor.BladePollProcessor.java

License:Open Source License

@Override
protected PollerResponse doReceive(PollerRequest pollerRequest) throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("Recevied the poller request" + pollerRequest);
    }//from   ww w.j  a v  a2  s  . c  om

    JSONObject responseJSON = JSONFactoryUtil.createJSONObject();
    PollerResponse pollerResponse = new DefaultPollerResponse();
    responseJSON.put("message", "Hello from BLADE Poller, time now is:" + new Date());
    pollerResponse.setParameter("content", responseJSON);

    return pollerResponse;
}

From source file:com.liferay.chat.poller.ChatPollerProcessor.java

License:Open Source License

protected void getBuddies(PollerRequest pollerRequest, PollerResponse pollerResponse) throws Exception {

    List<Object[]> buddies = BuddyFinderUtil.getBuddies(pollerRequest.getCompanyId(),
            pollerRequest.getUserId());//from   w  w  w.  j  a  v  a  2 s  . co  m

    JSONArray buddiesJSONArray = JSONFactoryUtil.createJSONArray();

    for (Object[] buddy : buddies) {
        boolean awake = (Boolean) buddy[0];
        String firstName = (String) buddy[1];
        long groupId = (Long) buddy[2];
        String lastName = (String) buddy[3];
        boolean male = (Boolean) buddy[4];
        String middleName = (String) buddy[5];
        long portraitId = (Long) buddy[6];
        String screenName = (String) buddy[7];
        long userId = (Long) buddy[8];
        String userUuid = (String) buddy[9];

        JSONObject curUserJSONObject = JSONFactoryUtil.createJSONObject();

        Status buddyStatus = StatusLocalServiceUtil.getUserStatus(userId);

        awake = buddyStatus.getAwake();

        curUserJSONObject.put("awake", awake);

        String fullName = ContactConstants.getFullName(firstName, middleName, lastName);

        curUserJSONObject.put("fullName", fullName);
        curUserJSONObject.put("groupId", groupId);
        curUserJSONObject.put("portraitId", portraitId);

        String portraitURL = UserConstants.getPortraitURL(StringPool.BLANK, male, portraitId, userUuid);

        curUserJSONObject.put("portraitURL", portraitURL);

        curUserJSONObject.put("screenName", screenName);

        String statusMessage = buddyStatus.getMessage();

        curUserJSONObject.put("statusMessage", statusMessage);
        curUserJSONObject.put("userId", userId);

        buddiesJSONArray.put(curUserJSONObject);
    }

    pollerResponse.setParameter("buddies", buddiesJSONArray);
}

From source file:com.liferay.chat.poller.ChatPollerProcessor.java

License:Open Source License

protected void getEntries(PollerRequest pollerRequest, PollerResponse pollerResponse) throws Exception {

    Status status = StatusLocalServiceUtil.getUserStatus(pollerRequest.getUserId());

    long createDate = 0;

    if (pollerRequest.isInitialRequest()) {
        createDate = status.getModifiedDate() - Time.DAY;
    }/*from   ww  w  .ja  v a  2  s .c o  m*/

    List<Entry> entries = EntryLocalServiceUtil.getNewEntries(pollerRequest.getUserId(), createDate, 0,
            PortletPropsValues.BUDDY_LIST_MAX_BUDDIES);

    entries = ListUtil.copy(entries);

    Collections.reverse(entries);

    JSONArray entriesJSONArray = JSONFactoryUtil.createJSONArray();

    for (Entry entry : entries) {
        JSONObject entryJSONObject = JSONFactoryUtil.createJSONObject();

        entryJSONObject.put("entryId", entry.getEntryId());
        entryJSONObject.put("createDate", entry.getCreateDate());
        entryJSONObject.put("fromUserId", entry.getFromUserId());

        if (entry.getFromUserId() != pollerRequest.getUserId()) {
            try {
                User fromUser = UserLocalServiceUtil.getUserById(entry.getFromUserId());

                entryJSONObject.put("fromFullName", fromUser.getFullName());
                entryJSONObject.put("fromPortraitId", fromUser.getPortraitId());
            } catch (NoSuchUserException nsue) {
                continue;
            }
        }

        entryJSONObject.put("toUserId", entry.getToUserId());
        entryJSONObject.put("content", HtmlUtil.escape(entry.getContent()));
        entryJSONObject.put("flag", entry.getFlag());

        entriesJSONArray.put(entryJSONObject);
    }

    pollerResponse.setParameter("entries", entriesJSONArray);

    if (!entries.isEmpty()) {
        pollerResponse.setParameter(PollerResponse.POLLER_HINT_HIGH_CONNECTIVITY, Boolean.TRUE.toString());
    }

    boolean updatePresence = getBoolean(pollerRequest, "updatePresence");

    if (updatePresence) {
    } else if (!entries.isEmpty()) {
        updatePresence = true;
    } else {
        long onlineTimestamp = status.getModifiedDate() + ChatConstants.ONLINE_DELTA
                - ChatConstants.MAX_POLL_LATENCY;

        if (onlineTimestamp < pollerRequest.getTimestamp()) {
            updatePresence = true;
        }
    }

    if (updatePresence) {
        StatusLocalServiceUtil.updateStatus(pollerRequest.getUserId(), pollerRequest.getTimestamp());
    }
}

From source file:com.liferay.chat.video.poller.ChatVideoPollerProcessor.java

License:Open Source License

@Override
protected PollerResponse doReceive(PollerRequest pollerRequest) throws Exception {

    PollerResponse pollerResponse = pollerRequest.createPollerResponse();

    JSONObject webRTCResponseJSONObject = JSONFactoryUtil.createJSONObject();

    JSONArray webRTCClientsJSONArray = JSONFactoryUtil.createJSONArray();

    for (Long userId : _webRTCManager.getAvailableWebRTCClientIds()) {
        if (userId != pollerRequest.getUserId()) {
            webRTCClientsJSONArray.put(userId);
        }/*from   w ww.ja v a2s.com*/
    }

    webRTCResponseJSONObject.put("clients", webRTCClientsJSONArray);

    WebRTCClient webRTCClient = _webRTCManager.getWebRTCClient(pollerRequest.getUserId());

    JSONArray webRTCMailsJSONArray = JSONFactoryUtil.createJSONArray();

    if (webRTCClient != null) {
        WebRTCMailbox webRTCMailbox = webRTCClient.getOutgoingWebRTCMailbox();

        List<WebRTCMail> webRTCMails = webRTCMailbox.popWebRTCMails();

        for (WebRTCMail webRTCMail : webRTCMails) {
            JSONObject mailJSONObject = JSONFactoryUtil.createJSONObject();

            mailJSONObject.put("message", webRTCMail.getMessageJSONObject());
            mailJSONObject.put("sourceUserId", webRTCMail.getSourceUserId());
            mailJSONObject.put("type", webRTCMail.getMessageType());

            webRTCMailsJSONArray.put(mailJSONObject);
        }
    }

    webRTCResponseJSONObject.put("mails", webRTCMailsJSONArray);

    pollerResponse.setParameter("webRTCResponse", webRTCResponseJSONObject);

    return pollerResponse;
}

From source file:com.liferay.notifications.dockbarnotifications.poller.DockbarNotificationsPollerProcessor.java

License:Open Source License

protected PollerResponse setUserNotificationsCount(PollerRequest pollerRequest) throws Exception {

    PollerResponse pollerResponse = pollerRequest.createPollerResponse();

    pollerResponse.setParameter("timestamp", String.valueOf(System.currentTimeMillis()));

    if (PortletPropsValues.USER_NOTIFICATION_DOCKBAR_SPLIT) {
        int newActionableUserNotificationsCount = UserNotificationEventLocalServiceUtil
                .getDeliveredUserNotificationEventsCount(pollerRequest.getUserId(),
                        UserNotificationDeliveryConstants.TYPE_WEBSITE, false, true);

        pollerResponse.setParameter("newActionableUserNotificationsCount",
                String.valueOf(newActionableUserNotificationsCount));

        int newNonactionableUserNotificationsCount = UserNotificationEventLocalServiceUtil
                .getDeliveredUserNotificationEventsCount(pollerRequest.getUserId(),
                        UserNotificationDeliveryConstants.TYPE_WEBSITE, false, false);

        pollerResponse.setParameter("newNonactionableUserNotificationsCount",
                String.valueOf(newNonactionableUserNotificationsCount));

        int unreadActionableUserNotificationsCount = UserNotificationEventLocalServiceUtil
                .getArchivedUserNotificationEventsCount(pollerRequest.getUserId(),
                        UserNotificationDeliveryConstants.TYPE_WEBSITE, true, false);

        pollerResponse.setParameter("unreadActionableUserNotificationsCount",
                String.valueOf(unreadActionableUserNotificationsCount));

        int unreadNonactionableUserNotificationsCount = UserNotificationEventLocalServiceUtil
                .getArchivedUserNotificationEventsCount(pollerRequest.getUserId(),
                        UserNotificationDeliveryConstants.TYPE_WEBSITE, false, false);

        pollerResponse.setParameter("unreadNonactionableUserNotificationsCount",
                String.valueOf(unreadNonactionableUserNotificationsCount));
    } else {/*from w w w .j a  v  a2 s .  co m*/
        int newUserNotificationsCount = UserNotificationEventLocalServiceUtil
                .getDeliveredUserNotificationEventsCount(pollerRequest.getUserId(),
                        UserNotificationDeliveryConstants.TYPE_WEBSITE, false);

        pollerResponse.setParameter("newUserNotificationsCount", String.valueOf(newUserNotificationsCount));

        int unreadUserNotificationsCount = UserNotificationEventLocalServiceUtil
                .getArchivedUserNotificationEventsCount(pollerRequest.getUserId(),
                        UserNotificationDeliveryConstants.TYPE_WEBSITE, false);

        pollerResponse.setParameter("unreadUserNotificationsCount",
                String.valueOf(unreadUserNotificationsCount));
    }

    return pollerResponse;
}

From source file:com.liferay.notifications.web.internal.poller.NotificationsPollerProcessor.java

License:Open Source License

protected PollerResponse setUserNotificationsCount(PollerRequest pollerRequest) throws Exception {

    PollerResponse pollerResponse = pollerRequest.createPollerResponse();

    pollerResponse.setParameter("timestamp", String.valueOf(System.currentTimeMillis()));

    int newUserNotificationsCount = _userNotificationEventLocalService.getDeliveredUserNotificationEventsCount(
            pollerRequest.getUserId(), UserNotificationDeliveryConstants.TYPE_WEBSITE, false);

    pollerResponse.setParameter("newUserNotificationsCount", String.valueOf(newUserNotificationsCount));

    int unreadUserNotificationsCount = _userNotificationEventLocalService
            .getArchivedUserNotificationEventsCount(pollerRequest.getUserId(),
                    UserNotificationDeliveryConstants.TYPE_WEBSITE, false);

    pollerResponse.setParameter("unreadUserNotificationsCount", String.valueOf(unreadUserNotificationsCount));

    return pollerResponse;
}

From source file:org.opencps.notification.dockbarnotifications.poller.DockbarNotificationsPollerProcessor.java

License:Open Source License

protected void setUserNotificationsCount(PollerRequest pollerRequest, PollerResponse pollerResponse)
        throws Exception {

    pollerResponse.setParameter("timestamp", String.valueOf(System.currentTimeMillis()));

    int unreadUserNotificationsCount = UserNotificationEventLocalServiceUtil
            .getArchivedUserNotificationEventsCount(pollerRequest.getUserId(), false);

    pollerResponse.setParameter("unreadUserNotificationsCount", String.valueOf(unreadUserNotificationsCount));
}