Beispiel #1
0
  protected void notifyUsers(
      List<User> users, AnnouncementsEntry entry, Locale locale, String toAddress, String toName)
      throws PortalException {

    if (_log.isDebugEnabled()) {
      _log.debug("Notifying " + users.size() + " users");
    }

    boolean notifyUsers = false;

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    for (User user : users) {
      AnnouncementsDelivery announcementsDelivery =
          announcementsDeliveryLocalService.getUserDelivery(user.getUserId(), entry.getType());

      if (announcementsDelivery.isEmail()) {
        subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());

        notifyUsers = true;
      }

      if (announcementsDelivery.isSms()) {
        String smsSn = user.getContact().getSmsSn();

        subscriptionSender.addRuntimeSubscribers(smsSn, user.getFullName());

        notifyUsers = true;
      }
    }

    if (!notifyUsers) {
      return;
    }

    String body = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_BODY);
    String fromAddress =
        PrefsPropsUtil.getStringFromNames(
            entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_ADDRESS,
            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
    String fromName =
        PrefsPropsUtil.getStringFromNames(
            entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_NAME,
            PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String subject = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_SUBJECT);

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttribute("[$ENTRY_CONTENT$]", entry.getContent(), false);
    subscriptionSender.setContextAttributes(
        "[$ENTRY_ID$]",
        entry.getEntryId(),
        "[$ENTRY_TITLE$]",
        entry.getTitle(),
        "[$ENTRY_TYPE$]",
        LanguageUtil.get(locale, entry.getType()),
        "[$ENTRY_URL$]",
        entry.getUrl(),
        "[$PORTLET_NAME$]",
        LanguageUtil.get(locale, (entry.isAlert() ? "alert" : "announcement")));
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("announcements_entry", entry.getEntryId());
    subscriptionSender.setPortletId(PortletKeys.ANNOUNCEMENTS);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setSubject(subject);

    subscriptionSender.addRuntimeSubscribers(toAddress, toName);

    subscriptionSender.flushNotificationsAsync();
  }
Beispiel #2
0
  protected void notifyUsers(AnnouncementsEntry entry) throws PortalException {

    Company company = companyPersistence.findByPrimaryKey(entry.getCompanyId());

    String className = entry.getClassName();
    long classPK = entry.getClassPK();

    String toName = PropsValues.ANNOUNCEMENTS_EMAIL_TO_NAME;
    String toAddress = PropsValues.ANNOUNCEMENTS_EMAIL_TO_ADDRESS;

    long teamId = 0;

    LinkedHashMap<String, Object> params = new LinkedHashMap<>();

    params.put("announcementsDeliveryEmailOrSms", entry.getType());

    if (classPK > 0) {
      if (className.equals(Group.class.getName())) {
        Group group = groupPersistence.findByPrimaryKey(classPK);

        toName = group.getDescriptiveName();

        params.put("inherit", Boolean.TRUE);
        params.put("usersGroups", classPK);
      } else if (className.equals(Organization.class.getName())) {
        Organization organization = organizationPersistence.findByPrimaryKey(classPK);

        toName = organization.getName();

        params.put("usersOrgsTree", ListUtil.fromArray(new Organization[] {organization}));
      } else if (className.equals(Role.class.getName())) {
        Role role = rolePersistence.findByPrimaryKey(classPK);

        toName = role.getName();

        if (role.getType() == RoleConstants.TYPE_REGULAR) {
          params.put("inherit", Boolean.TRUE);
          params.put("usersRoles", classPK);
        } else if (role.isTeam()) {
          teamId = role.getClassPK();
        } else {
          params.put("userGroupRole", new Long[] {Long.valueOf(0), classPK});
        }
      } else if (className.equals(UserGroup.class.getName())) {
        UserGroup userGroup = userGroupPersistence.findByPrimaryKey(classPK);

        toName = userGroup.getName();

        params.put("usersUserGroups", classPK);
      }
    }

    if (className.equals(User.class.getName())) {
      User user = userPersistence.findByPrimaryKey(classPK);

      if (Validator.isNull(user.getEmailAddress())) {
        return;
      }

      notifyUsers(
          ListUtil.fromArray(new User[] {user}),
          entry,
          company.getLocale(),
          user.getEmailAddress(),
          user.getFullName());
    } else {
      int count = 0;

      if (teamId > 0) {
        count = userLocalService.getTeamUsersCount(teamId);
      } else {
        count =
            userLocalService.searchCount(
                company.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED, params);
      }

      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;

        List<User> users = null;

        if (teamId > 0) {
          users = userLocalService.getTeamUsers(teamId, start, end);
        } else {
          users =
              userLocalService.search(
                  company.getCompanyId(),
                  null,
                  WorkflowConstants.STATUS_APPROVED,
                  params,
                  start,
                  end,
                  (OrderByComparator<User>) null);
        }

        notifyUsers(users, entry, company.getLocale(), toAddress, toName);
      }
    }
  }