internal string Execute(DateTime changeDate, string targetXmlPath, ISerializationHelper serializationHelper,
                                ICompressionHelper compressionHelper, HEREBaseService hereBaseService)
        {
            hereBaseService.AppendAuditLogEvent("Getting data.");

            CAFO ds = _dbService.GetCAFOAddData(changeDate);

            hereBaseService.AppendAuditLogEvent("Data retrieved. (Record Count = {0}).", ds.CAFO_FAC.Rows.Count);

            hereBaseService.AppendAuditLogEvent("Transforming results.");

            CAFOFacilityList facs = CAFOTransform.Transform(ds);

            if (facs == null || facs.CAFOFacilities == null || facs.CAFOFacilities.Count == 0)
            {
                return(null);
            }
            else
            {
                hereBaseService.AppendAuditLogEvent("Results transformed: (Record Count: {0})", facs.CAFOFacilities.Count);

                hereBaseService.AppendAuditLogEvent(
                    "Serializing transformed results to file (File = {0}).",
                    targetXmlPath);

                serializationHelper.Serialize(facs, targetXmlPath);

                return(compressionHelper.CompressFile(targetXmlPath));
            }
        }
        protected virtual string GenerateSubmissionFileAndAddToTransaction(T data)
        {
            string submitFile = GenerateSubmissionFile(data);
            string zippedFile = _settingsProvider.NewTempFilePath(".zip");

            try
            {
                _compressionHelper.CompressFile(submitFile, zippedFile);

                AppendAuditLogEvent("Attaching submission document to transaction \"{0}\"",
                                    _dataRequest.TransactionId);
                _documentManager.AddDocument(_dataRequest.TransactionId,
                                             CommonTransactionStatusCode.Completed,
                                             null, zippedFile);
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to attach submission document \"{0}\" to transaction \"{1}\" with exception: {2}",
                                    submitFile, _dataRequest.TransactionId, ExceptionUtils.ToShortString(e));
                FileUtils.SafeDeleteFile(zippedFile);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(submitFile);
            }
            return(zippedFile);
        }
Exemple #3
0
        protected virtual void AttachSubmissionResponseToTransaction(string transactionId)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();
            string tempZipFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                Windsor.Node2008.WNOSPlugin.ICISAIR_54.SubmissionResponseDataType response =
                    new Windsor.Node2008.WNOSPlugin.ICISAIR_54.SubmissionResponseDataType();
                response.CreationDate          = response.SubmissionDate = DateTime.Now;
                response.TransactionIdentifier = transactionId;

                _serializationHelper.Serialize(response, tempXmlFilePath);

                string zipDocumentName         = string.Format("{0}_Response.xml", transactionId);
                string transactionDocumentName = Path.ChangeExtension(zipDocumentName, ".zip");

                _compressionHelper.CompressFile(tempXmlFilePath, zipDocumentName, tempZipFilePath);

                var document =
                    new Windsor.Node2008.WNOSDomain.Document(transactionDocumentName, CommonContentType.ZIP,
                                                             File.ReadAllBytes(tempZipFilePath));
                _documentManager.AddDocument(transactionId, CommonTransactionStatusCode.Completed, null, document);
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to add response file to transaction \"{0}\" with error: {1}",
                                    transactionId, ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
