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