Exemple #1
0
  @Override
  public void deleteEntry(AnnouncementsEntry entry) throws PortalException {

    // Entry

    announcementsEntryPersistence.remove(entry);

    // Resources

    resourceLocalService.deleteResource(
        entry.getCompanyId(),
        AnnouncementsEntry.class.getName(),
        ResourceConstants.SCOPE_INDIVIDUAL,
        entry.getEntryId());

    // Flags

    announcementsFlagLocalService.deleteFlags(entry.getEntryId());
  }
Exemple #2
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();
  }
Exemple #3
0
  @Override
  public AnnouncementsEntry addEntry(
      long userId,
      long classNameId,
      long classPK,
      String title,
      String content,
      String url,
      String type,
      int displayDateMonth,
      int displayDateDay,
      int displayDateYear,
      int displayDateHour,
      int displayDateMinute,
      boolean displayImmediately,
      int expirationDateMonth,
      int expirationDateDay,
      int expirationDateYear,
      int expirationDateHour,
      int expirationDateMinute,
      int priority,
      boolean alert)
      throws PortalException {

    // Entry

    User user = userPersistence.findByPrimaryKey(userId);

    Date displayDate = new Date();

    if (!displayImmediately) {
      displayDate =
          PortalUtil.getDate(
              displayDateMonth,
              displayDateDay,
              displayDateYear,
              displayDateHour,
              displayDateMinute,
              user.getTimeZone(),
              EntryDisplayDateException.class);
    }

    Date expirationDate =
        PortalUtil.getDate(
            expirationDateMonth,
            expirationDateDay,
            expirationDateYear,
            expirationDateHour,
            expirationDateMinute,
            user.getTimeZone(),
            EntryExpirationDateException.class);

    validate(title, content, url);

    long entryId = counterLocalService.increment();

    AnnouncementsEntry entry = announcementsEntryPersistence.create(entryId);

    entry.setCompanyId(user.getCompanyId());
    entry.setUserId(user.getUserId());
    entry.setUserName(user.getFullName());
    entry.setClassNameId(classNameId);
    entry.setClassPK(classPK);
    entry.setTitle(title);
    entry.setContent(content);
    entry.setUrl(url);
    entry.setType(type);
    entry.setDisplayDate(displayDate);
    entry.setExpirationDate(expirationDate);
    entry.setPriority(priority);
    entry.setAlert(alert);

    announcementsEntryPersistence.update(entry);

    // Resources

    resourceLocalService.addResources(
        user.getCompanyId(),
        0,
        user.getUserId(),
        AnnouncementsEntry.class.getName(),
        entry.getEntryId(),
        false,
        false,
        false);

    return entry;
  }
Exemple #4
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);
      }
    }
  }
Exemple #5
0
  @Override
  public AnnouncementsEntry updateEntry(
      long userId,
      long entryId,
      String title,
      String content,
      String url,
      String type,
      int displayDateMonth,
      int displayDateDay,
      int displayDateYear,
      int displayDateHour,
      int displayDateMinute,
      boolean displayImmediately,
      int expirationDateMonth,
      int expirationDateDay,
      int expirationDateYear,
      int expirationDateHour,
      int expirationDateMinute,
      int priority)
      throws PortalException {

    // Entry

    User user = userPersistence.findByPrimaryKey(userId);

    Date displayDate = new Date();

    if (!displayImmediately) {
      displayDate =
          PortalUtil.getDate(
              displayDateMonth,
              displayDateDay,
              displayDateYear,
              displayDateHour,
              displayDateMinute,
              user.getTimeZone(),
              EntryDisplayDateException.class);
    }

    Date expirationDate =
        PortalUtil.getDate(
            expirationDateMonth,
            expirationDateDay,
            expirationDateYear,
            expirationDateHour,
            expirationDateMinute,
            user.getTimeZone(),
            EntryExpirationDateException.class);

    validate(title, content, url);

    AnnouncementsEntry entry = announcementsEntryPersistence.findByPrimaryKey(entryId);

    entry.setTitle(title);
    entry.setContent(content);
    entry.setUrl(url);
    entry.setType(type);
    entry.setDisplayDate(displayDate);
    entry.setExpirationDate(expirationDate);
    entry.setPriority(priority);

    announcementsEntryPersistence.update(entry);

    // Flags

    announcementsFlagLocalService.deleteFlags(entry.getEntryId());

    return entry;
  }