Exemple #4
0
        protected string CreateSubmissionFile(Organization data)
        {
            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");
            string tempXmlFilePath = _settingsProvider.NewTempFilePath(".xml");

            try
            {
                var content = new ATTAINSDataType()
                {
                    Organization = new Organization[] { data }
                };
                AppendAuditLogEvent("Serializing data to an xml file");
                _serializationHelper.Serialize(content, tempXmlFilePath);

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

                AppendAuditLogEvent("Generating submission file (with an exchange header) from results");

                IHeaderDocument2Helper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                // Configure the submission exchange header and add header to xml file
                headerDocumentHelper.Configure(_authorName, _organizationName, _documentTitle, FLOW_NAME,
                                               null, _senderContact, null, null);
                headerDocumentHelper.AddNotification(_senderAddress);

                string tempXmlFilePath2 = _settingsProvider.NewTempFilePath(".xml");
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempXmlFilePath);

                    headerDocumentHelper.AddPayload(_payloadOperation, doc.DocumentElement);

                    headerDocumentHelper.Serialize(tempXmlFilePath2);

                    _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath);
                }
                finally
                {
                    FileUtils.SafeDeleteFile(tempXmlFilePath2);
                }
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(tempZipFilePath);
        }
        internal string Execute(DateTime changeDate, string targetXmlPath, ISerializationHelper serializationHelper,
                                ICompressionHelper compressionHelper, HEREBaseService hereBaseService)
        {
            hereBaseService.AppendAuditLogEvent("Getting data.");

            HERE10.DomainDataSet ds = _dbService.GetDomainData(changeDate);

            hereBaseService.AppendAuditLogEvent("Data retrieved. (List Count = {0}).", ds.List.Rows.Count);

            hereBaseService.AppendAuditLogEvent("Transforming results.");

            List <HERE10.DomainList> lists = new List <HERE10.DomainList>();

            foreach (HERE10.DomainDataSet.ListRow listRow in ds.List.Rows)
            {
                HERE10.DomainList item = new HERE10.DomainList();

                item.DomainListNameText     = listRow.ListName;
                item.OriginatingPartnerName = listRow.ListOwnerName;

                List <DomainValueItemDataType> listItems = new List <DomainValueItemDataType>();

                foreach (HERE10.DomainDataSet.ListItemRow listItemRow in listRow.GetListItemRows())
                {
                    DomainValueItemDataType listItem = new DomainValueItemDataType();

                    listItem.ItemCode            = listItemRow.ItemCode;
                    listItem.ItemText            = listItemRow.ItemValue;
                    listItem.ItemDescriptionText = listItemRow.ItemDesc;

                    listItems.Add(listItem);
                }

                item.DomainListItem = listItems.ToArray();

                lists.Add(item);
            }

            if (lists.Count == 0)
            {
                return(null);
            }
            else
            {
                HERE10.DomainValueListDataType domain = new HERE10.DomainValueListDataType();
                domain.DomainList = lists.ToArray();

                hereBaseService.AppendAuditLogEvent("Results transformed.");

                hereBaseService.AppendAuditLogEvent(
                    "Serializing transformed results to file (File = {0}).",
                    targetXmlPath);

                serializationHelper.Serialize(domain, targetXmlPath);

                return(compressionHelper.CompressFile(targetXmlPath));
            }
        }
Exemple #6
0
        internal string Execute(DateTime changeDate, string flowName, string targetXmlPath,
                                ISerializationHelper serializationHelper, ICompressionHelper compressionHelper,
                                IObjectsFromDatabase objectsFromDatabase,
                                IAppendAuditLogEvent appendAuditLogEvent)
        {
            appendAuditLogEvent.AppendAuditLogEvent("Querying TANKS data ...");

            string whereQuery =
                string.Format("FAC_SITE_IDEN IN (SELECT ST_FAC_IND FROM CHANGED_FACILITIES WHERE IS_DELETED = 0 AND UPPER(FLOW_TYPE) = UPPER('{0}') AND UPDATE_DATE >= '{1}')",
                              flowName, changeDate.ToString("dd-MMM-yyyy").ToUpper());

            Dictionary <string, DbAppendSelectWhereClause> selectClauses = new Dictionary <string, DbAppendSelectWhereClause>();

            selectClauses.Add("TANKS_FAC_SITE", new DbAppendSelectWhereClause(whereQuery, null));
            List <TanksSubmissionDataType> dataList =
                objectsFromDatabase.LoadFromDatabase <TanksSubmissionDataType>(_baseDao, selectClauses);

            TanksSubmissionDataType data;

            if (CollectionUtils.IsNullOrEmpty(dataList))
            {
                appendAuditLogEvent.AppendAuditLogEvent("Did not find any TANKS data in database.");
                return(null);
            }
            else if (dataList.Count > 1)
            {
                throw new InvalidOperationException("More than one set of TANKS data was found in database.");
            }
            else
            {
                data = dataList[0];
                if (CollectionUtils.IsNullOrEmpty(data.TanksFacilitySite))
                {
                    appendAuditLogEvent.AppendAuditLogEvent("Did not find any tanks facilities.");
                    return(null);
                }
                else
                {
                    appendAuditLogEvent.AppendAuditLogEvent("Found {0} facilities and {1} unique tanks.",
                                                            data.TanksFacilitySite.Length,
                                                            GetUniqueTankCount(data));
                }
            }

            appendAuditLogEvent.AppendAuditLogEvent(
                "Serializing transformed results to file (File = {0}).",
                targetXmlPath);

            serializationHelper.Serialize(data, targetXmlPath);

            return(compressionHelper.CompressFile(targetXmlPath));
        }
