예제 #1
0
        protected virtual bool DoXmlLoad(out string submitFilePath)
        {
            submitFilePath = null;
            Type mappingAttributesType = typeof(Windsor.Node2008.WNOSPlugin.ICISNPDES_56.MappingAttributes);
            IDictionary <string, DbAppendSelectWhereClause>             selectClauses = Windsor.Node2008.WNOSPlugin.ICISNPDES_56.PayloadData.GetDefaultSelectClauses(_stagingDao);
            List <Windsor.Node2008.WNOSPlugin.ICISNPDES_56.PayloadData> payloads      =
                _objectsFromDatabase.LoadFromDatabase <Windsor.Node2008.WNOSPlugin.ICISNPDES_56.PayloadData>(_stagingDao, selectClauses, mappingAttributesType);

            // Remove payloads that don't contain any data
            if (payloads != null)
            {
                for (int i = payloads.Count - 1; i >= 0; i--)
                {
                    if (CollectionUtils.IsNullOrEmpty(payloads[i].Items))
                    {
                        // TSM: Is this log really necessary?
                        //AppendAuditLogEvent(string.Format("The payload with operation \"{0}\" will not be included in the submission because it does not contain any data", payloads[i].Operation.ToString()));
                        payloads.RemoveAt(i);
                    }
                }
            }

            if (CollectionUtils.IsNullOrEmpty(payloads))
            {
                _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Completed;
                _submissionTrackingDataType.WorkflowStatusMessage = "The staging database does not contain any payloads to submit";
                AppendAuditLogEvent(_submissionTrackingDataType.WorkflowStatusMessage + ", exiting plugin ...");
                SubmissionTrackingTableHelper.Update(_stagingDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);
                return(false);
            }

            AppendAuditLogEvent("The following ICIS payload(s) were loaded from the database: {0}", GetPayloadsDescription(payloads));

            Windsor.Node2008.WNOSPlugin.ICISNPDES_56.Document document = new Document();

            document.Payload = payloads.ToArray();
            document.Header  = CreateHeader();

            string tempFolder  = _settingsProvider.CreateNewTempFolderPath();
            string tempXmlPath = Path.Combine(tempFolder, ICIS_SUBMISSION_XML_FILENAME);
            string tempZipPath = Path.Combine(tempFolder, ICIS_SUBMISSION_ZIP_FILENAME);

            try
            {
                AppendAuditLogEvent("Serializing ICIS payload(s) to xml ...");

                _serializationHelper.Serialize(document, tempXmlPath);

                if (_validateXml)
                {
                    ValidateXmlFileAndAttachErrorsAndFileToTransaction(tempXmlPath, "xml_schema.xml_schema.zip",
                                                                       null, _dataRequest.TransactionId);
                }

                _compressionHelper.CompressFile(tempXmlPath, tempZipPath);

                _documentManager.AddDocument(_dataRequest.TransactionId, CommonTransactionStatusCode.Completed, null, tempZipPath);
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipPath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlPath);
            }

            submitFilePath = tempZipPath;

            return(true);
        }
        protected virtual bool DoProcessResponseDocuments(string localTransactionId, IList <string> documentNames, out Windsor.Node2008.WNOSDomain.Document zipResponseFile)
        {
            AppendAuditLogEvent("Attempting to process response documents for ICIS submission with transaction id \"{0}\"", _submissionTrackingDataType.SubmissionTransactionId);

            string responseZipFileName = FindResponseZipFileName(documentNames);

            AppendAuditLogEvent("Extracting response document content ...");

            zipResponseFile = _documentManager.GetDocumentByName(localTransactionId, responseZipFileName, true);

            string tempFolder = _settingsProvider.CreateNewTempFolderPath();

            _compressionHelper.UncompressDirectory(zipResponseFile.Content, tempFolder);

            string[] responseFiles = Directory.GetFiles(tempFolder);

            string responseAcceptedFilePath = FindResponseAcceptedFilePath(responseFiles);
            string responseRejectedFilePath = FindResponseRejectedFilePath(responseFiles);

            AppendAuditLogEvent("Loading response document content ...");

            AppendAuditLogEvent("Transforming accepted response file ...");
            string responseAcceptedTransformedFilePath = TransformResponseFile50(responseAcceptedFilePath);
            SubmissionResultList acceptedList          = _serializationHelper.Deserialize <SubmissionResultList>(responseAcceptedTransformedFilePath);

#if INCLUDE_TEST_SUBMIT_PROCESSOR
            if (DebugUtils.IsDebugging)
            {
                foreach (var submissionResultsDataType in acceptedList.SubmissionResult)
                {
                    if (string.IsNullOrEmpty(submissionResultsDataType.SubmissionTransactionId))
                    {
                        throw new ArgException("submissionResultsDataType.SubmissionTransactionId is null");
                    }
                }
            }
#endif // INCLUDE_TEST_SUBMIT_PROCESSOR

            AppendAuditLogEvent("Transforming rejected response file ...");
            string responseRejectedTransformedFilePath = TransformResponseFile50(responseRejectedFilePath);
            SubmissionResultList rejectedList          = _serializationHelper.Deserialize <SubmissionResultList>(responseRejectedTransformedFilePath);
#if INCLUDE_TEST_SUBMIT_PROCESSOR
            if (DebugUtils.IsDebugging)
            {
                foreach (var submissionResultsDataType in rejectedList.SubmissionResult)
                {
                    if (string.IsNullOrEmpty(submissionResultsDataType.SubmissionTransactionId))
                    {
                        throw new ArgException("submissionResultsDataType.SubmissionTransactionId is null");
                    }
                }
            }
#endif // INCLUDE_TEST_SUBMIT_PROCESSOR

            List <SubmissionResultsDataType> saveList = new List <SubmissionResultsDataType>(CollectionUtils.Count(acceptedList.SubmissionResult) +
                                                                                             CollectionUtils.Count(rejectedList.SubmissionResult));

            DateTime now = DateTime.Now;
            CollectionUtils.ForEach(acceptedList.SubmissionResult, delegate(SubmissionResultsDataType result)
            {
                //DebugUtils.AssertDebuggerBreak(result.SubmissionTransactionId == _submissionTrackingDataType.SubmissionTransactionId);
                result.CreatedDateTime = now;
                saveList.Add(result);
            });
            CollectionUtils.ForEach(rejectedList.SubmissionResult, delegate(SubmissionResultsDataType result)
            {
                //DebugUtils.AssertDebuggerBreak(result.SubmissionTransactionId == _submissionTrackingDataType.SubmissionTransactionId);
                result.CreatedDateTime = now;
                saveList.Add(result);
            });


            _baseDao.TransactionTemplate.Execute(delegate(Spring.Transaction.ITransactionStatus status)
            {
                try
                {
                    AppendAuditLogEvent("Saving response data to database ...");
                    Type mappingAttributesType = typeof(Windsor.Node2008.WNOSPlugin.ICISNPDES_50.MappingAttributes);

                    Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(saveList, _baseDao, false, mappingAttributesType);

                    AppendAuditLogEvent("Response data saved to database with the following insert row counts: {0}", CreateTableRowCountsString(tableRowCounts));
                }
                catch (Exception ex1)
                {
                    AppendAuditLogEvent("Failed to save response data to database, rolling back transaction: {0}", ExceptionUtils.GetDeepExceptionMessage(ex1));
                    throw;
                }

                ExecuteStoredProc();

                return(null);
            });

            return(true);
        }
