Example #1
0
        protected virtual bool DoExtract()
        {
            if (!_submissionTrackingDataType.ETLCompletionDateTimeSpecified || !_submissionTrackingDataType.DETChangeCompletionDateTimeSpecified)
            {
                // Attempt to run the ETL to populate staging tables
                if (_submissionTrackingDataType.ETLCompletionDateTimeSpecified || _submissionTrackingDataType.DETChangeCompletionDateTimeSpecified)
                {
                    // Both must be specified, or neither must be specified
                    throw new ArgException("Both ETL completion dates have not been set for row {0} in the submission tracking table",
                                           _submissionTrackingDataTypePK);
                }
                if (string.IsNullOrEmpty(_storedProcName))
                {
                    AppendAuditLogEvent("The \"{0}\" config param has not been specified for the service and the ETL stored procedure has not executed, so the service cannot continue, exiting plugin ...",
                                        CONFIG_PARAM_ETL_NAME);
                    return(false);
                }
                _submissionTrackingDataTypePK = DoExtract(this, _etlDao, _storedProcName, _commandTimeout);
                if (_submissionTrackingDataTypePK == null)
                {
                    AppendAuditLogEvent("The ETL stored procedure indicated that this service should not continue, exiting plugin ...");
                    return(false);
                }
                AppendAuditLogEvent("The ETL stored procedure returned \"{0}\" for the submission tracking PK ...", _submissionTrackingDataTypePK);


                try
                {
                    AppendAuditLogEvent("Attempting to read the submission tracking row with PK \"{0}\" ...", _submissionTrackingDataTypePK);
                    _submissionTrackingDataType = SubmissionTrackingTableHelper.GetActiveSubmissionTrackingElement(_stagingDao, _submissionTrackingDataTypePK);
                    AppendAuditLogEvent("Successfully read the submission tracking row with PK \"{0}\".", _submissionTrackingDataTypePK);
                }
                catch (Exception ex)
                {
                    AppendAuditLogEvent("Failed to read the submission tracking row with PK \"{0}\" with exception: {1}",
                                        _submissionTrackingDataTypePK, ExceptionUtils.GetDeepExceptionMessage(ex));
                    throw;
                }
            }
            else
            {
                AppendAuditLogEvent("The ETL stored procedure has already run as referenced by row {0} in the submission tracking table with status \"{1}\" ...",
                                    _submissionTrackingDataTypePK, _submissionTrackingDataType.WorkflowStatus.ToString());
            }
            return(true);
        }
