]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/CompanyContact.java
sorted members
[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.OneToMany;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
36 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
37 import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData;
38 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
39 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
40 import org.mxchange.jcontactsbusiness.employee.Employee;
41 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
42 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
43 import org.mxchange.jusercore.model.user.LoginUser;
44 import org.mxchange.jusercore.model.user.User;
45
46 /**
47  * A POJO for business contacts
48  * <p>
49  * @author Roland Haeder
50  */
51 @Entity (name = "company_contacts")
52 @Table (name = "company_contacts")
53 public class CompanyContact implements BusinessContact, Comparable<BusinessContact> {
54
55         /**
56          * Serial number
57          */
58         private static final long serialVersionUID = 478_378_178_748_691L;
59
60         /**
61          * Reference to basic data
62          */
63         @JoinColumn (name = "company_basic_data_id", nullable = false, updatable = false)
64         @OneToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
65         private BusinessBasicData basicBusinessData;
66
67         /**
68          * Reference to company branch offfices
69          */
70         @Transient
71         private List<BranchOffice> brancheOffices;
72
73         /**
74          * Reference to contact person
75          */
76         @JoinColumn (name = "company_contact_id")
77         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
78         private Employee companyContact;
79
80         /**
81          * Id number
82          */
83         @Id
84         @Column (name = "company_id", length = 20, nullable = false, updatable = false)
85         @GeneratedValue (strategy = GenerationType.IDENTITY)
86         private Long companyContactId;
87
88         /**
89          * Reference to CEO "employee"
90          */
91         @JoinColumn (name = "company_founder_id")
92         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
93         private Employee companyFounder;
94
95         /**
96          * Timestamp when this entry has been created
97          */
98         @Basic (optional = false)
99         @Temporal (TemporalType.TIMESTAMP)
100         @Column (name = "company_entry_created", nullable = false, updatable = false)
101         private Calendar contactCreated;
102
103         /**
104          * User owner instance
105          */
106         @JoinColumn (name = "company_user_id", nullable = false, updatable = false)
107         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
108         private User contactUserOwner;
109
110         /**
111          * Reference to employee list
112          */
113         @JoinColumn (name = "company_employees_id", nullable = false, updatable = false)
114         @OneToMany (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
115         private List<Employee> employees;
116
117         /**
118          * Reference to headquarters data
119          */
120         @JoinColumn (name = "company_headquarters_data_id", nullable = false, updatable = false)
121         @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL, optional = false)
122         private HeadQuartersData headQuartersData;
123
124         @Override
125         public int compareTo (final BusinessContact businessContact) {
126                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
127         }
128
129         @Override
130         public boolean equals (final Object object) {
131                 if (object == null) {
132                         return false;
133                 } else if (getClass() != object.getClass()) {
134                         return false;
135                 }
136
137                 final BusinessContact other = (BusinessContact) object;
138
139                 return Objects.equals(this.getBasicBusinessData(), other.getBasicBusinessData());
140         }
141
142         @Override
143         public BusinessBasicData getBasicBusinessData () {
144                 return this.basicBusinessData;
145         }
146
147         @Override
148         public void setBasicBusinessData (final BusinessBasicData basicBusinessData) {
149                 this.basicBusinessData = basicBusinessData;
150         }
151
152         @Override
153         public List<BranchOffice> getBrancheOffices () {
154                 return this.brancheOffices;
155         }
156
157         @Override
158         public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
159                 this.brancheOffices = brancheOffices;
160         }
161
162         @Override
163         public Employee getCompanyContact () {
164                 return this.companyContact;
165         }
166
167         @Override
168         public void setCompanyContact (final Employee companyContact) {
169                 this.companyContact = companyContact;
170         }
171
172         @Override
173         public Long getCompanyContactId () {
174                 return this.companyContactId;
175         }
176
177         @Override
178         public void setCompanyContactId (final Long companyContactId) {
179                 this.companyContactId = companyContactId;
180         }
181
182         @Override
183         public Employee getCompanyFounder () {
184                 return this.companyFounder;
185         }
186
187         @Override
188         public void setCompanyFounder (final Employee companyFounder) {
189                 this.companyFounder = companyFounder;
190         }
191
192         @Override
193         public Calendar getContactCreated () {
194                 return this.contactCreated;
195         }
196
197         @Override
198         public void setContactCreated (final Calendar contactCreated) {
199                 this.contactCreated = contactCreated;
200         }
201
202         @Override
203         public User getContactUserOwner () {
204                 return this.contactUserOwner;
205         }
206
207         @Override
208         public void setContactUserOwner (final User contactUserOwner) {
209                 this.contactUserOwner = contactUserOwner;
210         }
211
212         @Override
213         public List<Employee> getEmployees () {
214                 return this.employees;
215         }
216
217         @Override
218         public void setEmployees (final List<Employee> employees) {
219                 this.employees = employees;
220         }
221
222         @Override
223         public HeadQuartersData getHeadQuartersData () {
224                 return this.headQuartersData;
225         }
226
227         @Override
228         public void setHeadQuartersData (final HeadQuartersData headQuartersData) {
229                 this.headQuartersData = headQuartersData;
230         }
231
232         @Override
233         public int hashCode () {
234                 int hash = 3;
235                 hash = 37 * hash + Objects.hashCode(this.getBasicBusinessData());
236                 return hash;
237         }
238 }