예제 #3
0
        protected virtual WQXDataType GetWQXData(string transactionId, string docId,
                                                 out Windsor.Node2008.WNOSPlugin.WQX1XsdOrm.WQXDataType data1,
                                                 out WQXDeleteDataType deleteData, out string attachmentsFolderPath)
        {
            WQXDataType data = null;

            data1      = null;
            deleteData = null;
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            attachmentsFolderPath = null;
            string tempFolder = null;

            try
            {
                IHeaderDocumentHelper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (document.IsZipFile)
                {
                    tempFolder = _settingsProvider.CreateNewTempFolderPath();
                    AppendAuditLogEvent("Decompressing document to temporary folder");
                    _compressionHelper.UncompressDirectory(document.Content, tempFolder);
                    string[] xmlFiles = Directory.GetFiles(tempFolder, "*.xml");
                    if (xmlFiles.Length == 0)
                    {
                        throw new ArgException("Failed to locate a WQX xml file in the WQX data");
                    }
                    else if (xmlFiles.Length > 1)
                    {
                        throw new ArgException("More than one xml file was found in the WQX data");
                    }
                    tempXmlFilePath = xmlFiles[0];
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                XmlElement loadElement = null;
                try
                {
                    AppendAuditLogEvent("Attempting to load document with Exchange Header");
                    headerDocumentHelper.Load(tempXmlFilePath);
                    loadElement = headerDocumentHelper.GetPayload("Update-Insert");
                    if (loadElement == null)
                    {
                        loadElement = headerDocumentHelper.GetPayload("Delete");
                        if (loadElement == null)
                        {
                            throw new ArgumentException("The submitted document does not contain an \"Update-Insert\" or \"Delete\" payload");
                        }
                    }
                }
                catch (Exception)
                {
                    AppendAuditLogEvent("Document does not contain an Exchange Header");
                    // Assume, for now, that document does not have a header
                }

                AppendAuditLogEvent("Deserializing document data to WQX data");
                if (loadElement != null)
                {
                    try
                    {
                        data = _serializationHelper.Deserialize <WQXDataType>(loadElement);
                        attachmentsFolderPath = tempFolder;
                    }
                    catch (Exception)
                    {
                        AppendAuditLogEvent("Failed to deserialize WQX v2, trying WQX v1 ...");
                        try
                        {
                            data1 = _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.WQX1XsdOrm.WQXDataType>(loadElement);
                        }
                        catch (Exception)
                        {
                            AppendAuditLogEvent("Failed to deserialize WQX v1, trying WQX v2 Delete data ...");
                            deleteData = _serializationHelper.Deserialize <WQXDeleteDataType>(loadElement);
                        }
                    }
                }
                else
                {
                    try
                    {
                        data = _serializationHelper.Deserialize <WQXDataType>(tempXmlFilePath);
                        attachmentsFolderPath = tempFolder;
                    }
                    catch (Exception)
                    {
                        AppendAuditLogEvent("Failed to deserialize WQX v2, trying WQX v1 ...");
                        try
                        {
                            data1 = _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.WQX1XsdOrm.WQXDataType>(tempXmlFilePath);
                        }
                        catch (Exception)
                        {
                            AppendAuditLogEvent("Failed to deserialize WQX v1, trying WQX v2 Delete data ...");
                            deleteData = _serializationHelper.Deserialize <WQXDeleteDataType>(tempXmlFilePath);
                        }
                    }
                }
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteAllFilesAndFoldersInFolder(tempFolder);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(data);
        }