/** * Convert alert source from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GAlertSource asGrpcAlertSource(AlertSource api) throws SiteWhereException { switch (api) { case Device: return GAlertSource.ALERT_SOURCE_DEVICE; case System: return GAlertSource.ALERT_SOURCE_SYSTEM; } throw new SiteWhereException("Unknown alert source: " + api.name()); }
/** * Load fields from value map. * * @param event * @param values * @throws SiteWhereException */ public static void loadFromMap(DeviceAlert event, Map<String, Object> values) throws SiteWhereException { event.setEventType(DeviceEventType.Alert); event.setType((String) values.get(ALERT_TYPE)); event.setSource(AlertSource.valueOf((String) values.get(ALERT_SOURCE))); event.setLevel(AlertLevel.valueOf((String) values.get(ALERT_LEVEL))); event.setMessage((String) values.get(ALERT_MESSAGE)); InfluxDbDeviceEvent.loadFromMap(event, values); }
/** * Get indicator value for alert source. * * @param source * @return * @throws SiteWhereException */ public static Byte getIndicatorForAlertSource(AlertSource source) throws SiteWhereException { switch (source) { case Device: { return 0; } case System: { return 1; } default: { throw new SiteWhereException("Unsupported alert source: " + source.name()); } } }
/** * Parse and {@link IDeviceAlert} record from a {@link SolrDocument}. * * @param document * @return * @throws SiteWhereException */ protected static IDeviceAlert parseAlertFromDocument(SolrDocument document) throws SiteWhereException { DeviceAlert alert = new DeviceAlert(); String alertType = (String) document.get(ISolrFields.ALERT_TYPE); String alertMessage = (String) document.get(ISolrFields.ALERT_MESSAGE); String alertLevelStr = (String) document.get(ISolrFields.ALERT_LEVEL); String alertSourceStr = (String) document.get(ISolrFields.ALERT_SOURCE); alert.setType(alertType); alert.setMessage(alertMessage); alert.setLevel(AlertLevel.valueOf(alertLevelStr)); alert.setSource(AlertSource.valueOf(alertSourceStr)); addFieldsFromEventDocument(document, alert); return alert; }
/** * 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()); }
/** * Copy information from Mongo DBObject to model object. * * @param source * @param target * @param isNested */ public static void fromDocument(Document source, DeviceAlert target, boolean isNested) { MongoDeviceEvent.fromDocument(source, target, isNested); String sourceName = (String) source.get(PROP_SOURCE); String levelName = (String) source.get(PROP_LEVEL); String type = (String) source.get(PROP_TYPE); String message = (String) source.get(PROP_MESSAGE); if (sourceName != null) { target.setSource(AlertSource.valueOf(sourceName)); } if (levelName != null) { target.setLevel(AlertLevel.valueOf(levelName)); } target.setType(type); target.setMessage(message); }
/** * 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()); }
/** * Copy information from Mongo DBObject to model object. * * @param source * @param target * @param isNested */ public static void fromDocument(Document source, DeviceAlert target, boolean isNested) { MongoDeviceEvent.fromDocument(source, target, isNested); String sourceName = (String) source.get(PROP_SOURCE); String levelName = (String) source.get(PROP_LEVEL); String type = (String) source.get(PROP_TYPE); String message = (String) source.get(PROP_MESSAGE); if (sourceName != null) { target.setSource(AlertSource.valueOf(sourceName)); } if (levelName != null) { target.setLevel(AlertLevel.valueOf(levelName)); } target.setType(type); target.setMessage(message); }
/** * Save fields to builder. * * @param event * @param builder * @throws SiteWhereException */ public static void saveToBuilder(DeviceAlert event, Point.Builder builder) throws SiteWhereException { builder.tag(ALERT_TYPE, event.getType()); builder.tag(ALERT_SOURCE, event.getSource().name()); builder.tag(ALERT_LEVEL, event.getLevel().name()); builder.addField(ALERT_MESSAGE, event.getMessage()); InfluxDbDeviceEvent.saveToBuilder(event, builder); } }
/** * Unmarshal a {@link DeviceAlert}. * * @param pb * @return * @throws SiteWhereException */ protected DeviceAlert unmarshalDeviceAlert(ProtobufMarshaler.DeviceAlert pb) throws SiteWhereException { DeviceAlert alert = new DeviceAlert(); alert.setSource(AlertSource.valueOf(pb.getSource())); alert.setLevel(AlertLevel.valueOf(pb.getLevel())); alert.setType(pb.getType()); alert.setMessage(pb.getMessage()); loadDeviceEventData(alert, pb.getEventData()); return alert; }
/** * Create a {@link SolrInputDocument} based on information in * {@link IDeviceAlert}. * * @param alert * @return * @throws SiteWhereException */ public static SolrInputDocument createDocumentFromAlert(IDeviceAlert alert) throws SiteWhereException { SolrInputDocument document = new SolrInputDocument(); document.addField(ISolrFields.EVENT_TYPE, SolrEventType.Alert.name()); addFieldsForEvent(document, alert); document.addField(ISolrFields.ALERT_TYPE, alert.getType()); document.addField(ISolrFields.ALERT_MESSAGE, alert.getMessage()); document.addField(ISolrFields.ALERT_LEVEL, alert.getLevel().name()); document.addField(ISolrFields.ALERT_SOURCE, alert.getSource().name()); return document; }
/** * Parse and {@link IDeviceAlert} record from a {@link SolrDocument}. * * @param document * @return * @throws SiteWhereException */ protected static IDeviceAlert parseAlertFromDocument(SolrDocument document) throws SiteWhereException { DeviceAlert alert = new DeviceAlert(); String alertType = (String) document.get(ISolrFields.ALERT_TYPE); String alertMessage = (String) document.get(ISolrFields.ALERT_MESSAGE); String alertLevelStr = (String) document.get(ISolrFields.ALERT_LEVEL); String alertSourceStr = (String) document.get(ISolrFields.ALERT_SOURCE); alert.setType(alertType); alert.setMessage(alertMessage); alert.setLevel(AlertLevel.valueOf(alertLevelStr)); alert.setSource(AlertSource.valueOf(alertSourceStr)); addFieldsFromEventDocument(document, alert); return alert; }
/** * Marshal an {@link IDeviceAlert}. * * @param alert * @return * @throws SiteWhereException */ protected ProtobufMarshaler.DeviceAlert marshalDeviceAlert(IDeviceAlert alert) throws SiteWhereException { ProtobufMarshaler.DeviceAlert.Builder builder = ProtobufMarshaler.DeviceAlert.newBuilder(); builder.setSource(alert.getSource().name()); builder.setLevel(alert.getLevel().name()); builder.setType(alert.getType()); builder.setMessage(alert.getMessage()); builder.setEventData(createDeviceEventData(alert)); return builder.build(); }
/** * Create a {@link SolrInputDocument} based on information in * {@link IDeviceAlert}. * * @param alert * @return * @throws SiteWhereException */ public static SolrInputDocument createDocumentFromAlert(IDeviceAlert alert) throws SiteWhereException { SolrInputDocument document = new SolrInputDocument(); document.addField(ISolrFields.EVENT_TYPE, SolrEventType.Alert.name()); addFieldsForEvent(document, alert); document.addField(ISolrFields.ALERT_TYPE, alert.getType()); document.addField(ISolrFields.ALERT_MESSAGE, alert.getMessage()); document.addField(ISolrFields.ALERT_LEVEL, alert.getLevel().name()); document.addField(ISolrFields.ALERT_SOURCE, alert.getSource().name()); return document; }