import org.mxchange.jcontactsbusiness.model.utils.DepartmentUtils;
import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean;
import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jjobs.model.skill.Skillable;
+import org.mxchange.jjobs.model.utils.SkillUtils;
import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
super(factoryJndi, queueJndi);
}
+ /**
+ * Creates a managed instance of given detached Skillable class
+ * <p>
+ * @param detachedSkill A deteched instance of a Skillable class
+ *
+ * @return
+ */
+ protected Skillable createManaged (final Skillable detachedSkill) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedSkill)); //NOI18N
+
+ // user should not be null
+ if (null == detachedSkill) {
+ // Abort here
+ throw new NullPointerException("detachedSkill is null"); //NOI18N
+ } else if (detachedSkill.getSkillId() == null) {
+ // Id is set
+ throw new NullPointerException("detachedSkill.skillId is null"); //NOI18N
+ } else if (detachedSkill.getSkillId() < 1) {
+ // Id is set
+ throw new IllegalArgumentException(MessageFormat.format("detachedSkill.skillId={0} is invalid", detachedSkill.getSkillId())); //NOI18N
+ }
+
+ // Try to find it (should be there)
+ final Skillable managedSkill = this.getEntityManager().find(detachedSkill.getClass(), detachedSkill.getSkillId());
+
+ // Should be there
+ assert (managedSkill instanceof Skillable) : "managedSkill is null"; //NOI18N
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedSkill={1} - EXIT!", this.getClass().getSimpleName(), managedSkill)); //NOI18N
+
+ // Return it
+ return managedSkill;
+ }
+
/**
* Get back a managed instance from given contact
* <p>
return detachedNumber;
}
+ /**
+ * Merges given contact's data
+ * <p>
+ * @param detachedSkill Contact instance to merge
+ * <p>
+ * @return Detached contact instance
+ */
+ protected Skillable mergeSkillData (final Skillable detachedSkill) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeSkillData: detachedSkill={0} - CALLED!", detachedSkill)); //NOI18N
+
+ // The contact instance must be valid
+ if (null == detachedSkill) {
+ // Throw NPE again
+ throw new NullPointerException("detachedSkill is null"); //NOI18N
+ } else if (detachedSkill.getSkillId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("detachedSkill.skillId is null"); //NOI18N //NOI18N
+ } else if (detachedSkill.getSkillId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("detachedSkill.skillId={0} is not valid.", detachedSkill.getSkillId())); //NOI18N
+ }
+
+ // Get contact from it and find it
+ final Skillable foundSkill = this.createManaged(detachedSkill);
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeSkillData: foundSkill.skillId={0}", foundSkill.getSkillId())); //NOI18N
+
+ // Copy all
+ SkillUtils.copySkillData(detachedSkill, foundSkill);
+
+ // Merge contact instance
+ final Skillable managedSkill = this.getEntityManager().merge(foundSkill);
+
+ // Set updated timestamp
+ managedSkill.setSkillEntryUpdated(new Date());
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeSkillData: managedSkill={0} - EXIT!", managedSkill)); //NOI18N
+
+ // Return detached contact
+ return managedSkill;
+ }
+
/**
* Sends an email with given subject line, template name to given recipient
* and user data
--- /dev/null
+/*
+ * 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.model.skill;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
+import org.mxchange.jjobs.exceptions.SkillAlreadyAddedException;
+import org.mxchange.jjobs.model.exceptions.SkillNotFoundException;
+import org.mxchange.jjobs.model.utils.SkillUtils;
+
+/**
+ * A stateless session bean for administrative skillpurposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminSkill", description = "An administrative statless bean for handling department data (all)")
+public class JobsAdminSkillSessionBean extends BaseJobsEnterpriseBean implements AdminSkillSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 58_467_386_571_705L;
+
+ /**
+ * General department bean
+ */
+ @EJB (lookup = "java:global/jjobs-ejb/skill!org.mxchange.jjobs.model.skill.SkillSessionBeanRemote")
+ private SkillSessionBeanRemote skillBean;
+
+ /**
+ * Default constructor
+ */
+ public JobsAdminSkillSessionBean () {
+ // Call super constructor
+ super();
+ }
+
+ @Override
+ public Skillable addSkill (final Skillable skill) throws SkillAlreadyAddedException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addSkill(): skill={1} - CALLED!", this.getClass().getSimpleName(), skill)); //NOI18N
+
+ // Validate parameter
+ if (null == skill) {
+ // Throw NPE
+ throw new NullPointerException("department is null"); //NOI18N
+ } else if (skill.getSkillId() instanceof Long) {
+ // Should not happen
+ throw new IllegalArgumentException("skill.skillId should not be set."); //NOI18N
+ } else if (skill.getSkillName() == null) {
+ // Throw NPE
+ throw new NullPointerException("skill.skillName is empty"); //NOI18N
+ } else if (skill.getSkillName().isEmpty()) {
+ // Throw NPE
+ throw new NullPointerException("skill.skillName is null"); //NOI18N
+ } else if (skill.getSkillStatus() == null) {
+ // Throw NPE
+ throw new NullPointerException("skill.skillStatus null"); //NOI18N
+ } else if (this.isSkillFound(skill)) {
+ // Already added, abort here
+ throw new SkillAlreadyAddedException(skill);
+ }
+
+ // Set created timestamp
+ skill.setSkillEntryCreated(new Date());
+
+ // Persist it
+ this.getEntityManager().persist(skill);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addSkill(): skill.skillId={1} - EXIT!", this.getClass().getSimpleName(), skill.getSkillId())); //NOI18N
+
+ // Return updated instance
+ return skill;
+ }
+
+ @Override
+ public Skillable updateSkill (final Skillable skill) throws SkillNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateSkill(): skill={1} - CALLED!", this.getClass().getSimpleName(), skill)); //NOI18N
+
+ // Validate parameter
+ if (null == skill) {
+ // Throw NPE
+ throw new NullPointerException("skill is null"); //NOI18N
+ } else if (skill.getSkillId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("skill.skillId is null"); //NOI18N
+ } else if (skill.getSkillId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("skill.skillId={0} is not valid", skill.getSkillId())); //NOI18N
+ } else if (skill.getSkillName() == null) {
+ // Throw NPE
+ throw new NullPointerException("skill.skillName is empty"); //NOI18N
+ } else if (skill.getSkillName().isEmpty()) {
+ // Throw NPE
+ throw new NullPointerException("skill.skillName is null"); //NOI18N
+ } else if (skill.getSkillStatus() == null) {
+ // Throw NPE
+ throw new NullPointerException("skill.skillStatus null"); //NOI18N
+ } else if (!this.isSkillFound(skill)) {
+ // Already added, abort here
+ throw new SkillNotFoundException(skill);
+ }
+
+ // Merge data
+ final Skillable updatedSkill = this.mergeSkillData(skill);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updatedSkill(): updatedSkill={1} - EXIT!", this.getClass().getSimpleName(), updatedSkill));
+
+ // Return updated instance
+ return updatedSkill;
+ }
+
+ /**
+ * Checks if given skill's name is already persisted. The whole (persisted)
+ * list is being loaded and each name is being matched against the given
+ * department's address.
+ * <p>
+ * @param skillable Skill being checked
+ * <p>
+ * @return Whether it has been found
+ */
+ private boolean isSkillFound (final Skillable skillable) {
+ // Get whole list
+ final List<Skillable> skills = this.skillBean.fetchAllSkills();
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Check all single addresses
+ for (final Skillable skill : skills) {
+ // Is the same address found?
+ if (SkillUtils.isSameSkill(skill, skillable)) {
+ // Found one
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+}