Exemple #7
0
        public void ProcessSolicit(string requestId)
        {
            AppendAuditLogEvent("Initializing {0} plugin ...", this.GetType().Name);

            GetServiceImplementation(out _serializationHelper);
            GetServiceImplementation(out _compressionHelper);
            GetServiceImplementation(out _requestManager);
            GetServiceImplementation(out _documentManager);
            GetServiceImplementation(out _settingsProvider);

            _baseDao = ValidateDBProvider(SOURCE_PROVIDER_KEY, typeof(NamedNullMappingDataReader));

            TryGetConfigParameter(CONFIG_COMPRESS_RESULTS, ref _compressResults);

            AppendAuditLogEvent("Loading request with id \"{0}\"", requestId);
            _dataRequest = _requestManager.GetDataRequest(requestId);
            AppendAuditLogEvent("Request loaded: {0}", _dataRequest);

            //get params
            GetParameters();

            //call the build here
            string results = GetAssessmentData(_cycle, _huc, _county, _waterbody, _waterType, _IRCategory);

            string tempXmlPath = _settingsProvider.NewTempFilePath(".xml");

            using (StreamWriter outfile = new StreamWriter(tempXmlPath))
            {
                outfile.Write(results);
            }

            AppendAuditLogEvent("Attaching submission document to transaction \"{0}\"", _dataRequest.TransactionId);

            if (_compressResults)
            {
                //.zip the results before returning
                string tempZipPath = _settingsProvider.NewTempFilePath(".zip");
                _compressionHelper.CompressFile(tempXmlPath, tempZipPath);
                _documentManager.AddDocument(_dataRequest.TransactionId,
                                             CommonTransactionStatusCode.Completed, null, tempZipPath);
            }
            else
            {
                _documentManager.AddDocument(_dataRequest.TransactionId,
                                             CommonTransactionStatusCode.Completed, null, tempXmlPath);
            }
        }
Exemple #8
0
        protected string GenerateSubmissionFile(EMTSDataType data)
        {
            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");
            string tempXmlFilePath = _settingsProvider.NewTempFilePath(".xml");

            try
            {
                _serializationHelper.Serialize(data, tempXmlFilePath);

                AppendAuditLogEvent("Generating submission file (with an exchange header) from results");

                IHeaderDocument2Helper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);
                // Configure the submission header helper
                headerDocumentHelper.Configure(_authorName, _settingsProvider.NodeOrganizationName, EMTS_FLOW_NAME,
                                               EMTS_FLOW_NAME, string.Empty, string.Empty, null);

                string tempXmlFilePath2 = _settingsProvider.NewTempFilePath(".xml");
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempXmlFilePath);

                    headerDocumentHelper.AddPayload(string.Empty, doc.DocumentElement);

                    headerDocumentHelper.Serialize(tempXmlFilePath2);

                    _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath);
                }
                finally
                {
                    FileUtils.SafeDeleteFile(tempXmlFilePath2);
                }
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(tempZipFilePath);
        }
        public void ProcessSolicit(string requestId)
        {
            try
            {
                AppendAuditLogEvent("Getting request...");
                LOG.DebugEnter(MethodBase.GetCurrentMethod(), requestId);

                LazyInit();

                DataRequest request = _requestManager.GetDataRequest(requestId);

                AppendAuditLogEvent("Getting data from request...");
                object returnData = GetObjectFromRequest(request);

                AppendAuditLogEvent("Serializing data to file...");
                LOG.Debug("Serializing results to file...");
                string serializedFilePath = _serializationHelper.SerializeToTempFile(returnData);
                LOG.Debug("Serialized file path: " + serializedFilePath);

                AppendAuditLogEvent("Compressing serialized data...");
                LOG.Debug("Compressing serialized file...");
                string compressedFilePath = _compressionHelper.CompressFile(serializedFilePath);
                LOG.Debug("Compressed file path: " + compressedFilePath);

                AppendAuditLogEvent("Saving compressed data...");
                LOG.Debug("Saving data");
                _documentManager.AddDocument(request.TransactionId,
                                             CommonTransactionStatusCode.Processed,
                                             "Request Processed: " + request.ToString(),
                                             compressedFilePath);

                AppendAuditLogEvent("Plugin done");
                LOG.Debug("OK");
            }
            catch (Exception ex)
            {
                LOG.Error(ex);
                AppendAuditLogEvent("Error: " + ex.StackTrace);
                throw new ApplicationException("Error while executing plugin", ex);
            }
        }
        internal string Execute(DateTime changeDate, string targetXmlPath, ISerializationHelper serializationHelper,
                                ICompressionHelper compressionHelper, HEREBaseService hereBaseService)
        {
            hereBaseService.AppendAuditLogEvent("Getting data.");

            Tier2DataSet ds = _dbService.GetTier2DataSet(changeDate);

            hereBaseService.AppendAuditLogEvent("Data retrieved. (Record Count = {0}).",
                                                ds.T2_SUBMISSION.Rows.Count);

            hereBaseService.AppendAuditLogEvent("Transforming results.");

            TierIIDataType facs = Tier2Transform.Transform(ds);

            if (facs == null || facs.Submission == null || facs.Submission.Length == 0)
            {
                return(null);
            }
            else
            {
                hereBaseService.AppendAuditLogEvent("Results transformed. (Record Count = {0}).",
                                                    facs.Submission.Length);

                hereBaseService.AppendAuditLogEvent("Serializing transformed results to file (File = {0}).",
                                                    targetXmlPath);

                serializationHelper.Serialize(facs, targetXmlPath);

                hereBaseService.AppendAuditLogEvent("Transformed results Serialized.");

                if (compressionHelper != null)
                {
                    return(compressionHelper.CompressFile(targetXmlPath));
                }
                else
                {
                    return(targetXmlPath);
                }
            }
        }
