From 8b6c5e37aff416b59f4182f901328479d543a71e Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 30 Oct 2023 15:30:10 +0100 Subject: Add country to tax id definition --- .../integration/billing/MockBillingController.java | 2 +- .../yahoo/vespa/hosted/controller/tenant/TaxId.java | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'controller-api') diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java index 18dd339b4a1..92a84ad9918 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java @@ -221,7 +221,7 @@ public class MockBillingController implements BillingController { @Override public void validateTaxId(TaxId id) throws IllegalArgumentException { - if (id.isEmpty() || id.isLegacy()) return; + if (id.isEmpty() || id.isLegacy() || id.country().isEmpty()) return; if (!List.of("eu_vat", "no_vat").contains(id.type().value())) throw new IllegalArgumentException("Unknown tax id type '%s'".formatted(id.type().value())); if (!id.code().value().matches("\\w+")) diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java index 99c2400c58c..172ad257f6a 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java @@ -8,17 +8,27 @@ import static ai.vespa.validation.Validation.requireLength; /** * @author olaa */ -public record TaxId(Type type, Code code) { +public record TaxId(Country country, Type type, Code code) { - public TaxId(String type, String code) { this(new Type(type), new Code(code)); } + public TaxId(String country, String type, String code) { this(new Country(country), new Type(type), new Code(code)); } - public static TaxId empty() { return new TaxId(Type.empty(), Code.empty()); } - public boolean isEmpty() { return type.isEmpty() && code.isEmpty(); } + public static TaxId empty() { return new TaxId(Country.empty(), Type.empty(), Code.empty()); } + public boolean isEmpty() { return country.isEmpty() && type.isEmpty() && code.isEmpty(); } // TODO(bjorncs) Remove legacy once no longer present in ZK - public static TaxId legacy(String code) { return new TaxId(Type.empty(), new Code(code)); } + public static TaxId legacy(String code) { return new TaxId(Country.empty(), Type.empty(), new Code(code)); } public boolean isLegacy() { return type.isEmpty() && !code.isEmpty(); } + public static class Country extends StringWrapper { + public Country(String value) { + super(value); + requireLength(value, "tax code country length", 0, 2); + } + + public static Country empty() { return new Country(""); } + public boolean isEmpty() { return value().isEmpty(); } + } + public static class Type extends StringWrapper { public Type(String value) { super(value); -- cgit v1.2.3