Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
added support for austria and liechtenstein
Browse files Browse the repository at this point in the history
  • Loading branch information
fan711 committed Aug 7, 2017
1 parent eb43be1 commit b451aa7
Show file tree
Hide file tree
Showing 9 changed files with 1,106 additions and 0 deletions.
49 changes: 49 additions & 0 deletions countries/at.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Chris Grieger
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

package countries

import (
"encoding/csv"
"strings"
)

type AustriaBankFileEntry struct {
Name string
Bic string
Bankcode string
}

func AustriaBankStringToEntry(val string, bankCodeLengthMap map[string]int) *AustriaBankFileEntry {
bankCodeLength := bankCodeLengthMap["AT"]
r := csv.NewReader(strings.NewReader(val))
r.LazyQuotes = true
r.Comma = ';'
records, _ := r.ReadAll()
return &AustriaBankFileEntry{
records[0][6],
records[0][19],
PadLeftZero(records[0][2], bankCodeLength),
}
}
20 changes: 20 additions & 0 deletions countries/at_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package countries

import (
"testing"
)

func TestCanConvertStringToAustriaBankEntry(t *testing.T) {
data := "Hauptanstalt;\"10050973\";\"52300\";\"KI\";\"Joint stock banks and private banks\";\"350921k\";\"Addiko Bank AG\";\"Wipplingerstraße 34/4\";\"1010\";\"Wien\";\"\";\"\";\"\";\"\";\"\";\"Wien\";\"050232\";\"050232/3000\";\"[email protected]\";\"HSEEAT2KXXX\";\"www.addiko.com\";\"20130621\";;"
result := AustriaBankStringToEntry(data)

if result.Bankcode != "52300" {
t.Errorf("Couldn't parse bank code.")
}
if result.Name != "Addiko Bank AG" {
t.Errorf("Couldn't parse name.")
}
if result.Bic != "HSEEAT2KXXX" {
t.Errorf("Couldn't parse bic.", result.Bic)
}
}
43 changes: 43 additions & 0 deletions countries/li.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Chris Grieger
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package countries

import "strings"

type LiechtensteinFileEntry struct {
Bankcode string
Name string
Bic string
}

// Return a slice of BankEntries because BICs can map to multiple
// Bankcodes
func LiechtensteinRowToEntry(row []string, bankCodeLengthMap map[string]int) LiechtensteinFileEntry {
bankCodeLength := bankCodeLengthMap["CH"]
return LiechtensteinFileEntry{
Name: strings.TrimSpace(row[0]),
Bic: strings.TrimSpace(row[1]),
Bankcode: PadLeftZero(strings.TrimSpace(row[2]), bankCodeLength),
}
}
20 changes: 20 additions & 0 deletions countries/li_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package countries

import "testing"

func TestCanConvertSliceToLiechtensteinBankEntry(t *testing.T) {
data := []string{"Bank Alpinum AG", "BALPLI22", "8801"}
entry := LiechtensteinRowToEntry(data)

if entry.Bankcode != "8801" {
t.Errorf("expected 8801 as bankcode, got %v", entry.Bankcode)
}

if entry.Bic != "BALPLI22" {
t.Errorf("expected BALPLI22 as bic, got %v", entry.Bic)
}

if entry.Name != "Bank Alpinum AG" {
t.Errorf("expected Bank Alpinum AG as name, got %v", entry.Name)
}
}
30 changes: 30 additions & 0 deletions external_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ func ReadFileToEntries(path string, t interface{}, out chan interface{}) {
switch t := t.(type) {
default:
fmt.Println("default:", t)
case *co.AustriaBankFileEntry:
go readLines(path, cLines)
var temp string
temp = <-cLines
if temp == "" {
out <- nil
return
}
var num int
for l := range cLines {
num++
if num < 7 { //skip first six lines
continue
}
if len(l) == 0 {
out <- nil
return
}
out <- co.AustriaBankStringToEntry(l, COUNTRY_CODE_TO_BANK_CODE_LENGTH)
}
case *co.BundesbankFileEntry:
go readLines(path, cLines)
for l := range cLines {
Expand Down Expand Up @@ -175,6 +195,16 @@ func ReadFileToEntries(path string, t interface{}, out chan interface{}) {
for _, r := range rows[2:] {
out <- co.SwitzerlandRowToEntry(r, COUNTRY_CODE_TO_BANK_CODE_LENGTH)
}
case *co.LiechtensteinFileEntry:
file, err := xlsx.FileToSlice(path)
if err != nil {
out <- nil
return
}
rows := file[0]
for _, r := range rows[1:] {
out <- co.LiechtensteinRowToEntry(r, COUNTRY_CODE_TO_BANK_CODE_LENGTH)
}
}
close(out)
}
52 changes: 52 additions & 0 deletions external_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ var (
db, err = sql.Open("mysql", "root:root@/goiban?charset=utf8")
)

func TestCanReadFromAustriaFile(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/austria.csv", &co.AustriaBankFileEntry{}, ch)

peek := (<-ch).(*co.AustriaBankFileEntry)
if peek.Name == "" {
t.Errorf("Failed to read file.")
}
}

func TestCannotReadFromNonExistingAustriaFile(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/austria_blablablabla.csv", &co.AustriaBankFileEntry{}, ch)
result := <-ch
if result != nil {
t.Errorf("Failed to read file.")
}
}
func TestCanReadFromBundesbankFile(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/bundesbank.txt", &co.BundesbankFileEntry{}, ch)
Expand Down Expand Up @@ -90,3 +108,37 @@ func TestCanReadFromNetherlandsXLSX(t *testing.T) {
t.Errorf("Failed to read file.")
}
}
func TestCanReadFromSwitzerlandFile(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/switzerland.txt", &co.SwitzerlandBankFileEntry{}, ch)

peek := (<-ch).(*co.SwitzerlandBankFileEntry)
if peek.Bic != "SNBZCHZZXXX" {
t.Errorf("Failed to read file.")
}
}

func TestCannotReadFromNonExistingSwitzerlandFile(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/switzerland_blablablabla.txt", &co.SwitzerlandBankFileEntry{}, ch)
result := <-ch
if result != nil {
t.Errorf("Failed to read file.")
}
}
func TestCanReadFromLiechtensteinXLSX(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/liechtenstein.xlsx", &co.LiechtensteinFileEntry{}, ch)
peek := (<-ch).(co.LiechtensteinFileEntry)
if peek.Bic != "BALPLI22" {
t.Errorf("Failed to read file." + peek.Bic)
}
}
func TestCannotReadFromNonExistingLiechtensteinFile(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/lliechtenstein_blablablabla.xlsx", &co.LiechtensteinFileEntry{}, ch)
result := <-ch
if result != nil {
t.Errorf("Failed to read file.")
}
}
2 changes: 2 additions & 0 deletions length_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
"NL": 4,
"LU": 3,
"CH": 5,
"AT": 5,
"LI": 5,
}

COUNTRY_CODE_TO_LENGTH_MAP = map[string]int{
Expand Down
Loading

0 comments on commit b451aa7

Please sign in to comment.