Exemple #11
0
        protected virtual string GenerateQuerySolicitFile(BeachDataSubmissionDataType data)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath(".xml");
            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");

            try
            {
                AppendAuditLogEvent("Generating submission file from results");
                _serializationHelper.Serialize(data, tempXmlFilePath);
                _compressionHelper.CompressFile(tempXmlFilePath, tempZipFilePath);
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(tempZipFilePath);
        }
Exemple #12
0
        public void ProcessSolicit(string requestId)
        {
            LOG.DebugEnter(MethodBase.GetCurrentMethod(), requestId);

            LazyInit();

            _dataRequest = _requestManager.GetDataRequest(requestId);

            if (TryGetParameter(_dataRequest, PARAM_NAAS_SUBMIT_USERNAME, 0, ref _submitUsername))
            {
                if (_naasUsernameToPasswordMap == null)
                {
                    throw new ArgumentException(string.Format("A request parameter \"{0}\" = \"{1}\" was specified, but the service does not specify a \"{2}\" config parameter",
                                                              PARAM_NAAS_SUBMIT_USERNAME, _submitUsername, CONFIG_NAAS_USER_MAPPING_FILE_PATH));
                }
                if (!_naasUsernameToPasswordMap.ContainsKey(_submitUsername.ToUpper()))
                {
                    throw new ArgumentException(string.Format("A request parameter \"{0}\" = \"{1}\" was specified, but the username was not found in the mapping file specified by the \"{2}\" config parameter",
                                                              PARAM_NAAS_SUBMIT_USERNAME, _submitUsername, CONFIG_NAAS_USER_MAPPING_FILE_PATH));
                }
                UserSubmitInfo userSubmitInfo = _naasUsernameToPasswordMap[_submitUsername.ToUpper()];
                _rcraInfoUserId = userSubmitInfo.RCRAInfoUserID;
            }

            object returnData = GetObjectFromRequest(_dataRequest);

            string serializedFilePath = null;

            if (_addHeader)
            {
                LOG.Debug("Serializing results and making header...");
                AppendAuditLogEvent("Serializing results and making header...");
                serializedFilePath = MakeHeaderFile(returnData);
            }
            else
            {
                LOG.Debug("Serializing results to file...");
                AppendAuditLogEvent("Serializing results to file...");
                serializedFilePath = _serializationHelper.SerializeToTempFile(returnData);
                if (_validateXml)
                {
                    ValidateXmlFileAndAttachErrorsAndFileToTransaction(serializedFilePath, "xml_schema.xml_schema.zip",
                                                                       null, _dataRequest.TransactionId);
                }
            }

            LOG.Debug("Serialized file path: " + serializedFilePath);
            AppendAuditLogEvent("Serialized file path: " + serializedFilePath);

            LOG.Debug("Compressing serialized file...");
            AppendAuditLogEvent("Compressing serialized file...");
            string compressedFilePath = _compressionHelper.CompressFile(serializedFilePath);

            LOG.Debug("Compressed file path: " + compressedFilePath);
            AppendAuditLogEvent("Compressed file path: " + compressedFilePath);

            LOG.Debug("Adding document...");
            AppendAuditLogEvent("Adding document...");
            _documentManager.AddDocument(_dataRequest.TransactionId,
                                         CommonTransactionStatusCode.Processed,
                                         "Request Processed: " + _dataRequest.ToString(),
                                         compressedFilePath);

            if (_submitUsername != null)
            {
                SubmitFile(compressedFilePath, _dataRequest.TransactionId);
            }
            LOG.Debug("OK");
            AppendAuditLogEvent("ProcessQuery: OK");
        }
Exemple #13
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);
        }
