Skip to content

Commit

Permalink
x9 to image cash letter changes
Browse files Browse the repository at this point in the history
x9 to image cash letter changes
  • Loading branch information
bkmoovio committed Jun 4, 2019
1 parent ad2ad42 commit e660142
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 74 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -74,7 +74,7 @@ To Be Done

github.com/moov-io/ach/cmd/writeImageCashLetter

main.go will create an X9 file with 4 cash letters each containing 4 bundles with 1250 check detail records
main.go will create an Image Cash Letter file with 4 cash letters each containing 4 bundles with 1250 check detail records

A custom path can be used by defining fPath ( e.g. -fPath=github.com/moov-io/_directory_ )

Expand Down
6 changes: 3 additions & 3 deletions CheckDetailAddendumC.go
Expand Up @@ -82,9 +82,9 @@ type CheckDetailAddendumC struct {
EndorsingBankIdentifier int `json:"endorsingBankIdentifier"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string
// validator is composed for x9 data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -143,7 +143,7 @@ func (cdAddendumC *CheckDetailAddendumC) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 (cdAddendumC *CheckDetailAddendumC) Validate() error {
if err := cdAddendumC.fieldInclusion(); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -59,12 +59,12 @@ The following is a high level example of reading and writing an Image Cash Lette
import icl "github.com/moov-io/imagecashletter
// open a file for reading or pass any io.Reader NewReader()
f, err := os.Open("name-of-your-icl-file.x9")
f, err := os.Open("name-of-your-icl-file.icl")
if err != nil {
log.Panicf("Can not open local file: %s: \n", err)
}
r := icl.NewReader(f)
x9File, err := r.Read()
image cash letterFile, err := r.Read()
if err != nil {
fmt.Printf("Issue reading file: %+v \n", err)
}
Expand All @@ -77,7 +77,7 @@ if x9File.Validate(); err != nil {
### Create a file
Explicitly create an X9 file with a Bundle of Forward Presentment Items and a Bundle of Return Items
Explicitly create an Image Cash Letter file with a Bundle of Forward Presentment Items and a Bundle of Return Items
```go
// Create a File
Expand Down Expand Up @@ -130,7 +130,7 @@ if err := file.Validate(); err != nil {
}
````
Which will generate a well formed X9 flat file.
Which will generate a well formed ICL flat file.
```text
0135T231380104121042882201810032226NCitadel Wells Fargo US
Expand Down
6 changes: 3 additions & 3 deletions bundleControl.go
Expand Up @@ -38,9 +38,9 @@ type BundleControl struct {
CreditTotalIndicator int `json:"creditTotalIndicator"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string
// validator is composed for imagecashletter data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -92,7 +92,7 @@ func (bc *BundleControl) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 (bc *BundleControl) Validate() error {
if err := bc.fieldInclusion(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions checkDetailAddendumA.go
Expand Up @@ -78,9 +78,9 @@ type CheckDetailAddendumA struct {
UserField string `json:"userField"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string
// validator is composed for x9 data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -142,7 +142,7 @@ func (cdAddendumA *CheckDetailAddendumA) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 (cdAddendumA *CheckDetailAddendumA) Validate() error {
if err := cdAddendumA.fieldInclusion(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions checkDetailAddendumB.go
Expand Up @@ -44,9 +44,9 @@ type CheckDetailAddendumB struct {
UserField string `json:"userField"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string
// validator is composed for x9 data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -94,7 +94,7 @@ func (cdAddendumB *CheckDetailAddendumB) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 (cdAddendumB *CheckDetailAddendumB) Validate() error {
if err := cdAddendumB.fieldInclusion(); err != nil {
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions cmd/readImageCashLetter/main.go
Expand Up @@ -11,10 +11,10 @@ import (
)

var (
fPath = flag.String("fPath", "BNK20181015-A.x9", "File Path")
fPath = flag.String("fPath", "BNK20181015-A.icl", "File Path")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

flagJson = flag.Bool("json", false, "Output X9 File in JSON to stdout")
flagJson = flag.Bool("json", false, "Output ICL File in JSON to stdout")
)

func main() {
Expand All @@ -39,31 +39,31 @@ func main() {
}

r := imagecashletter.NewReader(f)
x9File, err := r.Read()
ICLFile, err := r.Read()
if err != nil {
fmt.Printf("Issue reading file: %+v \n", err)
}

// ensure we have a validated file structure
if x9File.Validate(); err != nil {
if ICLFile.Validate(); err != nil {
fmt.Printf("Could not validate entire read file: %v", err)
}

// If you trust the file but it's formating is off building will probably resolve the malformed file.
if x9File.Create(); err != nil {
if ICLFile.Create(); err != nil {
fmt.Printf("Could not build file with read properties: %v", err)
}

// Output file contents
if *flagJson {
if err := json.NewEncoder(os.Stdout).Encode(x9File); err != nil {
fmt.Printf("ERROR: problem writing X9 File to stdout: %v\n", err)
if err := json.NewEncoder(os.Stdout).Encode(ICLFile); err != nil {
fmt.Printf("ERROR: problem writing ICL File to stdout: %v\n", err)
os.Exit(1)
}
} else {
fmt.Printf("Total record count: %v \n", x9File.Control.TotalRecordCount)
fmt.Printf("Cash Letter count: %v \n", x9File.Control.CashLetterCount)
fmt.Printf("File total Item count: %v \n", x9File.Control.TotalItemCount)
fmt.Printf("File total amount: %v \n", x9File.Control.FileTotalAmount)
fmt.Printf("Total record count: %v \n", ICLFile.Control.TotalRecordCount)
fmt.Printf("Cash Letter count: %v \n", ICLFile.Control.CashLetterCount)
fmt.Printf("File total Item count: %v \n", ICLFile.Control.TotalItemCount)
fmt.Printf("File total amount: %v \n", ICLFile.Control.FileTotalAmount)
}
}
4 changes: 2 additions & 2 deletions cmd/readImageCashLetter/main_test.go
Expand Up @@ -6,15 +6,15 @@ func TestFileRead(t *testing.T) {
testFileRead(t)
}

/*//BenchmarkTestFileCreate benchmarks creating an X9 File
/*//BenchmarkTestFileCreate benchmarks creating an ICL File
func BenchmarkTestFileRead(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testFileRead(b)
}
}*/

// FileCreate creates an X9 File
// FileCreate creates an ICL File
func testFileRead(t testing.TB) {
main()
}
6 changes: 3 additions & 3 deletions cmd/writeImageCashLetter/main.go
Expand Up @@ -21,7 +21,7 @@ var (
flagJson = flag.Bool("json", false, "Output file in json")
)

// main creates an X9 File with 2 CashLetters
// main creates an ICL File with 2 CashLetters
// Each CashLetter contains 2 Bundles, with 100 CheckDetails
func main() {
flag.Parse()
Expand All @@ -30,7 +30,7 @@ func main() {
if *flagJson {
filename += ".json"
} else {
filename += ".x9"
filename += ".icl"
}

path := filepath.Join(*fPath, filename)
Expand Down Expand Up @@ -264,7 +264,7 @@ func write(path string) {
fmt.Printf("%T: %s", err, err)
}
} else {
// Write in X9 plain text format
// Write in ICL plain text format
w := imagecashletter.NewWriter(f)
if err := w.Write(file); err != nil {
fmt.Printf("%T: %s", err, err)
Expand Down
9 changes: 5 additions & 4 deletions cmd/writeImageCashLetter/main_test.go
Expand Up @@ -6,22 +6,23 @@ import (
"testing"
)

// TestFileCreate tests creating an X9 File
// TestFileCreate tests creating an ICL File
func TestFileWrite(t *testing.T) {
testFileWrite(t)
}

/*//BenchmarkTestFileCreate benchmarks creating an X9 File
/*//BenchmarkTestFileCreate benchmarks creating an ICL File
func BenchmarkTestFileWrite(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testFileWrite(b)
}
}*/

// testFileWrite creates an X9 File
// testFileWrite creates an ICL File
func testFileWrite(t testing.TB) {
tmp, err := ioutil.TempFile("", "x9-writeX9-test")
// tmp, err := ioutil.TempFile("", "x9-writeX9-test")
tmp, err := ioutil.TempFile("", "icl-writeICL-test")
if err != nil {
t.Fatal(err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions fileControl.go
Expand Up @@ -37,9 +37,9 @@ type FileControl struct {
CreditTotalIndicator int `json:"creditTotalIndicator"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string
// validator is composed for x9 data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func (fc *FileControl) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 (fc *FileControl) Validate() error {
if err := fc.fieldInclusion(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions imageViewData.go
Expand Up @@ -135,9 +135,9 @@ type ImageViewData struct {
// Shall be present when ImageViewDetail.ImageIndicator Record is NOT 0.
// Size: 0-9999999
ImageData []byte `json:"imageData"`
// validator is composed for x9 data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func (ivData *ImageViewData) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 (ivData *ImageViewData) Validate() error {
if err := ivData.fieldInclusion(); err != nil {
Expand Down
26 changes: 13 additions & 13 deletions reader_test.go
Expand Up @@ -12,9 +12,9 @@ import (
"testing"
)

// TestX9FileRead validates reading an x9 file
func TestX9FileRead(t *testing.T) {
f, err := os.Open("./test/testdata/BNK20180905121042882-A.x9")
// TestICLFileRead validates reading an ICL file
func TestICLFileRead(t *testing.T) {
f, err := os.Open("./test/testdata/BNK20180905121042882-A.icl")
if err != nil {
t.Errorf("%T: %s", err, err)
}
Expand Down Expand Up @@ -47,19 +47,19 @@ func TestX9FileRead(t *testing.T) {
}
}

// TestX9File validates reading an x9 file
func TestX9File(t *testing.T) {
f, err := os.Open("./test/testdata/BNK20180905121042882-A.x9")
// TestICLFile validates reading an ICL file
func TestICLFile(t *testing.T) {
f, err := os.Open("./test/testdata/BNK20180905121042882-A.icl")
if err != nil {
log.Panicf("Can not open local file: %s: \n", err)
}
r := NewReader(f)
x9File, err := r.Read()
ICLFile, err := r.Read()
if err != nil {
fmt.Printf("Issue reading file: %+v \n", err)
}
// ensure we have a validated file structure
if x9File.Validate(); err != nil {
if ICLFile.Validate(); err != nil {
fmt.Printf("Could not validate entire read file: %v", err)
}
}
Expand Down Expand Up @@ -968,19 +968,19 @@ func TestIVAnalysisBundleError(t *testing.T) {
}
}

// TestX9CreditItemFile validates reading an x9 file with a CreditItem
func TestX9CreditItemFile(t *testing.T) {
f, err := os.Open("./test/testdata/BNK20181010121042882-A.x9")
// TestICLCreditItemFile validates reading an ICL file with a CreditItem
func TestICLCreditItemFile(t *testing.T) {
f, err := os.Open("./test/testdata/BNK20181010121042882-A.icl")
if err != nil {
log.Panicf("Can not open local file: %s: \n", err)
}
r := NewReader(f)
x9File, err := r.Read()
ICLFile, err := r.Read()
if err != nil {
fmt.Printf("Issue reading file: %+v \n", err)
}
// ensure we have a validated file structure
if x9File.Validate(); err != nil {
if ICLFile.Validate(); err != nil {
fmt.Printf("Could not validate entire read file: %v", err)
}
}
6 changes: 3 additions & 3 deletions returnDetail.go
Expand Up @@ -126,9 +126,9 @@ type ReturnDetail struct {
ImageViewData []ImageViewData `json:"imageViewData"`
// ImageViewAnalysis
ImageViewAnalysis []ImageViewAnalysis `json:"imageViewAnalysis"`
// validator is composed for x9 data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -196,7 +196,7 @@ func (rd *ReturnDetail) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 {
if err := rd.fieldInclusion(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions returnDetailAddendumA.go
Expand Up @@ -80,9 +80,9 @@ type ReturnDetailAddendumA struct {
UserField string `json:"userField"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string
// validator is composed for x9 data validation
// validator is composed for image cash letter data validation
validator
// converters is composed for x9 to golang Converters
// converters is composed for image cash letter to golang Converters
converters
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func (rdAddendumA *ReturnDetailAddendumA) String() string {
return buf.String()
}

// Validate performs X9 format rule checks on the record and returns an error if not Validated
// 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 (rdAddendumA *ReturnDetailAddendumA) Validate() error {
if err := rdAddendumA.fieldInclusion(); err != nil {
Expand Down

0 comments on commit e660142

Please sign in to comment.