2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.jjobs.model.jobskill;
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;
43 * A POJO entity for job position skills (linking job position and skill
46 * @author Roland Häder<roland@mxchange.org>
48 @Entity (name = "job_skills")
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class JobPositionSkill implements SkillableJobPosition {
59 private static final long serialVersionUID = 186_757_123_896_419L;
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;
69 * When this entry has been created
71 @Basic (optional = false)
72 @Column (name = "skill_job_entry_created", nullable = false, updatable = false)
73 @Temporal (TemporalType.TIMESTAMP)
74 private Date jobPositionSkillEntryCreated;
77 * Id number (primary key
80 @GeneratedValue (strategy = GenerationType.IDENTITY)
81 @Column (name = "skill_job_id", nullable = false, updatable = false)
82 private Long jobPositionSkillId;
85 * When this entry has been updated
87 @Column (name = "skill_job_updated", insertable = false)
88 @Temporal (TemporalType.TIMESTAMP)
89 private Date jobPositionSkillUpdated;
92 * Link to skill entity
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;
99 * User added this skill (optional as administrators can add skills, too)
101 @JoinColumn (name = "skill_job_user_id", referencedColumnName = "user_id")
102 @OneToOne (cascade = CascadeType.REFRESH, targetEntity = LoginUser.class)
103 private User skillAddedUser;
106 * Skill importance (0=unimportant, 10=very important)
108 @Basic (optional = false)
109 @Column (name = "skill_job_importance", nullable = false)
110 private Short skillImportance;
113 * Default constructor, required for the JPA.
115 public JobPositionSkill () {
116 // Nothing to do here
120 * Constructor with all required entity properties
122 * @param jobPosition An instance of a HireableJobPosition class
123 * @param jobSkill An instance of a Skillable class
124 * @param skillImportance Importance level
126 public JobPositionSkill (final HireableJobPosition jobPosition, final Skillable jobSkill, final Short skillImportance) {
127 // Invoke default constructor
130 // Validate all parameter
131 if (null == jobPosition) {
133 throw new NullPointerException("jobPosition is null"); //NOI18N
134 } else if (jobPosition.getJobPositionId() == null) {
136 throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N
137 } else if (jobPosition.getJobPositionId() < 1) {
139 throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N
140 } else if (null == jobSkill) {
142 throw new NullPointerException("jobSill is null"); //NOI18N
143 } else if (jobSkill.getSkillId() == null) {
145 throw new NullPointerException("jobSill.skillId is null"); //NOI18N
146 } else if (jobSkill.getSkillId() < 1) {
148 throw new IllegalArgumentException(MessageFormat.format("jobSill.skillId={0} is invalid", jobSkill.getSkillId())); //NOI18N
149 } else if (null == skillImportance) {
151 throw new NullPointerException("skillImportance is null"); //NOI18N
155 this.jobPosition = jobPosition;
156 this.jobSkill = jobSkill;
157 this.skillImportance = skillImportance;
161 public boolean equals (final Object object) {
162 if (this == object) {
164 } else if (null == object) {
166 } else if (this.getClass() != object.getClass()) {
170 // Cast to wanted type
171 final SkillableJobPosition position = (SkillableJobPosition) object;
173 // Check all false conditions
174 if (!Objects.equals(this.getSkillImportance(), position.getSkillImportance())) {
176 } else if (!Objects.equals(this.getJobPosition(), position.getJobPosition())) {
178 } else if (!Objects.equals(this.getJobSkill(), position.getJobSkill())) {
180 } else if (!Objects.equals(this.getJobPositionSkillId(), position.getJobPositionSkillId())) {
184 // Okay, entities are matching (not objects)
189 public HireableJobPosition getJobPosition () {
190 return this.jobPosition;
194 public void setJobPosition (final HireableJobPosition jobPosition) {
195 this.jobPosition = jobPosition;
199 @SuppressWarnings ("ReturnOfDateField")
200 public Date getJobPositionSkillEntryCreated () {
201 return this.jobPositionSkillEntryCreated;
205 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
206 public void setJobPositionSkillEntryCreated (final Date jobPositionSkillEntryCreated) {
207 this.jobPositionSkillEntryCreated = jobPositionSkillEntryCreated;
211 public Long getJobPositionSkillId () {
212 return this.jobPositionSkillId;
216 public void setJobPositionSkillId (final Long jobPositionSkillId) {
217 this.jobPositionSkillId = jobPositionSkillId;
221 @SuppressWarnings ("ReturnOfDateField")
222 public Date getJobPositionSkillUpdated () {
223 return this.jobPositionSkillUpdated;
227 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
228 public void setJobPositionSkillUpdated (final Date jobPositionSkillUpdated) {
229 this.jobPositionSkillUpdated = jobPositionSkillUpdated;
233 public Skillable getJobSkill () {
234 return this.jobSkill;
238 public void setJobSkill (final Skillable jobSkill) {
239 this.jobSkill = jobSkill;
243 public User getSkillAddedUser () {
244 return this.skillAddedUser;
248 public void setSkillAddedUser (final User skillAddedUser) {
249 this.skillAddedUser = skillAddedUser;
253 public Short getSkillImportance () {
254 return this.skillImportance;
258 public void setSkillImportance (final Short skillImportance) {
259 this.skillImportance = skillImportance;
263 public int hashCode () {
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());