class EventServiceImpl implements EventService, LocalDhisRepositoryPersistCallback<Event> {

    @Nonnull
    protected Event create( @Nonnull Event event )
    {
        final ResponseEntity<ImportSummariesWebMessage> response;

        if ( event.getId() == null )
        {
            event.setId( CodeGenerator.generateUid() );
        }

        try
        {
            response = restTemplate.exchange( CREATE_URI, HttpMethod.POST, new HttpEntity<>( event ), ImportSummariesWebMessage.class );
        }
        catch ( HttpClientErrorException e )
        {
            if ( HttpStatus.CONFLICT.equals( e.getStatusCode() ) )
            {
                throw new DhisConflictException( "Event could not be created: " + e.getResponseBodyAsString(), e );
            }

            throw e;
        }

        final ImportSummariesWebMessage result = Objects.requireNonNull( response.getBody() );

        if ( result.isNotSuccessful() )
        {
            throw new DhisImportUnsuccessfulException( "Response indicates an unsuccessful event import." );
        }

        event.setId( result.getResponse().getImportSummaries().get( 0 ).getReference() );
        event.resetNewResource();
        event.setLocal( false );

        return event;
    }

    @Autowired public  EventServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull RequestCacheService requestCacheService, @Nonnull PolledProgramRetriever polledProgramRetriever );

}