protected boolean sendAgeingNotification(
      UserDTO user, UserStatusDTO oldStatus, UserStatusDTO newStatus) {
    try {
      MessageDTO message =
          new NotificationBL()
              .getAgeingMessage(
                  user.getEntity().getId(),
                  user.getLanguage().getId(),
                  newStatus.getId(),
                  user.getId());

      INotificationSessionBean notification =
          (INotificationSessionBean) Context.getBean(Context.Name.NOTIFICATION_SESSION);
      notification.notify(user, message);

    } catch (NotificationNotFoundException e) {
      LOG.warn(
          "Failed to send ageing notification. Entity "
              + user.getEntity().getId()
              + " does not have an ageing message configured for status '"
              + getStatusDescription(newStatus)
              + "'.");
      return false;
    }
    return true;
  }
Example #2
0
  public void sendReminders(Date today) throws SQLException, SessionInternalError {
    GregorianCalendar cal = new GregorianCalendar();

    for (Iterator it = new CompanyDAS().findEntities().iterator(); it.hasNext(); ) {
      CompanyDTO thisEntity = (CompanyDTO) it.next();
      Integer entityId = thisEntity.getId();
      PreferenceBL pref = new PreferenceBL();
      try {
        pref.set(entityId, Constants.PREFERENCE_USE_INVOICE_REMINDERS);
      } catch (EmptyResultDataAccessException e1) {
        // let it use the defaults
      }
      if (pref.getInt() == 1) {
        prepareStatement(InvoiceSQL.toRemind);

        cachedResults.setDate(1, new java.sql.Date(today.getTime()));
        cal.setTime(today);
        pref.set(entityId, Constants.PREFERENCE_FIRST_REMINDER);
        cal.add(GregorianCalendar.DAY_OF_MONTH, -pref.getInt());
        cachedResults.setDate(2, new java.sql.Date(cal.getTimeInMillis()));
        cal.setTime(today);
        pref.set(entityId, Constants.PREFERENCE_NEXT_REMINDER);
        cal.add(GregorianCalendar.DAY_OF_MONTH, -pref.getInt());
        cachedResults.setDate(3, new java.sql.Date(cal.getTimeInMillis()));

        cachedResults.setInt(4, entityId.intValue());

        execute();
        while (cachedResults.next()) {
          int invoiceId = cachedResults.getInt(1);
          set(Integer.valueOf(invoiceId));
          NotificationBL notif = new NotificationBL();
          long mils = invoice.getDueDate().getTime() - today.getTime();
          int days = Math.round(mils / 1000 / 60 / 60 / 24);

          try {
            MessageDTO message =
                notif.getInvoiceReminderMessage(
                    entityId,
                    invoice.getBaseUser().getUserId(),
                    Integer.valueOf(days),
                    invoice.getDueDate(),
                    invoice.getPublicNumber(),
                    invoice.getTotal(),
                    invoice.getCreateDatetime(),
                    invoice.getCurrency().getId());

            INotificationSessionBean notificationSess =
                (INotificationSessionBean) Context.getBean(Context.Name.NOTIFICATION_SESSION);

            notificationSess.notify(invoice.getBaseUser(), message);

            invoice.setLastReminder(today);
          } catch (NotificationNotFoundException e) {
            LOG.warn(
                "There are invoice to send reminders, but "
                    + "the notification message is missing for "
                    + "entity "
                    + entityId);
          }
        }
      }
    }

    if (conn != null) { // only if somthing run
      conn.close();
    }
  }