diff options
author | Ola Aunronning <olaa@yahooinc.com> | 2023-10-24 14:14:44 +0200 |
---|---|---|
committer | Ola Aunronning <olaa@yahooinc.com> | 2023-10-24 14:14:44 +0200 |
commit | 1e92bd3eaac015e2794298e392a69bb8b218a57b (patch) | |
tree | e35c907b06cc4f8ee32fd97a0815a3785a19fd39 /controller-server | |
parent | 900209e698fc4921103c505ed357eb368059e1a4 (diff) |
Wrap attributes in StringWrapper
Diffstat (limited to 'controller-server')
3 files changed, 32 insertions, 25 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java index 087e7d54e12..c733ccc0a5e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java @@ -28,6 +28,8 @@ import com.yahoo.vespa.hosted.controller.tenant.CloudTenant; import com.yahoo.vespa.hosted.controller.tenant.DeletedTenant; import com.yahoo.vespa.hosted.controller.tenant.Email; import com.yahoo.vespa.hosted.controller.tenant.LastLoginInfo; +import com.yahoo.vespa.hosted.controller.tenant.PurchaseOrder; +import com.yahoo.vespa.hosted.controller.tenant.TaxCode; import com.yahoo.vespa.hosted.controller.tenant.Tenant; import com.yahoo.vespa.hosted.controller.tenant.TenantAddress; import com.yahoo.vespa.hosted.controller.tenant.TenantBilling; @@ -285,9 +287,9 @@ public class TenantSerializer { } private TenantBilling tenantInfoBillingContactFromSlime(Inspector billingObject) { - var taxCode = billingObject.field(taxCodeField).asString(); - var purchaseOrder = billingObject.field(purchaseOrderField).asString(); - var invoiceEmail = billingObject.field(invoiceEmailField).asString(); + var taxCode = new TaxCode(billingObject.field(taxCodeField).asString()); + var purchaseOrder = new PurchaseOrder(billingObject.field(purchaseOrderField).asString()); + var invoiceEmail = new Email(billingObject.field(invoiceEmailField).asString(), false); return TenantBilling.empty() .withContact(TenantContact.from( @@ -359,9 +361,9 @@ public class TenantSerializer { billingCursor.setString("email", billingContact.contact().email().getEmailAddress()); billingCursor.setBool("emailVerified", billingContact.contact().email().isVerified()); billingCursor.setString("phone", billingContact.contact().phone()); - billingCursor.setString(taxCodeField, billingContact.getTaxCode()); - billingCursor.setString(purchaseOrderField, billingContact.getPurchaseOrder()); - billingCursor.setString(invoiceEmailField, billingContact.getInvoiceEmail()); + billingCursor.setString(taxCodeField, billingContact.getTaxCode().value()); + billingCursor.setString(purchaseOrderField, billingContact.getPurchaseOrder().value()); + billingCursor.setString(invoiceEmailField, billingContact.getInvoiceEmail().getEmailAddress()); toSlime(billingContact.address(), billingCursor); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index d1d65f85dd3..c108040c7a1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -127,6 +127,8 @@ import com.yahoo.vespa.hosted.controller.tenant.DeletedTenant; import com.yahoo.vespa.hosted.controller.tenant.Email; import com.yahoo.vespa.hosted.controller.tenant.LastLoginInfo; import com.yahoo.vespa.hosted.controller.tenant.PendingMailVerification; +import com.yahoo.vespa.hosted.controller.tenant.PurchaseOrder; +import com.yahoo.vespa.hosted.controller.tenant.TaxCode; import com.yahoo.vespa.hosted.controller.tenant.Tenant; import com.yahoo.vespa.hosted.controller.tenant.TenantAddress; import com.yahoo.vespa.hosted.controller.tenant.TenantBilling; @@ -694,9 +696,9 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { contact.setString("email", billingContact.contact().email().getEmailAddress()); contact.setBool("emailVerified", billingContact.contact().email().isVerified()); contact.setString("phone", billingContact.contact().phone()); - root.setString("taxCode", billingContact.getTaxCode()); - root.setString("purchaseOrder", billingContact.getPurchaseOrder()); - root.setString("invoiceEmail", billingContact.getInvoiceEmail()); + root.setString("taxCode", billingContact.getTaxCode().value()); + root.setString("purchaseOrder", billingContact.getPurchaseOrder().value()); + root.setString("invoiceEmail", billingContact.getInvoiceEmail().getEmailAddress()); toSlime(billingContact.address(), root); // will create "address" on the parent } @@ -706,14 +708,15 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { private SlimeJsonResponse putTenantInfoBilling(CloudTenant cloudTenant, Inspector inspector) { var info = cloudTenant.info(); - var contact = info.billingContact().contact(); - var address = info.billingContact().address(); + var billing = info.billingContact(); + var contact = billing.contact(); + var address = billing.address(); var mergedContact = updateBillingContact(inspector.field("contact"), cloudTenant.name(), contact); - var mergedAddress = updateTenantInfoAddress(inspector.field("address"), info.billingContact().address()); - var mergedTaxCode = getString(inspector.field("taxCode"), info.billingContact().getTaxCode()); - var mergedPurchaseOrder = getString(inspector.field("purchaseOrder"), info.billingContact().getPurchaseOrder()); - var mergedInvoiceEmail = getString(inspector.field("invoiceEmail"), info.billingContact().getInvoiceEmail()); + var mergedAddress = updateTenantInfoAddress(inspector.field("address"), billing.address()); + var mergedTaxCode = optional("taxCode", inspector).map(TaxCode::new).orElse(billing.getTaxCode()); + var mergedPurchaseOrder = optional("purchaseOrder", inspector).map(PurchaseOrder::new).orElse(billing.getPurchaseOrder()); + var mergedInvoiceEmail = optional("invoiceEmail", inspector).map(mail -> new Email(mail, false)).orElse(billing.getInvoiceEmail()); var mergedBilling = info.billingContact() .withContact(mergedContact) @@ -775,7 +778,7 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { } if (! mergedInfo.billingContact().getInvoiceEmail().isBlank()) { // TODO: Validate invoice email is set if collection method is INVOICE - if (! mergedInfo.billingContact().getInvoiceEmail().contains("@")) + if (! mergedInfo.billingContact().getInvoiceEmail().getEmailAddress().contains("@")) throw new IllegalArgumentException("'Invoice email' needs to be an email address"); } } @@ -799,9 +802,9 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { billingCursor.setString("email", billingContact.contact().email().getEmailAddress()); billingCursor.setBool("emailVerified", billingContact.contact().email().isVerified()); billingCursor.setString("phone", billingContact.contact().phone()); - billingCursor.setString("taxCode", billingContact.getTaxCode()); - billingCursor.setString("purchaseOrder", billingContact.getPurchaseOrder()); - billingCursor.setString("invoiceEmail", billingContact.getInvoiceEmail()); + billingCursor.setString("taxCode", billingContact.getTaxCode().value()); + billingCursor.setString("purchaseOrder", billingContact.getPurchaseOrder().value()); + billingCursor.setString("invoiceEmail", billingContact.getInvoiceEmail().getEmailAddress()); toSlime(billingContact.address(), billingCursor); } @@ -931,9 +934,9 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { private TenantBilling updateTenantInfoBillingContact(Inspector insp, TenantName tenantName, TenantBilling oldContact) { if (!insp.valid()) return oldContact; - var taxCode = getString(insp.field("taxCode"), oldContact.getTaxCode()); - var purchaseOrder = getString(insp.field("purchaseOrder"), oldContact.getPurchaseOrder()); - var invoiceEmail = getString(insp.field("purchaseOrder"), oldContact.getInvoiceEmail()); + var taxCode = optional("taxCode", insp).map(TaxCode::new).orElse(oldContact.getTaxCode()); + var purchaseOrder = optional("purchaseOrder", insp).map(PurchaseOrder::new).orElse(oldContact.getPurchaseOrder()); + var invoiceEmail = optional("invoiceEmail", insp).map(mail -> new Email(mail, false)).orElse(oldContact.getInvoiceEmail()); return TenantBilling.empty() .withContact(updateBillingContact(insp, tenantName, oldContact.contact())) .withAddress(updateTenantInfoAddress(insp.field("address"), oldContact.address())) diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java index 31794aad350..bab5aec8cf7 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java @@ -24,6 +24,8 @@ import com.yahoo.vespa.hosted.controller.tenant.CloudTenant; import com.yahoo.vespa.hosted.controller.tenant.DeletedTenant; import com.yahoo.vespa.hosted.controller.tenant.Email; import com.yahoo.vespa.hosted.controller.tenant.LastLoginInfo; +import com.yahoo.vespa.hosted.controller.tenant.PurchaseOrder; +import com.yahoo.vespa.hosted.controller.tenant.TaxCode; import com.yahoo.vespa.hosted.controller.tenant.TenantAddress; import com.yahoo.vespa.hosted.controller.tenant.TenantBilling; import com.yahoo.vespa.hosted.controller.tenant.TenantContact; @@ -235,9 +237,9 @@ public class TenantSerializerTest { .withCountry("Sodor") .withAddress("Central Station") .withRegion("Irish Sea")) - .withPurchaseOrder("PO42") - .withTaxCode("1234L") - .withInvoiceEmail("billing@mycomp.any") + .withPurchaseOrder(new PurchaseOrder("PO42")) + .withTaxCode(new TaxCode("1234L")) + .withInvoiceEmail(new Email("billing@mycomp.any", false)) ); Slime slime = new Slime(); |