From 0344d5091cf75c41751f7661f836ac5d3143088e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 24 Nov 2022 04:21:37 +0100 Subject: [PATCH] Continued: - renamed fields from "Created/Updated" to "EntryCreated/EntryUpdated" - "validate" all parameters of public methods --- .../model/jobskill/JobPositionSkill.java | 41 +++++++-- .../model/jobskill/SkillableJobPosition.java | 10 +-- .../mxchange/jjobs/model/skill/JobSkill.java | 4 +- .../model/user/skills/SkillableUser.java | 14 +-- .../jjobs/model/user/skills/UserSkill.java | 87 +++++++++++-------- 5 files changed, 97 insertions(+), 59 deletions(-) diff --git a/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java b/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java index 86a087c..410ae68 100644 --- a/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java +++ b/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java @@ -16,6 +16,7 @@ */ package org.mxchange.jjobs.model.jobskill; +import java.text.MessageFormat; import java.util.Date; import java.util.Objects; import javax.persistence.Basic; @@ -68,9 +69,9 @@ public class JobPositionSkill implements SkillableJobPosition { * When this entry has been created */ @Basic (optional = false) - @Column (name = "skill_job_created", nullable = false, updatable = false) + @Column (name = "skill_job_entry_created", nullable = false, updatable = false) @Temporal (TemporalType.TIMESTAMP) - private Date jobPositionSkillCreated; + private Date jobPositionSkillEntryCreated; /** * Id number (primary key @@ -118,14 +119,38 @@ public class JobPositionSkill implements SkillableJobPosition { /** * Constructor with all required entity properties *

- * @param jobPosition An instance of a HireableJobPosition class - * @param jobSkill An instance of a Skillable class + * @param jobPosition An instance of a HireableJobPosition class + * @param jobSkill An instance of a Skillable class * @param skillImportance Importance level */ public JobPositionSkill (final HireableJobPosition jobPosition, final Skillable jobSkill, final Short skillImportance) { // Invoke default constructor this(); + // Validate all parameter + if (null == jobPosition) { + // ThroW NPE + throw new NullPointerException("jobPosition is null"); //NOI18N + } else if (jobPosition.getJobPositionId() == null) { + // Throw it again + throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N + } else if (jobPosition.getJobPositionId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N + } else if (null == jobSkill) { + // Throw NPE + throw new NullPointerException("jobSill is null"); //NOI18N + } else if (jobSkill.getSkillId() == null) { + // Throw it again + throw new NullPointerException("jobSill.skillId is null"); //NOI18N + } else if (jobSkill.getSkillId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("jobSill.skillId={0} is invalid", jobSkill.getSkillId())); //NOI18N + } else if (null == skillImportance) { + // Throw NPE + throw new NullPointerException("skillImportance is null"); //NOI18N + } + // Set fields this.jobPosition = jobPosition; this.jobSkill = jobSkill; @@ -172,14 +197,14 @@ public class JobPositionSkill implements SkillableJobPosition { @Override @SuppressWarnings ("ReturnOfDateField") - public Date getJobPositionSkillCreated () { - return this.jobPositionSkillCreated; + public Date getJobPositionSkillEntryCreated () { + return this.jobPositionSkillEntryCreated; } @Override @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setJobPositionSkillCreated (final Date jobPositionSkillCreated) { - this.jobPositionSkillCreated = jobPositionSkillCreated; + public void setJobPositionSkillEntryCreated (final Date jobPositionSkillEntryCreated) { + this.jobPositionSkillEntryCreated = jobPositionSkillEntryCreated; } @Override diff --git a/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java b/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java index 99c18f5..0287898 100644 --- a/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java +++ b/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java @@ -48,14 +48,14 @@ public interface SkillableJobPosition extends Serializable { *

* @return Job position skill created timestamp */ - Date getJobPositionSkillCreated (); + Date getJobPositionSkillEntryCreated (); /** * Setter for job position skill created timestamp *

- * @param jobPositionSkillCreated Job position skill created timestamp + * @param jobPositionSkillEntryCreated Job position skill created timestamp */ - void setJobPositionSkillCreated (final Date jobPositionSkillCreated); + void setJobPositionSkillEntryCreated (final Date jobPositionSkillEntryCreated); /** * Getter for job position skill updated timestamp @@ -67,9 +67,9 @@ public interface SkillableJobPosition extends Serializable { /** * Setter for job position skill updated timestamp *

- * @param jobPositionSkillUpdated Job position skill updated timestamp + * @param jobPositionSkillEntryUpdated Job position skill updated timestamp */ - void setJobPositionSkillUpdated (final Date jobPositionSkillUpdated); + void setJobPositionSkillUpdated (final Date jobPositionSkillEntryUpdated); /** * Getter for job skill diff --git a/src/org/mxchange/jjobs/model/skill/JobSkill.java b/src/org/mxchange/jjobs/model/skill/JobSkill.java index e67dc71..963b744 100644 --- a/src/org/mxchange/jjobs/model/skill/JobSkill.java +++ b/src/org/mxchange/jjobs/model/skill/JobSkill.java @@ -16,7 +16,6 @@ */ package org.mxchange.jjobs.model.skill; -import org.mxchange.jjobs.model.skill.status.SkillStatus; import java.util.Date; import java.util.Objects; import javax.persistence.Basic; @@ -31,6 +30,7 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.mxchange.jjobs.model.skill.status.SkillStatus; /** * A POJO entity for skills @@ -105,7 +105,7 @@ public class JobSkill implements Skillable { /** * Constructor with required fields *

- * @param skillName Name of skill + * @param skillName Name of skill * @param skillStatus Status */ public JobSkill (final String skillName, final SkillStatus skillStatus) { diff --git a/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java b/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java index d2695f0..3f2116f 100644 --- a/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java +++ b/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java @@ -16,9 +16,9 @@ */ package org.mxchange.jjobs.model.user.skills; -import org.mxchange.jjobs.model.skill.Skillable; import java.io.Serializable; import java.util.Date; +import org.mxchange.jjobs.model.skill.Skillable; import org.mxchange.jusercore.model.user.User; /** @@ -47,28 +47,28 @@ public interface SkillableUser extends Serializable { *

* @return Job position skill created timestamp */ - Date getUserSkillCreated (); + Date getUserSkillEntryCreated (); /** * Setter for user skill created timestamp *

- * @param userSkillCreated Job position skill created timestamp + * @param userSkillEntryCreated Job position skill created timestamp */ - void setUserSkillCreated (final Date userSkillCreated); + void setUserSkillEntryCreated (final Date userSkillEntryCreated); /** * Getter for user skill updated timestamp *

* @return Job position skill updated timestamp */ - Date getUserSkillUpdated (); + Date getUserSkillEntryUpdated (); /** * Setter for user skill updated timestamp *

- * @param userSkillUpdated Job position skill updated timestamp + * @param userSkillEntryUpdated Job position skill updated timestamp */ - void setUserSkillUpdated (final Date userSkillUpdated); + void setUserSkillEntryUpdated (final Date userSkillEntryUpdated); /** * Getter for job skill diff --git a/src/org/mxchange/jjobs/model/user/skills/UserSkill.java b/src/org/mxchange/jjobs/model/user/skills/UserSkill.java index 64c07c0..aa089b3 100644 --- a/src/org/mxchange/jjobs/model/user/skills/UserSkill.java +++ b/src/org/mxchange/jjobs/model/user/skills/UserSkill.java @@ -16,8 +16,7 @@ */ package org.mxchange.jjobs.model.user.skills; -import org.mxchange.jjobs.model.skill.JobSkill; -import org.mxchange.jjobs.model.skill.Skillable; +import java.text.MessageFormat; import java.util.Date; import java.util.Objects; import javax.persistence.Basic; @@ -32,6 +31,8 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import org.mxchange.jjobs.model.skill.JobSkill; +import org.mxchange.jjobs.model.skill.Skillable; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -55,7 +56,7 @@ public class UserSkill implements SkillableUser { /** * Link to skills entity */ - @JoinColumn (name = "user_skill_id", referencedColumnName = "skill_id", nullable = false, updatable = false) + @JoinColumn (name = "user_skill_skill_id", referencedColumnName = "skill_id", nullable = false, updatable = false) @OneToOne (cascade = CascadeType.REFRESH, optional = false, targetEntity = JobSkill.class) private Skillable jobSkill; @@ -70,25 +71,25 @@ public class UserSkill implements SkillableUser { * When this entry has been created */ @Basic (optional = false) - @Column (name = "user_skill_created", nullable = false, updatable = false) + @Column (name = "user_skill_entry_created", nullable = false, updatable = false) @Temporal (TemporalType.TIMESTAMP) - private Date userSkillCreated; + private Date userSkillEntryCreated; + + /** + * When this entry has been updated + */ + @Column (name = "user_skill_entry_updated", insertable = false) + @Temporal (TemporalType.TIMESTAMP) + private Date userSkillEntryUpdated; /** * Id number (primary key) */ @Id @GeneratedValue (strategy = GenerationType.IDENTITY) - @Column (name = "user_skill_entry_id", nullable = false, updatable = false) + @Column (name = "user_skill_id", nullable = false, updatable = false) private Long userSkillId; - /** - * When this entry has been updated - */ - @Column (name = "user_skill_updated", insertable = false) - @Temporal (TemporalType.TIMESTAMP) - private Date userSkillUpdated; - /** * Default constructor, required for the EJB */ @@ -99,7 +100,7 @@ public class UserSkill implements SkillableUser { /** * Constructor with all required entity properties *

- * @param jobSkill An instance of a Skillable class + * @param jobSkill An instance of a Skillable class * @param skillUser An instance of a User class */ public UserSkill (final Skillable jobSkill, final User skillUser) { @@ -110,9 +111,21 @@ public class UserSkill implements SkillableUser { if (null == jobSkill) { // Throw NPE throw new NullPointerException("jobSkill is null"); //NOI18N + } else if (jobSkill.getSkillId() == null) { + // Throw it again + throw new NullPointerException("jobSill.skillId is null"); //NOI18N + } else if (jobSkill.getSkillId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("jobSill.skillId={0} is invalid", jobSkill.getSkillId())); //NOI18N } else if (null == skillUser) { // Throw NPE throw new NullPointerException("skillUser is null"); //NOI18N + } else if (skillUser.getUserId() == null) { + // Throw it agin + throw new NullPointerException("skillUser.userId is null"); //NOI18N + } else if (skillUser.getUserId() < 1) { + // Throw IAE + throw new NullPointerException(MessageFormat.format("skillUser.userId={0} is invalid", skillUser.getUserId())); //NOI18N } // Set fields @@ -143,17 +156,6 @@ public class UserSkill implements SkillableUser { return true; } - @Override - public int hashCode () { - int hash = 7; - - hash = 17 * hash + Objects.hashCode(this.getJobSkill()); - hash = 17 * hash + Objects.hashCode(this.getSkillUser()); - hash = 17 * hash + Objects.hashCode(this.getUserSkillId()); - - return hash; - } - @Override public Skillable getJobSkill () { return this.jobSkill; @@ -176,14 +178,26 @@ public class UserSkill implements SkillableUser { @Override @SuppressWarnings ("ReturnOfDateField") - public Date getUserSkillCreated () { - return this.userSkillCreated; + public Date getUserSkillEntryCreated () { + return this.userSkillEntryCreated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setUserSkillEntryCreated (final Date userSkillEntryCreated) { + this.userSkillEntryCreated = userSkillEntryCreated; + } + + @Override + @SuppressWarnings ("ReturnOfDateField") + public Date getUserSkillEntryUpdated () { + return this.userSkillEntryUpdated; } @Override @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setUserSkillCreated (final Date userSkillCreated) { - this.userSkillCreated = userSkillCreated; + public void setUserSkillEntryUpdated (final Date userSkillEntryUpdated) { + this.userSkillEntryUpdated = userSkillEntryUpdated; } @Override @@ -197,15 +211,14 @@ public class UserSkill implements SkillableUser { } @Override - @SuppressWarnings ("ReturnOfDateField") - public Date getUserSkillUpdated () { - return this.userSkillUpdated; - } + public int hashCode () { + int hash = 7; - @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setUserSkillUpdated (final Date userSkillUpdated) { - this.userSkillUpdated = userSkillUpdated; + hash = 17 * hash + Objects.hashCode(this.getJobSkill()); + hash = 17 * hash + Objects.hashCode(this.getSkillUser()); + hash = 17 * hash + Objects.hashCode(this.getUserSkillId()); + + return hash; } } -- 2.39.5