Exemple #14
0
        protected string GenerateSubmissionFile()
        {
            string authorName, organizationName;
            bool   isProductionSubmission;

            CERSDataType data = GetCERSData.GetData(this, _databasePath, _dataCategory, out authorName, out organizationName, out isProductionSubmission);

            string tempZipFilePath      = _settingsProvider.NewTempFilePath(".zip");
            string tempXmlFilePath      = _settingsProvider.NewTempFilePath(".xml");
            string tempXmlCleanFilePath = _settingsProvider.NewTempFilePath(".xml");
            string validationResultsFilePath;

            // Required for the EIS backend parser:
            //XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            //ns.Add("cer", "http://www.exchangenetwork.net/schema/cer/1");
            try
            {
                //_serializationHelper.SerializerNamespaces = ns;
                _serializationHelper.Serialize(data, tempXmlFilePath);

                XmlDocument xsl = new XmlDocument();
                xsl.LoadXml(XSL_REMOVE_EMPTY_TAGS); // constant contains the XSL above

                System.Xml.Xsl.XslCompiledTransform transform = new System.Xml.Xsl.XslCompiledTransform();
                transform.Load(xsl);
                transform.Transform(tempXmlFilePath, tempXmlCleanFilePath);

                validationResultsFilePath = ValidateXmlFile(tempXmlCleanFilePath, "xml_schema.CER_Schema_v1.2.zip", null);

                if (validationResultsFilePath == null)
                {
                    _passedSchemaValidation = true;
                }
                else
                {
                    _passedSchemaValidation = false;
                    _documentManager.AddDocument(_dataRequest.TransactionId,
                                                 CommonTransactionStatusCode.Failed,
                                                 null, validationResultsFilePath);
                }
                AppendAuditLogEvent("Generating submission file (with an exchange header) from results");

                IHeaderDocument2Helper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                //headerDocumentHelper.SerializerNamespaces = ns;
                // Configure the submission header helper
                headerDocumentHelper.Configure(authorName, organizationName, "EIS", "EIS_v1_0", string.Empty,
                                               string.Empty, null);

                DataCategory submissionDataCategory = data.DataCategory;

                headerDocumentHelper.AddPropery(SUBMISSION_TYPE_HEADER_KEY,
                                                isProductionSubmission ? PRODUCTION_SUBMISSION_TYPE_NAME : QA_SUBMISSION_TYPE_NAME);
                headerDocumentHelper.AddPropery(DATA_CATEGORY_HEADER_KEY,
                                                EnumUtils.ToDescription(submissionDataCategory));

                string tempXmlFilePath2 = _settingsProvider.NewTempFilePath(".xml");

                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempXmlCleanFilePath);

                    headerDocumentHelper.AddPayload(string.Empty, doc.DocumentElement);

                    headerDocumentHelper.Serialize(tempXmlFilePath2);

                    _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath);
                }
                finally
                {
                    FileUtils.SafeDeleteFile(tempXmlFilePath2);
                }
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }

            return(tempZipFilePath);
        }
