]> git.mxchange.org Git - jjobs-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 04:24:42 +0000 (05:24 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 04:43:06 +0000 (05:43 +0100)
- added event class and interface when an administrator adds a new skill
- added exception when a skill wasn't found
- renamed skill_<created|updated> to skill_entry_*
- added named query AllSkills

src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java [new file with mode: 0644]
src/org/mxchange/jjobs/events/skill/add/ObservableAdminAddedSkillEvent.java [new file with mode: 0644]
src/org/mxchange/jjobs/exceptions/SkillNotFoundException.java [new file with mode: 0644]
src/org/mxchange/jjobs/model/skill/JobSkill.java
src/org/mxchange/jjobs/model/skill/Skillable.java

diff --git a/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java b/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java
new file mode 100644 (file)
index 0000000..d364627
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.events.skill.add;
+
+import java.text.MessageFormat;
+import org.mxchange.jjobs.model.skill.Skillable;
+
+/**
+ * An event being fired when an administrator has added a new skill
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class AdminAddedSkillEvent implements ObservableAdminAddedSkillEvent {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 14_785_787_174_600_001L;
+
+       /**
+        * Instance of added skillable
+        */
+       private final Skillable skillable;
+
+       /**
+        * Constrcutor with skill instance
+        * <p>
+        * @param skillable An instance of a Skillable class
+        */
+       public AdminAddedSkillEvent (final Skillable skillable) {
+               // Validate parameter
+               if (null == skillable) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter 'skillable' is null"); //NOI18N
+               } else if (skillable.getSkillId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("skillable.skillId is null"); //NOI18N
+               } else if (skillable.getSkillId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("skillable.skillId={0} is invalid", skillable.getSkillId())); //NOI18N
+               }
+
+               // Set it here
+               this.skillable = skillable;
+       }
+
+       @Override
+       public Skillable getSkillable () {
+               return this.skillable;
+       }
+}
diff --git a/src/org/mxchange/jjobs/events/skill/add/ObservableAdminAddedSkillEvent.java b/src/org/mxchange/jjobs/events/skill/add/ObservableAdminAddedSkillEvent.java
new file mode 100644 (file)
index 0000000..851bc83
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.events.skill.add;
+
+import java.io.Serializable;
+import org.mxchange.jjobs.model.skill.Skillable;
+
+/**
+ * An interface for events being fired when an administrator has added a skill
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface ObservableAdminAddedSkillEvent extends Serializable {
+
+       /**
+        * Getter for Skillable class field
+        * <p>
+        * @return An instance of a Skillable class
+        */
+       Skillable getSkillable ();
+
+}
diff --git a/src/org/mxchange/jjobs/exceptions/SkillNotFoundException.java b/src/org/mxchange/jjobs/exceptions/SkillNotFoundException.java
new file mode 100644 (file)
index 0000000..1cf8687
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.model.exceptions;
+
+import java.text.MessageFormat;
+
+/**
+ * An exception thrown when a Skillable instance wasn't found
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class SkillNotFoundException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 42_895_928_956_700_001L;
+
+       /**
+        * Constructor with primary key
+        * <p>
+        * @param skillId Primary key
+        */
+       public SkillNotFoundException (final Long skillId) {
+               super(MessageFormat.format("Skill id {0} not found.", skillId)); //NOI18N
+       }
+
+}
index f479d10d209bac021de816ff6110430d06e3d41c..26e18cd70b3790262f3e2cac159f775ea0bffecf 100644 (file)
@@ -26,6 +26,8 @@ import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
@@ -44,6 +46,9 @@ import org.mxchange.jjobs.model.skill.status.SkillStatus;
 @Table (
                name = "skills"
 )
+@NamedQueries (
+               @NamedQuery (name = "AllSkills", query = "SELECT s FROM skills AS s ORDER BY s.skillId")
+)
 @SuppressWarnings ("PersistenceUnitPresent")
 public class JobSkill implements Skillable {
 
@@ -57,9 +62,16 @@ public class JobSkill implements Skillable {
         * When this entry has been created
         */
        @Basic (optional = false)
-       @Column (name = "skill_created", nullable = false, updatable = false)
+       @Column (name = "skill_entry_created", nullable = false, updatable = false)
        @Temporal (TemporalType.TIMESTAMP)
-       private Date skillCreated;
+       private Date skillEntryCreated;
+
+       /**
+        * When this entry has been updated
+        */
+       @Column (name = "skill_entry_updated", insertable = false)
+       @Temporal (TemporalType.TIMESTAMP)
+       private Date skillEntryUpdated;
 
        /**
         * Id number (primary key)
@@ -91,13 +103,6 @@ public class JobSkill implements Skillable {
        @Column (name = "skill_status", nullable = false)
        private SkillStatus skillStatus;
 
-       /**
-        * When this entry has been updated
-        */
-       @Column (name = "skill_updated", insertable = false)
-       @Temporal (TemporalType.TIMESTAMP)
-       private Date skillUpdated;
-
        /**
         * Default constructor, required for the JPA.
         */
@@ -183,14 +188,26 @@ public class JobSkill implements Skillable {
 
        @Override
        @SuppressWarnings ("ReturnOfDateField")
-       public Date getSkillCreated () {
-               return this.skillCreated;
+       public Date getSkillEntryCreated () {
+               return this.skillEntryCreated;
        }
 
        @Override
        @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setSkillCreated (final Date skillCreated) {
-               this.skillCreated = skillCreated;
+       public void setSkillEntryCreated (final Date skillEntryCreated) {
+               this.skillEntryCreated = skillEntryCreated;
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getSkillEntryUpdated () {
+               return this.skillEntryUpdated;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setSkillEntryUpdated (final Date skillEntryUpdated) {
+               this.skillEntryUpdated = skillEntryUpdated;
        }
 
        @Override
@@ -235,18 +252,6 @@ public class JobSkill implements Skillable {
                this.skillStatus = skillStatus;
        }
 
-       @Override
-       @SuppressWarnings ("ReturnOfDateField")
-       public Date getSkillUpdated () {
-               return this.skillUpdated;
-       }
-
-       @Override
-       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setSkillUpdated (final Date skillUpdated) {
-               this.skillUpdated = skillUpdated;
-       }
-
        @Override
        public int hashCode () {
                int hash = 7;
index 3ebc78055f9f2f6a74f508e26dc5a20140ab3a24..a51a53892023a4daa7e1ffd6d6fbc4951a083202 100644 (file)
@@ -60,28 +60,28 @@ public interface Skillable extends Comparable<Skillable>, Serializable {
         * <p>
         * @return Skill created timestamp
         */
-       Date getSkillCreated ();
+       Date getSkillEntryCreated ();
 
        /**
         * Setter for skill created timestamp
         * <p>
         * @param skillCreated Skill created timestamp
         */
-       void setSkillCreated (final Date skillCreated);
+       void setSkillEntryCreated (final Date skillCreated);
 
        /**
         * Getter for skill updated timestamp
         * <p>
         * @return Skill updated timestamp
         */
-       Date getSkillUpdated ();
+       Date getSkillEntryUpdated ();
 
        /**
         * Setter for skill updated timestamp
         * <p>
         * @param skillUpdated Skill updated timestamp
         */
-       void setSkillUpdated (final Date skillUpdated);
+       void setSkillEntryUpdated (final Date skillUpdated);
 
        /**
         * Getter for skill last locked timestamp