@Test(expected = EventProcessingException.class) public void testContextElementConversionNull() throws Exception { ContextElement ce = new ContextElement(); ce.setEntityId(new EntityId("S1", "TempSensor", false)); List<ContextAttribute> attributes = new LinkedList<>(); attributes.add(new ContextAttribute("1", "string", null)); ce.setContextAttributeList(attributes); eventMapper.eventFromContextElement(ce).getValues(); }
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);  }