aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java
blob: 36a302ed0d83fe3114b0f4fa0083c8c2b55c16f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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;

/**
 * Tenant information beyond technical tenant id and user authorizations.
 *
 * This info is used to capture generic support information and invoiced billing information.
 *
 * All fields are non null but strings can be empty
 *
 * @author smorgrav
 */
public class TenantInfo {

    private final String name;
    private final String email;
    private final String website;

    private final TenantContact contact;
    private final TenantAddress address;
    private final TenantBilling billingContact;
    private final TenantContacts contacts;

    TenantInfo(String name, String email, String website, String contactName, Email contactEmail,
               TenantAddress address, TenantBilling billingContact, TenantContacts contacts) {
        this(name, email, website, TenantContact.from(contactName, contactEmail), address, billingContact, contacts);
    }

    TenantInfo(String name, String email, String website, TenantContact contact, TenantAddress address, TenantBilling billing, TenantContacts contacts) {
        this.name = Objects.requireNonNull(name);
        this.email = Objects.requireNonNull(email);
        this.website = Objects.requireNonNull(website);
        this.contact = Objects.requireNonNull(contact);
        this.address = Objects.requireNonNull(address);
        this.billingContact = Objects.requireNonNull(billing);
        this.contacts = Objects.requireNonNull(contacts);
    }

    public static TenantInfo empty() {
        return new TenantInfo("", "", "", "", Email.empty(), TenantAddress.empty(), TenantBilling.empty(), TenantContacts.empty());
    }

    public String name() {
        return name;
    }

    public String email() {
        return email;
    }

    public String website() {
        return website;
    }

    public TenantContact contact() { return contact; }

    public TenantAddress address() { return address; }

    public TenantBilling billingContact() {
        return billingContact;
    }

    public TenantContacts contacts() { return contacts; }

    public boolean isEmpty() {
        return this.equals(empty());
    }

    public TenantInfo withName(String name) {
        return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
    }

    public TenantInfo withEmail(String email) {
        return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
    }

    public TenantInfo withWebsite(String website) {
        return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
    }

    public TenantInfo withContact(TenantContact contact) {
        return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
    }

    public TenantInfo withAddress(TenantAddress address) {
        return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
    }

    public TenantInfo withBilling(TenantBilling billingContact) {
        return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
    }

    public TenantInfo withContacts(TenantContacts contacts) {
        return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TenantInfo that = (TenantInfo) o;
        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) &&
                Objects.equals(contacts, that.contacts);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, email, website, contact, address, billingContact, contacts);
    }

    @Override
    public String toString() {
        return "TenantInfo{" +
                "name='" + name + '\'' +
                ", email='" + email + '\'' +
                ", website='" + website + '\'' +
                ", contact=" + contact +
                ", address=" + address +
                ", billingContact=" + billingContact +
                ", contacts=" + contacts +
                '}';
    }
}