LuceneStoreImpl implements Store { @Override public String store(Event event) throws Exception { Document document = new Document(); for (String property : event.getPropertyNames()) { Object value = event.getProperty(property); if (value instanceof Long) { document.add(new LongPoint(property, ((Long) value))); document.add(new StoredField(property, ((Long) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Long.class)); } else if (value instanceof Integer) { document.add(new IntPoint(property, ((Integer) value))); document.add(new StoredField(property, ((Integer) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Integer.class)); } else if (value instanceof Float) { document.add(new FloatPoint(property, ((Float) value))); document.add(new StoredField(property, ((Integer) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Float.class)); } else if (value instanceof Double) { document.add(new DoublePoint(property, ((Double) value))); document.add(new StoredField(property, ((Double) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Double.class)); } else { if (value != null) { String stringValue = value.toString(); if (stringValue.getBytes("UTF-8").length > 32766) { stringValue = new String(stringValue.getBytes("UTF-8"), 0, 32766, "UTF-8"); } document.add(new StringField(property, stringValue, Field.Store.YES)); } } } if (event.getProperty("alertTimestamp") == null) { long now = System.currentTimeMillis(); document.add(new LongPoint("alertTimestamp", System.currentTimeMillis())); document.add(new StoredField("alertTimestamp", now)); points.put("alertTimestamp", new PointsConfig(NumberFormat.getInstance(), Long.class)); } String uuid = UUID.randomUUID().toString(); document.add(new StringField("alertUUID", uuid, Field.Store.YES)); try { indexWriter.addDocument(document); indexWriter.commit(); } catch (Exception e) { LOGGER.warn("Can't store alert: {}", e.getMessage()); } return uuid; }  @Activate void activate(); @Deactivate void deactivate(); @Override String store(Event event); @Override void cleanup(); @Override void eviction(); @Override void flag(String queryString, String ruleName); @Override List<Alert> list(); @Override List<Alert> query(String queryString); @Override void delete(String queryString); static final String INDEX_DIRECTORY; static final String POINTS_DIRECTORY; }
@Test public void testStore() throws Exception { HashMap<String, Object> data = new HashMap<>(); data.put("foo", "bar"); data.put("myint", 28); data.put("myfloat", 2.5); data.put("mylong", 100L); data.put("mypojo", new MyPojo("pojo")); Event event = new Event("topic", data); alertingService.store(event); List<Alert> alerts = alertingService.list(); Assert.assertEquals(1, alerts.size()); Alert alert = alerts.get(0); Assert.assertEquals("bar", alert.get("foo")); Assert.assertEquals(28, alert.get("myint")); Assert.assertEquals(2.5, alert.get("myfloat")); Assert.assertEquals(100L, alert.get("mylong")); Assert.assertEquals("pojo", alert.get("mypojo")); Assert.assertEquals("topic", alert.get("event.topics")); Assert.assertNotNull(alert.get("alertTimestamp")); }