Example #2
0
        public override void ProcessTask(string requestId)
        {
            ProcessTaskInit(requestId);

#if !XML_LOAD_ONLY
            _submissionTrackingDataType = SubmissionTrackingTableHelper.GetActiveSubmissionTrackingElement(_stagingDao, out _submissionTrackingDataTypePK);

            if (_submissionTrackingDataType == null)
            {
                _submissionTrackingDataType = new SubmissionTrackingDataType();
            }

            if (_submissionTrackingDataType.WorkflowStatus == TransactionStatusCode.Pending && _submissionTrackingDataType.ETLCompletionDateTimeSpecified == false)
            {
                AppendAuditLogEvent("Previous ETL execution in the tracking table with primary key \"{0}\" did not complete due to unrecoverable database error. Setting transaction to Failed."
                                    , _submissionTrackingDataTypePK);
                // Update submission status in tracking table
                _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Failed;
                _submissionTrackingDataType.WorkflowStatusMessage = "ETL did not complete due to unrecoverable database error";
                SubmissionTrackingTableHelper.Update(_stagingDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);

                //create a new submission tracking record for the current workflow execution
                _submissionTrackingDataType   = new SubmissionTrackingDataType();
                _submissionTrackingDataTypePK = null;
            }
            else if (_submissionTrackingDataType.SubmissionDateTimeSpecified)
            {
                DebugUtils.AssertDebuggerBreak(_submissionTrackingDataTypePK != null);
                AppendAuditLogEvent("There is a pending partner submission in the tracking table with primary key \"{0}\", exiting plugin ...",
                                    _submissionTrackingDataTypePK);
                return;
            }
#endif // !XML_LOAD_ONLY
            try
            {
#if !XML_LOAD_ONLY
                // Attempt to run the ETL to populate staging tables
                if (!DoExtract())
                {
                    return;
                }
                DebugUtils.AssertDebuggerBreak(_submissionTrackingDataTypePK != null);
#endif // !XML_LOAD_ONLY

                // Attempt to load the submission file from staging
                string submitFilePath;
                if (!DoXmlLoad(out submitFilePath))
                {
                    return;
                }

#if !XML_LOAD_ONLY
                // Attempt to submit file
                string submitTransactionId;
                if (!DoSubmission(submitFilePath, out submitTransactionId))
                {
                    return;
                }

                // Update submission status in tracking table
                _submissionTrackingDataType.WorkflowStatus              = TransactionStatusCode.Pending;
                _submissionTrackingDataType.WorkflowStatusMessage       = "The ICIS data has been submitted";
                _submissionTrackingDataType.SubmissionDateTime          = DateTime.Now;
                _submissionTrackingDataType.SubmissionDateTimeSpecified = true;
                _submissionTrackingDataType.SubmissionTransactionId     = submitTransactionId;
                SubmissionTrackingTableHelper.Update(_stagingDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);
#endif // !XML_LOAD_ONLY
            }
#if XML_LOAD_ONLY
            catch (Exception)
            {
                throw;
            }
#else // XML_LOAD_ONLY
            catch (Exception ex)
            {
                if (_submissionTrackingDataTypePK != null)
                {
                    _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Failed;
                    _submissionTrackingDataType.WorkflowStatusMessage = string.Format("An error occurred during processing: {0}", ExceptionUtils.GetDeepExceptionMessage(ex));
                    SubmissionTrackingTableHelper.Update(_stagingDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);
                }
                throw;
            }
#endif // !XML_LOAD_ONLY
        }
        public virtual void ProcessTask(string requestId)
        {
            ProcessTaskInit(requestId);

            _submissionTrackingDataType = SubmissionTrackingTableHelper.GetActiveSubmissionTrackingElement(_baseDao, out _submissionTrackingDataTypePK);
            if (_submissionTrackingDataType == null)
            {
                AppendAuditLogEvent("There are no pending submissions in the submission tracking table, existing plugin ...");
                return;
            }
            DebugUtils.AssertDebuggerBreak(_submissionTrackingDataTypePK != null);
            if (!_submissionTrackingDataType.SubmissionDateTimeSpecified)
            {
                AppendAuditLogEvent("There is a pending row in the submission tracking table, \"{0},\" but it does not have a submission date/time yet, existing plugin ...",
                                    _submissionTrackingDataTypePK);
                return;
            }
            try
            {
                if (string.IsNullOrEmpty(_submissionTrackingDataType.SubmissionTransactionId))
                {
                    throw new ArgumentException("There is a pending row in the submission tracking table, \"{0},\" with a submission date/time, but the submission transaction id is missing",
                                                _submissionTrackingDataTypePK);
                }

                // Attempt to get status of the active submission and download the response documents
                IList <string> documentNames;
                string         localTransactionId;

                if (!DoGetStatusAndDownloadDocuments(out localTransactionId, out documentNames))
                {
                    return;
                }

                Windsor.Node2008.WNOSDomain.Document zipResponseFile;
                if (!DoProcessResponseDocuments(localTransactionId, documentNames, out zipResponseFile))
                {
                    return;
                }

                _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Completed;
                _submissionTrackingDataType.WorkflowStatusMessage = string.Format("Successfully downloaded response data and inserted into database");
                SubmissionTrackingTableHelper.Update(_baseDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);

                DoEmailNotifications(zipResponseFile, localTransactionId);
            }
            catch (WorkflowStatusFailedException workflowStatusFailedException)
            {
                string errorMessage =
                    string.Format("An error occurred during processing: {0}",
                                  ExceptionUtils.GetDeepExceptionMessage(workflowStatusFailedException));
                if (_submissionTrackingDataTypePK != null)
                {
                    _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Failed;
                    _submissionTrackingDataType.WorkflowStatusMessage = errorMessage;
                    SubmissionTrackingTableHelper.Update(_baseDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);
                }
                throw new ArgException(errorMessage);
            }
            catch (Exception)
            {
                // Continue on, do not set workflow status to failed, per Bill
                throw;
            }
        }