private static DocumentPlugValidationInfo GetDocumentPlugValidationInfo(ZipFileEntry fileEntry, IDalManager dalManager) { string specCertName = Path.ChangeExtension(fileEntry.FileName, "xlsx"); DocumentPlugValidationInfo documentPlugValidationInfo = new DocumentPlugValidationInfo() { SpecCertName = specCertName, FileContents = fileEntry.Content, FileName = fileEntry.FileName, }; TradingPartnerSpecCertMetadata tradingPartnerSpecCertMetadata = new TradingPartnerSpecCertMetadata(); List <string> errors = tradingPartnerSpecCertMetadata.Initialize(specCertName); if (errors == null || errors.Count == 0) { try { documentPlugValidationInfo.DocumentPlug = SchemaCache.GetDocumentPlug(tradingPartnerSpecCertMetadata, dalManager); } catch (Exception) { // Ignore error here as we want to add EdiValidationResult error during ValidateEdi call. } } return(documentPlugValidationInfo); }
/// <summary> Wrapper over EDIReader for GC validation feature (Based on spec cert). </summary> /// <param name="ediData">EDI text data (edi file content)</param> /// <param name="ediFileName">This is for record keeping only, not used by EDIReader</param> /// <param name="certFileFullName">Spec cert file (relative path)</param> /// <param name="dalManager">To retrieve schema</param> /// <returns></returns> public static EDIValidationResult ValidateEdi(string ediData, string ediFileName, string certFileFullName, IDalManager dalManager) { if (string.IsNullOrWhiteSpace(ediData)) { throw new ArgumentNullException("ediData", "Edi file content cannot be empty"); } if (string.IsNullOrWhiteSpace(certFileFullName)) { throw new ArgumentNullException("certFileFullName", "certFileFullName cannot be empty"); } if (dalManager == null) { throw new ArgumentNullException("dalManager", "dalManager cannot be null"); } TradingPartnerSpecCertMetadata tradingPartnerSpecCertMetadata = new TradingPartnerSpecCertMetadata(); // Purposely ignoring Initialize function return type (errors) since I don't expect errors here. // Spec cert is uploaded only after validation. tradingPartnerSpecCertMetadata.Initialize(certFileFullName, null, DateTime.MinValue); EDIValidationResult ediValidationResult = new EDIValidationResult() { FileName = ediFileName, SchemaName = tradingPartnerSpecCertMetadata.SchemaFileName, SegmentValidationResults = new List <SegmentValidationResult>(), TransactionNumbers = new List <string>(), DisplayName = tradingPartnerSpecCertMetadata.GetCertFileDisplayName(), Type = tradingPartnerSpecCertMetadata.Type, }; try { IDocumentPlug documentPlug = SchemaCache.GetDocumentPlug(tradingPartnerSpecCertMetadata, dalManager); IFatpipeDocument fatpipeDocument; ediValidationResult = ValidateEdi(ediData, ediFileName, certFileFullName, documentPlug, out fatpipeDocument); } catch (Exception ex) { ediValidationResult.SegmentValidationResults.Add( new SegmentValidationResult() { Type = ResultType.Error, SequenceNumber = -1, Name = "N/A", Description = "Internal error occurred", //ex.Message, StartIndex = -1, EndIndex = -1, } ); } return(ediValidationResult); }
public static void DeleteTradingPartnerSpecCertWithMetadata(TradingPartnerSpecCertMetadata tradingPartnerSpecCertMetadata, IDalManager dalManager) { // TODO: Ideally we should keep audit trail of delete // Following function will remove the table entry altogether. dalManager.DeleteTradingPartnerSpecCertMetadata(tradingPartnerSpecCertMetadata); dalManager.DeleteTradingPartnerSpecCert(tradingPartnerSpecCertMetadata); SchemaCache.RemoveDocumentPlug(tradingPartnerSpecCertMetadata.SchemaFileName); }
// Should we always overwrite the existing one? public static void UploadSpecCert(string certFileName, Stream certFileStream, string userName, IDalManager dalManager) { TradingPartnerSpecCertMetadata tradingPartnerSpecCertMetadata = new TradingPartnerSpecCertMetadata(); // Purposely ignoring Initialize function return type (errors) since I don't expect errors here. tradingPartnerSpecCertMetadata.Initialize(certFileName, userName, DateTime.UtcNow); dalManager.SaveTradingPartnerSpecCert(certFileStream, tradingPartnerSpecCertMetadata); dalManager.SaveTradingPartnerSpecCertMetadata(tradingPartnerSpecCertMetadata); SchemaCache.RemoveDocumentPlug(tradingPartnerSpecCertMetadata.SchemaFileName); }
public static void DeleteTradingPartnerSpecCertWithMetadata(BizRuleCertMetadata bizRuleCertMetadata, IDalManager dalManager) { if (GCValidatorHelper.AddDummyDataForCertValidation) { return; } // TODO: Ideally we should keep audit trail of delete // Following function will remove the table entry altogether. dalManager.DeleteBizRuleCertMetadata(bizRuleCertMetadata); dalManager.DeleteBizRuleCert(bizRuleCertMetadata); SchemaCache.RemoveBizRuleCert(bizRuleCertMetadata.RuleCertFileName); }
// Should we always overwrite the existing one? public static void UploadBizRuleCert(string certFileName, Stream certFileStream, string userName, IDalManager dalManager) { if (GCValidatorHelper.AddDummyDataForCertValidation) { return; } BizRuleCertMetadata bizRuleCertMetadata = new BizRuleCertMetadata(); // Purposely ignoring Initialize function return type (errors) since I don't expect errors here. bizRuleCertMetadata.Initialize(certFileName, userName, DateTime.UtcNow); dalManager.SaveBizRuleCert(certFileStream, bizRuleCertMetadata); dalManager.SaveBizRuleCertMetadata(bizRuleCertMetadata); SchemaCache.RemoveBizRuleCert(bizRuleCertMetadata.RuleCertFileName); }
// This function is invoked from Ux public static BizRulesValidationResult ValidateBizRules(string userName, string homeOrg, ZipArchive zipArchive, BizRuleCertMetadata bizRuleCertMetadata, IDalManager dalManager) { if (zipArchive == null) { throw new ArgumentNullException("zipArchive", "zipFile cannot be empty"); } if (bizRuleCertMetadata == null) { throw new ArgumentNullException("bizRuleCertMetadata", "bizRuleCertMetadata cannot be empty"); } if (dalManager == null) { throw new ArgumentNullException("dalManager", "dalManager cannot be null"); } #region DummyCode if (GCValidatorHelper.AddDummyDataForInstanceValidation) { List <BizRuleInfo> ruleInfo1 = new List <BizRuleInfo>(); ruleInfo1.Add(new BizRuleInfo() { FileName = "Delphi Corp - Spec Cert - 810 - Send.dat", SegmentPath = "BIG->BIG03", Value = "1/2/2014" }); ruleInfo1.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SegmentPath = "PRF->PRF04", Value = "1/3/2014" }); ruleInfo1.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SegmentPath = "BEG->BEG05", Value = "1/2/2014" }); List <BizRuleInfo> ruleInfo2 = new List <BizRuleInfo>(); ruleInfo2.Add(new BizRuleInfo() { FileName = "Delphi Corp - Spec Cert - 810 - Send", SegmentPath = "BIG->BIG04", Value = "122014" }); ruleInfo2.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SegmentPath = "PRF->PRF01", Value = "122014" }); ruleInfo2.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SegmentPath = "BEG->BEG03", Value = "122014" }); List <BizRuleInfo> ruleInfo3 = new List <BizRuleInfo>(); ruleInfo3.Add(new BizRuleInfo() { FileName = "Delphi Corp - Spec Cert - 810 - Send.dat", SegmentPath = "IT1->IT101", Value = "123" }); ruleInfo3.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SegmentPath = "LIN->LIN01", Value = "234" }); ruleInfo3.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SegmentPath = "PO1->PO1O1", Value = "345" }); BizRulesValidationResult bizRulesValidationResultDummy = new BizRulesValidationResult() { BizRuleCertName = "3M - Biz Rule - X12 810-856-850" }; bizRulesValidationResultDummy.BizRuleValidationResults = new List <BizRuleValidationResult>(); bizRulesValidationResultDummy.BizRuleValidationResults.Add(new BizRuleValidationResult() { RuleName = "Purchase Order Date", Type = ResultType.Error, RuleInfo = ruleInfo1 }); bizRulesValidationResultDummy.BizRuleValidationResults.Add(new BizRuleValidationResult() { RuleName = "Purchase Order Number", Type = ResultType.Success, RuleInfo = ruleInfo2 }); bizRulesValidationResultDummy.BizRuleValidationResults.Add(new BizRuleValidationResult() { RuleName = "Assigned Identification", Type = ResultType.Warning, RuleInfo = ruleInfo3 }); bizRulesValidationResultDummy.EdiValidationResults = new List <EDIValidationResult>(); List <SegmentValidationResult> segmentValidationResult = new List <SegmentValidationResult>(); segmentValidationResult.Add(new SegmentValidationResult() { Description = "Invalid Segment XYZ", Name = "XYZ", SequenceNumber = 5, Type = ResultType.Error, StartIndex = 300, EndIndex = 305, }); bizRulesValidationResultDummy.EdiValidationResults.Add(new EDIValidationResult() { BeautifiedOriginalPayload = "EDI File Contents", FileName = "Delphi Corp - Spec Cert - 810 - Send.dat", SchemaName = "Delphi Corp - Spec Cert - 810 - Send", SegmentValidationResults = new List <SegmentValidationResult>(), // No validation failures TransactionNumbers = new List <string> { "1" }, DisplayName = "Delphi Corp - 810 - Send", Type = "X12_810" }); bizRulesValidationResultDummy.EdiValidationResults.Add(new EDIValidationResult() { BeautifiedOriginalPayload = "EDI File Contents", FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SchemaName = "Delphi Corporation - Spec Cert - 4010 - 850 - send", SegmentValidationResults = segmentValidationResult, TransactionNumbers = new List <string> { "1" }, DisplayName = "Delphi Corporation - 850 - send", Type = "X12_850" }); bizRulesValidationResultDummy.EdiValidationResults.Add(new EDIValidationResult() { BeautifiedOriginalPayload = "EDI File Contents", FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SchemaName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive", SegmentValidationResults = new List <SegmentValidationResult>(), // No validation failures TransactionNumbers = new List <string> { "1" }, DisplayName = "Delphi Corporation - 856 - receive", Type = "X12_856" }); return(bizRulesValidationResultDummy); } #endregion BizRulesValidationResult bizRulesValidationResult = null; string errorMessage = null; try { BizRuleSet bizRuleSet = SchemaCache.GetBizRuleSet(bizRuleCertMetadata, dalManager); List <ZipFileEntry> fileEntries = ZipFileUtil.GetFileEntries(zipArchive); List <DocumentPlugValidationInfo> documentPlugValidationInfoList = new List <DocumentPlugValidationInfo>(); foreach (ZipFileEntry fileEntry in fileEntries) { documentPlugValidationInfoList.Add(GetDocumentPlugValidationInfo(fileEntry, dalManager)); } bizRulesValidationResult = ValidateBizRules(userName, homeOrg, bizRuleCertMetadata.RuleCertFileName, bizRuleSet, documentPlugValidationInfoList, dalManager); } catch (GCEdiValidatorException gcException) { errorMessage = gcException.Message; } catch (Exception) { errorMessage = "Internal error occurred, please contact Maarg"; } if (errorMessage != null) { // TODO: Add generic error } return(bizRulesValidationResult); }