import java.text.MessageFormat;
import java.util.List;
import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
-import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
/**
* A contact EJB
return detachedContact;
}
- /**
- * Returns a contact instance which has the given id number.
- * <p>
- * @param contactId Contact id
- * <p>
- * @return Contact instance
- * <p>
- * @throws ContactNotFoundException If the contact was not found
- */
- private Contact findContactById (final Long contactId) throws ContactNotFoundException {
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contactId={1} - CALLED!", this.getClass().getSimpleName(), contactId)); //NOI18N
-
- // The parameter must be valid
- if (null == contactId) {
- // Throw NPE
- throw new NullPointerException("contactId is null"); //NOI18N
- } else if (contactId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N
- }
-
- // Get query instance
- final Query query = this.getEntityManager().createNamedQuery("SearchContactById", UserContact.class); //NOI18N
-
- // Set parameter
- query.setParameter("contactId", contactId); //NOI18N
- query.setMaxResults(1);
-
- // Init contact instance
- final Contact contact;
-
- // Try to find a result
- try {
- // Find a single result
- contact = (Contact) query.getSingleResult();
-
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N
- } catch (final NoResultException ex) {
- // No result found
- throw new ContactNotFoundException(contactId, ex);
- }
-
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N
-
- // Return found instance
- return contact;
- }
-
}
--- /dev/null
+/*
+ * Copyright (C) 2022 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.jcontacts.model.mobile;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.Objects;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
+import org.mxchange.jphone.exceptions.mobile.MobileNumberAlreadyLinkedException;
+import org.mxchange.jphone.exceptions.mobile.MobileNumberNotLinkedException;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+
+/**
+ * A session EJB for administrative contact's mobile number purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminContactMobile", description = "An administrative bean handling contact's mobile data")
+public class AddressbookAdminContactMobileSessionBean extends BaseAddressbookEnterpriseBean implements AdminContactsMobileSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 189_217_561_460_237_108L;
+
+ /**
+ * Contact EJB
+ */
+ @EJB (lookup = "java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
+ private ContactSessionBeanRemote contactBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminContactMobileSessionBean () {
+ // Call super constructor
+ super();
+ }
+
+ @Override
+ public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberAlreadyLinkedException, ContactNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
+
+ // Is the contact set?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // ... and throw again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ // Not set cell mobile instance
+ throw new MobileNumberAlreadyLinkedException(mobileNumber);
+ } else if (null == mobileNumber) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (mobileNumber.getMobileId() == null) {
+ // Throw it again
+ throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N
+ } else if (mobileNumber.getMobileId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", mobileNumber.getMobileId())); //NOI18N
+ } else if (mobileNumber.getMobileProvider() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
+ // Throw NPE again
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
+ }
+
+ // Set mobile number in contact
+ contact.setContactMobileNumber(mobileNumber);
+
+ // Update database
+ final Contact updatedContact = this.contactBean.updateContactData(contact);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+
+ // Return it
+ return updatedContact;
+ }
+
+ @Override
+ public Contact linkNewMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberAlreadyLinkedException, ContactNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
+
+ // Is the contact set?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // ... and throw again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ // Not set cell mobile instance
+ throw new MobileNumberAlreadyLinkedException(mobileNumber);
+ } else if (null == mobileNumber) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (mobileNumber.getMobileId() instanceof Long) {
+ // Throw it again
+ throw new IllegalStateException(MessageFormat.format("mobileNumber.mobileId={0} is not null", mobileNumber.getMobileId())); //NOI18N
+ } else if (mobileNumber.getMobileProvider() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
+ // Throw NPE again
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
+ }
+
+ // Set created instance
+ mobileNumber.setMobileEntryCreated(new Date());
+
+ // Set mobile number in contact
+ contact.setContactMobileNumber(mobileNumber);
+
+ // Update database
+ final Contact updatedContact = this.contactBean.updateContactData(contact);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+
+ // Return it
+ return updatedContact;
+ }
+
+ @Override
+ public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberNotLinkedException, ContactNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
+
+ // Is the contact set?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // ... and throw again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ } else if (contact.getContactMobileNumber() == null) {
+ // Not set cell mobile instance
+ throw new MobileNumberNotLinkedException(mobileNumber);
+ } else if (contact.getContactMobileNumber().getMobileId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("contact.contactMobileNumber.mobileId is null"); //NOI18N
+ } else if (contact.getContactMobileNumber().getMobileId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.mobileId={0} is invalid.", contact.getContactMobileNumber().getMobileId())); //NOI18N
+ } else if (!Objects.equals(mobileNumber.getMobileId(), contact.getContactMobileNumber().getMobileId())) {
+ // Not same object
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.mobileId={0} and mobileNumber.mobileId={1} are not the same.", contact.getContactMobileNumber().getMobileId(), mobileNumber.getMobileId())); //NOI18N
+ }
+
+ // Remove it from contact
+ contact.setContactMobileNumber(null);
+
+ // Update database
+ final Contact updatedContact = this.contactBean.updateContactData(contact);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+
+ // Return it
+ return updatedContact;
+ }
+
+}
import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
/**
* A session EJB for administrative contact's phone number purposes
}
@Override
- public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
-
- // Is the contact set?
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // ... and throw again
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // Not set cell phone instance
- throw new PhoneNumberAlreadyLinkedException(mobileNumber);
- } else if (null == mobileNumber) {
- // Throw NPE
- throw new NullPointerException("mobileNumber is null"); //NOI18N
- } else if (mobileNumber.getMobileId() == null) {
- // Throw it again
- throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
- } else if (mobileNumber.getMobileId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getMobileId())); //NOI18N
- } else if (mobileNumber.getMobileProvider() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
- } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
- } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
- // Throw NPE again
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
- }
-
- // Set mobile number in contact
- contact.setContactMobileNumber(mobileNumber);
-
- // Update database
- final Contact updatedContact = this.contactBean.updateContactData(contact);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
-
- // Return it
- return updatedContact;
- }
-
- @Override
- public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException {
+ public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
}
@Override
- public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException {
+ public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
}
@Override
- public Contact linkNewMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
-
- // Is the contact set?
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // ... and throw again
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // Not set cell phone instance
- throw new PhoneNumberAlreadyLinkedException(mobileNumber);
- } else if (null == mobileNumber) {
- // Throw NPE
- throw new NullPointerException("mobileNumber is null"); //NOI18N
- } else if (mobileNumber.getMobileId() instanceof Long) {
- // Throw it again
- throw new IllegalStateException(MessageFormat.format("mobileNumber.phoneId={0} is not null", mobileNumber.getMobileId())); //NOI18N
- } else if (mobileNumber.getMobileProvider() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
- } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
- } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
- // Throw NPE again
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
- }
-
- // Set created instance
- mobileNumber.setMobileEntryCreated(new Date());
-
- // Set mobile number in contact
- contact.setContactMobileNumber(mobileNumber);
-
- // Update database
- final Contact updatedContact = this.contactBean.updateContactData(contact);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
-
- // Return it
- return updatedContact;
- }
-
- @Override
- public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException {
+ public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
}
@Override
- public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException {
+ public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
return updatedContact;
}
- @Override
- public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberNotLinkedException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
-
- // Is the contact set?
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // ... and throw again
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- } else if (contact.getContactMobileNumber() == null) {
- // Not set cell phone instance
- throw new PhoneNumberNotLinkedException(mobileNumber);
- } else if (contact.getContactMobileNumber().getMobileId() == null) {
- // Throw NPE again
- throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N
- } else if (contact.getContactMobileNumber().getMobileId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getMobileId())); //NOI18N
- } else if (!Objects.equals(mobileNumber.getMobileId(), contact.getContactMobileNumber().getMobileId())) {
- // Not same object
- throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getMobileId(), mobileNumber.getMobileId())); //NOI18N
- }
-
- // Remove it from contact
- contact.setContactMobileNumber(null);
-
- // Update database
- final Contact updatedContact = this.contactBean.updateContactData(contact);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
-
- // Return it
- return updatedContact;
- }
-
}
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
+import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
+import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
-import org.mxchange.jcontactsbusiness.model.employee.Employable;
import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.utils.DepartmentUtils;
import org.mxchange.jusercore.model.user.User;
/**
}
// Set created timestamp
- department.setDepartmentCreated(new Date());
+ department.setDepartmentEntryCreated(new Date());
// Get managed basic data instance
final BasicData managedBasicData = this.createManaged(department.getDepartmentCompany());
}
// Is lead employee set?
- if (department.getDepartmentLead()instanceof Employable) {
- // Get managed lead employee
- final Employable managedEmployee = this.createManaged(department.getDepartmentLead());
+ if (department.getDepartmentLead() instanceof Contact) {
+ // Get managed lead contact
+ final Contact managedContact = this.createManaged(department.getDepartmentLead());
// Set it back
- department.setDepartmentLead(managedEmployee);
+ department.setDepartmentLead(managedContact);
}
// Is "owning" user set?
- if (department.getDepartmentUserOwner()instanceof User) {
+ if (department.getDepartmentUserOwner() instanceof User) {
// Get managed user
final User managedUser = this.createManaged(department.getDepartmentUserOwner());
return department;
}
+ @Override
+ public Department updateDepartment (final Department department) throws DepartmentNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateDepartment(): department={1} - CALLED!", this.getClass().getSimpleName(), department)); //NOI18N
+
+ // Validate parameter
+ if (null == department) {
+ // Throw NPE
+ throw new NullPointerException("department is null"); //NOI18N
+ } else if (department.getDepartmentId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("department.departmentId is null"); //NOI18N
+ } else if (department.getDepartmentId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("department.departmentId={0} is not valid", department.getDepartmentId())); //NOI18N
+ } else if (department.getDepartmentCompany() == null) {
+ // Throw NPE
+ throw new NullPointerException("department.departmentCompany is null"); //NOI18N
+ } else if (department.getDepartmentCompany().getBasicDataId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("department.departmentCompany.basicDataId is null"); //NOI18N
+ } else if (department.getDepartmentCompany().getBasicDataId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("department.departmentCompany.basicDataId={0} is invalid", department.getDepartmentCompany().getBasicDataId())); //NOI18N
+ } else if (department.getDepartmentI18nKey() == null) {
+ // Throw NPE
+ throw new NullPointerException("department.departmentName is null"); //NOI18N
+ } else if (department.getDepartmentI18nKey().isEmpty()) {
+ // Throw IAE
+ throw new NullPointerException("department.departmentName is empty"); //NOI18N
+ } else if (!this.isDepartmentFound(department)) {
+ // Already added, abort here
+ throw new DepartmentNotFoundException(department);
+ }
+
+ // Merge data
+ final Department updatedDepartment = this.mergeDepartmentData(department);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateDepartment(): updatedDepartment={1} - EXIT!", this.getClass().getSimpleName(), updatedDepartment));
+
+ // Return updated instance
+ return updatedDepartment;
+ }
+
/**
* Checks if given department's address is already persisted. The whole
* (persisted) list is being loaded and each address is being matched
// Check all single addresses
for (final Department dep : departments) {
// Is the same address found?
- if (Departments.isSameDepartment(dep, department)) {
+ if (DepartmentUtils.isSameDepartment(dep, department)) {
// Found one
isFound = true;
break;