-
Notifications
You must be signed in to change notification settings - Fork 48
adding ValidateOpts #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
adding ValidateOpts #295
Changes from 1 commit
74c4927
1aa2813
64bf1e1
7964276
7c2ee0c
d15b6ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,15 @@ var ( | |
| msgFileCredit = "Credit outside of cash letter" | ||
| ) | ||
|
|
||
| // ValidateOpts contains specific overrides from the default set of validations | ||
| type ValidateOpts struct { | ||
| // SkipAll will disable all validation checks of a File. It has no effect when set on records. | ||
| SkipAll bool `json:"skipAll"` | ||
|
Comment on lines
+96
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exact validation function of record will hit within reader function only |
||
|
|
||
| // ArchiveTypeIndicator can be set to enable archiveTypeIndicator validation | ||
| ArchiveTypeIndicator bool `json:"ArchiveTypeIndicator"` | ||
mfdeveloper508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // FileError is an error describing issues validating a file | ||
| type FileError struct { | ||
| FieldName string | ||
|
|
@@ -119,6 +128,8 @@ type File struct { | |
| Bundles []Bundle `json:"bundle,omitempty"` | ||
| // FileControl is an imagecashletter FileControl | ||
| Control FileControl `json:"fileControl"` | ||
|
|
||
| validateOpts *ValidateOpts | ||
| } | ||
|
|
||
| // NewFile constructs a file template with a FileHeader and FileControl. | ||
|
|
@@ -322,3 +333,30 @@ func (f *File) setRecordTypes() { | |
| } | ||
| f.Control.setRecordType() | ||
| } | ||
|
|
||
| // SetValidation stores ValidateOpts | ||
| func (f *File) SetValidation(opts *ValidateOpts) { | ||
| if f == nil || opts == nil { | ||
| return | ||
| } | ||
|
|
||
| f.validateOpts = opts | ||
| } | ||
|
|
||
| // ValidateOpts returns Validation option | ||
| func (f *File) ValidateOpts() *ValidateOpts { | ||
| return f.validateOpts | ||
| } | ||
|
|
||
| // IsArchiveTypeIndicator indicate to enable ArchiveTypeIndicator validation | ||
| func (v *ValidateOpts) IsArchiveTypeIndicator() bool { | ||
mfdeveloper508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if v == nil { | ||
| return true | ||
| } | ||
|
|
||
| if v.SkipAll || v.ArchiveTypeIndicator == false { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -265,7 +265,13 @@ func (rd *ReturnDetail) String() string { | |
|
|
||
| // Validate performs image cash letter format rule checks on the record and returns an error if not Validated | ||
| // The first error encountered is returned and stops the parsing. | ||
| func (rd *ReturnDetail) Validate() error { | ||
| func (rd *ReturnDetail) Validate(opts ...*ValidateOpts) error { | ||
|
||
|
|
||
| var opt *ValidateOpts | ||
| if len(opts) > 0 { | ||
| opt = opts[0] | ||
| } | ||
|
|
||
| if err := rd.fieldInclusion(); err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -288,7 +294,7 @@ func (rd *ReturnDetail) Validate() error { | |
| return &FieldError{FieldName: "ReturnNotificationIndicator", Value: rd.ReturnNotificationIndicatorField(), Msg: err.Error()} | ||
| } | ||
| } | ||
| if rd.ArchiveTypeIndicator != "" { | ||
| if rd.ArchiveTypeIndicator != "" && opt.IsArchiveTypeIndicator() { | ||
| if err := rd.isArchiveTypeIndicator(rd.ArchiveTypeIndicator); err != nil { | ||
| return &FieldError{FieldName: "ArchiveTypeIndicator", Value: rd.ArchiveTypeIndicatorField(), Msg: err.Error()} | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.