Search in sources :

Example 1 with OnmsMemo

use of org.opennms.netmgt.model.OnmsMemo in project opennms by OpenNMS.

the class MemoDaoIT method testAddStickyMemoToExistingAlarm.

@Test
@Transactional
public void testAddStickyMemoToExistingAlarm() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.whoami());
    event.setEventTime(new Date());
    event.setEventSeverity(new Integer(7));
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);
    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.whoami());
    alarm.setReductionKey("fristReductionKey");
    m_alarmDao.save(alarm);
    // It works we're so smart! hehe
    OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
    final OnmsMemo memo = new OnmsMemo();
    memo.setBody("Call me Ishmael...");
    memo.setAuthor("Herman Melville");
    Date memoCreation = new Date();
    memo.setCreated(memoCreation);
    newAlarm.setStickyMemo(memo);
    m_alarmDao.update(newAlarm);
    m_alarmDao.flush();
    assertNotNull(newAlarm.getStickyMemo().getId());
    assertNotNull(newAlarm.getStickyMemo().getCreated());
    assertNotNull(newAlarm.getStickyMemo().getAuthor());
    assertNotNull(newAlarm.getStickyMemo().getBody());
    assertNotNull(alarm.getStickyMemo().getId());
    assertNotNull(alarm.getStickyMemo().getCreated());
    assertNotNull(alarm.getStickyMemo().getAuthor());
    assertNotNull(alarm.getStickyMemo().getBody());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsMemo(org.opennms.netmgt.model.OnmsMemo) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OnmsMemo

use of org.opennms.netmgt.model.OnmsMemo in project opennms by OpenNMS.

the class AlarmRepositoryHibernate method updateStickyMemo.

/**
     * {@inheritDoc}
     */
@Override
@Transactional
public void updateStickyMemo(Integer alarmId, String body, String user) {
    OnmsAlarm onmsAlarm = m_alarmDao.get(alarmId);
    if (onmsAlarm != null) {
        if (onmsAlarm.getStickyMemo() == null) {
            onmsAlarm.setStickyMemo(new OnmsMemo());
            onmsAlarm.getStickyMemo().setCreated(new Date());
        }
        onmsAlarm.getStickyMemo().setBody(body);
        onmsAlarm.getStickyMemo().setAuthor(user);
        onmsAlarm.getStickyMemo().setUpdated(new Date());
        m_alarmDao.saveOrUpdate(onmsAlarm);
    }
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsMemo(org.opennms.netmgt.model.OnmsMemo) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Date (java.util.Date)2 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)2 OnmsMemo (org.opennms.netmgt.model.OnmsMemo)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Test (org.junit.Test)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1