use of org.springframework.beans.factory.access.BeanFactoryReference in project opennms by OpenNMS.
the class AlarmEventSynchronization method getEvents.
@Override
public List<Event> getEvents() {
BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
final AlarmDao alarmDao = BeanUtils.getBean(bf, "alarmDao", AlarmDao.class);
final List<Event> xmlevents = new ArrayList<Event>();
TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
try {
transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
Map<String, OnmsAlarm> forwardAlarms = new HashMap<String, OnmsAlarm>();
for (OnmsAlarm alarm : alarmDao.findAll()) {
// Got Clear alarm
if (alarm.getAlarmType() == 2) {
if (forwardAlarms.containsKey(alarm.getClearKey())) {
OnmsAlarm raise = forwardAlarms.get(alarm.getClearKey());
if (raise.getLastEventTime().before(alarm.getLastEventTime())) {
forwardAlarms.remove(alarm.getClearKey());
}
} else {
forwardAlarms.put(alarm.getClearKey(), alarm);
}
} else if (alarm.getAlarmType() == 1) {
if (forwardAlarms.containsKey(alarm.getReductionKey())) {
OnmsAlarm clear = forwardAlarms.get(alarm.getReductionKey());
if (clear.getLastEventTime().before(alarm.getLastEventTime())) {
forwardAlarms.put(alarm.getReductionKey(), alarm);
}
} else {
forwardAlarms.put(alarm.getReductionKey(), alarm);
}
} else {
forwardAlarms.put(alarm.getReductionKey(), alarm);
}
}
for (OnmsAlarm alarm : forwardAlarms.values()) {
if (alarm.getAlarmType() != 2) {
Event xmlEvent = getXMLEvent(alarm);
if (xmlEvent != null)
xmlevents.add(xmlEvent);
}
}
}
});
} catch (final RuntimeException e) {
}
return xmlevents;
}
Aggregations