protected Map < String , Object > validateAndBuildEvent ( KeenProject project , String eventCollection , Map < String , Object > event , Map < String , Object > keenProperties ) { if ( project . getWriteKey ( ) == null ) { throw new NoWriteKeyException ( "You can't send events to Keen if you haven't set a write key." ) ; } validateEventCollection ( eventCollection ) ; validateEvent ( event ) ; KeenLogging . log ( String . format ( Locale . US , "Adding event to collection: %s" , eventCollection ) ) ; // Create maps to aggregate keen & non-keen properties Map < String , Object > newEvent = new HashMap < String , Object > ( ) ; Map < String , Object > mergedKeenProperties = new HashMap < String , Object > ( ) ; // separate keen & non-keen properties from static globals and merge them into separate maps if ( null != globalProperties ) { mergeGlobalProperties ( getGlobalProperties ( ) , mergedKeenProperties , newEvent ) ; } // separate keen & non-keen properties from dynamic globals and merge them into separate maps GlobalPropertiesEvaluator globalPropertiesEvaluator = getGlobalPropertiesEvaluator ( ) ; if ( globalPropertiesEvaluator != null ) { mergeGlobalProperties ( globalPropertiesEvaluator . getGlobalProperties ( eventCollection ) , mergedKeenProperties , newEvent ) ; } // merge any per-event keen properties if ( keenProperties != null ) { mergedKeenProperties . putAll ( keenProperties ) ; } // if no keen.timestamp was provided by globals or event, add one now if ( ! mergedKeenProperties . containsKey ( "timestamp" ) ) { Calendar currentTime = Calendar . getInstance ( ) ; String timestamp = ISO_8601_FORMAT . format ( currentTime . getTime ( ) ) ; mergedKeenProperties . put ( "timestamp" , timestamp ) ; } // add merged keen properties to event newEvent . put ( "keen" , mergedKeenProperties ) ; // merge any per-event non-keen properties newEvent . putAll ( event ) ; return newEvent ; }
Validates an event and inserts global properties producing a new event object which is ready to be published to the Keen service .