Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
jdk:
- openjdk8
- oraclejdk11
before_install:
- chmod +x gradlew
- chmod +x gradle/wrapper/gradle-wrapper.jar
Expand Down
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ subprojects{

apply from: "$rootDir/dependencies.gradle"
apply plugin: 'kotlin'
apply plugin: 'io.spring.dependency-management'

group = 'org.suggs.companydatafinder'

repositories {
clear()
jcenter()
mavenCentral()
}


dependencies {
implementation libs.kotlin,
Expand All @@ -40,6 +43,13 @@ subprojects{

testRuntimeOnly libs.test.junitEngine,
libs.logback

implementation ("org.springframework.boot:spring-boot-starter-web-services:${springBootVersion}") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}

implementation 'org.springframework.ws:spring-ws-core'
compile group: 'org.jvnet.mimepull', name: 'mimepull', version: '1.9.12'
}

ext {
Expand All @@ -51,6 +61,7 @@ subprojects{
useJUnitPlatform()
}


compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
Expand Down
24 changes: 24 additions & 0 deletions company-data-finder-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'org.springframework.boot'
apply plugin: 'kotlin'

bootJar {
archiveBaseName = 'company-data-finder-app'
Expand All @@ -15,4 +16,27 @@ dependencies {
testImplementation libs.test.restAssured

runtime project(':company-data-finder-lib')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
22 changes: 18 additions & 4 deletions company-data-finder-lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}
jar {
archiveBaseName = 'company-data-finder-lib'
version = '0.0.1'
}

repositories {
mavenCentral()
}
dependencies {
implementation libs.springBootStarterWeb

testImplementation libs.snakeYaml
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

3 changes: 3 additions & 0 deletions company-data-finder-lib/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rootProject.name = 'company-data-finder-lib'
include ':main',
':test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.suggs.companydatafinderlib.cro

import org.slf4j.LoggerFactory
import org.springframework.http.client.BufferingClientHttpRequestFactory
import org.springframework.http.client.SimpleClientHttpRequestFactory
import org.springframework.web.client.RestTemplate
import org.suggs.companydatafinderlib.cro.interceptors.RequestResponseLoggingInterceptor
import org.suggs.companydatafinderlib.cro.domain.CROCompanyProfile
import org.suggs.companydatafinderlib.cro.interceptors.CROAuthInterceptor

class CROProxy(private val authUsername: String) {

private val restTemplate = createRestTemplateWithInterceptorsForAuthentication()
private val log = LoggerFactory.getLogger(this::class.java)

private fun createRestTemplateWithInterceptorsForAuthentication(): RestTemplate {
val factory = BufferingClientHttpRequestFactory(SimpleClientHttpRequestFactory())
val template = RestTemplate(factory)
template.interceptors = listOf(
CROAuthInterceptor(authUsername),
RequestResponseLoggingInterceptor())
return template
}

/**
* Retrieves company profile data for a given cro company id
*/
fun getCompanyDataFor(companyId: String): List<CROCompanyProfile> {
log.debug("Retrieving company profile data for company id $companyId")
val url = "https://services.cro.ie/cws/companies?company_num=$companyId"
return when (val profile = restTemplate.getForEntity(url, Array<CROCompanyProfile>::class.java).body) {
null -> throw IllegalStateException("Could not create company profile for company number $companyId")
else -> profile.asList()
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CRO API
Use this API for accessing data and documents from CRO (Irish registrar of companies).
See the tests for details on how to use the api and simplified api access.
API access is directly to CRO. Details for connection etc can be found at the [CRO API](https://services.cro.ie/companies.aspx) pages.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.suggs.companydatafinderlib.cro.domain

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import java.util.*


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class CROCompanyProfile(@JsonProperty("company_num") val croNumber: String,
@JsonProperty("company_name") val croBusinessName: String,
@JsonProperty("company_addr_1") val croAddress1: String,
@JsonProperty("company_addr_2") val croAddress2: String,
@JsonProperty("company_addr_3") val croAddress3: String,
@JsonProperty("company_addr_4") val croAddress4: String,
@JsonProperty("company_reg_date") val croRegisteredDate: Date)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.suggs.companydatafinderlib.cro.interceptors

import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import java.util.*

class CROAuthInterceptor(private val username: String) : ClientHttpRequestInterceptor {
override fun intercept(request: HttpRequest, body: ByteArray, execution: ClientHttpRequestExecution): ClientHttpResponse {
val auth = "$username"
val encodedAuth = Base64.getEncoder().encodeToString(auth.toByteArray())
request.headers.add("Authorization", "Basic $encodedAuth")
return execution.execute(request, body)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.suggs.companydatafinderlib.cro.interceptors

import org.slf4j.LoggerFactory
import org.springframework.http.HttpRequest
import org.springframework.http.MediaType
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import org.springframework.util.StreamUtils
import java.io.IOException
import java.nio.charset.Charset

class RequestResponseLoggingInterceptor : ClientHttpRequestInterceptor {

private val log = LoggerFactory.getLogger(this::class.java)

override fun intercept(request: HttpRequest, body: ByteArray, execution: ClientHttpRequestExecution): ClientHttpResponse {
logRequest(request, body)
val response = execution.execute(request, body)
logResponse(response)
return response
}

@Throws(IOException::class)
private fun logRequest(request: HttpRequest, body: ByteArray) {
if (log.isDebugEnabled) {
log.debug("===========================request begin================================================")
log.debug("URI : ${request.uri}")
log.debug("Method : ${request.method}")
log.debug("Headers : ${request.headers}")
log.debug("Request body: ${String(body, Charset.forName("UTF-8"))}")
log.debug("==========================request end================================================")
}
}

@Throws(IOException::class)
private fun logResponse(response: ClientHttpResponse) {
if (log.isDebugEnabled) {
log.debug("============================response begin==========================================")
log.debug("Status code : ${response.statusCode}")
log.debug("Status text : ${response.statusText}")
log.debug("Headers : ${response.headers}")
if (response.headers.contentType!!.compareTo(MediaType.APPLICATION_JSON) == 0) {
log.debug("Response body: ${StreamUtils.copyToString(response.body, Charset.defaultCharset())}")
} else {
//log.debug("Response body: {huge blob of data}")
log.debug("Response body: ${StreamUtils.copyToString(response.body, Charset.defaultCharset())}")
}
log.debug("=======================response end=================================================")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.suggs.companydatafinderlib.kvk

import org.slf4j.LoggerFactory
import org.springframework.http.client.BufferingClientHttpRequestFactory
import org.springframework.http.client.SimpleClientHttpRequestFactory
import org.springframework.web.client.RestTemplate
import org.suggs.companydatafinderlib.cro.interceptors.RequestResponseLoggingInterceptor
import org.suggs.companydatafinderlib.kvk.domain.KVKCompanyProfile
import org.suggs.companydatafinderlib.kvk.interceptors.KVKAuthInterceptor

class KVKProxy(private val authUsername: String, private val authPassword: String) {

private val restTemplate = createRestTemplateWithInterceptorsForAuthentication()
private val log = LoggerFactory.getLogger(this::class.java)

private fun createRestTemplateWithInterceptorsForAuthentication(): RestTemplate {
val factory = BufferingClientHttpRequestFactory(SimpleClientHttpRequestFactory())
val template = RestTemplate(factory)
template.interceptors = listOf(
RequestResponseLoggingInterceptor(),
KVKAuthInterceptor(authUsername, authPassword))
return template
}

/**
* Retrieves company profile data for a given kvk company id
*/
fun getCompanyDataFor(companyId: String): KVKCompanyProfile {
log.debug("Retrieving company profile data for company id $companyId")
val url = "https://api.kvk.nl:443/api/v2/testprofile/companies?kvkNumber=$companyId"
return when (val profile = restTemplate.getForObject(url, KVKCompanyProfile::class.java)) {
null -> throw IllegalStateException("Could not create company profile for company number $companyId")
else -> profile
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# KVK API
Use this API for accessing data and documents from KVK (Dutch registered companies).
See the tests for details on how to use the api and simplified api access.
API access is directly to KVK. Details for connection etc can be found at the [KVK API](https://developers.kvk.nl/documentation/search-v2-test) pages.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.suggs.companydatafinderlib.kvk.domain

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import java.util.*

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class KVKCompanyProfile(@JsonProperty("data") val kvkData: KVKData)


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class KVKData(@JsonProperty("items") val kvkDataItems: List<KVKDataItem>)


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class KVKDataItem(@JsonProperty("kvkNumber") val kvkNumber: String,
@JsonProperty("tradeNames") val kvkTradeNames: KVKTradeNames,
@JsonProperty("addresses") val kvkAddresses: List<KVKAddress>,
@JsonProperty("foundationDate") val kvkFoundationDate: Date)


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class KVKTradeNames(@JsonProperty("businessName") val kvkBusinessName: String,
@JsonProperty("currentTradeNames") val kvkTradeNames: List<String>)


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class KVKAddress(@JsonProperty("street") val kvkStreetAddress: String,
@JsonProperty("houseNumber") val kvkHouseNumber: String,
@JsonProperty("postalCode") val kvkPostCode: String,
@JsonProperty("city") val kvkCity: String,
@JsonProperty("country") val kvkCountry: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.suggs.companydatafinderlib.kvk.interceptors

import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import java.util.*

class KVKAuthInterceptor(private val username: String, private val password: String) : ClientHttpRequestInterceptor {
override fun intercept(request: HttpRequest, body: ByteArray, execution: ClientHttpRequestExecution): ClientHttpResponse {
val auth = "$username:$password"
val encodedAuth = Base64.getEncoder().encodeToString(auth.toByteArray())
request.headers.add("Authorization", "Basic $encodedAuth")
return execution.execute(request, body)
}
}
Loading