]> git.mxchange.org Git - jjobs-core.git/blob - src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java
Updated copyright year
[jjobs-core.git] / src / org / mxchange / jjobs / model / jobskill / JobPositionSkill.java
1 /*
2  * Copyright (C) 2016 - 2024 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.text.MessageFormat;
20 import java.util.Date;
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.model.jobposition.EmployeePosition;
36 import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition;
37 import org.mxchange.jcontactsbusiness.model.utils.JobPositionUtils;
38 import org.mxchange.jcoreutils.comparable.ComparableUtils;
39 import org.mxchange.jcoreutils.number.SafeNumberUtils;
40 import org.mxchange.jjobs.model.skill.JobSkill;
41 import org.mxchange.jjobs.model.skill.Skillable;
42 import org.mxchange.jjobs.model.utils.SkillUtils;
43 import org.mxchange.jusercore.model.user.LoginUser;
44 import org.mxchange.jusercore.model.user.User;
45 import org.mxchange.jusercore.model.utils.UserUtils;
46
47 /**
48  * A POJO entity for job position skills (linking job position and skill
49  * together)
50  * <p>
51  * @author Roland Häder<roland@mxchange.org>
52  */
53 @Entity (name = "job_skills")
54 @Table (
55                 name = "jobs_skills"
56 )
57 @SuppressWarnings ("PersistenceUnitPresent")
58 public class JobPositionSkill implements SkillableJobPosition {
59
60         /**
61          * Serial number
62          */
63         @Transient
64         private static final long serialVersionUID = 186_757_123_896_419L;
65
66         /**
67          * Linked job position
68          */
69         @JoinColumn (name = "skill_job_position_id", referencedColumnName = "job_position_id", updatable = false, nullable = false)
70         @OneToOne (cascade = CascadeType.ALL, targetEntity = EmployeePosition.class, optional = false)
71         private HireableJobPosition jobPosition;
72
73         /**
74          * When this entry has been created
75          */
76         @Basic (optional = false)
77         @Column (name = "skill_job_entry_created", nullable = false, updatable = false)
78         @Temporal (TemporalType.TIMESTAMP)
79         private Date jobPositionSkillEntryCreated;
80
81         /**
82          * Id number (primary key
83          */
84         @Id
85         @GeneratedValue (strategy = GenerationType.IDENTITY)
86         @Column (name = "skill_job_id", nullable = false, updatable = false)
87         private Long jobPositionSkillId;
88
89         /**
90          * When this entry has been updated
91          */
92         @Column (name = "skill_job_updated", insertable = false)
93         @Temporal (TemporalType.TIMESTAMP)
94         private Date jobPositionSkillUpdated;
95
96         /**
97          * Link to skill entity
98          */
99         @JoinColumn (name = "skill_job_skill_id", nullable = false, updatable = false, referencedColumnName = "skill_id")
100         @OneToOne (cascade = CascadeType.REFRESH, targetEntity = JobSkill.class)
101         private Skillable jobSkill;
102
103         /**
104          * User added this skill (optional as administrators can add skills, too)
105          */
106         @JoinColumn (name = "skill_job_user_id", referencedColumnName = "user_id")
107         @OneToOne (cascade = CascadeType.REFRESH, targetEntity = LoginUser.class)
108         private User skillAddedUser;
109
110         /**
111          * Skill importance (0=unimportant, 10=very important)
112          */
113         @Basic (optional = false)
114         @Column (name = "skill_job_importance", nullable = false)
115         private Short skillImportance;
116
117         /**
118          * Default constructor, required for the JPA.
119          */
120         public JobPositionSkill () {
121                 // Nothing to do here
122         }
123
124         /**
125          * Constructor with all required entity properties
126          * <p>
127          * @param jobPosition     An instance of a HireableJobPosition class
128          * @param jobSkill        An instance of a Skillable class
129          * @param skillImportance Importance level
130          */
131         public JobPositionSkill (final HireableJobPosition jobPosition, final Skillable jobSkill, final Short skillImportance) {
132                 // Invoke default constructor
133                 this();
134
135                 // Validate all parameter
136                 if (null == jobPosition) {
137                         // ThroW NPE
138                         throw new NullPointerException("jobPosition is null"); //NOI18N
139                 } else if (jobPosition.getJobPositionId() == null) {
140                         // Throw it again
141                         throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N
142                 } else if (jobPosition.getJobPositionId() < 1) {
143                         // Throw IAE
144                         throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N
145                 } else if (null == jobSkill) {
146                         // Throw NPE
147                         throw new NullPointerException("jobSill is null"); //NOI18N
148                 } else if (jobSkill.getSkillId() == null) {
149                         // Throw it again
150                         throw new NullPointerException("jobSill.skillId is null"); //NOI18N
151                 } else if (jobSkill.getSkillId() < 1) {
152                         // Throw IAE
153                         throw new IllegalArgumentException(MessageFormat.format("jobSill.skillId={0} is invalid", jobSkill.getSkillId())); //NOI18N
154                 } else if (null == skillImportance) {
155                         // Throw NPE
156                         throw new NullPointerException("skillImportance is null"); //NOI18N
157                 }
158
159                 // Set fields
160                 this.jobPosition = jobPosition;
161                 this.jobSkill = jobSkill;
162                 this.skillImportance = skillImportance;
163         }
164
165         @Override
166         public int compareTo (final SkillableJobPosition skillableJobPosition) {
167                 // Checkparameter and return 0 if equal
168                 if (null == skillableJobPosition) {
169                         // Should not happen
170                         throw new NullPointerException("Parameter 'skillableJobPosition' is null"); //NOI18N
171                 } else if (Objects.equals(this, skillableJobPosition)) {
172                         // Same object
173                         return 0;
174                 }
175
176                 // Init comparitors
177                 final int comparitors[] = {
178                         // First compare job position
179                         JobPositionUtils.compare(this.getJobPosition(), skillableJobPosition.getJobPosition()),
180                         // ... next skill
181                         SkillUtils.compare(this.getJobSkill(), skillableJobPosition.getJobSkill()),
182                         // next job importance
183                         SafeNumberUtils.compare(this.getSkillImportance(), skillableJobPosition.getSkillImportance()),
184                         // ... next user
185                         UserUtils.compare(this.getSkillAddedUser(), skillableJobPosition.getSkillAddedUser()),
186                         // ... next primary key
187                         SafeNumberUtils.compare(this.getJobPositionSkillId(), skillableJobPosition.getJobPositionSkillId())
188                 };
189
190                 // Check all values
191                 final int comparison = ComparableUtils.checkAll(comparitors);
192
193                 // Return value
194                 return comparison;
195         }
196
197         @Override
198         public boolean equals (final Object object) {
199                 if (this == object) {
200                         return true;
201                 } else if (null == object) {
202                         return false;
203                 } else if (this.getClass() != object.getClass()) {
204                         return false;
205                 }
206
207                 // Cast to wanted type
208                 final SkillableJobPosition position = (SkillableJobPosition) object;
209
210                 // Check all false conditions
211                 if (!Objects.equals(this.getSkillImportance(), position.getSkillImportance())) {
212                         return false;
213                 } else if (!Objects.equals(this.getJobPosition(), position.getJobPosition())) {
214                         return false;
215                 } else if (!Objects.equals(this.getJobSkill(), position.getJobSkill())) {
216                         return false;
217                 } else if (!Objects.equals(this.getJobPositionSkillId(), position.getJobPositionSkillId())) {
218                         return false;
219                 }
220
221                 // Okay, entities are matching (not objects)
222                 return true;
223         }
224
225         @Override
226         public HireableJobPosition getJobPosition () {
227                 return this.jobPosition;
228         }
229
230         @Override
231         public void setJobPosition (final HireableJobPosition jobPosition) {
232                 this.jobPosition = jobPosition;
233         }
234
235         @Override
236         @SuppressWarnings ("ReturnOfDateField")
237         public Date getJobPositionSkillEntryCreated () {
238                 return this.jobPositionSkillEntryCreated;
239         }
240
241         @Override
242         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
243         public void setJobPositionSkillEntryCreated (final Date jobPositionSkillEntryCreated) {
244                 this.jobPositionSkillEntryCreated = jobPositionSkillEntryCreated;
245         }
246
247         @Override
248         public Long getJobPositionSkillId () {
249                 return this.jobPositionSkillId;
250         }
251
252         @Override
253         public void setJobPositionSkillId (final Long jobPositionSkillId) {
254                 this.jobPositionSkillId = jobPositionSkillId;
255         }
256
257         @Override
258         @SuppressWarnings ("ReturnOfDateField")
259         public Date getJobPositionSkillUpdated () {
260                 return this.jobPositionSkillUpdated;
261         }
262
263         @Override
264         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
265         public void setJobPositionSkillUpdated (final Date jobPositionSkillUpdated) {
266                 this.jobPositionSkillUpdated = jobPositionSkillUpdated;
267         }
268
269         @Override
270         public Skillable getJobSkill () {
271                 return this.jobSkill;
272         }
273
274         @Override
275         public void setJobSkill (final Skillable jobSkill) {
276                 this.jobSkill = jobSkill;
277         }
278
279         @Override
280         public User getSkillAddedUser () {
281                 return this.skillAddedUser;
282         }
283
284         @Override
285         public void setSkillAddedUser (final User skillAddedUser) {
286                 this.skillAddedUser = skillAddedUser;
287         }
288
289         @Override
290         public Short getSkillImportance () {
291                 return this.skillImportance;
292         }
293
294         @Override
295         public void setSkillImportance (final Short skillImportance) {
296                 this.skillImportance = skillImportance;
297         }
298
299         @Override
300         public int hashCode () {
301                 int hash = 5;
302
303                 hash = 41 * hash + Objects.hashCode(this.getJobPosition());
304                 hash = 41 * hash + Objects.hashCode(this.getJobSkill());
305                 hash = 41 * hash + Objects.hashCode(this.getSkillImportance());
306                 hash = 41 * hash + Objects.hashCode(this.getJobPositionSkillId());
307
308                 return hash;
309         }
310
311 }