/** * Create a {@link SolrInputDocument} based on information in * {@link IDeviceMeasurements}. * * @param measurements * @return * @throws SiteWhereException */ public static SolrInputDocument createDocumentFromMeasurements(IDeviceMeasurements measurements) throws SiteWhereException { SolrInputDocument document = new SolrInputDocument(); document.addField(ISolrFields.EVENT_TYPE, SolrEventType.Measurements.name()); addFieldsForEvent(document, measurements); for (String key : measurements.getMeasurements().keySet()) { document.addField(ISolrFields.MEASUREMENT_PREFIX + key, measurements.getMeasurement(key)); } return document; }
/** * Parses a {@link SolrDocument} into a {@link IDeviceEvent}. * * @param document * @return * @throws SiteWhereException */ public static IDeviceEvent parseDocument(SolrDocument document) throws SiteWhereException { String type = (String) document.getFieldValue(ISolrFields.EVENT_TYPE); if (type == null) { throw new SiteWhereException("Solr event does not contain an event type indicator."); } SolrEventType eventType = SolrEventType.valueOf(type); switch (eventType) { case Location: { return parseLocationFromDocument(document); } case Measurements: { return parseMeasurementsFromDocument(document); } case Alert: { return parseAlertFromDocument(document); } default: { throw new SiteWhereException("Solr docuemnt contained unknown device event type."); } } }
/** * Create a {@link SolrInputDocument} based on information in * {@link IDeviceMeasurement}. * * @param mx * @return * @throws SiteWhereException */ public static SolrInputDocument createDocumentFromMeasurement(IDeviceMeasurement mx) throws SiteWhereException { SolrInputDocument document = new SolrInputDocument(); document.addField(ISolrFields.EVENT_TYPE, SolrEventType.Measurement.name()); addFieldsForEvent(document, mx); document.addField(ISolrFields.MX_NAME, mx.getName()); document.addField(ISolrFields.MX_VALUE, mx.getValue()); return document; }
/** * Parses a {@link SolrDocument} into a {@link IDeviceEvent}. * * @param document * @return * @throws SiteWhereException */ public static IDeviceEvent parseDocument(SolrDocument document) throws SiteWhereException { String type = (String) document.getFieldValue(ISolrFields.EVENT_TYPE); if (type == null) { throw new SiteWhereException("Solr event does not contain an event type indicator."); } SolrEventType eventType = SolrEventType.valueOf(type); switch (eventType) { case Location: { return parseLocationFromDocument(document); } case Measurement: { return parseMeasurementFromDocument(document); } case Alert: { return parseAlertFromDocument(document); } default: { throw new SiteWhereException("Solr docuemnt contained unknown device event type."); } } }
/** * Create a {@link SolrInputDocument} based on information in * {@link IDeviceLocation}. * * @param location * @return * @throws SiteWhereException */ public static SolrInputDocument createDocumentFromLocation(IDeviceLocation location) throws SiteWhereException { SolrInputDocument document = new SolrInputDocument(); document.addField(ISolrFields.EVENT_TYPE, SolrEventType.Location.name()); addFieldsForEvent(document, location); String latLong = "" + location.getLatitude() + ", " + location.getLongitude(); document.addField(ISolrFields.LOCATION, latLong); document.addField(ISolrFields.ELEVATION, location.getElevation()); return document; }
/** * Create a {@link SolrInputDocument} based on information in * {@link IDeviceLocation}. * * @param location * @return * @throws SiteWhereException */ public static SolrInputDocument createDocumentFromLocation(IDeviceLocation location) throws SiteWhereException { SolrInputDocument document = new SolrInputDocument(); document.addField(ISolrFields.EVENT_TYPE, SolrEventType.Location.name()); addFieldsForEvent(document, location); String latLong = "" + location.getLatitude() + ", " + location.getLongitude(); document.addField(ISolrFields.LOCATION, latLong); document.addField(ISolrFields.ELEVATION, location.getElevation()); return document; }
/** * 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; }
/** * 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; }