@Test public void parseRawBodyToRow() { final EventParser eventParser = new EventParser(MappingDefinition.load("/simple_body_row_raw.json")); assertThat(eventParser.parse(EventBuilder.withBody("TEST".getBytes(Charsets.UTF_8))).get("data")).isEqualTo( "TEST".getBytes(Charsets.UTF_8)); }
public DBObject parse(Event event) { DBObject dbObject = new BasicDBObject(); if (definition.getBodyType() != MongoDataType.NULL) { Object obj = null; if (definition.getBodyType() == MongoDataType.BINARY && definition.getBodyEncoding().equals("raw")) { obj = event.getBody(); } else if (definition.getBodyType() == MongoDataType.STRING) { Charset charset = Charset.forName(definition.getBodyEncoding()); obj = new String(event.getBody(), charset); } else { SimpleFieldDefinition fd = new SimpleFieldDefinition(); fd.setType(definition.getBodyType()); fd.setEncoding(definition.getBodyEncoding()); obj = parseValue(fd, new String(event.getBody(), Charsets.UTF_8)); } if (!"".equals(definition.getBodyField())) { dbObject.put(definition.getBodyField(), obj); } else if (obj instanceof DBObject) { dbObject = (DBObject) obj; } else { log.warn("Could not map body to JSON document: {}", obj); } } final Map<String, String> eventHeaders = event.getHeaders(); if (definition.allowsAdditionalProperties()) { for (final Map.Entry<String, String> headerEntry : eventHeaders.entrySet()) { final String fieldName = headerEntry.getKey(); final String fieldValue = headerEntry.getValue(); FieldDefinition def = definition.getFieldDefinitionByName(fieldName); if (def == null) { dbObject.put(fieldName, parseValue(null, fieldValue)); } else { final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (eventHeaders.containsKey(fieldName)) { dbObject.put(mappedName, parseValue(def, fieldValue)); } } } } else { for (FieldDefinition def : definition.getFields()) { final String fieldName = def.getFieldName(); final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (containsKey(eventHeaders, fieldName)) { dbObject.put(mappedName, parseValue(def, getFieldName(eventHeaders, fieldName))); } } } return dbObject; }
EventParser { public DBObject parse(Event event) { DBObject dbObject = new BasicDBObject(); if (definition.getBodyType() != MongoDataType.NULL) { Object obj = null; if (definition.getBodyType() == MongoDataType.BINARY && definition.getBodyEncoding().equals("raw")) { obj = event.getBody(); } else if (definition.getBodyType() == MongoDataType.STRING) { Charset charset = Charset.forName(definition.getBodyEncoding()); obj = new String(event.getBody(), charset); } else { SimpleFieldDefinition fd = new SimpleFieldDefinition(); fd.setType(definition.getBodyType()); fd.setEncoding(definition.getBodyEncoding()); obj = parseValue(fd, new String(event.getBody(), Charsets.UTF_8)); } if (!"".equals(definition.getBodyField())) { dbObject.put(definition.getBodyField(), obj); } else if (obj instanceof DBObject) { dbObject = (DBObject) obj; } else { log.warn("Could not map body to JSON document: {}", obj); } } final Map<String, String> eventHeaders = event.getHeaders(); if (definition.allowsAdditionalProperties()) { for (final Map.Entry<String, String> headerEntry : eventHeaders.entrySet()) { final String fieldName = headerEntry.getKey(); final String fieldValue = headerEntry.getValue(); FieldDefinition def = definition.getFieldDefinitionByName(fieldName); if (def == null) { dbObject.put(fieldName, parseValue(null, fieldValue)); } else { final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (eventHeaders.containsKey(fieldName)) { dbObject.put(mappedName, parseValue(def, fieldValue)); } } } } else { for (FieldDefinition def : definition.getFields()) { final String fieldName = def.getFieldName(); final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (containsKey(eventHeaders, fieldName)) { dbObject.put(mappedName, parseValue(def, getFieldName(eventHeaders, fieldName))); } } } return dbObject; } }
EventParser { public DBObject parse(Event event) { DBObject dbObject = new BasicDBObject(); if (definition.getBodyType() != MongoDataType.NULL) { Object obj = null; if (definition.getBodyType() == MongoDataType.BINARY && definition.getBodyEncoding().equals("raw")) { obj = event.getBody(); } else if (definition.getBodyType() == MongoDataType.STRING) { Charset charset = Charset.forName(definition.getBodyEncoding()); obj = new String(event.getBody(), charset); } else { SimpleFieldDefinition fd = new SimpleFieldDefinition(); fd.setType(definition.getBodyType()); fd.setEncoding(definition.getBodyEncoding()); obj = parseValue(fd, new String(event.getBody(), Charsets.UTF_8)); } if (!"".equals(definition.getBodyField())) { dbObject.put(definition.getBodyField(), obj); } else if (obj instanceof DBObject) { dbObject = (DBObject) obj; } else { log.warn("Could not map body to JSON document: {}", obj); } } final Map<String, String> eventHeaders = event.getHeaders(); if (definition.allowsAdditionalProperties()) { for (final Map.Entry<String, String> headerEntry : eventHeaders.entrySet()) { final String fieldName = headerEntry.getKey(); final String fieldValue = headerEntry.getValue(); FieldDefinition def = definition.getFieldDefinitionByName(fieldName); if (def == null) { dbObject.put(fieldName, parseValue(null, fieldValue)); } else { final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (eventHeaders.containsKey(fieldName)) { dbObject.put(mappedName, parseValue(def, fieldValue)); } } } } else { for (FieldDefinition def : definition.getFields()) { final String fieldName = def.getFieldName(); final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (containsKey(eventHeaders, fieldName)) { dbObject.put(mappedName, parseValue(def, getFieldName(eventHeaders, fieldName))); } } } return dbObject; } EventParser();  EventParser(final MappingDefinition mappingDefinition); }
EventParser { public DBObject parse(Event event) { DBObject dbObject = new BasicDBObject(); if (definition.getBodyType() != MongoDataType.NULL) { Object obj = null; if (definition.getBodyType() == MongoDataType.BINARY && definition.getBodyEncoding().equals("raw")) { obj = event.getBody(); } else if (definition.getBodyType() == MongoDataType.STRING) { Charset charset = Charset.forName(definition.getBodyEncoding()); obj = new String(event.getBody(), charset); } else { SimpleFieldDefinition fd = new SimpleFieldDefinition(); fd.setType(definition.getBodyType()); fd.setEncoding(definition.getBodyEncoding()); obj = parseValue(fd, new String(event.getBody(), Charsets.UTF_8)); } if (!"".equals(definition.getBodyField())) { dbObject.put(definition.getBodyField(), obj); } else if (obj instanceof DBObject) { dbObject = (DBObject) obj; } else { log.warn("Could not map body to JSON document: {}", obj); } } final Map<String, String> eventHeaders = event.getHeaders(); if (definition.allowsAdditionalProperties()) { for (final Map.Entry<String, String> headerEntry : eventHeaders.entrySet()) { final String fieldName = headerEntry.getKey(); final String fieldValue = headerEntry.getValue(); FieldDefinition def = definition.getFieldDefinitionByName(fieldName); if (def == null) { dbObject.put(fieldName, parseValue(null, fieldValue)); } else { final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (eventHeaders.containsKey(fieldName)) { dbObject.put(mappedName, parseValue(def, fieldValue)); } } } } else { for (FieldDefinition def : definition.getFields()) { final String fieldName = def.getFieldName(); final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (containsKey(eventHeaders, fieldName)) { dbObject.put(mappedName, parseValue(def, getFieldName(eventHeaders, fieldName))); } } } return dbObject; } EventParser();  EventParser(final MappingDefinition mappingDefinition); Object parseValue(final FieldDefinition fd, final String stringValue); DBObject parse(Event event); List<DBObject> parse(List<Event> events); }
EventParser { public DBObject parse(Event event) { DBObject dbObject = new BasicDBObject(); if (definition.getBodyType() != MongoDataType.NULL) { Object obj = null; if (definition.getBodyType() == MongoDataType.BINARY && definition.getBodyEncoding().equals("raw")) { obj = event.getBody(); } else if (definition.getBodyType() == MongoDataType.STRING) { Charset charset = Charset.forName(definition.getBodyEncoding()); obj = new String(event.getBody(), charset); } else { SimpleFieldDefinition fd = new SimpleFieldDefinition(); fd.setType(definition.getBodyType()); fd.setEncoding(definition.getBodyEncoding()); obj = parseValue(fd, new String(event.getBody(), Charsets.UTF_8)); } if (!"".equals(definition.getBodyField())) { dbObject.put(definition.getBodyField(), obj); } else if (obj instanceof DBObject) { dbObject = (DBObject) obj; } else { log.warn("Could not map body to JSON document: {}", obj); } } final Map<String, String> eventHeaders = event.getHeaders(); if (definition.allowsAdditionalProperties()) { for (final Map.Entry<String, String> headerEntry : eventHeaders.entrySet()) { final String fieldName = headerEntry.getKey(); final String fieldValue = headerEntry.getValue(); FieldDefinition def = definition.getFieldDefinitionByName(fieldName); if (def == null) { dbObject.put(fieldName, parseValue(null, fieldValue)); } else { final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (eventHeaders.containsKey(fieldName)) { dbObject.put(mappedName, parseValue(def, fieldValue)); } } } } else { for (FieldDefinition def : definition.getFields()) { final String fieldName = def.getFieldName(); final String mappedName = (def.getMappedName() == null) ? def.getFieldName() : def.getMappedName(); if (containsKey(eventHeaders, fieldName)) { dbObject.put(mappedName, parseValue(def, getFieldName(eventHeaders, fieldName))); } } } return dbObject; } EventParser();  EventParser(final MappingDefinition mappingDefinition); Object parseValue(final FieldDefinition fd, final String stringValue); DBObject parse(Event event); List<DBObject> parse(List<Event> events);  }