Added more of the API JSON.

This commit is contained in:
Mark Nellemann 2019-08-19 20:58:01 +02:00
parent 0fc5ebec08
commit 2286658446
13 changed files with 196 additions and 29 deletions

View file

@ -15,12 +15,12 @@ The *Company* represents most of the same properties as seen in the example JSON
### Gradle ### Gradle
repositories { repositories {
maven { url 'https://dl.bintray.com/mnellemann/libs' } maven { url 'https://dl.bintray.com/mnellemann/libs' }
} }
dependencies { dependencies {
compile 'biz.nellemann.libs:libcvrapi:1.0.0' compile 'biz.nellemann.libs:libcvrapi:1.+'
runtime "org.slf4j:slf4j-simple:1.7.25" runtime "org.slf4j:slf4j-simple:1.7.28"
} }
## Development ## Development

View file

@ -21,7 +21,7 @@ repositories {
dependencies { dependencies {
implementation("org.slf4j:slf4j-api:${slf4jVersion}") implementation("org.slf4j:slf4j-api:${slf4jVersion}")
implementation("org.slf4j:slf4j-simple:${slf4jVersion}") //implementation("org.slf4j:slf4j-simple:${slf4jVersion}")
implementation('com.google.code.gson:gson:2.8.5') implementation('com.google.code.gson:gson:2.8.5')
implementation("com.squareup.okhttp3:okhttp:4.1.0") implementation("com.squareup.okhttp3:okhttp:4.1.0")
@ -35,6 +35,17 @@ dependencies {
} }
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
bintray { bintray {
user = System.getenv('BINTRAY_USER') user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY') key = System.getenv('BINTRAY_KEY')

View file

@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package biz.nellemann.libcvrapi;
import java.util.List;
public class Accounting {
Boolean revision;
List<AccountingDocument> documents;
}

View file

@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package biz.nellemann.libcvrapi;
public class AccountingDocument {
String url;
String type;
String start;
String end;
String publicdate;
String extension;
AccountingDocumentSummary summary;
}

View file

@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package biz.nellemann.libcvrapi;
import java.math.BigDecimal;
public class AccountingDocumentSummary {
String start;
String end;
BigDecimal revenue;
BigDecimal grossprofitloss;
BigDecimal profitloss;
BigDecimal equity;
Integer averagenumberofemployees;
/* TODO: Add fields if needed
"employeebenefitsexpense": "-27446000",
"depreciationamortisationexpenseprofitorloss": null,
"profitlossfromordinaryoperatingactivities": null,
"incomefrominvestmentsingroupenterprises": null,
"otherfinanceincome": null,
"otherfinanceexpenses": null,
"profitlossfromordinaryactivitiesbeforetax": null,
"taxexpenseonordinaryactivities": null,
"taxexpense": null,
"assets": "47380000",
"proposeddividendrecognisedinequity": null,
"proposeddividend": null,
"dividend": null,
"noncurrentassets": "21387000",
"landandbuildings": null,
"currentassets": "25993000",
"inventories": null,
"shorttermtradereceivables": null,
"cashandcashequivalents": "12312000",
"equityloan": null,
"provisions": null,
"longtermliabilitiesotherthanprovisions": null,
"shorttermliabilitiesotherthanprovisions": null,
"liabilitiesandequity": null,
"coverage": null,
"operatingmargin": null,
"roi": null,
"liquidityratio": null,
"solvencyratio": 7.389193752638244,
"equityreturn": null,
*/
}

View file

@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
@ -30,11 +30,11 @@ public class Company {
Address address; Address address;
Contact contact; Contact contact;
Industrycode industrycode; Industrycode industrycode;
Companyform compantform; Companyform companyform;
Companystatus companystatus; Companystatus companystatus;
Status status; Status status;
// Accounting accounting; Accounting accounting;
// Tax tax; // Tax tax;
Capital capital; Capital capital;

View file

@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
@ -21,7 +21,7 @@ package biz.nellemann.libcvrapi;
public class Companyform { public class Companyform {
String code; Integer code;
String description; String description;
String longdescription; String longdescription;
Boolean holding; Boolean holding;

View file

@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
@ -23,6 +23,7 @@ import java.io.IOException;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -66,7 +67,7 @@ public class CvrApi {
/** /**
* https://rest.cvrapi.dk/v1/dk/company/vatNumber * https://rest.cvrapi.dk/v1/dk/company/vatNumber
* *
* @param vatNumber * @param vatNumber
* @return * @return
* @throws IOException * @throws IOException
@ -78,20 +79,13 @@ public class CvrApi {
/** /**
* Use GSON to deserialize JSON into objects. * Use GSON to deserialize JSON into objects.
* *
* @param json * @param json
* @return * @return
*/ */
protected Company parseJsonIntoCompany(String json) { protected Company parseJsonIntoCompany(String json) throws JsonSyntaxException {
Gson gson = new Gson();
Company company; Company company = gson.fromJson(json, Company.class);
try {
company = new Company();
company = new Gson().fromJson(json, Company.class);
} catch (Exception e) {
log.error("Error deserializing json into Company", e);
return null;
}
return company; return company;
} }

View file

@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
@ -21,7 +21,7 @@ package biz.nellemann.libcvrapi;
public class Industrycode { public class Industrycode {
String code; Integer code;
String text; String text;
} }

View file

@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
@ -32,4 +32,6 @@ public class Info {
* "intervalAmountEmployees": "ANTAL_50_99", "amountEmployeesLow": "50", * "intervalAmountEmployees": "ANTAL_50_99", "amountEmployeesLow": "50",
* "amountEmployeesHigh": "99", "year": "2019", "month": "2" } * "amountEmployeesHigh": "99", "year": "2019", "month": "2" }
*/ */
InfoEmployment employment;
} }

View file

@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package biz.nellemann.libcvrapi;
public class InfoEmployment {
String intervalAmountEmployees;
Integer amountEmployeesLow;
Integer amountEmployeesHigh;
Integer year;
Integer month;
}

View file

@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
@ -21,7 +21,7 @@ package biz.nellemann.libcvrapi;
public class Status { public class Status {
String code; Integer code;
String creditcode; String creditcode;
String start; String start;
String end; String end;

View file

@ -22,10 +22,12 @@ class CvrApiSpec extends Specification {
def company = api.parseJsonIntoCompany(testJson) def company = api.parseJsonIntoCompany(testJson)
then: then:
company != null company != null
company.vat == 25063864 company.vat == 25063864
company.life.name == 'AGILLIC A/S' company.life.name == 'AGILLIC A/S'
company.secondarynames.contains('Wavetech A/S') company.secondarynames.contains('Wavetech A/S')
company.info.employment.amountEmployeesLow == 50
company.info.employment.amountEmployeesHigh == 99
} }
} }