Last active
October 1, 2022 20:47
-
-
Save fschutte/f532c5056153215de10ca892f1fbe849 to your computer and use it in GitHub Desktop.
EISCD slurper with Spring Boot and Kotlin. Reads EISCD xml file and outputs map from sort code to bank code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.DeserializationFeature | |
import com.fasterxml.jackson.databind.MapperFeature | |
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule | |
import com.fasterxml.jackson.dataformat.xml.XmlMapper | |
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty | |
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | |
import org.springframework.boot.* | |
import org.springframework.boot.autoconfigure.SpringBootApplication | |
import org.springframework.stereotype.Component | |
import java.io.File | |
@SpringBootApplication | |
class EiscdslurperApplication | |
fun main(args: Array<String>) { | |
runApplication<EiscdslurperApplication>(*args) { | |
setBannerMode(Banner.Mode.OFF) | |
webApplicationType = WebApplicationType.NONE | |
} | |
} | |
@Component | |
class ApplicationRunnerBean() : ApplicationRunner { | |
internal val xmlMapper = XmlMapper.builder() | |
.defaultUseWrapper(false) | |
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) | |
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | |
.build() | |
.registerKotlinModule() | |
override fun run(arg0: ApplicationArguments) { | |
File("src/main/resources/report.xml").inputStream().use { | |
val doc = xmlMapper.readValue(it, BACSDocument::class.java) | |
val y = doc.data.iscdDocument.banks.flatMap { bank -> | |
bank.bankOffices.map { | |
it.sortCode to bank.bankCode | |
} | |
}.toMap() | |
println(y) | |
// output: {608326=0944, 165192=0523, 609275=0115, 301114=0115, 090025=0641, 622294=0078, 609165=0615, ... | |
} | |
} | |
} | |
//<BACSDocument xmlns="http://www.bacs.co.uk/schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bacs.co.uk/schemas Extended_ISCD_Extract_Schema.xsd"> | |
//<Data> | |
//<ISCDDocument> | |
//<Version>1.0</Version> | |
//<ProcessingDate>2019-07-15</ProcessingDate> | |
//<Created>2019-07-12</Created> | |
//<Bank BankCode="0944"> | |
// <SupervisoryBody>A</SupervisoryBody> | |
// <AbbreviatedBankName>1ST CLASS CREDIT UN</AbbreviatedBankName> | |
// <BankName>1ST CLASS CREDIT UNION LIMITED</BankName> | |
// <BankOffices SortCode="608326" BicBank="" BicBranch="" Suffix="00"> | |
// <BankOfficeTitle>1st Class Credit Union Ltd</BankOfficeTitle> | |
// <BankOfficeType>M</BankOfficeType> | |
// <DateLastChanged>2017-04-11</DateLastChanged> | |
// <PrintIndicator>0</PrintIndicator> | |
// <Address> | |
data class BACSDocument(val data:Data) | |
data class Data(val iscdDocument:ISCDDocument) | |
data class ISCDDocument( | |
val version:String, | |
val created:String, | |
@get:JacksonXmlProperty(localName = "Bank") val banks:List<Bank>) | |
data class Bank( | |
@get:JacksonXmlProperty(isAttribute = true) val bankCode:String, | |
val supervisoryBody:String, | |
val abbreviatedBankName:String, | |
val bankName:String, | |
@get:JacksonXmlProperty(localName = "BankOffices") val bankOffices:List<BankOffices>) | |
data class BankOffices( | |
@get:JacksonXmlProperty(isAttribute = true) val sortCode:String, | |
val bankOfficeTitle:String | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment