public void createNotificationSchedulersForUser(UserBean userBean) { for (int i = 0; i < m_oAllUserNotificationUnit.size(); i++) { UserNotificationUnit notficationUnit = m_oAllUserNotificationUnit.get(i); EmailBean notificatonEmail = createEmailByTemplate(userBean, notficationUnit.getTemplate()); NotificationScheduler scheduler = null; if (notficationUnit.getTemplate().getTemplateType() == WebConstants.FREE_TRIAL_EXPIRED_TEMPLATE) { scheduler = new EmailNotificationSechedularOfFreeTrialEnd( userBean.getExpired_date() + notficationUnit.getTime(), notificatonEmail, EmailHandler.getInstance()); } else { scheduler = new EmailNotificationScheduler( userBean.getExpired_date() + notficationUnit.getTime(), notificatonEmail, EmailHandler.getInstance()); } addNotificationSchedulear(userBean.getId(), scheduler); // store into DB SchedulerNotificationsBean notification = new SchedulerNotificationsBean(); notification.setId(0); notification.setTemplate_type(notficationUnit.getTemplate().getTemplateType()); notification.setTime(userBean.getExpired_date() + notficationUnit.getTime()); notification.setUser_id(userBean.getId()); DBAccessor.getInstance().storeSchedulerNotification(notification); } }
/** load all scheduler notifications while init this Handler */ public void loadAllNotificationSchedulers() { List<SchedulerNotificationsBean> pendingNotifications = DBAccessor.getInstance().getAllSchedulerNotification(); LogTools.getInstance() .insertLog( DebugLevel.INFO, "Load all notification schedulers, size:" + pendingNotifications.size()); for (int i = 0; i < pendingNotifications.size(); i++) { SchedulerNotificationsBean notification = pendingNotifications.get(i); NotificationTemplate emailTemplate = EmailNotificationFactory.getNotificationTemplate(notification.getTemplate_type()); // get user info UserBean userBean = DBAccessor.getInstance().getUserInfoByID(notification.getUser_id()); if (null == userBean) { // this user is not exist DBAccessor.getInstance().removeAllExpiredSchedulersForUser(notification.getUser_id()); } else { EmailBean notificatonEmail = createEmailByTemplate(userBean, emailTemplate); NotificationScheduler scheduler = null; if (notification.getTemplate_type() == WebConstants.FREE_TRIAL_EXPIRED_TEMPLATE) { scheduler = new EmailNotificationSechedularOfFreeTrialEnd( notification.getTime(), notificatonEmail, EmailHandler.getInstance()); } else { scheduler = new EmailNotificationScheduler( notification.getTime(), notificatonEmail, EmailHandler.getInstance()); } addNotificationSchedulear(notification.getUser_id(), scheduler); } } }