class MetadataSyncPreProcessor {

    public List<MetadataVersion> handleMetadataVersionsList( MetadataRetryContext context, MetadataVersion metadataVersion )
    {
        log.debug( "Fetching the list of remote versions" );

        List<MetadataVersion> metadataVersionList;

        try
        {
            metadataVersionList = metadataVersionDelegate.getMetaDataDifference( metadataVersion );

            if ( metadataVersion == null )
            {
                log.info( "There is no initial version in the system" );
            }

            if ( isRemoteVersionEmpty( metadataVersion, metadataVersionList ) )
            {
                log.info( "There are no metadata versions created in the remote instance." );
                return metadataVersionList;
            }

            if ( isUsingLatestVersion( metadataVersion, metadataVersionList ) )
            {
                log.info( "Your instance is already using the latest version:" + metadataVersion );
                return metadataVersionList;
            }

            MetadataVersion latestVersion = getLatestVersion( metadataVersionList );
            assert latestVersion != null;

            systemSettingManager.saveSystemSetting( SettingKey.REMOTE_METADATA_VERSION, latestVersion.getName() );
            log.info( "Remote system is at version: " + latestVersion.getName() );

        }
        catch ( MetadataVersionServiceException e )
        {
            String message = setVersionListErrorInfoInContext( context, metadataVersion, e );
            throw new MetadataSyncServiceException( message, e );
        }
        catch ( Exception ex )
        {
            if ( ex instanceof MetadataSyncServiceException )
            {
                log.error( ex.getMessage(), ex );
                throw ex;
            }

            String message = setVersionListErrorInfoInContext( context, metadataVersion, ex );
            log.error( message, ex );
            throw new MetadataSyncServiceException( message, ex );
        }

        return metadataVersionList;
    }

    public  MetadataSyncPreProcessor(
        SystemSettingManager systemSettingManager,
        MetadataVersionService metadataVersionService,
        MetadataVersionDelegate metadataVersionDelegate,
        TrackerSynchronization trackerSync,
        EventSynchronization eventSync,
        DataValueSynchronization dataValueSync,
        CompleteDataSetRegistrationSynchronization completeDataSetRegistrationSync );

}