From 9ea7406d531affa4302844807333871cb851a526 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 23 Nov 2022 21:51:02 +0100 Subject: [PATCH] Don't cherry-pick: - added splitted mobile bean - synchronized code from JFinancials - updated jar(s) --- lib/jcontacts-lib.jar | Bin 5456 -> 5463 bytes .../AddressbookContactSessionBean.java | 53 ----- ...ressbookAdminContactMobileSessionBean.java | 203 ++++++++++++++++++ ...dressbookAdminContactPhoneSessionBean.java | 153 +------------ ...AddressbookAdminDepartmentSessionBean.java | 65 +++++- 5 files changed, 263 insertions(+), 211 deletions(-) create mode 100644 src/java/org/mxchange/jcontacts/model/mobile/AddressbookAdminContactMobileSessionBean.java diff --git a/lib/jcontacts-lib.jar b/lib/jcontacts-lib.jar index 2625c0716b58383268279ac2cf76f6bdb35b6496..87eb95b5e57c10219e22125028222a11196fd788 100644 GIT binary patch delta 541 zcmcbhbzO@$z?+$ci-CcIfnn~N@`=0}ymQu+hjwU4-YaEbU?`pF6mO$vp=S_pXl|%$ zQ3@iH3=MUSK%|0(e^Fv`PO5@)eo;YwQDRAEex4>T7cUpW$d41RDKdVX_(O~F<78z< z6CfGEXvGY)X!2A>2QYnu(H=}oG1-CW&CyKPnZOKFRs&`*BZFfVgdxiFgaxejkAMZL zDGsI&bC$AKgwfzE>$*oAvNX$!5MODIaEd(eJ z2jXy+0K;2HdB({FB9fD3gm{3qXbQ0KsG)3ti^PR ziGcxxo#8eyFf3`*X9eq*6ETtpDRezmc*>EPfdPd5P!uLj&KHRV+i_k*nu(tWtc_dL Kp6!bONF4x!T#ZZs delta 536 zcmcbvbwP_az?+$ci-CcIfq{uHZ6dD*FC$-C=#%>LmOKUqhP;VR@ur4)26~2O+7`M6 z`Nbu=E~!bGiFvw)DXB?@hNXrI8V~_ZUM^lPgjt^^-c@A$H1WR{KBGODR%EgR(VLT)t}}rdHmnBBU`9U2DhNY{=Lri~Ewi8ns`Dm$2$}-T zt`n3MJq>hjeo?x9fHxzP2s6Y-pC)e*lx2K7`JA8(P}OTeStbd_$%RakKu;qpG7yqw z@&!rAPtFtK0ozn7B+b+T5>n?!RtxgL1)$Vvh-zLYPA!B%K*>;`Bj7+8&JtjF>&VLl zw!oi>15L~N3zJ@zFflNIum@ZV1H+O=Kadu$$=)ImH@y^=X3}5 - * @param contactId Contact id - *

- * @return Contact instance - *

- * @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; - } - } diff --git a/src/java/org/mxchange/jcontacts/model/mobile/AddressbookAdminContactMobileSessionBean.java b/src/java/org/mxchange/jcontacts/model/mobile/AddressbookAdminContactMobileSessionBean.java new file mode 100644 index 0000000..b7d6b49 --- /dev/null +++ b/src/java/org/mxchange/jcontacts/model/mobile/AddressbookAdminContactMobileSessionBean.java @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2022 Roland Häder + * + * 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 . + */ +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 + *

+ * @author Roland Häder + */ +@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; + } + +} diff --git a/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java index d8722a6..0f7b0d9 100644 --- a/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java @@ -29,7 +29,6 @@ import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException; 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 @@ -173,58 +172,7 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookEnte } @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 @@ -281,7 +229,7 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookEnte } @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 @@ -338,58 +286,7 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookEnte } @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 @@ -431,7 +328,7 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookEnte } @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 @@ -472,46 +369,4 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookEnte 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; - } - } diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java index 18d5bfa..fcb71e0 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java @@ -21,12 +21,14 @@ import java.util.Date; 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; /** @@ -89,7 +91,7 @@ public class AddressbookAdminDepartmentSessionBean extends BaseAddressbookEnterp } // Set created timestamp - department.setDepartmentCreated(new Date()); + department.setDepartmentEntryCreated(new Date()); // Get managed basic data instance final BasicData managedBasicData = this.createManaged(department.getDepartmentCompany()); @@ -116,16 +118,16 @@ public class AddressbookAdminDepartmentSessionBean extends BaseAddressbookEnterp } // 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()); @@ -143,6 +145,51 @@ public class AddressbookAdminDepartmentSessionBean extends BaseAddressbookEnterp 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 @@ -162,7 +209,7 @@ public class AddressbookAdminDepartmentSessionBean extends BaseAddressbookEnterp // 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; -- 2.39.5