Exemple #15
0
        internal string Execute(DateTime changeDate, string flowName, string targetXmlPath,
                                ISerializationHelper serializationHelper, ICompressionHelper compressionHelper,
                                IObjectsFromDatabase objectsFromDatabase,
                                IAppendAuditLogEvent appendAuditLogEvent)
        {
            appendAuditLogEvent.AppendAuditLogEvent("Querying FACID data ...");

            Dictionary <string, DbAppendSelectWhereClause> selectClauses = new Dictionary <string, DbAppendSelectWhereClause>();
            string facIdQuery = string.Format("SELECT ST_FAC_IND FROM CHANGED_FACILITIES WHERE IS_DELETED = 0 AND UPPER(FLOW_TYPE) = UPPER('{0}') AND UPDATE_DATE >= '{1}'",
                                              flowName, changeDate.ToString("dd-MMM-yyyy").ToUpper());
            string whereQuery = string.Format("FAC_SITE_IDEN_VAL IN ({0})", facIdQuery);

            selectClauses.Add("FACID_FAC", new DbAppendSelectWhereClause(whereQuery, null));

            string affiliateTableClause = string.Format(
                "AFFL_IDEN IN (SELECT AFFL_IDEN FROM FACID_FAC_FAC_AFFL WHERE FAC_ID IN (SELECT FAC_ID FROM FACID_FAC WHERE {0}) UNION " +
                "SELECT AFFL_IDEN FROM FACID_ENVR_INTR_FAC_AFFL WHERE ENVR_INTR_ID IN (SELECT ENVR_INTR_ID FROM FACID_ENVR_INTR WHERE FAC_ID IN (SELECT FAC_ID FROM FACID_FAC WHERE {0})))",
                whereQuery);

            //string affiliateTableClause = string.Format("(AFFL_IDEN IN (SELECT AFFL_IDEN FROM FACID_FAC_FAC_AFFL WHERE FAC_ID IN (SELECT FAC_ID FROM FACID_FAC WHERE {0}))) OR " +
            //                                            "(AFFL_IDEN IN (SELECT AFFL_IDEN FROM FACID_ENVR_INTR_FAC_AFFL WHERE ENVR_INTR_ID IN (SELECT ENVR_INTR_ID FROM FACID_ENVR_INTR WHERE FAC_ID IN (SELECT FAC_ID FROM FACID_FAC WHERE {0}))))",
            //                                            whereQuery);
            //string affiliateTableClause = string.Format("(AFFL_IDEN IN (SELECT AFFL_IDEN FROM FACID_FAC_FAC_AFFL WHERE FAC_ID IN (SELECT FAC_ID FROM FACID_FAC WHERE {0})))",
            //                                            whereQuery);
            //string affiliateTableClause = string.Format("(AFFL_IDEN IN (SELECT AFFL_IDEN FROM FACID_ENVR_INTR_FAC_AFFL WHERE ENVR_INTR_ID IN (SELECT ENVR_INTR_ID FROM FACID_ENVR_INTR WHERE FAC_ID IN (SELECT FAC_ID FROM FACID_FAC WHERE {0}))))",
            //                                            whereQuery);

            //string affiliateTableClause = string.Format("(AFFL_IDEN IN (SELECT AFFL_IDEN FROM FACID_FAC_FAC_AFFL WHERE FAC_ID IN ({0}))) OR " +
            //                                            "(AFFL_IDEN IN (SELECT AFFL_IDEN FROM FACID_ENVR_INTR_FAC_AFFL WHERE ENVR_INTR_ID IN (SELECT ENVR_INTR_ID FROM FACID_ENVR_INTR WHERE FAC_ID IN ({0}))))",
            //                                            facIdQuery);
            selectClauses.Add("FACID_AFFL", new DbAppendSelectWhereClause(affiliateTableClause, null));
            List <FacilityDetailsDataType> dataList =
                objectsFromDatabase.LoadFromDatabase <FacilityDetailsDataType>(_baseDao, selectClauses);

            FacilityDetailsDataType data = FacIdHelper.CombineFacilityDetailsQueryResults(dataList);

#if DEBUG
            {
            }
#endif // DEBUG

            if (CollectionUtils.IsNullOrEmpty(data.FacilityList))
            {
                appendAuditLogEvent.AppendAuditLogEvent("Did not find any FACID data in database.");
                return(null);
            }
            else
            {
                appendAuditLogEvent.AppendAuditLogEvent("Found {0} facilities and {1} affiliates.",
                                                        data.FacilityList.Length,
                                                        (data.AffiliateList != null) ? data.AffiliateList.Length : 0);
            }

            appendAuditLogEvent.AppendAuditLogEvent(
                "Serializing transformed results to file (File = {0}).",
                targetXmlPath);

            serializationHelper.Serialize(data, targetXmlPath);

            return(compressionHelper.CompressFile(targetXmlPath));
        }
        public static string GenerateAndValidateWqxQueryFile(IAppendAuditLogEvent appendAuditLogEvent, IObjectsFromDatabase objectsFromDatabase, SpringBaseDao baseDao,
                                                             string queryOrganizationName, string queryOrganizationIdentifier, string sysTempFolderPath,
                                                             Assembly xmlSchemaZippedResourceAssembly, string xmlSchemaZippedQualifiedResourceName,
                                                             string xmlSchemaRootFileName, ISerializationHelper serializationHelper, ICompressionHelper compressionHelper,
                                                             out string validationErrorsFile)
        {
            validationErrorsFile = null;

            WQXDataType wqx = GenerateWqxQueryFromDatabase(appendAuditLogEvent, objectsFromDatabase, baseDao, queryOrganizationIdentifier);

            if (wqx == null)
            {
                return(null);
            }

            appendAuditLogEvent.AppendAuditLogEvent("Generating WQX xml file from query results ...");
            string tempFolderPath  = Path.Combine(sysTempFolderPath, Guid.NewGuid().ToString());
            string fileName        = Guid.NewGuid().ToString();
            string tempXmlFilePath = Path.Combine(tempFolderPath, WQX_FILE_PREFIX + fileName + ".xml");
            string zipXmlFilePath  = Path.ChangeExtension(Path.Combine(sysTempFolderPath, fileName), ".zip");

            Directory.CreateDirectory(tempFolderPath);

            try
            {
                serializationHelper.Serialize(wqx, tempXmlFilePath);

                appendAuditLogEvent.AppendAuditLogEvent("Inserting header into WQX xml file");
                tempXmlFilePath = MakeHeaderFile(tempXmlFilePath, tempFolderPath, queryOrganizationName, queryOrganizationIdentifier, serializationHelper);
                appendAuditLogEvent.AppendAuditLogEvent("Inserted header into WQX xml file");

                appendAuditLogEvent.AppendAuditLogEvent("Generated WQX xml file from query results");

                validationErrorsFile =
                    BaseWNOSPlugin.ValidateXmlFile(tempXmlFilePath, xmlSchemaZippedResourceAssembly, xmlSchemaZippedQualifiedResourceName,
                                                   xmlSchemaRootFileName, sysTempFolderPath, appendAuditLogEvent, compressionHelper);



                if (validationErrorsFile != null)
                {
                    compressionHelper.CompressFile(tempXmlFilePath, zipXmlFilePath);
                    return(zipXmlFilePath);
                }

                try
                {
                    appendAuditLogEvent.AppendAuditLogEvent("Writing attachment files to temp folder ...");
                    WriteAttachmentFilesToFolder(baseDao, wqx, tempFolderPath);
                    appendAuditLogEvent.AppendAuditLogEvent("Wrote attachment files to temp folder.");

                    appendAuditLogEvent.AppendAuditLogEvent("Compressing WQX xml data file and attachments ...");
                    compressionHelper.CompressDirectory(zipXmlFilePath, tempFolderPath);
                    appendAuditLogEvent.AppendAuditLogEvent("Compressed WQX xml data file and attachments.");
                }
                catch (Exception ex)
                {
                    FileUtils.SafeDeleteFile(zipXmlFilePath);
                    throw ex;
                }
                finally
                {
                    FileUtils.SafeDeleteDirectory(tempFolderPath);
                }

                return(zipXmlFilePath);
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
                throw;
            }
        }
