コード例 #1
0
  public static boolean contains(
      PermissionChecker permissionChecker, MicroblogsEntry microblogsEntry, String actionId) {

    if (actionId.equals(ActionKeys.DELETE) || actionId.equals(ActionKeys.UPDATE)) {

      if (permissionChecker.hasOwnerPermission(
          microblogsEntry.getCompanyId(),
          MicroblogsEntry.class.getName(),
          microblogsEntry.getMicroblogsEntryId(),
          microblogsEntry.getUserId(),
          actionId)) {

        return true;
      }

      return false;
    }

    if (permissionChecker.hasOwnerPermission(
        microblogsEntry.getCompanyId(),
        MicroblogsEntry.class.getName(),
        microblogsEntry.getMicroblogsEntryId(),
        microblogsEntry.getUserId(),
        actionId)) {

      return true;
    }

    if (microblogsEntry.getSocialRelationType() == 0) {
      return true;
    }

    if ((microblogsEntry.getUserId() != permissionChecker.getUserId())
        && SocialRelationLocalServiceUtil.hasRelation(
            permissionChecker.getUserId(),
            microblogsEntry.getUserId(),
            microblogsEntry.getSocialRelationType())) {

      return true;
    }

    return false;
  }
コード例 #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
  public void updateAsset(
      MicroblogsEntry microblogsEntry, long[] assetCategoryIds, String[] assetTagNames)
      throws PortalException, SystemException {

    Group group = GroupLocalServiceUtil.getCompanyGroup(microblogsEntry.getCompanyId());

    AssetEntryLocalServiceUtil.updateEntry(
        microblogsEntry.getUserId(),
        group.getGroupId(),
        MicroblogsEntry.class.getName(),
        microblogsEntry.getMicroblogsEntryId(),
        assetCategoryIds,
        assetTagNames);
  }
コード例 #4
0
  protected void sendNotificationEvent(MicroblogsEntry microblogsEntry)
      throws PortalException, SystemException {

    JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject();

    notificationEventJSONObject.put("body", microblogsEntry.getContent());
    notificationEventJSONObject.put("entryId", microblogsEntry.getMicroblogsEntryId());
    notificationEventJSONObject.put("entryKeyName", "receiverMicroblogsEntryId");
    notificationEventJSONObject.put("mvcPath", "/microblogs/view.jsp");
    notificationEventJSONObject.put("portletId", "1_WAR_microblogsportlet");
    notificationEventJSONObject.put("title", "x-commented-on-your-post");
    notificationEventJSONObject.put("userId", microblogsEntry.getUserId());

    NotificationEvent notificationEvent =
        NotificationEventFactoryUtil.createNotificationEvent(
            System.currentTimeMillis(), "6_WAR_soportlet", notificationEventJSONObject);

    notificationEvent.setDeliveryRequired(0);

    ChannelHubManagerUtil.sendNotificationEvent(
        microblogsEntry.getCompanyId(), microblogsEntry.getReceiverUserId(), notificationEvent);
  }
コード例 #5
0
  @Override
  protected String getTitle(
      JSONObject jsonObject, AssetRenderer<?> assetRenderer, ServiceContext serviceContext) {

    MicroblogsEntry microblogsEntry =
        _microblogsEntryLocalService.fetchMicroblogsEntry(assetRenderer.getClassPK());

    String title = StringPool.BLANK;

    String userFullName =
        HtmlUtil.escape(PortalUtil.getUserName(microblogsEntry.getUserId(), StringPool.BLANK));

    int notificationType = jsonObject.getInt("notificationType");

    if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY) {

      title = serviceContext.translate("x-commented-on-your-post", userFullName);
    } else if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_REPLIED) {

      long parentMicroblogsEntryUserId = microblogsEntry.fetchParentMicroblogsEntryUserId();

      User user = _userLocalService.fetchUser(parentMicroblogsEntryUserId);

      if (user != null) {
        title =
            serviceContext.translate(
                "x-also-commented-on-x's-post", userFullName, user.getFullName());
      }
    } else if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_TAGGED) {

      title = serviceContext.translate("x-commented-on-a-post-you-are-tagged-in", userFullName);
    } else if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_TAG) {

      title = serviceContext.translate("x-tagged-you-in-a-post", userFullName);
    }

    return title;
  }
コード例 #6
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);
    }
  }