package ExoSeq::APE::DnaCollection_FC;

$ExoSeq::APE::DnaCollection_FC::VERSION = '0.1';

use base qw(APE::FlushControllerFactory::ConcreteFlushController::DN_FlushController);
use strict;
use warnings;


=head1 NAME

ExoSeq::APE::DnaCollection_FC - XXX fill in.


=head1 SYNOPSIS

use ExoSeq::APE::DnaCollection_FC

my $object = ExoSeq::APE::DnaCollection_FC->new
  (
   XXX fill in options
   );


=head1 DESCRIPTION

XXX fill in description.


=head1 CONSTANTS

=over 5

=item TRUE

This is a boolean true constant.

=cut

use constant TRUE  => 1;


=item FALSE

This is a boolean false constant.

=cut

use constant FALSE => 0;

=item LOGIN

The login name used to connect to the database.

=cut

use constant LOGIN => 'snp';


=back

=head1 CONSTRUCTOR

=over 5

=item $object = ExoSeq::APE::DnaCollection_FC->new(option => value,...?);

The following arguments may be passed to the constructor so are
options for all derived classes of type Entity.

=over 5

=item example

Required. An example option.

=back

=cut

my %_attributes = ();


=head2 INSTANTIATION PROCESS

The new method for this object calls the _init() method on $self. If
$self is a derived class then it's _init() method will be called
giving it the chance to remove any arguments it requires from the
%args hash. If there is no _init() method in the derived class then
the _init() method in this class is called.

Derived classes implementing a _init() method should return the %args
hash to the base class:

package Derived::Class;

sub _init {
   my ($self,%args) = @_;
   my $argument = delete $args{classArgument};
   return $self->SUPER::_init(%args);
}

=cut


=head1 METHODS

=over 10

=item $plate->_init(%args);

Private method. This method is called by the new method during object
instantiation (see the INSTANTIATION process). The method removes any
of the arguments required by the object from the %args hash and
returns it.

See the INSTANTIATION section for information on how to use this
method in a derived class.

=cut

sub _init {
    my ($self,%args) = @_;
    foreach my $arg (keys(%args)) {
	$self->{"_".$arg} = delete $args{$arg}
	  if exists $_attributes{$arg};
    }

    ## Check for required attributes.
    foreach my $requiredArg (qw//) {
	die "Error: argument '$requiredArg' is required"
	  unless $self->{"_".$requiredArg};
    }

    return $self->SUPER::_init(%args);
}


=item example_get_method

XXX fill in attribute get method documentation.

=cut

foreach my $attName (keys(%_attributes)) {
    no strict 'refs';
    *{__PACKAGE__ . "::get\u$attName"} = sub { $_[0]->{"_".$attName} }
}


=item object_method

Overrides the base classes flush() method. Calls the base classes
flush() method before inserting a new status to the input entity of 16
'Sent to ExoSeq'.

=cut

sub flush {
    my $self = shift;
    my $result = $self->SUPER::flush();
    my $arrayingEntity  = $self->getArrayingEntity();
    my $user            = ${$self->getUserObj()};
    my $team            = $user->getWorkingTeam();
    my $idRole          = $team->getWorkingRole()->getRoleId();
    my $sqlEngine       = $self->getSqlEngine();
    my $dbh             = $self->getDbh();
    my $inEntity        = $arrayingEntity->getAtomicProcessList()->[0]->getInDataId();
    my ($p,$idDnaPlate) = $inEntity =~ /^(\w\w)(\d+)/;
    my $sessionId      = $arrayingEntity->getSessionId();
    my $programName    = $self->getProgramName();
    $sqlEngine->do('ExoSeq/APE/DnaCollection_FC::UpdateInEntityStatus',
		   [$idDnaPlate],$dbh);
    $sqlEngine->do('ExoSeq/APE/DnaCollection_FC::InsertInEntityStatus',
		   [$idDnaPlate,16,$idRole,$sessionId,$programName],$dbh);
    return $result;
}

1;

=back

=head1 ALSO SEE


=head1 AUTHOR

Simon Holroyd <holroyd@sanger.ac.uk>

=cut

