Skip to content

Commit

Permalink
fix read error of ImageViewData
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdeveloper508 committed Oct 18, 2023
1 parent e089a1d commit 8d7a936
Showing 1 changed file with 2 additions and 50 deletions.
52 changes: 2 additions & 50 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,10 @@ func (r *Reader) parseFileHeader() error {
// There can only be one File Header per File
r.error(&FileError{Msg: msgFileHeader})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

r.File.Header.Parse(lineOut)
// Ensure valid FileHeader
if err := r.File.Header.Validate(); err != nil {
Expand All @@ -351,12 +349,10 @@ func (r *Reader) parseCashLetterHeader() error {
// CashLetterHeader inside of current cash letter
return r.error(&FileError{Msg: msgFileCashLetterInside})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

clh := NewCashLetterHeader()
clh.Parse(lineOut)
// Ensure we have a valid CashLetterHeader
Expand All @@ -383,7 +379,6 @@ func (r *Reader) parseBundleHeader() error {
if err != nil {
return err
}

bh := NewBundleHeader()
bh.Parse(lineOut)
if err := bh.Validate(); err != nil {
Expand All @@ -402,12 +397,10 @@ func (r *Reader) parseCheckDetail() error {
if r.currentCashLetter.currentBundle == nil {
return r.error(&FileError{Msg: msgFileBundleOutside})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

cd := new(CheckDetail)
cd.Parse(lineOut)
// Ensure valid CheckDetail
Expand All @@ -428,12 +421,10 @@ func (r *Reader) parseCheckDetailAddendumA() error {
msg := fmt.Sprint(msgFileBundleOutside)
return r.error(&FileError{FieldName: "CheckDetailAddendumA", Msg: msg})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

cdAddendumA := NewCheckDetailAddendumA()
cdAddendumA.Parse(lineOut)
if err := cdAddendumA.Validate(); err != nil {
Expand All @@ -452,12 +443,10 @@ func (r *Reader) parseCheckDetailAddendumB() error {
msg := fmt.Sprint(msgFileBundleOutside)
return r.error(&FileError{FieldName: "CheckDetailAddendumB", Msg: msg})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

cdAddendumB := NewCheckDetailAddendumB()
cdAddendumB.Parse(lineOut)
if err := cdAddendumB.Validate(); err != nil {
Expand All @@ -475,12 +464,10 @@ func (r *Reader) parseCheckDetailAddendumC() error {
msg := fmt.Sprint(msgFileBundleOutside)
return r.error(&FileError{FieldName: "CheckDetailAddendumC", Msg: msg})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

cdAddendumC := NewCheckDetailAddendumC()
cdAddendumC.Parse(lineOut)
if err := cdAddendumC.Validate(); err != nil {
Expand All @@ -497,12 +484,10 @@ func (r *Reader) parseReturnDetail() error {
if r.currentCashLetter.currentBundle == nil {
return r.error(&FileError{Msg: msgFileBundleOutside})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

rd := new(ReturnDetail)
rd.Parse(lineOut)
if err := rd.Validate(); err != nil {
Expand All @@ -521,12 +506,10 @@ func (r *Reader) parseReturnDetailAddendumA() error {
msg := fmt.Sprint(msgFileBundleOutside)
return r.error(&FileError{FieldName: "ReturnDetailAddendumA", Msg: msg})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

rdAddendumA := NewReturnDetailAddendumA()
rdAddendumA.Parse(lineOut)
if err := rdAddendumA.Validate(); err != nil {
Expand All @@ -545,12 +528,10 @@ func (r *Reader) parseReturnDetailAddendumB() error {
msg := fmt.Sprint(msgFileBundleOutside)
return r.error(&FileError{FieldName: "ReturnDetailAddendumB", Msg: msg})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

rdAddendumB := NewReturnDetailAddendumB()
rdAddendumB.Parse(lineOut)
if err := rdAddendumB.Validate(); err != nil {
Expand All @@ -568,12 +549,10 @@ func (r *Reader) parseReturnDetailAddendumC() error {
msg := fmt.Sprint(msgFileBundleOutside)
return r.error(&FileError{FieldName: "ReturnDetailAddendumC", Msg: msg})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

rdAddendumC := NewReturnDetailAddendumC()
rdAddendumC.Parse(lineOut)
if err := rdAddendumC.Validate(); err != nil {
Expand All @@ -592,12 +571,10 @@ func (r *Reader) parseReturnDetailAddendumD() error {
msg := fmt.Sprint(msgFileBundleOutside)
return r.error(&FileError{FieldName: "ReturnDetailAddendumD", Msg: msg})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

rdAddendumD := NewReturnDetailAddendumD()
rdAddendumD.Parse(lineOut)
if err := rdAddendumD.Validate(); err != nil {
Expand All @@ -624,7 +601,6 @@ func (r *Reader) ImageViewDetail() error {
if err != nil {
return err
}

ivDetail := NewImageViewDetail()
ivDetail.Parse(lineOut)
if err := ivDetail.Validate(); err != nil {
Expand All @@ -638,7 +614,6 @@ func (r *Reader) ImageViewDetail() error {
if err != nil {
return err
}

ivDetail := NewImageViewDetail()
ivDetail.Parse(lineOut)
if err := ivDetail.Validate(); err != nil {
Expand Down Expand Up @@ -666,27 +641,17 @@ func (r *Reader) parseImageViewData() error {
// ImageViewData takes the input record string and parses ImageViewData for a check
func (r *Reader) ImageViewData() error {
if r.currentCashLetter.currentBundle.GetChecks() != nil {
lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

ivData := NewImageViewData()
ivData.Parse(lineOut)
ivData.ParseAndDecode(r.line, r.decodeLine)
if err := ivData.Validate(); err != nil {
return r.error(err)
}
entryIndex := len(r.currentCashLetter.currentBundle.GetChecks()) - 1
r.currentCashLetter.currentBundle.Checks[entryIndex].AddImageViewData(ivData)

} else if r.currentCashLetter.currentBundle.GetReturns() != nil {
lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

ivData := NewImageViewData()
ivData.Parse(lineOut)
ivData.ParseAndDecode(r.line, r.decodeLine)
if err := ivData.Validate(); err != nil {
return r.error(err)
}
Expand Down Expand Up @@ -716,7 +681,6 @@ func (r *Reader) ImageViewAnalysis() error {
if err != nil {
return err
}

ivAnalysis := NewImageViewAnalysis()
ivAnalysis.Parse(lineOut)
if err := ivAnalysis.Validate(); err != nil {
Expand All @@ -730,7 +694,6 @@ func (r *Reader) ImageViewAnalysis() error {
if err != nil {
return err
}

ivAnalysis := NewImageViewAnalysis()
ivAnalysis.Parse(lineOut)
if err := ivAnalysis.Validate(); err != nil {
Expand All @@ -753,12 +716,10 @@ func (r *Reader) parseCredit() error {
if r.currentCashLetter.CashLetterHeader == nil {
return r.error(&FileError{Msg: msgFileCredit})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

cr := new(Credit)
cr.Parse(lineOut)
if err := cr.Validate(); err != nil {
Expand All @@ -775,12 +736,10 @@ func (r *Reader) parseCreditItem() error {
if r.currentCashLetter.CashLetterHeader == nil {
return r.error(&FileError{Msg: msgFileCreditItem})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

ci := new(CreditItem)
ci.Parse(lineOut)
if err := ci.Validate(); err != nil {
Expand All @@ -793,16 +752,13 @@ func (r *Reader) parseCreditItem() error {
// parseBundleControl takes the input record string and parses the BundleControl values
func (r *Reader) parseBundleControl() error {
r.recordName = "BundleControl"

if r.currentCashLetter.currentBundle == nil || r.currentCashLetter.currentBundle.BundleControl == nil {
return r.error(&FileError{Msg: msgFileBundleControl})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

r.currentCashLetter.currentBundle.GetControl().Parse(lineOut)
if err := r.currentCashLetter.currentBundle.GetControl().Validate(); err != nil {
return r.error(err)
Expand All @@ -816,12 +772,10 @@ func (r *Reader) parseRoutingNumberSummary() error {
if r.currentCashLetter.CashLetterHeader == nil {
return r.error(&FileError{Msg: msgFileRoutingNumberSummary})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

rns := NewRoutingNumberSummary()
rns.Parse(lineOut)
if err := rns.Validate(); err != nil {
Expand All @@ -837,12 +791,10 @@ func (r *Reader) parseCashLetterControl() error {
// CashLetterControl without a current CashLetter
return r.error(&FileError{Msg: msgFileCashLetterControl})
}

lineOut, err := r.decodeLine(r.line)
if err != nil {
return err
}

r.currentCashLetter.GetControl().Parse(lineOut)
// Ensure valid CashLetterControl
if err := r.currentCashLetter.GetControl().Validate(); err != nil {
Expand Down

0 comments on commit 8d7a936

Please sign in to comment.