]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java
No, putting these methods into admin (request-scoped) controller is not good as no...
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / contact / AddressbookContactWebSessionBean.java
index e06149a3acbae6282612a4585f93843fb6bac0a3..e5e360ef8e0e6214298ab5d3282cc4c5c7810e80 100644 (file)
@@ -48,6 +48,7 @@ import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 
 /**
@@ -204,9 +205,6 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
         * Default constructor
         */
        public AddressbookContactWebSessionBean () {
-               // Set gender to UNKNOWN
-               this.gender = Gender.UNKNOWN;
-
                // Try it
                try {
                        // Get initial context
@@ -226,10 +224,37 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                this.emailAddressList.add(contactEmailAddress);
        }
 
+       @Override
+       public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: 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.getAddedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.addedUser is null"); //NOI18N
+               } else if (event.getAddedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
+               } else if (event.getAddedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
+               }
+
+               // Clear all data
+               this.clear();
+
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
+       }
+
        @Override
        public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
                // Trace message
-               System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: 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) {
@@ -275,7 +300,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
        @Override
        public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
                // Trace message
-               System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
 
                // event should not be null
                if (null == event) {
@@ -296,7 +321,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                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);
@@ -308,13 +333,13 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                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) {
                // 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) {
@@ -335,46 +360,25 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                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;
        }
 
-       /**
-        * Clears this bean
-        */
-       @Override
-       public void clear () {
-               // Clear all data
-               // - personal data
-               this.setGender(Gender.UNKNOWN);
-               this.setFirstName(null);
-               this.setFamilyName(null);
-               this.setStreet(null);
-               this.setHouseNumber(null);
-               this.setZipCode(null);
-               this.setCity(null);
-               this.setCountry(null);
-
-               // - contact data
-               this.setEmailAddress(null);
-               this.setEmailAddressRepeat(null);
-               this.setPhoneAreaCode(null);
-               this.setCellphoneCarrier(null);
-               this.setFaxAreaCode(null);
-
-               // - other data
-               this.setBirthday(null);
-               this.setComment(null);
-       }
-
        @Override
        public Contact createContactInstance () {
                // User message
-               //this.getLogger().logTrace("createContactInstance: CALLED!");
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
+
+               // Is all required data set?
+               if (!this.isRequiredPersonalDataSet()) {
+                       // No, then abort here
+                       throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
+               }
 
                // Required personal data must be set
                assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
@@ -395,7 +399,11 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                contact.setContactCity(this.getCity());
                contact.setContactCountry(this.getCountry());
                contact.setContactEmailAddress(this.getEmailAddress());
+               contact.setContactBirthday(this.getBirthday());
+               contact.setContactComment(this.getComment());
 
+               // Debug message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
                // Don't set null or wrong references
                if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
                        // Now the number must be given
@@ -453,9 +461,8 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                        contact.setContactCellphoneNumber(cellphone);
                }
 
-               contact.setContactBirthday(this.getBirthday());
-               contact.setContactComment(this.getComment());
-
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
                // Created timestamp and ownContact
                contact.setContactOwnContact(Boolean.TRUE);
 
@@ -715,6 +722,11 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                this.zipCode = zipCode;
        }
 
+       @Override
+       public boolean hasContacts () {
+               return (!this.allContacts().isEmpty());
+       }
+
        /**
         * Post-initialization of this class
         */
@@ -829,6 +841,33 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                this.emailAddressList.add(contact.getContactEmailAddress());
        }
 
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all data
+               // - personal data
+               this.setGender(Gender.UNKNOWN);
+               this.setFirstName(null);
+               this.setFamilyName(null);
+               this.setStreet(null);
+               this.setHouseNumber(null);
+               this.setZipCode(null);
+               this.setCity(null);
+               this.setCountry(null);
+
+               // - contact data
+               this.setEmailAddress(null);
+               this.setEmailAddressRepeat(null);
+               this.setPhoneAreaCode(null);
+               this.setCellphoneCarrier(null);
+               this.setFaxAreaCode(null);
+
+               // - other data
+               this.setBirthday(null);
+               this.setComment(null);
+       }
+
        /**
         * Copies given contact into the controller
         * <p>