Search in sources :

Example 6 with BeanFactoryReference

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;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) Event(org.opennms.netmgt.xml.event.Event) HashMap(java.util.HashMap) Map(java.util.Map) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Aggregations

BeanFactoryReference (org.springframework.beans.factory.access.BeanFactoryReference)6 TransactionStatus (org.springframework.transaction.TransactionStatus)4 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)4 ArrayList (java.util.ArrayList)3 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 Event (org.opennms.netmgt.xml.event.Event)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ScriptdConfigFactory (org.opennms.netmgt.config.ScriptdConfigFactory)1 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)1 EventDao (org.opennms.netmgt.dao.api.EventDao)1 SnmpInterfaceDao (org.opennms.netmgt.dao.api.SnmpInterfaceDao)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)1