@Override public SortedEventsList<AlarmMessage> getLastAlarmsMessages(final Sensor sensor) { // To retrieve the latest alarms associated with the sensor alerts, we must first retrieve the // sensor alerts list and then, for each alert, recover their last alarm. final List<AlarmMessage> lastAlarmMessages = new ArrayList<AlarmMessage>(); final List<Alert> sensorAlerts = getSensorAlerts(sensor); for (final Alert alert : sensorAlerts) { final QueryFilterParams filterParams = new QueryFilterParams(SentiloConstants.NUM_MAXIM_ELEMENTS); final AlarmInputMessage message = new AlarmInputMessage(alert.getId(), filterParams); final AlarmsOutputMessage outMessage = platformTemplate.getAlarmOps().getLastAlarmMessages(message); if (!CollectionUtils.isEmpty(outMessage.getAlarms())) { lastAlarmMessages.addAll(outMessage.getAlarms()); } } return new SortedEventsList<AlarmMessage>(lastAlarmMessages); }
@Test public void _01_publish() throws Exception { final AlarmInputMessage message = new AlarmInputMessage(ALERT_NAME, "Level theshold reached"); platformTemplate.getAlarmOps().publish(message); assertTrue("Wrong call to Sentilo", true); }
@Test public void _02_publishWithoutAlarmMessage() throws Exception { final AlarmInputMessage message = new AlarmInputMessage("mockTestAlert"); boolean error = false; try { platformTemplate.getAlarmOps().publish(message); } catch (final PlatformClientAccessException e) { error = true; } assertTrue("Wrong call to Sentilo", error); }
@Test public void _03_getLastAlarmMessages() throws Exception { final AlarmInputMessage message = new AlarmInputMessage(ALERT_NAME); final AlarmsOutputMessage response = platformTemplate.getAlarmOps().getLastAlarmMessages(message); assertTrue(response != null && !CollectionUtils.isEmpty(response.getAlarms())); assertTrue(response.getAlarms().size() == 1); }
public void publishAlarm(final InternalAlert alert, final String message) { LOGGER.debug("Publishing new alarm, related to (alert, sensor, provider) ({}, {} , {}), with message: {} ", alert.getId(), alert.getSensorId(), alert.getProviderId(), message); // Publish directly via API REST final AlarmInputMessage alarmMessage = new AlarmInputMessage(alert.getId(), message); alarmMessage.setProviderId(alert.getProviderId()); alarmMessage.setSensorId(alert.getSensorId()); alarmMessage.setAlertType(alert.getTrigger().name()); platformClient.getAlarmOps().publish(alarmMessage); } }
@Test public void _04_getFilteredLastAlarmMessages() throws Exception { final QueryFilterParams filterParams = new QueryFilterParams(1); final AlarmInputMessage message = new AlarmInputMessage(ALERT_NAME, filterParams); final AlarmsOutputMessage response = platformTemplate.getAlarmOps().getLastAlarmMessages(message); assertTrue(response != null && !CollectionUtils.isEmpty(response.getAlarms())); assertEquals(1, response.getAlarms().size()); }