#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Raptor::Tracker::Command::DownloadAllExceptionsFile;
use strict;
use warnings;

use IO::File;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;
use RSApache::Response::Download;
use Common::Assert;

use lib '/app/tools/raptor/lib';
use Raptor::Tracker::Command::Main;

use Raptor::Command;
use base 'Raptor::Tracker::Command::Base';

sub cmd  { return "exceptionsdl"; }
sub area { return "tracker"; }

use constant kTemplate => '/app/tools/raptor/templates/tracker.xsl';

sub execute {
    my ($self) = @_;

    # Give any inherited methods the first crack at this.
    # (This checks for login and basic access permissions).
    #
    my $response = $self->SUPER::execute();
    return $response if $response;

    my $filename = $self->getAllExceptionsFilename;
    assert($filename);

    my $fh = new IO::File;
    open( $fh, $filename );

    my @stat     = $fh->stat;
    my $fileSize = $stat[7];

    my $clean_name = $self->_getUser()->ClientNameClean();
    return RSApache::Response::Download->new( $fh, 'application/octet-stream', $clean_name . "_all_exceptions.txt", $fileSize );
}

1;
