/**
   * This method is used to generate the contents of notification (alert/reminder)
   *
   * @param VsdAlertRule vsdAlertRule
   * @param Date startDate
   * @param Date endDate
   * @return Map<Long, Message>
   * @throws VSDException
   * @throws Exception
   */
  public Map<Long, Message> generateNotifications(
      VsdAlertRule vsdAlertRule, Date startDate, Date endDate) throws VSDException, Exception {
    log.info("START");
    Map<Long, Message> messages = null;
    try {
      if (vsdAlertRule != null && vsdAlertRule.getRuleValue() != null) {
        String testStatus = vsdAlertRule.getRuleValue();
        List<Long> violationStatuses = new ArrayList<Long>();
        log.info("Printing test status ... " + testStatus);
        if (testStatus.equalsIgnoreCase(Constant.TEST_STATUS_ENUM.PASS.toString())) {
          violationStatuses.add(Constant.VIOLATION_STATUS_CLOSED);
        } else {
          violationStatuses.add(Constant.VIOLATION_STATUS_OPEN);
          violationStatuses.add(Constant.VIOLATION_STATUS_OPEN_OVERDUE);
        }
        List<VsdViolation> list =
            SchedulerServiceImpl.getInstance()
                .getViolationsTestResultForNotifications(
                    startDate, endDate, violationStatuses, testStatus);
        log.info("Alerting violation count: " + list.size());

        messages = generateNotifications(vsdAlertRule, list, true);
      } else {
        throw new VSDException("SR.09");
      }
    } catch (VSDException ve) {
      log.error(ve.getMessage(), ve);
      throw ve;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw e;
    }
    log.info("END");
    return messages;
  }
 @Override
 public void run() {
   log.info("START");
   log.info("Executing ViolationTestResultAlertTask.run()...");
   try {
     Map<Long, Message> messages = new HashMap<Long, Message>();
     List<VsdAlertRule> list =
         SchedulerServiceImpl.getInstance()
             .getAlertRulesByAlertTypeCode(VIOLATION_TEST_RESULT, TASK_TEMPLATE_CODE);
     setTaskName(TASK_NAME);
     setRunMultipleTimesInADay(canRunMultipleTimesInADay);
     List<Date> dates = getTaskDates();
     log.info("Printing dates.size() ... " + dates.size());
     if (dates != null && dates.size() > 0) {
       Date startDate = dates.get(0);
       Date endDate = dates.get(dates.size() - 1);
       log.info("Printing date range: " + startDate + " --- " + endDate);
       setTaskStatus(IN_PROGRESS, startDate);
       if (list != null && list.size() > 0) {
         log.info("Rules count : " + list.size());
         for (VsdAlertRule vsdAlertRule : list) {
           log.info("vsdAlertRule.getAlertRuleId() ... " + vsdAlertRule.getAlertRuleId());
           messages.putAll(generateNotifications(vsdAlertRule, startDate, endDate));
         }
       }
       setTaskStatus(COMPLETED, endDate);
       sendNotifications(messages);
     }
   } catch (VSDException ve) {
     log.error(ve.getMessage(), ve);
   } catch (Exception e) {
     log.error(e.getMessage(), e);
   }
   log.info("END");
 }
Ejemplo n.º 3
0
 /** @throws java.lang.Exception */
 @Before
 public void setUp() throws Exception {
   schedulerService = SchedulerServiceImpl.getInstance();
   retrieveArabicData = false;
 }