class FileResourceCleanUpJob extends AbstractJob {

    @Override
    public void execute( JobConfiguration jobConfiguration )
    {
        FileResourceRetentionStrategy retentionStrategy = (FileResourceRetentionStrategy) systemSettingManager
            .getSystemSetting( SettingKey.FILE_RESOURCE_RETENTION_STRATEGY );

        List<Pair<String, String>> deletedOrphans = new ArrayList<>();

        List<Pair<String, String>> deletedAuditFiles = new ArrayList<>();

        // Delete expired FRs
        if ( !FileResourceRetentionStrategy.FOREVER.equals( retentionStrategy ) )
        {
            List<FileResource> expired = fileResourceService.getExpiredFileResources( retentionStrategy );
            expired.forEach( this::safeDelete );
            expired.forEach( fr -> deletedAuditFiles.add( ImmutablePair.of( fr.getName(), fr.getUid() ) ) );
        }

        // Delete failed uploads
        fileResourceService.getOrphanedFileResources().stream()
            .filter( fr -> !isFileStored( fr ) )
            .filter( this::safeDelete )
            .forEach( fr -> deletedOrphans.add( ImmutablePair.of( fr.getName(), fr.getUid() ) ) );

        if ( !deletedOrphans.isEmpty() )
        {
            log.info( String.format( "Deleted %d orphaned FileResources: %s", deletedOrphans.size(),
                prettyPrint( deletedOrphans ) ) );
        }

        if ( !deletedAuditFiles.isEmpty() )
        {
            log.info( String.format( "Deleted %d expired FileResource audits: %s", deletedAuditFiles.size(),
                prettyPrint( deletedAuditFiles ) ) );
        }
    }

}