protected string GenerateSubmissionFileAndAddToTransaction(CERSDataType data, string transactionId, string authorName, string organizationName, string senderContactInfo, bool isProductionSubmission, string attachmentFolderPath, SpringBaseDao baseDao) { string submitFile = GenerateSubmissionFile(data, authorName, organizationName, senderContactInfo, isProductionSubmission, attachmentFolderPath, baseDao); try { AppendAuditLogEvent("Attaching submission document to transaction \"{0}\"", transactionId); _documentManager.AddDocument(transactionId, CommonTransactionStatusCode.Completed, null, submitFile); } catch (Exception e) { AppendAuditLogEvent("Failed to attach submission document \"{0}\" to transaction \"{1}\" with exception: {2}", submitFile, transactionId, ExceptionUtils.ToShortString(e)); FileUtils.SafeDeleteFile(submitFile); throw; } return(submitFile); }
protected override void ProcessSubmitDocument(string transactionId, string docId) { string filePath = null; try { CERSDataType data = GetSubmitDocumentData(transactionId, docId); filePath = GenerateSubmissionFileAndAddToTransaction(data, transactionId, _authorName, _organizationName, _senderContactInfo, _isProductionSubmission, _attachmentFolderPath, null); if (_epaPartnerNode != null) { SubmitData(transactionId, filePath); } } catch (Exception e) { AppendAuditLogEvent("Failed to process document with id \"{0}.\" EXCEPTION: {1}", docId.ToString(), ExceptionUtils.ToShortString(e)); throw; } finally { FileUtils.SafeDeleteFile(filePath); } }
protected string GenerateSubmissionFileAndAddToTransaction(DataCategory dataCategory) { Dictionary <string, DbAppendSelectWhereClause> selectClauses = new Dictionary <string, DbAppendSelectWhereClause>(); selectClauses.Add("CERS_CERS", new DbAppendSelectWhereClause(_baseDao, "DATA_CATEGORY = ? AND EMIS_YEAR = ?", dataCategory.ToString(), _emissionsYear)); List <CERSDataType> dataList = _objectsFromDatabase.LoadFromDatabase <CERSDataType>(_baseDao, selectClauses); if (CollectionUtils.IsNullOrEmpty(dataList)) { throw new ArgumentException(string.Format("No EIS data was found to submit for submission type \"{0}\"", EnumUtils.ToDescription(dataCategory))); } else if (dataList.Count > 1) { throw new ArgumentException(string.Format("More than one set of EIS data was found for submission type \"{0}\"", EnumUtils.ToDescription(dataCategory))); } else { CERSDataType data = dataList[0]; AppendAuditLogEvent(GetSubmissionResultsString(data, dataCategory)); return(GenerateSubmissionFileAndAddToTransaction(data, _dataRequest.TransactionId, _authorName, _organizationName, _senderContactInfo, _isProductionSubmission, _attachmentFolderPath, _baseDao)); } }
protected override CERSDataType GetSubmitDocumentData(string transactionId, string docId) { AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId); Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true); if (!document.IsZipFile) { throw new ArgumentException(string.Format("The submitted document \"{0}\" is not a zip file", document.DocumentName)); } int submitYear; string docName = Path.GetFileNameWithoutExtension(document.DocumentName); if (docName.Length < 10) { throw new ArgumentException(string.Format("The submitted document's name \"{0}\" is not valid", document.DocumentName)); } if (!int.TryParse(docName.Substring(docName.Length - 4, 4), out submitYear) || (submitYear > DateTime.Now.AddYears(1).Year) || (submitYear < 1900)) { throw new ArgumentException(string.Format("The submitted document's name \"{0}\" does not contain a valid year", document.DocumentName)); } int submitFIPSCode; if (!int.TryParse(docName.Substring(docName.Length - 10, 5), out submitFIPSCode)) { throw new ArgumentException(string.Format("The submitted document's name \"{0}\" does not contain a valid FIPS code", document.DocumentName)); } string submitFileName = submitFIPSCode.ToString("D5"); CERSDataType data = new CERSDataType(); data.DataCategory = DataCategory.OnroadNonroadActivity; data.EmissionsYear = submitYear.ToString(); data.UserIdentifier = _senderContactInfo; data.ProgramSystemCode = _programSystemCode; data.Location = new LocationDataType[1]; data.Location[0] = new LocationDataType(); data.Location[0].StateAndCountyFIPSCode = submitFileName; AppendAuditLogEvent("Submitted document contains data for FIPS code \"{0}\" and emissions year \"{1}\"", submitFileName, submitYear); submitFileName += ".zip"; string parentFolderPath = Path.Combine(_settingsProvider.TempFolderPath, transactionId); Directory.CreateDirectory(parentFolderPath); _attachmentFolderPath = parentFolderPath; string tempZipFilePath = Path.Combine(parentFolderPath, submitFileName); File.WriteAllBytes(tempZipFilePath, document.Content); data.AttachmentFileNames = new string[] { submitFileName }; return(data); }
protected override CERSDataType GetSubmitDocumentData(string transactionId, string docId) { CERSDataType data = base.GetSubmitDocumentData(transactionId, docId); if (_headerDataCategory == DataCategory.None) { throw new ArgumentException("The DataCategory for the submission document could not be determined"); } return(data); }
protected string GetSubmissionResultsString(CERSDataType data, DataCategory dataCategory) { StringBuilder sb = new StringBuilder(); if (data == null) { sb.AppendFormat("Did not find any EIS {0} submission data.", EnumUtils.ToDescription(dataCategory)); } else { sb.AppendFormat("Found the following EIS {0} submission data: ", EnumUtils.ToDescription(dataCategory)); int i = 0; AppendCountString("Facility Sites", data.FacilitySite, ++i == 1, sb); AppendCountString("Locations", data.Location, ++i == 1, sb); AppendCountString("Events", data.Event, ++i == 1, sb); AppendCountString("Quality Findings", data.QualityFinding, ++i == 1, sb); } return(sb.ToString()); }
protected override void ProcessSubmitDocument(string transactionId, string docId) { try { CERSDataType data = GetSubmitDocumentData(transactionId, docId); int numRowsDeleted = 0; Dictionary <string, int> tableRowCounts = null; _baseDao.TransactionTemplate.Execute(delegate { numRowsDeleted = _baseDao.DoSimpleDelete("CERS_CERS", "DATA_CATEGORY;EMIS_YEAR", data.DataCategory.ToString(), data.EmissionsYear); tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao); return(null); }); if (numRowsDeleted > 0) { AppendAuditLogEvent("Deleted {0} existing CERS data from the data store for data category \"{1}\" and emissions year \"{2}\"", numRowsDeleted.ToString(), data.DataCategory, data.EmissionsYear); } else { AppendAuditLogEvent("Did not delete any existing CERS data from the data store"); } AppendAuditLogEvent("Stored CERS data content with primary key \"{0}\" into data store with the following table row counts: {1}", data._PK, CreateTableRowCountsString(tableRowCounts)); } catch (Exception e) { AppendAuditLogEvent("Failed to process document with id \"{0}.\" EXCEPTION: {1}", docId.ToString(), ExceptionUtils.ToShortString(e)); throw; } }
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); }
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 virtual CERSDataType GetSubmitDocumentData(string transactionId, string docId) { string tempXmlFilePath = _settingsProvider.NewTempFilePath(); try { AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId); Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true); if (document.IsZipFile) { AppendAuditLogEvent("Decompressing document to temporary file"); _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath); } else { AppendAuditLogEvent("Writing document data to temporary file"); File.WriteAllBytes(tempXmlFilePath, document.Content); } IHeaderDocument2Helper headerDocumentHelper; GetServiceImplementation(out headerDocumentHelper); XmlElement loadElement = null; try { AppendAuditLogEvent("Attempting to load document with Exchange Header"); headerDocumentHelper.Load(tempXmlFilePath); string operation; loadElement = headerDocumentHelper.GetFirstPayload(out operation); if (loadElement == null) { throw new ArgumentException("The submitted document does not contain an EIS payload"); } string dataCategoryString = headerDocumentHelper.GetHeaderPropery(DATA_CATEGORY_HEADER_KEY); _headerDataCategory = EnumUtils.ParseEnum <DataCategory>(dataCategoryString); AppendAuditLogEvent("The Exchange Header contains a \"{0}\" property value of \"{1}\"", DATA_CATEGORY_HEADER_KEY, dataCategoryString ?? "None"); } 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 CERS data"); CERSDataType data = null; if (loadElement != null) { data = _serializationHelper.Deserialize <CERSDataType>(loadElement); } else { data = _serializationHelper.Deserialize <CERSDataType>(tempXmlFilePath); } data.DataCategory = this.DataCategory; AppendAuditLogEvent("Submitted document contains data for data category \"{0}\" and emissions year \"{1}\"", data.DataCategory, data.EmissionsYear); return(data); } finally { FileUtils.SafeDeleteFile(tempXmlFilePath); } }