aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorØyvind Grønnesby <oyving@verizonmedia.com>2022-03-01 11:24:18 +0100
committerLeandro Alves <leandroalves@yahooinc.com>2022-03-14 11:01:55 +0100
commit6012cf065da30cf9baee97706d67a6ff6e77cb46 (patch)
treedc5ba6fc61e3a6acab5b61d6b22cbf225296e95a /controller-api
parentfed4f6dddba35fe13b9d10dc79485fa7d4d97afb (diff)
Clean up the tenant info classes
There was some repetition in the TenantInfo classes. Created dedicated classes for TenantAddress and TenantContact. Used these throughout the TenantInfo tree. This commit also removes the 'invoiceEmail' field that was never used.
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/CloudTenant.java2
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantAddress.java97
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContact.java68
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java120
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoAddress.java97
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoBillingContact.java67
6 files changed, 237 insertions, 214 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/CloudTenant.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/CloudTenant.java
index 9894de86116..9a4e04ebb3a 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/CloudTenant.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/CloudTenant.java
@@ -53,7 +53,7 @@ public class CloudTenant extends Tenant {
createdAt,
LastLoginInfo.EMPTY,
Optional.ofNullable(creator),
- ImmutableBiMap.of(), TenantInfo.EMPTY, List.of(), Optional.empty());
+ ImmutableBiMap.of(), TenantInfo.empty(), List.of(), Optional.empty());
}
/** The user that created the tenant */
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantAddress.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantAddress.java
new file mode 100644
index 00000000000..02a8629eff1
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantAddress.java
@@ -0,0 +1,97 @@
+package com.yahoo.vespa.hosted.controller.tenant;
+
+import java.util.Objects;
+
+/**
+ * A generic address container that tries to make as few assumptions about addresses as possible.
+ * Most addresses have some of these fields, but with different names (e.g. postal code vs zip code).
+ *
+ * When consuming data from this class, do not make any assumptions about which fields have content.
+ * An address might be still valid with surprisingly little information.
+ *
+ * All fields are non-null, but might be empty strings.
+ *
+ * @author ogronnesby
+ */
+public class TenantAddress {
+ private final String address;
+ private final String code;
+ private final String city;
+ private final String region;
+ private final String country;
+
+ TenantAddress(String address, String code, String city, String region, String country) {
+ this.address = Objects.requireNonNull(address, "'address' was null");
+ this.code = Objects.requireNonNull(code, "'code' was null");
+ this.city = Objects.requireNonNull(city, "'city' was null");
+ this.region = Objects.requireNonNull(region, "'region' was null");
+ this.country = Objects.requireNonNull(country, "'country' was null");
+ }
+
+ public static TenantAddress empty() {
+ return new TenantAddress("", "", "", "", "");
+ }
+
+ /** Multi-line fields that has the contents of the street address (or similar) */
+ public String address() { return address; }
+
+ /** The ZIP or postal code part of the address */
+ public String code() { return code; }
+
+ /** The city of the address */
+ public String city() { return city; }
+
+ /** The region part of the address - e.g. a state, county, or province */
+ public String region() { return region; }
+
+ /** The country part of the address. Its name, not a code */
+ public String country() { return country; }
+
+ public boolean isEmpty() {
+ return this.equals(empty());
+ }
+
+ public TenantAddress withAddress(String address) {
+ return new TenantAddress(address, code, city, region, country);
+ }
+
+ public TenantAddress withCode(String code) {
+ return new TenantAddress(address, code, city, region, country);
+ }
+
+ public TenantAddress withCity(String city) {
+ return new TenantAddress(address, code, city, region, country);
+ }
+
+ public TenantAddress withRegion(String region) {
+ return new TenantAddress(address, code, city, region, country);
+ }
+
+ public TenantAddress withCountry(String country) {
+ return new TenantAddress(address, code, city, region, country);
+ }
+
+ @Override
+ public String toString() {
+ return "TenantAddress{" +
+ "address='" + address + '\'' +
+ ", code='" + code + '\'' +
+ ", city='" + city + '\'' +
+ ", region='" + region + '\'' +
+ ", country='" + country + '\'' +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ TenantAddress that = (TenantAddress) o;
+ return Objects.equals(address, that.address) && Objects.equals(code, that.code) && Objects.equals(city, that.city) && Objects.equals(region, that.region) && Objects.equals(country, that.country);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address, code, city, region, country);
+ }
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContact.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContact.java
new file mode 100644
index 00000000000..e99c126bef1
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContact.java
@@ -0,0 +1,68 @@
+package com.yahoo.vespa.hosted.controller.tenant;
+
+import java.util.Objects;
+
+/**
+ * @author ogronnesby
+ */
+public class TenantContact {
+ private String name;
+ private String email;
+ private String phone;
+
+ private TenantContact(String name, String email, String phone) {
+ this.name = Objects.requireNonNull(name);
+ this.email = Objects.requireNonNull(email);
+ this.phone = Objects.requireNonNull(phone);
+ }
+
+ public static TenantContact from(String name, String email, String phone) {
+ return new TenantContact(name, email, phone);
+ }
+
+ public static TenantContact from(String name, String email) {
+ return TenantContact.from(name, email, "");
+ }
+
+ public static TenantContact empty() {
+ return new TenantContact("", "", "");
+ }
+
+ public String name() { return name; }
+ public String email() { return email; }
+ public String phone() { return phone; }
+
+ public TenantContact withName(String name) {
+ return new TenantContact(name, email, phone);
+ }
+
+ public TenantContact withEmail(String email) {
+ return new TenantContact(name, email, phone);
+ }
+
+ public TenantContact withPhone(String phone) {
+ return new TenantContact(name, email, phone);
+ }
+
+ @Override
+ public String toString() {
+ return "TenantContact{" +
+ "name='" + name + '\'' +
+ ", email='" + email + '\'' +
+ ", phone='" + phone + '\'' +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ TenantContact that = (TenantContact) o;
+ return Objects.equals(name, that.name) && Objects.equals(email, that.email) && Objects.equals(phone, that.phone);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, email, phone);
+ }
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java
index 87d4f03b090..9a295c5d19a 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java
@@ -13,51 +13,32 @@ import java.util.Objects;
* @author smorgrav
*/
public class TenantInfo {
- // Editable as 'Tenant Information - Company Name'
- // Viewable in the 'Account - Profile' section as 'Company Name'
- private final String name;
- // Editable as 'Tenant Information - Email'
- // Not displayed outside of 'Edit profile'
+ private final String name;
private final String email;
-
- // Editable as 'Tenant Information - Website'
- // Viewable in the 'Account - Profile' section at bottom of 'Contact Information'
private final String website;
- // Editable as 'Contact Information - Contact Name'
- // Viewable in the 'Account - Profile' section in 'Contact Information'
- private final String contactName;
-
- // Editable as 'Contact Information - Contact Email'
- // Viewable in the 'Account - Profile' section in 'Contact Information'
- private final String contactEmail;
-
- // Not editable in the account setting
- // Not viewable.
- // TODO: Remove
- private final String invoiceEmail;
-
- // See class for more info
- private final TenantInfoAddress address;
-
- // See class for more info
+ private final TenantContact contact;
+ private final TenantAddress address;
private final TenantInfoBillingContact billingContact;
TenantInfo(String name, String email, String website, String contactName, String contactEmail,
- String invoiceEmail, TenantInfoAddress address, TenantInfoBillingContact billingContact) {
+ TenantAddress address, TenantInfoBillingContact billingContact) {
+ this(name, email, website, TenantContact.from(contactName, contactEmail), address, billingContact);
+ }
+
+ TenantInfo(String name, String email, String website, TenantContact contact, TenantAddress address, TenantInfoBillingContact billing) {
this.name = Objects.requireNonNull(name);
this.email = Objects.requireNonNull(email);
this.website = Objects.requireNonNull(website);
- this.contactName = Objects.requireNonNull(contactName);
- this.contactEmail = Objects.requireNonNull(contactEmail);
- this.invoiceEmail = Objects.requireNonNull(invoiceEmail);
+ this.contact = Objects.requireNonNull(contact);
this.address = Objects.requireNonNull(address);
- this.billingContact = Objects.requireNonNull(billingContact);
+ this.billingContact = Objects.requireNonNull(billing);
}
- public static final TenantInfo EMPTY = new TenantInfo("","","", "", "", "",
- TenantInfoAddress.EMPTY, TenantInfoBillingContact.EMPTY);
+ public static TenantInfo empty() {
+ return new TenantInfo("", "", "", "", "", TenantAddress.empty(), TenantInfoBillingContact.empty());
+ }
public String name() {
return name;
@@ -71,60 +52,40 @@ public class TenantInfo {
return website;
}
- public String contactName() {
- return contactName;
- }
+ public TenantContact contact() { return contact; }
- public String contactEmail() {
- return contactEmail;
- }
-
- public String invoiceEmail() {
- return invoiceEmail;
- }
-
- public TenantInfoAddress address() {
- return address;
- }
+ public TenantAddress address() { return address; }
public TenantInfoBillingContact billingContact() {
return billingContact;
}
- public TenantInfo withName(String newName) {
- return new TenantInfo(newName, email, website, contactName, contactEmail, invoiceEmail, address, billingContact);
- }
-
- public TenantInfo withEmail(String newEmail) {
- return new TenantInfo(name, newEmail, website, contactName, contactEmail, invoiceEmail, address, billingContact);
- }
-
- public TenantInfo withWebsite(String newWebsite) {
- return new TenantInfo(name, email, newWebsite, contactName, contactEmail, invoiceEmail, address, billingContact);
+ public boolean isEmpty() {
+ return this.equals(empty());
}
- public TenantInfo withContactName(String newContactName) {
- return new TenantInfo(name, email, website, newContactName, contactEmail, invoiceEmail, address, billingContact);
+ public TenantInfo withName(String name) {
+ return new TenantInfo(name, email, website, contact, address, billingContact);
}
- public TenantInfo withContactEmail(String newContactEmail) {
- return new TenantInfo(name, email, website, contactName, newContactEmail, invoiceEmail, address, billingContact);
+ public TenantInfo withEmail(String email) {
+ return new TenantInfo(name, email, website, contact, address, billingContact);
}
- public TenantInfo withInvoiceEmail(String newInvoiceEmail) {
- return new TenantInfo(name, email, website, contactName, contactEmail, newInvoiceEmail, address, billingContact);
+ public TenantInfo withWebsite(String website) {
+ return new TenantInfo(name, email, website, contact, address, billingContact);
}
- public TenantInfo withAddress(TenantInfoAddress newAddress) {
- return new TenantInfo(name, email, website, contactName, contactEmail, invoiceEmail, newAddress, billingContact);
+ public TenantInfo withContact(TenantContact contact) {
+ return new TenantInfo(name, email, website, contact, address, billingContact);
}
- public TenantInfo withBillingContact(TenantInfoBillingContact newBillingContact) {
- return new TenantInfo(name, email, website, contactName, contactEmail, invoiceEmail, address, newBillingContact);
+ public TenantInfo withAddress(TenantAddress address) {
+ return new TenantInfo(name, email, website, contact, address, billingContact);
}
- public boolean isEmpty() {
- return this.equals(EMPTY);
+ public TenantInfo withBilling(TenantInfoBillingContact billingContact) {
+ return new TenantInfo(name, email, website, contact, address, billingContact);
}
@Override
@@ -132,18 +93,23 @@ public class TenantInfo {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TenantInfo that = (TenantInfo) o;
- return name.equals(that.name) &&
- email.equals(that.email) &&
- website.equals(that.website) &&
- contactName.equals(that.contactName) &&
- contactEmail.equals(that.contactEmail) &&
- invoiceEmail.equals(that.invoiceEmail) &&
- address.equals(that.address) &&
- billingContact.equals(that.billingContact);
+ return Objects.equals(name, that.name) && Objects.equals(email, that.email) && Objects.equals(website, that.website) && Objects.equals(contact, that.contact) && Objects.equals(address, that.address) && Objects.equals(billingContact, that.billingContact);
}
@Override
public int hashCode() {
- return Objects.hash(name, email, website, contactName, contactEmail, invoiceEmail, address, billingContact);
+ return Objects.hash(name, email, website, contact, address, billingContact);
+ }
+
+ @Override
+ public String toString() {
+ return "TenantInfo{" +
+ "name='" + name + '\'' +
+ ", email='" + email + '\'' +
+ ", website='" + website + '\'' +
+ ", contact=" + contact +
+ ", address=" + address +
+ ", billingContact=" + billingContact +
+ '}';
}
}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoAddress.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoAddress.java
deleted file mode 100644
index 740adde4519..00000000000
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoAddress.java
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.tenant;
-
-import java.util.Objects;
-
-/**
- * Address formats are quite diverse across the world both in therms of what fields are used, named and
- * the order of them.
- *
- * To be generic a little future proof the address fields here are a mix of free text (address lines) and fixed fields.
- * The address lines can be street address, P.O box, c/o name, apartment, suite, unit, building floor etc etc.
- *
- * All fields are mandatory but can be an empty string (ie. not null)
- *
- * @author smorgrav
- */
-public class TenantInfoAddress {
-
- // All fields are editable in 'Edit Profile - Company Address'.
- // The fields are not exposed outside the 'Edit Profile' form.
- private final String addressLines;
- private final String postalCodeOrZip;
- private final String city;
- private final String stateRegionProvince;
- private final String country;
-
- TenantInfoAddress(String addressLines, String postalCodeOrZip, String city, String country, String stateRegionProvince) {
- this.addressLines = Objects.requireNonNull(addressLines);;
- this.city = Objects.requireNonNull(city);
- this.postalCodeOrZip = Objects.requireNonNull(postalCodeOrZip);
- this.country = Objects.requireNonNull(country);
- this.stateRegionProvince = Objects.requireNonNull(stateRegionProvince);
- }
-
- public static final TenantInfoAddress EMPTY = new TenantInfoAddress("","","", "", "");
-
- public String addressLines() {
- return addressLines;
- }
-
- public String postalCodeOrZip() {
- return postalCodeOrZip;
- }
-
- public String city() {
- return city;
- }
-
- public String country() {
- return country;
- }
-
- public String stateRegionProvince() {
- return stateRegionProvince;
- }
-
- public TenantInfoAddress withAddressLines(String newAddressLines) {
- return new TenantInfoAddress(newAddressLines, postalCodeOrZip, city, country, stateRegionProvince);
- }
-
- public TenantInfoAddress withPostalCodeOrZip(String newPostalCodeOrZip) {
- return new TenantInfoAddress(addressLines, newPostalCodeOrZip, city, country, stateRegionProvince);
- }
-
- public TenantInfoAddress withCity(String newCity) {
- return new TenantInfoAddress(addressLines, postalCodeOrZip, newCity, country, stateRegionProvince);
- }
-
- public TenantInfoAddress withCountry(String newCountry) {
- return new TenantInfoAddress(addressLines, postalCodeOrZip, city, newCountry, stateRegionProvince);
- }
-
- public TenantInfoAddress withStateRegionProvince(String newStateRegionProvince) {
- return new TenantInfoAddress(addressLines, postalCodeOrZip, city, country, newStateRegionProvince);
- }
-
- public boolean isEmpty() {
- return this.equals(EMPTY);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- TenantInfoAddress that = (TenantInfoAddress) o;
- return addressLines.equals(that.addressLines) &&
- postalCodeOrZip.equals(that.postalCodeOrZip) &&
- city.equals(that.city) &&
- stateRegionProvince.equals(that.stateRegionProvince) &&
- country.equals(that.country);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(addressLines, postalCodeOrZip, city, stateRegionProvince, country);
- }
-}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoBillingContact.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoBillingContact.java
index c875a19d57b..2c9a0196905 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoBillingContact.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoBillingContact.java
@@ -8,56 +8,40 @@ import java.util.Objects;
*/
public class TenantInfoBillingContact {
- // All fields are editable in 'Billing - Edit billing contact'
- // Only 'name' and 'email' are exposed outside the 'Edit billing contact' form.
- // All these fields are required by the billing process.
- private final String name;
- private final String email;
- private final String phone;
- private final TenantInfoAddress address;
+ private final TenantContact contact;
+ private final TenantAddress address;
- TenantInfoBillingContact(String name, String email, String phone, TenantInfoAddress address) {
- this.name = Objects.requireNonNull(name);
- this.email = Objects.requireNonNull(email);
- this.phone = Objects.requireNonNull(phone);
- this.address = Objects.requireNonNull(address);
+ TenantInfoBillingContact(String name, String email, String phone, TenantAddress address) {
+ this(TenantContact.from(name, email, phone), address);
}
- public static final TenantInfoBillingContact EMPTY =
- new TenantInfoBillingContact("","", "", TenantInfoAddress.EMPTY);
-
- public String name() {
- return name;
+ TenantInfoBillingContact(TenantContact contact, TenantAddress address) {
+ this.contact = Objects.requireNonNull(contact);
+ this.address = Objects.requireNonNull(address);
}
- public String email() { return email; }
-
- public String phone() {
- return phone;
+ public static TenantInfoBillingContact empty() {
+ return new TenantInfoBillingContact("", "", "", TenantAddress.empty());
}
- public TenantInfoAddress address() {
- return address;
+ public TenantContact contact() {
+ return contact;
}
- public TenantInfoBillingContact withName(String newName) {
- return new TenantInfoBillingContact(newName, email, phone, address);
- }
-
- public TenantInfoBillingContact withEmail(String newEmail) {
- return new TenantInfoBillingContact(name, newEmail, phone, address);
+ public TenantAddress address() {
+ return address;
}
- public TenantInfoBillingContact withPhone(String newPhone) {
- return new TenantInfoBillingContact(name, email, newPhone, address);
+ public TenantInfoBillingContact withContact(TenantContact updatedContact) {
+ return new TenantInfoBillingContact(updatedContact, this.address);
}
- public TenantInfoBillingContact withAddress(TenantInfoAddress newAddress) {
- return new TenantInfoBillingContact(name, email, phone, newAddress);
+ public TenantInfoBillingContact withAddress(TenantAddress updatedAddress) {
+ return new TenantInfoBillingContact(this.contact, updatedAddress);
}
public boolean isEmpty() {
- return this.equals(EMPTY);
+ return this.equals(empty());
}
@Override
@@ -65,14 +49,19 @@ public class TenantInfoBillingContact {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TenantInfoBillingContact that = (TenantInfoBillingContact) o;
- return name.equals(that.name) &&
- email.equals(that.email) &&
- phone.equals(that.phone) &&
- address.equals(that.address);
+ return Objects.equals(contact, that.contact) && Objects.equals(address, that.address);
}
@Override
public int hashCode() {
- return Objects.hash(name, email, phone, address);
+ return Objects.hash(contact, address);
+ }
+
+ @Override
+ public String toString() {
+ return "TenantInfoBillingContact{" +
+ "contact=" + contact +
+ ", address=" + address +
+ '}';
}
}