Exemple #17
0
        protected string GenerateSubmissionFile(CERSDataType data, string authorName, string organizationName,
                                                string senderContactInfo, bool isProductionSubmission,
                                                string attachmentFolderPath, SpringBaseDao baseDao)
        {
            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");
            string tempXmlFilePath = _settingsProvider.NewTempFilePath(".xml");

            // Required for the EIS backend parser:
            //XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            //ns.Add("cer", "http://www.exchangenetwork.net/schema/cer/1");
            try
            {
                //_serializationHelper.SerializerNamespaces = ns;
                _serializationHelper.Serialize(data, tempXmlFilePath);

                AppendAuditLogEvent("Generating submission file (with an exchange header) from results");

                IHeaderDocument2Helper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                //headerDocumentHelper.SerializerNamespaces = ns;
                // Configure the submission header helper
                headerDocumentHelper.Configure(authorName, organizationName, "EIS", "EIS_v1_0", string.Empty,
                                               senderContactInfo, null);

                DataCategory submissionDataCategory = (data.DataCategory == DataCategory.OnroadNonroadActivity) ?
                                                      DataCategory.Nonroad : data.DataCategory;
                headerDocumentHelper.AddPropery(SUBMISSION_TYPE_HEADER_KEY,
                                                isProductionSubmission ? PRODUCTION_SUBMISSION_TYPE_NAME : QA_SUBMISSION_TYPE_NAME);
                headerDocumentHelper.AddPropery(DATA_CATEGORY_HEADER_KEY,
                                                EnumUtils.ToDescription(submissionDataCategory));

                if (data.DataCategory == DataCategory.OnroadNonroadActivity)
                {
                    IList <string> attachmentFileNames = data.GetAttachmentFileNames();
                    CollectionUtils.ForEach(attachmentFileNames, delegate(string fileName)
                    {
                        headerDocumentHelper.AddPropery("NCDDataFile", fileName);
                    });
                }

                string tempXmlFilePath2 = _settingsProvider.NewTempFilePath(".xml");
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempXmlFilePath);

                    headerDocumentHelper.AddPayload(string.Empty, doc.DocumentElement);

                    headerDocumentHelper.Serialize(tempXmlFilePath2);

                    _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath);
                }
                finally
                {
                    FileUtils.SafeDeleteFile(tempXmlFilePath2);
                }
                data.AddAttachmentsToZipFile(tempZipFilePath, attachmentFolderPath, baseDao,
                                             _compressionHelper);
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(tempZipFilePath);
        }
        protected string GenerateSubmissionFile(UICDataType data)
        {
            AppendAuditLogEvent(GetSubmissionResultsString(data));

            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");
            string tempXmlFilePath = _settingsProvider.NewTempFilePath(".xml");

            try
            {
                //_serializationHelper.Serialize(data, tempXmlFilePath);
                _serializationHelper.SerializeWithLineBreaks(data, tempXmlFilePath);

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

                if (_addHeader)
                {
                    AppendAuditLogEvent("Generating submission file (with an exchange header) from results");

                    IHeaderDocumentHelper headerDocumentHelper;
                    GetServiceImplementation(out headerDocumentHelper);
                    // Configure the submission header helper
                    string organization = data.OrgId;
                    if (!string.IsNullOrEmpty(data.OrgName))
                    {
                        organization += " - " + data.OrgName;
                    }
                    headerDocumentHelper.Configure(_headerAuthor, organization, UIC_FLOW_NAME, UIC_FLOW_NAME,
                                                   _headerContactInfo, null);

                    string tempXmlFilePath2 = _settingsProvider.NewTempFilePath(".xml");
                    try
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(tempXmlFilePath);

                        headerDocumentHelper.AddPayload(EnumUtils.ToDescription(Submission_Type.DeleteInsert),
                                                        doc.DocumentElement);

                        headerDocumentHelper.SerializeWithLineBreaks(tempXmlFilePath2);

                        _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath);
                    }
                    finally
                    {
                        FileUtils.SafeDeleteFile(tempXmlFilePath2);
                    }
                }
                else
                {
                    AppendAuditLogEvent("Generating submission file (without an exchange header) from results");
                    _compressionHelper.CompressFile(tempXmlFilePath, tempZipFilePath);
                }
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(tempZipFilePath);
        }
