#!/usr/bin/perl package wcatp; ###################################################################################################### # wcatp.pl # # # # This Perl script executes the ATP.pm controller module. # # # # Created April 2007. # # Programmer: # # # # You must pass one of the following as an argument: # # 1 - All (entire process, note that current business rules dicate only 1 run per day) # # 2 - Preprocess (everything but submission of eligible files) # # 3 - Upload Override (no submissions, upload to Mainframe only) # # 4 - Diagnostics Only (Diagnostics distributed via email only) # # # # Maintenance/Notes # # ----------------- # # 04/26/2007 - Initial Release (Version 1.0). NJB. # ###################################################################################################### $VERSION = '1.0'; use lib '/workerscomp/sharedatp/modules'; use strict; use warnings; #Comment out prior to moving code to Production use ATP; my $runMode = $ARGV[0]; print "wcatp.pl - Run argument is $runMode\n"; my $returnCode; eval { my $objATP = ATP->new('wcatp','/workerscomp/wcatp'); $returnCode = $objATP->runProcess($runMode); }; if ($@) { print "$@\n"; exit 1; } else { if ($returnCode) { print "wcatp.pl - Execution completed successfully.\n"; exit 0; } else { print "wcatp.pl - Execution completed with handled errors, see logging for details...\n"; exit 1; } } #!/usr/bin/perl package ATP; ###################################################################################################### # ATP.pm # # # # This Perl module is the main controller of the Automated Transaction Processing system. # # # # Created April 2007. # # Programmer: # # # # Public Interface # # ---------------- # # new - Instantiate the object. You must pass the following parameters as scalars: # # systemName - System name, e.g. wcatp. # # baseDir - Base directory of installation. # # # # runProcess - Runs the process based upon the following parameter passed as a scalar: # # mode - 1 - All (entire process, note that current business rules dicate only 1 run # # per day) # # 2 - Preprocess (everything but submission of eligible files) # # 3 - Upload Override (no submissions, upload to Mainframe only) # # 4 - Diagnostics Only (Diagnostics distributed via email only) # # # # Maintenance/Notes # # ----------------- # # 04/26/2007 - Initial Release (Version 1.0). NJB. # ###################################################################################################### $VERSION = '1.0'; use strict; use warnings; #Comment out prior to moving code to Production use FDX; use FTP; use FileToObject; use TLProcessor; use Utils; use Zip; use ATPLogger; use ValidationManager; use TransactionBuilder; ### Public Methods ### ### Method new (constructor) ### sub new { my ($proto,$systemName,$baseDir) = @_; my $class = ref($proto) || $proto; my $self = {}; bless $self, $class; # set instance variables from caller $self->{_systemName} = $systemName || die "ATP.pm - System name not passed!"; $self->{_baseDir} = $baseDir || die "ATP.pm - Base directory not passed!"; $self->{_objFileToObjectInitial} = FileToObject->new('2'); # instantiate FileToObject in noLog mode -- can't log properly until params from config are loaded # obtain configuration file information my %configArgs = ( file => $self->{_baseDir} . '/config/' . $self->{_systemName} . '.cfg', returnObject => '3', delimiter => '3' ); my %config = $self->{_objFileToObjectInitial}->load(%configArgs); # set instance variables from config file $self->{_logMode} = $config{logmode}; $self->{_standardOut} = $config{standardout}; $self->{_standardErr} = $config{standarderr}; $self->{_historyLog} = $config{historylog}; $self->{_region} = $config{region}; $self->{_bypassSFTP} = $config{bypasssftp}; $self->{_sftpServer} = $config{sftpserver}; $self->{_sftpUid} = $config{sftpuid}; $self->{_sftpPwd} = $config{sftppwd}; $self->{_sftpLocalIn} = $config{sftplocalin}; $self->{_temp} = $config{temp}; $self->{_sftpRemoteCD} = $config{sftpremotecd}; $self->{_textFiles} = $config{textfiles}; $self->{_bypassPGP} = $config{bypasspgp}; $self->{_pgpServer} = $config{pgpserver}; $self->{_pgpUID} = $config{pgpuid}; $self->{_pgpPWD} = $config{pgppwd}; $self->{_pgpDirTemp} = $config{pgpdirtemp}; $self->{_pgpRetries} = $config{pgpretries}; $self->{_pgpSleepInterval} = $config{pgpsleepinterval}; $self->{_highLevelNode} = $config{highlevelnode}; $self->{_mfServer} = $config{mfserver}; $self->{_mfUID} = $config{mfuid}; $self->{_mfPWD} = $config{mfpwd}; $self->{_localTransferred} = $config{localtransferred}; $self->{_dirTemp} = $config{dirtemp}; $self->{_mfRetries} = $config{mfretries}; $self->{_mfSleepInterval} = $config{mfsleepinterval}; $self->{_localParentDir} = $config{localparentdir}; $self->{_remoteRunJCLPDS} = $config{remoterunjclpds}; $self->{_remoteSubmissionFileRecordFormat} = $config{remotesubmissionfilerecordformat}; $self->{_remoteSubmissionFileLogicalRecordLength} = $config{remotesubmissionfilelogicalrecordlength}; $self->{_serverSMTP} = $config{serversmtp}; $self->{_subjectBiz} = $config{subjectbiz}; $self->{_subjectPSupport} = $config{subjectpsupport}; $self->{_toBiz} = $config{tobiz}; $self->{_toPSupport} = $config{topsupport}; $self->{_ccBiz} = $config{ccbiz}; $self->{_ccPSupport} = $config{ccpsupport}; $self->{_fromBiz} = $config{frombiz}; $self->{_fromPSupport} = $config{frompssupport}; $self->{_tempDir} = $config{tempdir}; my %argsLogger = ( logMode => $self->{_logMode}, standardOut => $self->{_standardOut}, standardErr => $self->{_standardErr}, historyLog => $self->{_historyLog} ); $self->{_objLogger} = ATPLogger->new(%argsLogger); # instantiate logger $self->{_objJCL} = JCL->new(); # instantiate JCL $self->{_objFileToObject} = FileToObject->new(); # instantiate file to object # instance variables for jcl data stored in objects $self->{_allSteps} = undef; $self->{_allProjRes} = undef; $self->{_jobCard} = undef; return $self; } ### Method runProcess ### sub runProcess { my ($self,$mode) = @_; ### FIX this GHKHHJGHJKHJKHKHHJKLNKL)()()()()()()()()()()()()()()(GHHGJHGJBJHMB print STDOUT "argv 0 is $ARGV[0]\n"; if (defined($mode)) { # general setup $self->setup(); if ($mode eq '4') { # run diagnostics only $self->execDiagnostics(); return 1; } else { if (($mode ne '1') && ($mode ne '2') && ($mode ne '3')) { my $message = 'ATP.pm - Mode ' . $mode . 'is invalid!'; $self->{_objLogger}->error($message); exit 0; } else { # run process $self->processController($mode); return 1; } } } else { die "ATP.pm - Run mode was not passed!"; } } ### Private Methods ### ### Method DESTROY (destructor) ### #sub DESTROY #{ #} ### Method setup ### sub setup { my ($self) = @_; # load JCL and Job Card files in objects $self->loadJCLObjects(); } ### Method loadJCLObjects ### sub loadJCLObjects { my ($self) = @_; my %custJCLArgs = ( file => $self->{_baseDir} . '/config/' . $self->{_systemName} . '_jcl.list', returnObject => '2', delimiter => '2' ); my @file = $self->{_objFileToObject}->load(%custJCLArgs); $self->{_allSteps} = \$self->{_objJCL}->genAllSteps(@file); $self->{_allProjRes} = \$self->{_objJCL}->genAllProjRes(@file); my %jobCardArgs = ( file => $self->{_baseDir} . '/config/' . $self->{_systemName} . '_jobcard.list', returnObject => '3', delimiter => '3' ); $self->{_jobCard} = \$self->{_objFileToObject}->load(%jobCardArgs); return 1; } ### Method processController ### sub processController { my ($self, $mode) = @_; if (! $self->{_bypassSFTP} =~ /y/i) { # download all files from SecureFTP my %argsSecureFTP = ( site => $self->{_sftpServer}, uid => $self->{_sftpUid}, pwd => $self->{_sftpPwd}, localIn => $self->{_sftpLocalIn}, localTemp => $self->{_sftpLocalTemp}, remoteCD => $self->{_sftpRemoteCD} ); my $objFDX = FDX->new(%argsSecureFTP); $objFDX->receiveAll(1); # dynamically move/unzip files my $objZip = Zip->new(); my %argsZip = ( sourceDir => $self->{_sftpLocalIn}, targetDir => $self->{_textFiles}, errorDir => $self->{_temp} ); $objZip->moveAll(%argsZip); } if (! $self->{_bypassPGP} =~ /y/i) { # download all files from PGP my %argsPGP = ( site => $self->{_pgpServer}, uid => $self->{_pgpUID}, pwd => $self->{_pgpPWD}, localTransferred => undef, dirTemp => $self->{_pgpDirTemp}, retries => $self->{_pgpRetries}, sleepInterval => $self->{_pgpSleepInterval} ); my $objPGP = FTP->new(%argsPGP); my %argsGet = ( remoteCD => 'IN', mode => '1', regex => '/!pgp$/ && /!asc$/i', ); $objPGP->getAll(%argsGet); } # validation manager to call application specific validations or do nothing my $objValidationManager = ValidationManager->new(); my %argsValidationManager = { baseDir => $self->{_baseDir} }; $objValidationManager->validate(%argsValidationManager); if ($mode ne '2') { # transaction builder to build transactions my $sourceDir = $self->{_baseDir} . '/textfiles'; my $targetParentDir = $self->{_baseDir} . '/transactions'; my $objTransBuilder = TransactionBuilder->new(); my $bypassSubmission; if ($mode eq '3') { $bypassSubmission = '2'; } else { $bypassSubmission = '1'; } my %argsTransBuilder = ( exceptionFile => $self->{_baseDir} . '/config/' . $self->{_systemName} . '_exception.list', processedFile => $self->{_baseDir} . '/config/' . $self->{_systemName} . '_processed.list', jCLfile => $self->{_baseDir} . '/config/' . $self->{_systemName} . '_jcl.list', jobCardFile => $self->{_baseDir} . '/config/' . $self->{_systemName} . '_jobcard.list', sourceDir => $sourceDir, targetParentDir => $targetParentDir, bypassSubmission => $bypassSubmission, highLevelNode => $self->{_highLevelNode} ); $objTransBuilder->generateTransactions(%argsTransBuilder); # FTP files in transactions to the mainframe, submitting same when applicable my %argsFTP = ( site => $self->{_mfServer}, uid => $self->{_mfUID}, pwd => $self->{_mfPWD}, localTransferred => $self->{_localTransferred}, dirTemp => $self->{_dirTemp}, retries => $self->{_mfRetries}, sleepInterval => $self->{_mfSleepInterval} ); my $objFTP = FTP->new(%argsFTP); my %argsSend = ( localParentDir => $self->{_localParentDir}, remoteRunJCLPDS => $self->{_remoteRunJCLPDS}, remoteSubmissionFileRecordFormat => $self->{_remoteSubmissionFileRecordFormat}, remoteSubmissionFileLogicalRecordLength => $self->{_remoteSubmissionFileLogicalRecordLength} ); $objFTP->sendTransactions(%argsSend); } # send emails out and close logging my %email = ( serverSMTP => $self->{_serverSMTP}, subjectBiz => $self->{_subjectBiz}, subjectPSupport => $self->{_subjectPSupport}, toBiz => $self->{_toBiz}, toPSupport => $self->{_toPSupport}, ccBiz => $self->{_ccBiz}, ccPSupport => $self->{_ccPSupport}, fromBiz => $self->{_fromBiz}, fromPSupport => $self->{_fromPSupport}, tempDir => $self->{_tempDir} ); $self->{_objLogger}->sendEmail(%email); } ### Method execDiagnostics ### sub execDiagnostics { my ($self) = @_; $self->{_objLogger}->info("ATP.pm - Diagnostics not yet implemented..."); return 1; } 1;