From 0d1e9d355d98584c6e5c03b2e954bda223941e53 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Thu, 21 Jan 2021 21:21:31 +0100 Subject: [PATCH 1/4] Fix logging. --- build.gradle | 4 ++-- gradle.properties | 6 +++--- src/test/resources/simplelogger.properties | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/simplelogger.properties diff --git a/build.gradle b/build.gradle index 2bc5fb1..fa7a3f0 100644 --- a/build.gradle +++ b/build.gradle @@ -26,12 +26,12 @@ repositories { dependencies { - implementation("org.slf4j:slf4j-api:${slf4jVersion}") + implementation("org.slf4j:slf4j-api:${slf4jVersion}") api("com.google.code.gson:gson:2.8.5") api("com.squareup.okhttp3:okhttp:4.1.0") - testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}") testImplementation('com.squareup.okhttp3:mockwebserver:4.1.0') + testRuntime("org.slf4j:slf4j-simple:${slf4jVersion}") testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}") testCompile("org.spockframework:spock-core:${spockVersion}") { exclude group: "org.codehaus.groovy" diff --git a/gradle.properties b/gradle.properties index aaa61b6..eaecf3f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ id = libcvrapi group = biz.nellemann.libs -version = 1.0.7 +version = 1.0.8 licenses = ['APACHE-2.0'] // or something else -groovyVersion = 2.5.8 -slf4jVersion = 1.7.28 +groovyVersion = 2.5.14 +slf4jVersion = 1.7.30 spockVersion = 1.3-groovy-2.5 siteUrl = https://bitbucket.org/mnellemann/libcvrapi gitUrl = https://bitbucket.org/mnellemann/libcvrapi.git diff --git a/src/test/resources/simplelogger.properties b/src/test/resources/simplelogger.properties new file mode 100644 index 0000000..d13c7ee --- /dev/null +++ b/src/test/resources/simplelogger.properties @@ -0,0 +1,6 @@ +org.slf4j.simpleLogger.logFile=System.out +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.showShortLogName=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS +org.slf4j.simpleLogger.levelInBrackets=true +#org.slf4j.simpleLogger.defaultLogLevel=debug From 486f3131c68d5013aa0e2ab2f72f26ad4af00046 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Sun, 22 Aug 2021 15:55:46 +0200 Subject: [PATCH 2/4] Remove jcenter and update dependencies. --- bitbucket-pipelines.yml | 3 ++- build.gradle | 37 ++++--------------------------------- gradle.properties | 6 +++--- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index bb287f4..fbf96d7 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -15,4 +15,5 @@ pipelines: - gradle name: Build and Release script: - - bash ./gradlew clean build bintrayUpload + - bash ./gradlew clean build + - shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/libs/*.jar ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done diff --git a/build.gradle b/build.gradle index 2bc5fb1..3fdf960 100644 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,8 @@ -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' - //classpath 'com.bmuschko:gradle-clover-plugin:2.2.3' - } -} - -apply plugin: "idea" apply plugin: "java-library" apply plugin: "groovy" apply plugin: 'maven' apply plugin: 'jacoco' apply plugin: 'maven-publish' -apply plugin: 'com.jfrog.bintray' -//apply from: "${project.projectDir}/gradle/clover.gradle" sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -27,16 +14,16 @@ repositories { dependencies { implementation("org.slf4j:slf4j-api:${slf4jVersion}") - api("com.google.code.gson:gson:2.8.5") - api("com.squareup.okhttp3:okhttp:4.1.0") + api('com.google.code.gson:gson:2.8.7') + api('com.squareup.okhttp3:okhttp:4.9.1') testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}") - testImplementation('com.squareup.okhttp3:mockwebserver:4.1.0') + testImplementation('com.squareup.okhttp3:mockwebserver:4.9.1') testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}") testCompile("org.spockframework:spock-core:${spockVersion}") { exclude group: "org.codehaus.groovy" } - testCompile( 'com.athaydes:spock-reports:1.6.2' ) { + testCompile('com.athaydes:spock-reports:2.0-groovy-3.0') { transitive = false // this avoids affecting your version of Groovy/Spock } @@ -53,22 +40,6 @@ publishing { } } -bintray { - user = System.getenv('BINTRAY_USER') - key = System.getenv('BINTRAY_KEY') - - override = true - configurations = ['archives'] - pkg { - repo = "libs" - name = "libcvrapi" - websiteUrl = siteUrl - vcsUrl = gitUrl - licenses = licenses - publish = true - } -} - jacoco { toolVersion = "0.8.4" } diff --git a/gradle.properties b/gradle.properties index aaa61b6..0463ed9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ id = libcvrapi group = biz.nellemann.libs version = 1.0.7 licenses = ['APACHE-2.0'] // or something else -groovyVersion = 2.5.8 -slf4jVersion = 1.7.28 -spockVersion = 1.3-groovy-2.5 +groovyVersion = 3.0.8 +slf4jVersion = 1.7.32 +spockVersion = 2.0-groovy-3.0 siteUrl = https://bitbucket.org/mnellemann/libcvrapi gitUrl = https://bitbucket.org/mnellemann/libcvrapi.git From f24f9c5e40ca867e39a7bce9f6e59de5878904a5 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Wed, 3 Nov 2021 15:48:13 +0100 Subject: [PATCH 3/4] Work on free API --- README.md | 12 +---- build.gradle | 7 ++- gradle.properties | 2 +- .../java/biz/nellemann/libcvrapi/CvrApi.java | 16 +++--- src/test/resources/39895692-free.json | 52 +++++++++++++++++++ 5 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 src/test/resources/39895692-free.json diff --git a/README.md b/README.md index 9f6293e..c511fea 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ----------------------------------- -A Java library to query (a Danish VAT API service). Work in progress. +A Java library to query (a Danish VAT API service). ## Usage @@ -12,16 +12,6 @@ A Java library to query (a Danish VAT API service). Work The *Company* represents most of the same properties as seen in the example JSON in the [api documentation](http://docs.rest.cvrapi.dk/). -### Gradle - - repositories { - maven { url 'https://dl.bintray.com/mnellemann/libs' } - } - - dependencies { - compile 'biz.nellemann.libs:libcvrapi:1.+' - } - ## Development To build and test the code: diff --git a/build.gradle b/build.gradle index 3fdf960..866de91 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ repositories { dependencies { implementation("org.slf4j:slf4j-api:${slf4jVersion}") - api('com.google.code.gson:gson:2.8.7') + api('com.google.code.gson:gson:2.8.8') api('com.squareup.okhttp3:okhttp:4.9.1') testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}") @@ -40,6 +40,11 @@ publishing { } } + +test { + useJUnitPlatform() +} + jacoco { toolVersion = "0.8.4" } diff --git a/gradle.properties b/gradle.properties index 0463ed9..3ffab2f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ id = libcvrapi group = biz.nellemann.libs -version = 1.0.7 +version = 1.0.8 licenses = ['APACHE-2.0'] // or something else groovyVersion = 3.0.8 slf4jVersion = 1.7.32 diff --git a/src/main/java/biz/nellemann/libcvrapi/CvrApi.java b/src/main/java/biz/nellemann/libcvrapi/CvrApi.java index c6001b9..16ce51e 100644 --- a/src/main/java/biz/nellemann/libcvrapi/CvrApi.java +++ b/src/main/java/biz/nellemann/libcvrapi/CvrApi.java @@ -30,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.Objects; public class CvrApi { @@ -72,7 +73,7 @@ public class CvrApi { Response response = client.newCall(request).execute(); switch (response.code()) { case 200: - return response.body().string(); + return Objects.requireNonNull(response.body()).string(); case 401: log.warn("get() - 401 - Access Denied"); throw new Exception("Access Denied"); @@ -88,9 +89,8 @@ public class CvrApi { /** * Query the API: https://rest.cvrapi.dk/v1/dk/company/vatNumber * - * @param vatNumber - * @return - * @throws IOException + * @param vatNumber Danish VAT number + * @return String with JSON */ protected String getCompanyJson(String vatNumber) throws Exception { String response = get(BASE_URL + "/company/" + vatNumber); @@ -102,8 +102,8 @@ public class CvrApi { /** * Use GSON to deserialize JSON into POJO's. * - * @param json - * @return + * @param json String of JSON + * @return Company object */ protected Company parseJsonIntoCompany(String json) { Gson gson = new Gson(); @@ -114,8 +114,8 @@ public class CvrApi { /** * Lookup company by VAT number * - * @param vatNumber - * @return + * @param vatNumber Danish VAT number as String + * @return Company object */ public Company getCompanyByVatNumber(String vatNumber) { diff --git a/src/test/resources/39895692-free.json b/src/test/resources/39895692-free.json new file mode 100644 index 0000000..d770e31 --- /dev/null +++ b/src/test/resources/39895692-free.json @@ -0,0 +1,52 @@ +// https://cvrapi.dk/api?search=39895692&country=dk&format=json +{ + "vat": 39895692, + "name": "Cabcon AS", + "address": "Stamholmen 193A, 1. tv.", + "zipcode": "2650", + "city": "Hvidovre", + "cityname": null, + "protected": true, + "phone": "38760324", + "email": "jag@cabcon.dk", + "fax": null, + "startdate": "01\/10 - 2018", + "enddate": null, + "employees": null, + "addressco": "Cabcon A\/S", + "industrycode": 465210, + "industrydesc": "Engroshandel med elektronisk udstyr", + "companycode": 210, + "companydesc": "Anden udenlandsk virksomhed", + "creditstartdate": null, + "creditbankrupt": false, + "creditstatus": null, + "owners": [ + { + "name": "Cabcon AS" + } + ], + "productionunits": [ + { + "pno": 1024011204, + "main": true, + "name": "Cabcon AS", + "address": "Stamholmen 193A, 1. tv.", + "zipcode": "2650", + "city": "Hvidovre", + "cityname": null, + "protected": true, + "phone": "38760324", + "email": "jag@cabcon.dk", + "fax": null, + "startdate": "01\/10 - 2018", + "enddate": null, + "employees": null, + "addressco": "Cabcon A\/S", + "industrycode": 465210, + "industrydesc": "Engroshandel med elektronisk udstyr" + } + ], + "t": 100, + "version": 6 +} From 4200c0bf52102aba31c73858d333ddf7e2e56317 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Sat, 11 Dec 2021 20:17:52 +0100 Subject: [PATCH 4/4] Update 3rd party dependencies. --- build.gradle | 19 +++++++++---------- gradle.properties | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 866de91..9467216 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,5 @@ apply plugin: "java-library" apply plugin: "groovy" -apply plugin: 'maven' apply plugin: 'jacoco' apply plugin: 'maven-publish' @@ -14,16 +13,16 @@ repositories { dependencies { implementation("org.slf4j:slf4j-api:${slf4jVersion}") - api('com.google.code.gson:gson:2.8.8') - api('com.squareup.okhttp3:okhttp:4.9.1') + api('com.google.code.gson:gson:2.8.9') + api('com.squareup.okhttp3:okhttp:4.9.3') testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}") - testImplementation('com.squareup.okhttp3:mockwebserver:4.9.1') - testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}") - testCompile("org.spockframework:spock-core:${spockVersion}") { + testImplementation('com.squareup.okhttp3:mockwebserver:4.9.3') + testImplementation("org.codehaus.groovy:groovy-all:${groovyVersion}") + testImplementation("org.spockframework:spock-core:${spockVersion}") { exclude group: "org.codehaus.groovy" } - testCompile('com.athaydes:spock-reports:2.0-groovy-3.0') { + testImplementation('com.athaydes:spock-reports:2.1.1-groovy-3.0') { transitive = false // this avoids affecting your version of Groovy/Spock } @@ -46,14 +45,14 @@ test { } jacoco { - toolVersion = "0.8.4" + toolVersion = "0.8.7" } jacocoTestReport { group = "verification" reports { - xml.enabled false - csv.enabled false + xml.required = false + csv.required = false html.destination file("${buildDir}/reports/coverage") } afterEvaluate { diff --git a/gradle.properties b/gradle.properties index 3ffab2f..7a93942 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ id = libcvrapi group = biz.nellemann.libs -version = 1.0.8 +version = 1.0.9 licenses = ['APACHE-2.0'] // or something else -groovyVersion = 3.0.8 +groovyVersion = 3.0.9 slf4jVersion = 1.7.32 spockVersion = 2.0-groovy-3.0 siteUrl = https://bitbucket.org/mnellemann/libcvrapi diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ef9a9e0..84d1f85 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists