]> git.mxchange.org Git - jjobs-core.git/blob - src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java
Don't cherry-pick:
[jjobs-core.git] / src / org / mxchange / jjobs / model / jobskill / JobPositionSkill.java
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
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.jjobs.model.jobskill;
18
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.OneToOne;
30 import javax.persistence.Table;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33 import javax.persistence.Transient;
34 import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition;
35 import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition;
36 import org.mxchange.jjobs.model.skill.JobSkill;
37 import org.mxchange.jjobs.model.skill.Skillable;
38 import org.mxchange.jusercore.model.user.LoginUser;
39 import org.mxchange.jusercore.model.user.User;
40
41 /**
42  * A POJO entity for job position skills (linking job position and skill
43  * together)
44  * <p>
45  * @author Roland Häder<roland@mxchange.org>
46  */
47 @Entity (name = "job_skills")
48 @Table (
49                 name = "jobs_skills"
50 )
51 @SuppressWarnings ("PersistenceUnitPresent")
52 public class JobPositionSkill implements SkillableJobPosition {
53
54         /**
55          * Serial number
56          */
57         @Transient
58         private static final long serialVersionUID = 186_757_123_896_419L;
59
60         /**
61          * Linked job position
62          */
63         @JoinColumn (name = "skill_job_position_id", referencedColumnName = "job_position_id", updatable = false, nullable = false)
64         @OneToOne (cascade = CascadeType.ALL, targetEntity = EmployeePosition.class, optional = false)
65         private HireableJobPosition jobPosition;
66
67         /**
68          * When this entry has been created
69          */
70         @Basic (optional = false)
71         @Column (name = "skill_job_created", nullable = false, updatable = false)
72         @Temporal (TemporalType.TIMESTAMP)
73         private Date jobPositionSkillCreated;
74
75         /**
76          * Id number (primary key
77          */
78         @Id
79         @GeneratedValue (strategy = GenerationType.IDENTITY)
80         @Column (name = "skill_job_id", nullable = false, updatable = false)
81         private Long jobPositionSkillId;
82
83         /**
84          * When this entry has been updated
85          */
86         @Column (name = "skill_job_updated", insertable = false)
87         @Temporal (TemporalType.TIMESTAMP)
88         private Date jobPositionSkillUpdated;
89
90         /**
91          * Link to skill entity
92          */
93         @JoinColumn (name = "skill_job_skill_id", nullable = false, updatable = false, referencedColumnName = "skill_id")
94         @OneToOne (cascade = CascadeType.REFRESH, targetEntity = JobSkill.class)
95         private Skillable jobSkill;
96
97         /**
98          * User added this skill (optional as administrators can add skills, too)
99          */
100         @JoinColumn (name = "skill_job_user_id", referencedColumnName = "user_id")
101         @OneToOne (cascade = CascadeType.REFRESH, targetEntity = LoginUser.class)
102         private User skillAddedUser;
103
104         /**
105          * Skill importance (0=unimportant, 10=very important)
106          */
107         @Basic (optional = false)
108         @Column (name = "skill_job_importance", nullable = false)
109         private Short skillImportance;
110
111         /**
112          * Default constructor, required for the JPA.
113          */
114         public JobPositionSkill () {
115                 // Nothing to do here
116         }
117
118         /**
119          * Constructor with all required entity properties
120          * <p>
121          * @param jobPosition An instance of a HireableJobPosition class
122          * @param jobSkill An instance of a Skillable class
123          * @param skillImportance Importance level
124          */
125         public JobPositionSkill (final HireableJobPosition jobPosition, final Skillable jobSkill, final Short skillImportance) {
126                 // Invoke default constructor
127                 this();
128
129                 // Set fields
130                 this.jobPosition = jobPosition;
131                 this.jobSkill = jobSkill;
132                 this.skillImportance = skillImportance;
133         }
134
135         @Override
136         public boolean equals (final Object object) {
137                 if (this == object) {
138                         return true;
139                 } else if (null == object) {
140                         return false;
141                 } else if (this.getClass() != object.getClass()) {
142                         return false;
143                 }
144
145                 // Cast to wanted type
146                 final SkillableJobPosition position = (SkillableJobPosition) object;
147
148                 // Check all false conditions
149                 if (!Objects.equals(this.getSkillImportance(), position.getSkillImportance())) {
150                         return false;
151                 } else if (!Objects.equals(this.getJobPosition(), position.getJobPosition())) {
152                         return false;
153                 } else if (!Objects.equals(this.getJobSkill(), position.getJobSkill())) {
154                         return false;
155                 } else if (!Objects.equals(this.getJobPositionSkillId(), position.getJobPositionSkillId())) {
156                         return false;
157                 }
158
159                 // Okay, entities are matching (not objects)
160                 return true;
161         }
162
163         @Override
164         public HireableJobPosition getJobPosition () {
165                 return this.jobPosition;
166         }
167
168         @Override
169         public void setJobPosition (final HireableJobPosition jobPosition) {
170                 this.jobPosition = jobPosition;
171         }
172
173         @Override
174         @SuppressWarnings ("ReturnOfDateField")
175         public Date getJobPositionSkillCreated () {
176                 return this.jobPositionSkillCreated;
177         }
178
179         @Override
180         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
181         public void setJobPositionSkillCreated (final Date jobPositionSkillCreated) {
182                 this.jobPositionSkillCreated = jobPositionSkillCreated;
183         }
184
185         @Override
186         public Long getJobPositionSkillId () {
187                 return this.jobPositionSkillId;
188         }
189
190         @Override
191         public void setJobPositionSkillId (final Long jobPositionSkillId) {
192                 this.jobPositionSkillId = jobPositionSkillId;
193         }
194
195         @Override
196         @SuppressWarnings ("ReturnOfDateField")
197         public Date getJobPositionSkillUpdated () {
198                 return this.jobPositionSkillUpdated;
199         }
200
201         @Override
202         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
203         public void setJobPositionSkillUpdated (final Date jobPositionSkillUpdated) {
204                 this.jobPositionSkillUpdated = jobPositionSkillUpdated;
205         }
206
207         @Override
208         public Skillable getJobSkill () {
209                 return this.jobSkill;
210         }
211
212         @Override
213         public void setJobSkill (final Skillable jobSkill) {
214                 this.jobSkill = jobSkill;
215         }
216
217         @Override
218         public User getSkillAddedUser () {
219                 return this.skillAddedUser;
220         }
221
222         @Override
223         public void setSkillAddedUser (final User skillAddedUser) {
224                 this.skillAddedUser = skillAddedUser;
225         }
226
227         @Override
228         public Short getSkillImportance () {
229                 return this.skillImportance;
230         }
231
232         @Override
233         public void setSkillImportance (final Short skillImportance) {
234                 this.skillImportance = skillImportance;
235         }
236
237         @Override
238         public int hashCode () {
239                 int hash = 5;
240
241                 hash = 41 * hash + Objects.hashCode(this.getJobPosition());
242                 hash = 41 * hash + Objects.hashCode(this.getJobSkill());
243                 hash = 41 * hash + Objects.hashCode(this.getSkillImportance());
244                 hash = 41 * hash + Objects.hashCode(this.getJobPositionSkillId());
245
246                 return hash;
247         }
248
249 }