@Test public void testContextElementConversionMetadataString() throws Exception { ContextElement ce = new ContextElement(); ce.setEntityId(new EntityId("S1", "TempSensor", false)); ContextAttribute ca = new ContextAttribute("ATTR1", "string", "hello"); ce.setContextAttributeList(Collections.singletonList(ca)); List<ContextMetadata> metadatas = new LinkedList<>(); metadatas.add(new ContextMetadata("1", "string", "hello")); metadatas.add(new ContextMetadata("2", "float", "1.4")); metadatas.add(new ContextMetadata("3", "double", "3.1")); metadatas.add(new ContextMetadata("4", "int", "3")); metadatas.add(new ContextMetadata("5", "long", "3")); metadatas.add(new ContextMetadata("6", "boolean", "true")); metadatas.add(new ContextMetadata("7", "boolean", "false")); ca.setMetadata(metadatas); Map<String, Object> values = eventMapper.eventFromContextElement(ce).getValues(); assertEquals("hello", values.get("ATTR1_1")); assertEquals(1.4f, values.get("ATTR1_2")); assertEquals(3.1d, values.get("ATTR1_3")); assertEquals(3, values.get("ATTR1_4")); assertEquals(3l, values.get("ATTR1_5")); assertEquals(true, values.get("ATTR1_6")); assertEquals(false, values.get("ATTR1_7")); }
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);  }