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