コード例 #1
0
    protected void sendUserNotifications(
        List<Long> receiverUserIds,
        MicroblogsEntry microblogsEntry,
        JSONObject notificationEventJSONObject)
        throws PortalException {

      int count = receiverUserIds.size();

      int pages = count / Indexer.DEFAULT_INTERVAL;

      for (int i = 0; i <= pages; i++) {
        int start = (i * Indexer.DEFAULT_INTERVAL);
        int end = start + Indexer.DEFAULT_INTERVAL;

        if (count < end) {
          end = count;
        }

        for (int j = start; j < end; j++) {
          long subscriptionId = getSubscriptionId(receiverUserIds.get(j), microblogsEntry);

          notificationEventJSONObject.put("subscriptionId", subscriptionId);

          int notificationType =
              MicroblogsUtil.getNotificationType(
                  microblogsEntry,
                  receiverUserIds.get(j),
                  UserNotificationDeliveryConstants.TYPE_PUSH);

          if (notificationType != MicroblogsEntryConstants.NOTIFICATION_TYPE_UNKNOWN) {

            notificationEventJSONObject.put("notificationType", notificationType);

            userNotificationEventLocalService.sendUserNotificationEvents(
                receiverUserIds.get(j),
                MicroblogsPortletKeys.MICROBLOGS,
                UserNotificationDeliveryConstants.TYPE_PUSH,
                notificationEventJSONObject);
          }

          notificationType =
              MicroblogsUtil.getNotificationType(
                  microblogsEntry,
                  receiverUserIds.get(j),
                  UserNotificationDeliveryConstants.TYPE_WEBSITE);

          if (notificationType != MicroblogsEntryConstants.NOTIFICATION_TYPE_UNKNOWN) {

            notificationEventJSONObject.put("notificationType", notificationType);

            userNotificationEventLocalService.sendUserNotificationEvents(
                receiverUserIds.get(j),
                MicroblogsPortletKeys.MICROBLOGS,
                UserNotificationDeliveryConstants.TYPE_WEBSITE,
                notificationEventJSONObject);
          }
        }
      }
    }
コード例 #2
0
  protected void sendNotificationEvent(
      final MicroblogsEntry microblogsEntry, ServiceContext serviceContext) throws PortalException {

    final JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject();

    notificationEventJSONObject.put("className", MicroblogsEntry.class.getName());
    notificationEventJSONObject.put("classPK", microblogsEntry.getMicroblogsEntryId());
    notificationEventJSONObject.put(
        "entryTitle",
        MicroblogsUtil.getProcessedContent(
            StringUtil.shorten(microblogsEntry.getContent(), 50), serviceContext));

    AssetRendererFactory<MicroblogsEntry> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClass(MicroblogsEntry.class);

    AssetRenderer<MicroblogsEntry> assetRenderer =
        assetRendererFactory.getAssetRenderer(microblogsEntry.getMicroblogsEntryId());

    String entryURL = StringPool.BLANK;

    try {
      entryURL =
          assetRenderer.getURLViewInContext(
              serviceContext.getLiferayPortletRequest(),
              serviceContext.getLiferayPortletResponse(),
              null);
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug(e, e);
      }
    }

    notificationEventJSONObject.put("entryURL", entryURL);
    notificationEventJSONObject.put("userId", microblogsEntry.getUserId());

    final List<Long> receiverUserIds = MicroblogsUtil.getSubscriberUserIds(microblogsEntry);

    Callable<Void> callable =
        new Callable<Void>() {

          @Override
          public Void call() throws Exception {
            MessageBusUtil.sendMessage(
                DestinationNames.ASYNC_SERVICE,
                new NotificationProcessCallable(
                    receiverUserIds, microblogsEntry, notificationEventJSONObject));

            return null;
          }
        };

    TransactionCommitCallbackUtil.registerCallback(callable);
  }
コード例 #3
0
  protected void subscribeUsers(MicroblogsEntry microblogsEntry, ServiceContext serviceContext)
      throws PortalException {

    long rootMicroblogsEntryId = MicroblogsUtil.getRootMicroblogsEntryId(microblogsEntry);

    subscriptionLocalService.addSubscription(
        microblogsEntry.getUserId(),
        serviceContext.getScopeGroupId(),
        MicroblogsEntry.class.getName(),
        rootMicroblogsEntryId);

    List<String> screenNames = MicroblogsUtil.getScreenNames(microblogsEntry.getContent());

    for (String screenName : screenNames) {
      long userId =
          userLocalService.getUserIdByScreenName(serviceContext.getCompanyId(), screenName);

      subscriptionLocalService.addSubscription(
          userId,
          serviceContext.getScopeGroupId(),
          MicroblogsEntry.class.getName(),
          rootMicroblogsEntryId);
    }
  }