]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/CompanyContact.java
Added email address for author
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / CompanyContact.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontactsbusiness;
18
19 import java.util.Calendar;
20 import java.util.List;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
36 import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData;
37 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
38 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
39 import org.mxchange.jcontactsbusiness.employee.Employee;
40 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
41 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
42 import org.mxchange.jusercore.model.user.LoginUser;
43 import org.mxchange.jusercore.model.user.User;
44
45 /**
46  * A POJO for business contacts
47  * <p>
48  * @author Roland Haeder<roland@mxchange.org>
49  */
50 @Entity (name = "company_contacts")
51 @Table (name = "company_contacts")
52 public class CompanyContact implements BusinessContact, Comparable<BusinessContact> {
53
54         /**
55          * Serial number
56          */
57         private static final long serialVersionUID = 470_375_172_748_691L;
58
59         /**
60          * Reference to basic data
61          */
62         @JoinColumn (name = "company_basic_data_id", nullable = false, updatable = false)
63         @OneToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
64         private BusinessBasicData basicBusinessData;
65
66         /**
67          * Reference to company branch offfices
68          */
69         @Transient
70         private List<BranchOffice> brancheOffices;
71
72         /**
73          * Reference to contact person
74          */
75         @JoinColumn (name = "company_contact_id")
76         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
77         private Employee companyContact;
78
79         /**
80          * Id number
81          */
82         @Id
83         @Column (name = "company_id", length = 20, nullable = false, updatable = false)
84         @GeneratedValue (strategy = GenerationType.IDENTITY)
85         private Long companyContactId;
86
87         /**
88          * Reference to CEO "employee"
89          */
90         @JoinColumn (name = "company_founder_id")
91         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
92         private Employee companyFounder;
93
94         /**
95          * Timestamp when this entry has been created
96          */
97         @Basic (optional = false)
98         @Temporal (TemporalType.TIMESTAMP)
99         @Column (name = "company_entry_created", nullable = false, updatable = false)
100         private Calendar contactCreated;
101
102         /**
103          * User owner instance
104          */
105         @JoinColumn (name = "company_user_id", nullable = false, updatable = false)
106         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
107         private User contactUserOwner;
108
109         /**
110          * Reference to headquarters data
111          */
112         @JoinColumn (name = "company_headquarters_data_id", nullable = false, updatable = false)
113         @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL, optional = false)
114         private HeadQuartersData headQuartersData;
115
116         @Override
117         public int compareTo (final BusinessContact businessContact) {
118                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
119         }
120
121         @Override
122         public boolean equals (final Object object) {
123                 if (object == null) {
124                         return false;
125                 } else if (this.getClass() != object.getClass()) {
126                         return false;
127                 }
128
129                 final BusinessContact other = (BusinessContact) object;
130
131                 return Objects.equals(this.getBasicBusinessData(), other.getBasicBusinessData());
132         }
133
134         @Override
135         public BusinessBasicData getBasicBusinessData () {
136                 return this.basicBusinessData;
137         }
138
139         @Override
140         public void setBasicBusinessData (final BusinessBasicData basicBusinessData) {
141                 this.basicBusinessData = basicBusinessData;
142         }
143
144         @Override
145         public List<BranchOffice> getBrancheOffices () {
146                 return this.brancheOffices;
147         }
148
149         @Override
150         public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
151                 this.brancheOffices = brancheOffices;
152         }
153
154         @Override
155         public Employee getCompanyContact () {
156                 return this.companyContact;
157         }
158
159         @Override
160         public void setCompanyContact (final Employee companyContact) {
161                 this.companyContact = companyContact;
162         }
163
164         @Override
165         public Long getCompanyContactId () {
166                 return this.companyContactId;
167         }
168
169         @Override
170         public void setCompanyContactId (final Long companyContactId) {
171                 this.companyContactId = companyContactId;
172         }
173
174         @Override
175         public Employee getCompanyFounder () {
176                 return this.companyFounder;
177         }
178
179         @Override
180         public void setCompanyFounder (final Employee companyFounder) {
181                 this.companyFounder = companyFounder;
182         }
183
184         @Override
185         public Calendar getContactCreated () {
186                 return this.contactCreated;
187         }
188
189         @Override
190         public void setContactCreated (final Calendar contactCreated) {
191                 this.contactCreated = contactCreated;
192         }
193
194         @Override
195         public User getContactUserOwner () {
196                 return this.contactUserOwner;
197         }
198
199         @Override
200         public void setContactUserOwner (final User contactUserOwner) {
201                 this.contactUserOwner = contactUserOwner;
202         }
203
204         @Override
205         public HeadQuartersData getHeadQuartersData () {
206                 return this.headQuartersData;
207         }
208
209         @Override
210         public void setHeadQuartersData (final HeadQuartersData headQuartersData) {
211                 this.headQuartersData = headQuartersData;
212         }
213
214         @Override
215         public int hashCode () {
216                 int hash = 3;
217                 hash = 37 * hash + Objects.hashCode(this.getBasicBusinessData());
218                 return hash;
219         }
220 }