@Override public String getType() { return ((IDeviceAlert) getWrapped()).getType(); }
@Override public String getMessage() { return ((IDeviceAlert) getWrapped()).getMessage(); } }
@Override public AlertLevel getLevel() { return ((IDeviceAlert) getWrapped()).getLevel(); }
/** * Merge alert information. * * @param alert * @param original * @param request */ protected void mergeDeviceAlert(IDeviceAlert alert, IDeviceState original, DeviceStateCreateRequest request) { if (original != null) { request.getLastAlertEventIds().putAll(original.getLastAlertEventIds()); } request.getLastAlertEventIds().put(alert.getType(), alert.getId()); }
/** * Copy information from SPI into Mongo DBObject. * * @param source * @param target * @param isNested */ public static void toDocument(IDeviceAlert source, Document target, boolean isNested) { MongoDeviceEvent.toDocument(source, target, isNested); target.append(PROP_SOURCE, source.getSource().name()); target.append(PROP_LEVEL, source.getLevel().name()); target.append(PROP_TYPE, source.getType()); target.append(PROP_MESSAGE, source.getMessage()); }
@Override public void onAlert(IDeviceEventContext context, IDeviceAlert alert) throws SiteWhereException { List<EventCreateRequest> events = new ArrayList<EventCreateRequest>(); EventCreateRequest event = new EventCreateRequest(); event.setKey(alert.getType()); event.setValue(alert.getMessage()); event.setEpoch(((double) System.currentTimeMillis()) / ((double) 1000)); events.add(event); DeviceAssignment assignment = assureBucket(alert.getDeviceAssignmentId()); createEvents(assignment.getToken(), events); }
@Override public void onAlertNotFiltered(IDeviceAlert alert) throws SiteWhereException { List<EventCreateRequest> events = new ArrayList<EventCreateRequest>(); EventCreateRequest event = new EventCreateRequest(); event.setKey(alert.getType()); event.setValue(alert.getMessage()); event.setEpoch(((double) System.currentTimeMillis()) / ((double) 1000)); events.add(event); DeviceAssignment assignment = assureBucket(alert.getDeviceAssignmentToken()); createEvents(assignment.getToken(), events); }
/** * Update state with new alert. * * @param state * @param alert * @throws SiteWhereException */ private void updateWithAlert(DeviceAssignmentState state, IDeviceAlert alert) throws SiteWhereException { state.setLastInteractionDate(new Date()); Map<String, IDeviceAlert> alertsById = new HashMap<String, IDeviceAlert>(); for (IDeviceAlert a : state.getLatestAlerts()) { alertsById.put(a.getType(), a); } IDeviceAlert ea = alertsById.get(alert.getType()); if ((ea == null) || (ea.getEventDate().before(alert.getEventDate()))) { DeviceAlert newAlert = DeviceAlert.copy(alert); alertsById.put(newAlert.getType(), newAlert); } state.getLatestAlerts().clear(); for (IDeviceAlert a : alertsById.values()) { state.getLatestAlerts().add(a); } }
@Override public AlertSource getSource() { return ((IDeviceAlert) getWrapped()).getSource(); }
@Override public void onAlertNotFiltered(IDeviceAlert alert) throws SiteWhereException { DeviceAlert marshaled = DeviceAlert.copy(alert); alertsTopic.publish(marshaled); LOGGER.debug("Published alert event to Hazelcast (id=" + alert.getId() + ")"); }
/** * Create a copy of an SPI object. Used by web services for marshaling. * * @param input * @return */ public static DeviceAlert copy(IDeviceAlert input) throws SiteWhereException { DeviceAlert result = new DeviceAlert(); DeviceEvent.copy(input, result); result.setSource(input.getSource()); result.setType(input.getType()); result.setMessage(input.getMessage()); result.setLevel(input.getLevel()); return result; } }
@Override public AlertSource getSource() { return ((IDeviceAlert) getWrapped()).getSource(); }
@Override public void onDeviceAlertCreateRequest(String hardwareId, String originator, IDeviceAlertCreateRequest request) throws SiteWhereException { IDeviceAssignment assignment = getCurrentAssignment(hardwareId); IDeviceAlert alert = getDeviceEventManagement().addDeviceAlert(assignment.getToken(), request); handleLinkResponseToInvocation(originator, alert.getId(), assignment); }
/** * Create a copy of an SPI object. Used by web services for marshaling. * * @param input * @return */ public static DeviceAlert copy(IDeviceAlert input) throws SiteWhereException { DeviceAlert result = new DeviceAlert(); DeviceEvent.copy(input, result); result.setSource(input.getSource()); result.setType(input.getType()); result.setMessage(input.getMessage()); result.setLevel(input.getLevel()); return result; } }
/** * Returns true if event is an alert and has the given type. * * @param type * @return */ public boolean isAlertOfType(String type) { return (isAlert() && ((IDeviceAlert) event).getType().equals(type)); }
@Override public String getMessage() { return ((IDeviceAlert) getWrapped()).getMessage(); } }
@Override public AlertLevel getLevel() { return ((IDeviceAlert) getWrapped()).getLevel(); }
/** * Copy information from SPI into Mongo DBObject. * * @param source * @param target * @param isNested */ public static void toDocument(IDeviceAlert source, Document target, boolean isNested) { MongoDeviceEvent.toDocument(source, target, isNested); target.append(PROP_SOURCE, source.getSource().name()); target.append(PROP_LEVEL, source.getLevel().name()); target.append(PROP_TYPE, source.getType()); target.append(PROP_MESSAGE, source.getMessage()); }
@Override public String getType() { return ((IDeviceAlert) getWrapped()).getType(); }
/** * Get a short description of a device event. * * @param event * @return * @throws SiteWhereException */ public static String getDeviceEventDescription(IDeviceEvent event) throws SiteWhereException { if (event instanceof IDeviceMeasurements) { IDeviceMeasurements m = (IDeviceMeasurements) event; return "Measurements (" + m.getMeasurementsSummary() + ")"; } else if (event instanceof IDeviceLocation) { IDeviceLocation l = (IDeviceLocation) event; return "Location (" + l.getLatitude() + "/" + l.getLongitude() + "/" + l.getElevation() + ")"; } else if (event instanceof IDeviceAlert) { IDeviceAlert a = (IDeviceAlert) event; return "Alert (\"" + a.getMessage() + "\")"; } return "Unknown Event Type"; } }