]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java
Contined a bit:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / contact / JobsContactWebSessionBean.java
index 4080f6cb7e8f8ff5e135bd858bafece81a3d86b4..be0be4d9d94655b19a4788eb13cbc1b977d2acc8 100644 (file)
@@ -34,6 +34,8 @@ import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
 import org.mxchange.jcontacts.contact.UserContact;
 import org.mxchange.jcontacts.contact.gender.Gender;
+import org.mxchange.jcontacts.contact.utils.ContactUtils;
+import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
@@ -152,6 +154,21 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
         */
        private Short houseNumber;
 
+       /**
+        * Whether a cellphone entry has been unlinked
+        */
+       private boolean isCellphoneUnlinked;
+
+       /**
+        * Whether a fax entry has been unlinked
+        */
+       private boolean isFaxUnlinked;
+
+       /**
+        * Whether a land-line number has been unlinked
+        */
+       private boolean isLandLineUnlinked;
+
        /**
         * Login bean (controller)
         */
@@ -210,9 +227,55 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
        }
 
        @Override
-       public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
+       public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
                // Trace message
-               System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
+
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+               }
+
+               // Get iterator from list
+               Iterator<Contact> iterator = this.contactList.iterator();
+
+               // "Walk" through all entries
+               while (iterator.hasNext()) {
+                       // Get next element
+                       Contact next = iterator.next();
+
+                       // Is id number the same?
+                       if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
+                               // Found entry, so remove it and abort
+                               this.contactList.remove(next);
+
+                               // Remove also email from list
+                               this.emailAddressList.remove(next.getContactEmailAddress());
+                               break;
+                       }
+               }
+
+               // Add contact to list
+               this.contactList.add(event.getUpdatedContact());
+
+               // Add email address to list
+               this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
+       }
+
+       @Override
+       public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
 
                // event should not be null
                if (null == event) {
@@ -233,7 +296,7 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
                Contact registeredContact = event.getRegisteredUser().getUserContact();
 
                // Debug message
-               System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
 
                // Copy all data from registered->user
                this.copyContact(registeredContact);
@@ -245,13 +308,13 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
                this.clear();
 
                // Trace message
-               System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
        }
 
        @Override
-       public void afterUserLogin (final @Observes UserLoggedInEvent event) {
+       public void afterUserLogin (@Observes final UserLoggedInEvent event) {
                // Trace message
-               System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
 
                // event should not be null
                if (null == event) {
@@ -272,7 +335,13 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
                this.copyContact(event.getLoggedInUser().getUserContact());
 
                // Trace message
-               System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+       public List<Contact> allContacts () {
+               return this.contactList;
        }
 
        /**
@@ -429,49 +498,30 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
                contact.setContactCity(this.getCity());
                contact.setContactCountry(this.getCountry());
 
-               // Is there a phone number?
-               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
-                       // Debug message
-                       System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: phoneId={0}", contact.getContactLandLineNumber().getPhoneId())); //NOI18N
-
-                       // Yes, then update as well
-                       contact.getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode());
-                       contact.getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber());
-               }
-
-               // Is there a fax number?
-               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
-                       // Debug message
-                       System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: faxId={0}", contact.getContactFaxNumber().getPhoneId())); //NOI18N
+               // Update contact's cellphone number
+               this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
 
-                       // Yes, then update as well
-                       contact.getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode());
-                       contact.getContactFaxNumber().setPhoneNumber(this.getFaxNumber());
-               }
+               // Update contact's land-line number
+               this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
 
-               // Is there a cellphone number?
-               if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
-                       // Debug message
-                       System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: cellPhoneId={0}", contact.getContactCellphoneNumber().getPhoneId())); //NOI18N
-
-                       // Yes, then update as well
-                       contact.getContactCellphoneNumber().setCellphoneProvider(this.getCellphoneCarrier());
-                       contact.getContactCellphoneNumber().setPhoneNumber(this.getCellphoneNumber());
-               }
+               // Update contact's fax number
+               this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
 
                // Send it to the EJB
-               this.contactBean.updateContactPersonalData(contact);
+               this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
 
                // All fine
                return "contact_data_saved"; //NOI18N
        }
 
        @Override
+       @SuppressWarnings ("ReturnOfDateField")
        public Date getBirthday () {
                return this.birthday;
        }
 
        @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
        public void setBirthday (final Date birthday) {
                this.birthday = birthday;
        }