]> git.mxchange.org Git - addressbook-ejb.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Wed, 23 Nov 2022 20:51:02 +0000 (21:51 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 23 Nov 2022 20:51:02 +0000 (21:51 +0100)
- added splitted mobile bean
- synchronized code from JFinancials
- updated jar(s)

lib/jcontacts-lib.jar
src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java
src/java/org/mxchange/jcontacts/model/mobile/AddressbookAdminContactMobileSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java

index 2625c0716b58383268279ac2cf76f6bdb35b6496..87eb95b5e57c10219e22125028222a11196fd788 100644 (file)
Binary files a/lib/jcontacts-lib.jar and b/lib/jcontacts-lib.jar differ
index 019df2b5c2b6cbc87e1b962e87a47efba465fe47..70f5cdebacba497f9806ddcd2eeb541e0d4c62b3 100644 (file)
@@ -19,10 +19,8 @@ package org.mxchange.jcontacts.model.contact;
 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
@@ -126,55 +124,4 @@ public class AddressbookContactSessionBean extends BaseAddressbookEnterpriseBean
                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;
-       }
-
 }
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 (file)
index 0000000..b7d6b49
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * 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;
+       }
+
+}
index d8722a635e161e9ceb1b025a030363fb7309e513..0f7b0d95be4ed7f7f4e02368da5a41425484ce4f 100644 (file)
@@ -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;
-       }
-
 }
index 18d5bfac08fed94e95b6e99f70ef0b9383e04a96..fcb71e0f19ff6d81a387f359aee86e78b2c8b8ae 100644 (file)
@@ -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;