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());
}
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);
}
}
Aggregations