]> git.mxchange.org Git - jjobs-war.git/commitdiff
WIP:
authorRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 07:00:56 +0000 (08:00 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 07:07:08 +0000 (08:07 +0100)
- added administrative action controller with add/create and update methods
- added static data method SkillStatus enumeration
- added field for it
- added method isSkillAlreadyAdded()
- added form field skillStatus with converter

src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/jobs/skill/action/JobsAdminSkillActionWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/beans/jobs/skill/action/JobsAdminSkillActionWebRequestController.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/beans/jobs/skill/list/JobsSkillListWebViewBean.java
src/java/org/mxchange/jjobs/beans/jobs/skill/list/JobsSkillListWebViewController.java
src/java/org/mxchange/jjobs/converter/jobs/skill/JobsSkillStatusConverter.java [new file with mode: 0644]
web/admin/jobs/skill/admin_skill_list.xhtml

index 7915dc4c422b973fa4199db71b37f961bccb289a..4a725f3e20d13cf20fc5e50644f66ad3a6e0c067 100644 (file)
@@ -21,6 +21,7 @@ import javax.inject.Named;
 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
 import org.mxchange.jcoreee.dates.DayOfTheWeek;
 import org.mxchange.jjobs.beans.BaseJobsBean;
+import org.mxchange.jjobs.model.skill.status.SkillStatus;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
@@ -73,6 +74,15 @@ public class JobsDataWebApplicationBean extends BaseJobsBean {
                return ProfileMode.values();
        }
 
+       /**
+        * Returns an array of all skill statuses
+        * <p>
+        * @return An array of all skill statuses
+        */
+       public SkillStatus[] getSkillStatuses () {
+               return SkillStatus.values();
+       }
+
        /**
         * Returns an array of all user account statuses
         * <p>
diff --git a/src/java/org/mxchange/jjobs/beans/jobs/skill/action/JobsAdminSkillActionWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/jobs/skill/action/JobsAdminSkillActionWebRequestBean.java
new file mode 100644 (file)
index 0000000..8fb3b71
--- /dev/null
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2017 - 2022 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.jobs.skill.action;
+
+import java.text.MessageFormat;
+import java.util.Objects;
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jjobs.beans.BaseJobsBean;
+import org.mxchange.jjobs.beans.jobs.skill.list.JobsSkillListWebViewController;
+import org.mxchange.jjobs.events.skill.add.AdminAddedSkillEvent;
+import org.mxchange.jjobs.events.skill.add.ObservableAdminAddedSkillEvent;
+import org.mxchange.jjobs.events.skill.update.AdminUpdatedSkillEvent;
+import org.mxchange.jjobs.events.skill.update.ObservableAdminUpdatedSkillEvent;
+import org.mxchange.jjobs.exceptions.SkillAlreadyAddedException;
+import org.mxchange.jjobs.model.exceptions.SkillNotFoundException;
+import org.mxchange.jjobs.model.skill.AdminSkillSessionBeanRemote;
+import org.mxchange.jjobs.model.skill.JobSkill;
+import org.mxchange.jjobs.model.skill.Skillable;
+import org.mxchange.jjobs.model.skill.status.SkillStatus;
+import org.mxchange.jjobs.model.utils.SkillUtils;
+
+/**
+ * An administrative action bean for departments
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminSkillActionController")
+@RequestScoped
+public class JobsAdminSkillActionWebRequestBean extends BaseJobsBean implements JobsAdminSkillActionWebRequestController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 5_028_697_360_474L;
+
+       /**
+        * EJB for administrative purposes
+        */
+       @EJB (lookup = "java:global/jjobs-ejb/adminSkill!org.mxchange.jjobs.model.skill.AdminSkillSessionBeanRemote")
+       private AdminSkillSessionBeanRemote adminSkillBean;
+
+       /**
+        * Currently worked on department
+        */
+       private Skillable currentSkill;
+
+       /**
+        * An event being fired when a skill has been successfully added
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminAddedSkillEvent> skillAddedEvent;
+
+       /**
+        * Primary key
+        */
+       private Long skillId;
+
+       /**
+        * A general skill controller (backing bean)
+        */
+       @Inject
+       private JobsSkillListWebViewController skillListController;
+
+       /**
+        * Skill name
+        */
+       private String skillName;
+
+       /**
+        * Skill status
+        */
+       private SkillStatus skillStatus;
+
+       /**
+        * Event being fired when a department has been updated
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminUpdatedSkillEvent> updatedSkillEvent;
+
+       /**
+        * Default constructor
+        */
+       public JobsAdminSkillActionWebRequestBean () {
+               // Call super constructor
+               super();
+       }
+
+       /**
+        * Adds skill with all data from this backing bean. First this action method
+        * will validate if the skill's name is already registered and if found, it
+        * will output a proper faces message.
+        */
+       public void addSkill () {
+               // Get instance
+               final Skillable skill = this.createSkill();
+
+               // Is the department not created yet?
+               if (this.skillListController.isSkillAlreadyAdded(skill)) {
+                       // Then show proper faces message
+                       this.showFacesMessage("form-admin-add-department:branchStreet", "ADMIN_DEPARTMENT_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
+                       return;
+               }
+
+               // Delcare updated instance
+               final Skillable updatedSkill;
+
+               try {
+                       // Try to call EJB
+                       updatedSkill = this.adminSkillBean.addSkill(skill);
+               } catch (final SkillAlreadyAddedException ex) {
+                       // Output message
+                       this.showFacesMessage("form-admin-add-department:departmentI18nKey", "ADMIN_DEPARTMENT_ALREADY_CREATED", FacesMessage.SEVERITY_ERROR); //NOI18N
+                       return;
+               }
+
+               // Fire event
+               this.skillAddedEvent.fire(new AdminAddedSkillEvent(updatedSkill));
+       }
+
+       /**
+        * Copies all properties from current skill to this bean.
+        */
+       public void copyAllSkillProperties () {
+               // Is current skill set?
+               if (this.getCurrentSkill() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.currentSkill is null"); //NOI18N
+               } else if (this.getCurrentSkill().getSkillId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.currentSkill.departmentId is null"); //NOI18N
+               } else if (this.getCurrentSkill().getSkillId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("this.currentSkill.departmentId={0} is not valid", this.getCurrentSkill().getSkillId())); //NOI18N
+               }
+
+               // Copy all fields
+               this.setSkillName(this.getCurrentSkill().getSkillName());
+               this.setSkillId(this.getCurrentSkill().getSkillId());
+       }
+
+       /**
+        * Getter for current skill
+        * <p>
+        * @return Current department
+        */
+       public Skillable getCurrentSkill () {
+               return this.currentSkill;
+       }
+
+       /**
+        * Setter for current skill
+        * <p>
+        * @param currentSkill Current department
+        */
+       public void setCurrentSkill (final Skillable currentSkill) {
+               this.currentSkill = currentSkill;
+       }
+
+       /**
+        * Getter for primary key
+        * <p>
+        * @return Primary key
+        */
+       public Long getSkillId () {
+               return this.skillId;
+       }
+
+       /**
+        * Setter for primary key
+        * <p>
+        * @param skillId Primary key
+        */
+       public void setSkillId (final Long skillId) {
+               this.skillId = skillId;
+       }
+
+       /**
+        * Getter for skill name
+        * <p>
+        * @return Skill name
+        */
+       public String getSkillName () {
+               return this.skillName;
+       }
+
+       /**
+        * Setter for skill name
+        * <p>
+        * @param skillName Skill name
+        */
+       public void setSkillName (final String skillName) {
+               this.skillName = skillName;
+       }
+
+       /**
+        * Getter for skill status
+        * <p>
+        * @return Skill status
+        */
+       public SkillStatus getSkillStatus () {
+               return this.skillStatus;
+       }
+
+       /**
+        * Setter for skill status
+        * <p>
+        * @param skillStatus Skill status
+        */
+       public void setSkillStatus (final SkillStatus skillStatus) {
+               this.skillStatus = skillStatus;
+       }
+
+       /**
+        * Updates department record with data from this bean.
+        * <p>
+        * @return Redirection outcome
+        */
+       public String updateSkill () {
+               // Is current skill set?
+               if (this.getCurrentSkill() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.currentSkill is null"); //NOI18N
+               } else if (this.getCurrentSkill().getSkillId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.currentSkill.departmentId is null"); //NOI18N
+               } else if (this.getCurrentSkill().getSkillId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("this.currentSkill.departmentId={0} is not valid", this.getCurrentSkill().getSkillId())); //NOI18N
+               }
+
+               // Init instance with current data
+               final Skillable skill = this.createSkill();
+
+               // Does current (not updated) and just created (maybe updated) match?
+               if (Objects.equals(this.getCurrentSkill(), skill)) {
+                       // Yes, then output message
+                       this.showFacesMessage("form-admin-edit-department:departmentI18nKey", "ADMIN_DEPARTMENT_NOT_UPDATED", FacesMessage.SEVERITY_WARN); //NOI18N
+
+                       // Skip below code
+                       return ""; //NOI18N
+               }
+
+               // Copy all fields
+               SkillUtils.copySkillData(skill, this.getCurrentSkill());
+
+               // Initialize updated instance
+               final Skillable updatedSkill;
+
+               // Try it
+               try {
+                       // Invoke EJB
+                       updatedSkill = this.adminSkillBean.updateSkill(this.getCurrentSkill());
+               } catch (final SkillNotFoundException ex) {
+                       // Throw as a cause
+                       throw new FacesException(ex);
+               }
+
+               // Fire event
+               this.updatedSkillEvent.fire(new AdminUpdatedSkillEvent(updatedSkill));
+
+               // Return to list view
+               return "admin_list_departments"; //NOI18N
+       }
+
+       /**
+        * Prepares an instance of a Skill object (entity) with all data from this
+        * bean. If a complete fax number or land-line number was provided, it will
+        * be set in the instance as well.
+        * <p>
+        * @return An instance of a Skill class (entity)
+        */
+       private Skillable createSkill () {
+               // Create new skill instance
+               final Skillable skill = new JobSkill(this.getSkillName(), this.getSkillStatus());
+
+               // Return fully prepared instance
+               return skill;
+       }
+
+}
diff --git a/src/java/org/mxchange/jjobs/beans/jobs/skill/action/JobsAdminSkillActionWebRequestController.java b/src/java/org/mxchange/jjobs/beans/jobs/skill/action/JobsAdminSkillActionWebRequestController.java
new file mode 100644 (file)
index 0000000..08331b6
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.jobs.skill.action;
+
+/**
+ * An interface for administrative "action" controllers, like create, update and
+ * delete actions.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface JobsAdminSkillActionWebRequestController {
+
+}
index eeb5f4ba0646cba9a3d6ca6a2e58f8d1facf7894..dae3b6e417ef7009400f2359db65364e860907cd 100644 (file)
@@ -89,12 +89,11 @@ public class JobsSkillListWebViewBean extends BaseJobsBean implements JobsSkillL
        }
 
        /**
-        * Observers events being fired when an administrator has added company
-        * basic data.
+        * Observers events being fired when an administrator has added a new skill.
         * <p>
         * @param event Event being fired
         */