Exemple #19
0
        protected virtual string AddExchangeDocumentHeader(string inputFile, bool doCompress, string docTransactionId)
        {
            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");

            if (!_addHeader)
            {
                if (doCompress && !_compressionHelper.IsCompressed(inputFile))
                {
                    _compressionHelper.CompressFile(inputFile, tempZipFilePath);
                }
                else
                {
                    tempZipFilePath = inputFile;
                }
            }
            else
            {
                AppendAuditLogEvent("Adding an exchange header to the document ...");

                ExceptionUtils.ThrowIfFileNotFound(inputFile);

                string tempInputFilePath = _settingsProvider.NewTempFilePath(".xml");
                string tempXmlFilePath   = _settingsProvider.NewTempFilePath(".xml");

                try
                {
                    if (_compressionHelper.IsCompressed(inputFile))
                    {
                        _compressionHelper.Uncompress(inputFile, tempInputFilePath);
                        inputFile = tempInputFilePath;
                    }

                    XmlDocument doc = new XmlDocument();
                    doc.Load(inputFile);

                    _headerDocumentHelper.Configure(_author, _organization, "AQS Data", AQS_FLOW_NAME, null, null, _aqsUserId, null);
                    if (!string.IsNullOrEmpty(_senderAddress))
                    {
                        List <string> emails = StringUtils.SplitAndReallyRemoveEmptyEntries(_senderAddress, EMAIL_ADDRESS_SEPARATOR);
                        if (!CollectionUtils.IsNullOrEmpty(emails))
                        {
                            _headerDocumentHelper.AddNotifications(emails);
                        }
                    }
                    if (!string.IsNullOrEmpty(_aqsScreeningGroup))
                    {
                        _headerDocumentHelper.AddPropery("AQS.ScreeningGroup", _aqsScreeningGroup);
                    }
                    if (!string.IsNullOrEmpty(_aqsFinalProcessingStep))
                    {
                        _headerDocumentHelper.AddPropery("AQS.FinalProcessingStep", _aqsFinalProcessingStep);
                    }
                    if (!string.IsNullOrEmpty(_aqsStopOnError))
                    {
                        _headerDocumentHelper.AddPropery("AQS.StopOnError", _aqsStopOnError);
                    }
                    _headerDocumentHelper.AddPropery("AQS.SchemaVersion", "3.0");

                    _headerDocumentHelper.AddPropery("AQS.PayloadType", "XML");

                    _headerDocumentHelper.AddPayload(null, doc.DocumentElement);

                    _headerDocumentHelper.Serialize(tempXmlFilePath);

                    if (doCompress)
                    {
                        _compressionHelper.CompressFile(tempXmlFilePath, tempZipFilePath);
                    }
                    else
                    {
                        tempZipFilePath = tempXmlFilePath;
                    }
                }
                catch (Exception ex)
                {
                    AppendAuditLogEvent("Failed to add an exchange header to the document with the following exception: {0}",
                                        ExceptionUtils.GetDeepExceptionMessage(ex));
                    FileUtils.SafeDeleteFile(tempZipFilePath);
                    throw;
                }
                finally
                {
                    FileUtils.SafeDeleteFile(tempInputFilePath);
                    FileUtils.SafeDeleteFile(tempXmlFilePath);
                }
            }
            if (!string.IsNullOrEmpty(docTransactionId))
            {
                _documentManager.AddDocument(docTransactionId, CommonTransactionStatusCode.Completed, null, tempZipFilePath);
            }
            return(tempZipFilePath);
        }