class TrackedEntityServiceImpl implements TrackedEntityService, LocalDhisRepositoryPersistCallback<TrackedEntityInstance> {

    @Nonnull
    protected TrackedEntityInstance update( @Nonnull TrackedEntityInstance trackedEntityInstance )
    {
        final DhisSyncGroup syncGroup = storedItemService.findSyncGroupById( DhisSyncGroup.DEFAULT_ID )
            .orElseThrow( () -> new DhisResourceException( "Could not load default DHIS2 sync group." ) );

        final ResponseEntity<ImportSummariesWebMessage> response;
        try
        {
            clear( trackedEntityInstance );
            response = restTemplate.exchange( UPDATE_URI, HttpMethod.PUT, new HttpEntity<>( trackedEntityInstance ),
                ImportSummariesWebMessage.class, trackedEntityInstance.getId() );
        }
        catch ( HttpClientErrorException e )
        {
            if ( HttpStatus.CONFLICT.equals( e.getStatusCode() ) )
            {
                throw new DhisConflictException( "Tracked tracked entity instance could not be updated: " + e.getResponseBodyAsString(), e );
            }
            throw e;
        }
        final ImportSummariesWebMessage result = Objects.requireNonNull( response.getBody() );
        if ( result.getStatus() != Status.OK )
        {
            throw new DhisImportUnsuccessfulException( "Response indicates an unsuccessful import of tracked entity instance: " + result.getStatus() );
        }

        storeItem( syncGroup, trackedEntityInstance.getId(), response );
        return trackedEntityInstance;
    }

    @Autowired public  TrackedEntityServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull RequestCacheService requestCacheService,
        @Nonnull TrackedEntityMetadataService metadataService, @Nonnull StoredDhisResourceService storedItemService );

}