-       public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedSkillEvent event) {
+       public void afterAdminAddedSkillEvent (@Observes final ObservableAdminAddedSkillEvent event) {
                // Is the parameter valid?
                if (null == event) {
                        // Throw NPE
@@ -225,6 +224,40 @@ public class JobsSkillListWebViewBean extends BaseJobsBean implements JobsSkillL
                }
        }
 
+       @Override
+       public boolean isSkillAlreadyAdded (final Skillable skillable) {
+               // Validate parameter
+               if (null == skillable) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter 'skillable' is null"); //NOI18N
+               } else if (skillable.getSkillName() == null) {
+                       // Throw it again
+                       throw new NullPointerException("skillable.skillName is null"); //NOI18N
+               } else if (skillable.getSkillName().isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("skillable.skillName is empty"); //NOI18N
+               } else if (skillable.getSkillStatus() == null) {
+                       // Throw it again
+                       throw new NullPointerException("skillable.skillStatus is null"); //NOI18N
+               }
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Check all entries
+               for (final Skillable currentSkillable : this.getAllSkills()) {
+                       // Is name the same?
+                       if (Objects.equals(currentSkillable.getSkillName(), skillable.getSkillName())) {
+                               // Found it
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
        @Override
        public Boolean isSkillNameUsed (final String skillName) {
                // Validate parameter
index f286a2ee49b9e942b8d6681d3e0fe62b5cad4f81..5c45742adc43926e89733c1aedefa5e858e41ba6 100644 (file)
@@ -27,6 +27,15 @@ import org.mxchange.jjobs.model.skill.Skillable;
  */
 public interface JobsSkillListWebViewController extends Serializable {
 
+       /**
+        * Checks if given skill is already found
+        * <p>
+        * @param skillable An instance of a Skillable class
+        * <p>
+        * @return Whether it has been found
+        */
+       boolean isSkillAlreadyAdded (final Skillable skillable);
+
        /**
         * Checks if given skill name is already there.
         * <p>
diff --git a/src/java/org/mxchange/jjobs/converter/jobs/skill/JobsSkillStatusConverter.java b/src/java/org/mxchange/jjobs/converter/jobs/skill/JobsSkillStatusConverter.java
new file mode 100644 (file)
index 0000000..b398177
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 - 2022 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.converter.jobs.skill;
+
+import javax.faces.convert.EnumConverter;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.jjobs.model.skill.status.SkillStatus;
+
+/**
+ * A converter for skill status
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter ("SkillStatusConverter")
+public class JobsSkillStatusConverter extends EnumConverter {
+
+       /**
+        * Default constructor which calls the super constructor with the proper
+        * enumeration as class type.
+        */
+       public JobsSkillStatusConverter () {
+               super(SkillStatus.class);
+       }
+
+}
index 8b218e5d9e8ec3d415a521f3f79d86c2b348206c..35c2da4ca5522007c9ff4a09c663c59ebd5ed1d9 100644 (file)
                                                                >
                                                                <validator:skillNameValidator checkExisting="false" />
                                                        </p:inputText>
+
+                                                       <p:outputLabel for="skillStatus" value="#{msg.ADMIN_SKILL_STATUS}" />
+                                                       <p:selectOneMenu
+                                                               id="skillStatus"
+                                                               filter="true"
+                                                               filterMatchMode="contains"
+                                                               >
+                                                               <f:converter converterId="SkillStatusConverter" />
+                                                               <f:selectItems
+                                                                       value="#{dataController.skillStatuses}"
+                                                                       var="accountStatus"
+                                                                       itemValue="#{skillStatus}"
+                                                                       itemLabel="#{msg[skillStatus.messageKey]}"
+                                                                       />
+                                                       </p:selectOneMenu>
                                                </p:panelGrid>
                                        </p:fieldset>
                                </h:panelGroup>