@Test public void testContextElementConversion() throws Exception { ContextElement ce = new ContextElement(); ce.setEntityId(new EntityId("S1", "TempSensor", false)); List<ContextAttribute> attributes = new LinkedList<>(); attributes.add(new ContextAttribute("1", "string", "hello")); attributes.add(new ContextAttribute("1_string", null, "hello")); attributes.add(new ContextAttribute("2", "float", 1.4f)); attributes.add(new ContextAttribute("3", "double", 3.1d)); attributes.add(new ContextAttribute("4", "int", 3)); attributes.add(new ContextAttribute("5", "long", 3l)); attributes.add(new ContextAttribute("6", "boolean", true)); attributes.add(new ContextAttribute("7", "boolean", false)); attributes.add(new ContextAttribute("8", "date", "2015-12-01T17:12:28Z")); attributes.add(new ContextAttribute("9", "geo:point", "39.23, -10.3")); ce.setContextAttributeList(attributes); Map<String, Object> values = eventMapper.eventFromContextElement(ce).getValues(); assertEquals("S1", values.get("id")); assertEquals("hello", values.get("1")); assertEquals("hello", values.get("1_string")); assertEquals(1.4f, values.get("2")); assertEquals(3.1d, values.get("3")); assertEquals(3, values.get("4")); assertEquals(3l, values.get("5")); assertEquals(true, values.get("6")); assertEquals(false, values.get("7")); assertEquals(new Date(1448989948000l), values.get("8")); assertEquals(Geospatial.readGeometry("POINT(39.23 -10.3)"), values.get("9")); }
public Event eventFromContextElement(ContextElement contextElement) throws EventProcessingException, TypeNotFoundException { String eventId = contextElement.getEntityId().getId(); String eventType = contextElement.getEntityId().getType(); Event event = new Event(eventType); for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String attrName = contextAttribute.getName(); for (ContextMetadata contextMetada : contextAttribute.getMetadata()) { String name = contextMetada.getName(); String type = contextMetada.getType(); Object value = contextMetada.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + attrName + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); event.addValue(attrName + "_" + name, value); } } for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String name = contextAttribute.getName(); String type = contextAttribute.getType(); Object value = contextAttribute.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); if (value == null) { throw new EventProcessingException("Value cannot be null for attribute "+name); } event.addValue(name, value); } event.addValue("id", eventId); return event; }
EventMapper { public Event eventFromContextElement(ContextElement contextElement) throws EventProcessingException, TypeNotFoundException { String eventId = contextElement.getEntityId().getId(); String eventType = contextElement.getEntityId().getType(); Event event = new Event(eventType); for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String attrName = contextAttribute.getName(); for (ContextMetadata contextMetada : contextAttribute.getMetadata()) { String name = contextMetada.getName(); String type = contextMetada.getType(); Object value = contextMetada.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + attrName + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); event.addValue(attrName + "_" + name, value); } } for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String name = contextAttribute.getName(); String type = contextAttribute.getType(); Object value = contextAttribute.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); if (value == null) { throw new EventProcessingException("Value cannot be null for attribute "+name); } event.addValue(name, value); } event.addValue("id", eventId); return event; } }
EventMapper { public Event eventFromContextElement(ContextElement contextElement) throws EventProcessingException, TypeNotFoundException { String eventId = contextElement.getEntityId().getId(); String eventType = contextElement.getEntityId().getType(); Event event = new Event(eventType); for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String attrName = contextAttribute.getName(); for (ContextMetadata contextMetada : contextAttribute.getMetadata()) { String name = contextMetada.getName(); String type = contextMetada.getType(); Object value = contextMetada.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + attrName + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); event.addValue(attrName + "_" + name, value); } } for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String name = contextAttribute.getName(); String type = contextAttribute.getType(); Object value = contextAttribute.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); if (value == null) { throw new EventProcessingException("Value cannot be null for attribute "+name); } event.addValue(name, value); } event.addValue("id", eventId); return event; }  }
EventMapper { public Event eventFromContextElement(ContextElement contextElement) throws EventProcessingException, TypeNotFoundException { String eventId = contextElement.getEntityId().getId(); String eventType = contextElement.getEntityId().getType(); Event event = new Event(eventType); for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String attrName = contextAttribute.getName(); for (ContextMetadata contextMetada : contextAttribute.getMetadata()) { String name = contextMetada.getName(); String type = contextMetada.getType(); Object value = contextMetada.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + attrName + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); event.addValue(attrName + "_" + name, value); } } for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String name = contextAttribute.getName(); String type = contextAttribute.getType(); Object value = contextAttribute.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); if (value == null) { throw new EventProcessingException("Value cannot be null for attribute "+name); } event.addValue(name, value); } event.addValue("id", eventId); return event; }  void setConfiguration(Configuration configuration); Map<String, Object> esperTypeFromEventType(EventType eventType); Event eventFromContextElement(ContextElement contextElement); ContextElement contextElementFromEvent(EventBean eventBean, EventType eventType); Object attributeValueFromEventProperty(Object value, String type); }
EventMapper { public Event eventFromContextElement(ContextElement contextElement) throws EventProcessingException, TypeNotFoundException { String eventId = contextElement.getEntityId().getId(); String eventType = contextElement.getEntityId().getType(); Event event = new Event(eventType); for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String attrName = contextAttribute.getName(); for (ContextMetadata contextMetada : contextAttribute.getMetadata()) { String name = contextMetada.getName(); String type = contextMetada.getType(); Object value = contextMetada.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + attrName + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); event.addValue(attrName + "_" + name, value); } } for(ContextAttribute contextAttribute : contextElement.getContextAttributeList()) { String name = contextAttribute.getName(); String type = contextAttribute.getType(); Object value = contextAttribute.getValue(); JsonPath jsonPath = jsonpaths.get(eventType + "/" + name); if (jsonPath != null) { value = jsonPath.read(value); } value = valueForType(value, type, name); if (value == null) { throw new EventProcessingException("Value cannot be null for attribute "+name); } event.addValue(name, value); } event.addValue("id", eventId); return event; }  void setConfiguration(Configuration configuration); Map<String, Object> esperTypeFromEventType(EventType eventType); Event eventFromContextElement(ContextElement contextElement); ContextElement contextElementFromEvent(EventBean eventBean, EventType eventType); Object attributeValueFromEventProperty(Object value, String type);  }