2 * Copyright (C) 2017 - 2024 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (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 Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.model.skill;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.List;
23 import javax.ejb.Stateless;
24 import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
25 import org.mxchange.jjobs.exceptions.SkillAlreadyAddedException;
26 import org.mxchange.jjobs.model.exceptions.SkillNotFoundException;
27 import org.mxchange.jjobs.model.utils.SkillUtils;
30 * A stateless session bean for administrative skillpurposes
32 * @author Roland Häder<roland@mxchange.org>
34 @Stateless (name = "adminSkill", description = "An administrative statless bean for handling department data (all)")
35 public class JobsAdminSkillSessionBean extends BaseJobsEnterpriseBean implements AdminSkillSessionBeanRemote {
40 private static final long serialVersionUID = 58_467_386_571_705L;
43 * General department bean
45 @EJB (lookup = "java:global/jjobs-ejb/skill!org.mxchange.jjobs.model.skill.SkillSessionBeanRemote")
46 private SkillSessionBeanRemote skillBean;
51 public JobsAdminSkillSessionBean () {
52 // Call super constructor
57 public Skillable addSkill (final Skillable skill) throws SkillAlreadyAddedException {
59 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addSkill(): skill={1} - CALLED!", this.getClass().getSimpleName(), skill)); //NOI18N
64 throw new NullPointerException("department is null"); //NOI18N
65 } else if (skill.getSkillId() instanceof Long) {
67 throw new IllegalArgumentException("skill.skillId should not be set."); //NOI18N
68 } else if (skill.getSkillName() == null) {
70 throw new NullPointerException("skill.skillName is empty"); //NOI18N
71 } else if (skill.getSkillName().isEmpty()) {
73 throw new NullPointerException("skill.skillName is null"); //NOI18N
74 } else if (skill.getSkillStatus() == null) {
76 throw new NullPointerException("skill.skillStatus null"); //NOI18N
77 } else if (this.isSkillFound(skill)) {
78 // Already added, abort here
79 throw new SkillAlreadyAddedException(skill);
82 // Set created timestamp
83 skill.setSkillEntryCreated(new Date());
86 this.getEntityManager().persist(skill);
89 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addSkill(): skill.skillId={1} - EXIT!", this.getClass().getSimpleName(), skill.getSkillId())); //NOI18N
91 // Return updated instance
96 public Skillable updateSkill (final Skillable skill) throws SkillNotFoundException {
98 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateSkill(): skill={1} - CALLED!", this.getClass().getSimpleName(), skill)); //NOI18N
100 // Validate parameter
103 throw new NullPointerException("skill is null"); //NOI18N
104 } else if (skill.getSkillId() == null) {
106 throw new NullPointerException("skill.skillId is null"); //NOI18N
107 } else if (skill.getSkillId() < 1) {
109 throw new IllegalArgumentException(MessageFormat.format("skill.skillId={0} is not valid", skill.getSkillId())); //NOI18N
110 } else if (skill.getSkillName() == null) {
112 throw new NullPointerException("skill.skillName is empty"); //NOI18N
113 } else if (skill.getSkillName().isEmpty()) {
115 throw new NullPointerException("skill.skillName is null"); //NOI18N
116 } else if (skill.getSkillStatus() == null) {
118 throw new NullPointerException("skill.skillStatus null"); //NOI18N
119 } else if (!this.isSkillFound(skill)) {
120 // Already added, abort here
121 throw new SkillNotFoundException(skill);
125 final Skillable updatedSkill = this.mergeSkillData(skill);
128 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updatedSkill(): updatedSkill={1} - EXIT!", this.getClass().getSimpleName(), updatedSkill));
130 // Return updated instance
135 * Checks if given skill's name is already persisted. The whole (persisted)
136 * list is being loaded and each name is being matched against the given
137 * department's address.
139 * @param skillable Skill being checked
141 * @return Whether it has been found
143 private boolean isSkillFound (final Skillable skillable) {
145 final List<Skillable> skills = this.skillBean.fetchAllSkills();
147 // Default is not found
148 boolean isFound = false;
150 // Check all single addresses
151 for (final Skillable skill : skills) {
152 // Is the same address found?
153 if (SkillUtils.isSameSkill(skill, skillable)) {