]> git.mxchange.org Git - jjobs-war.git/commitdiff
Imported new way into + ignored .gitcommits (please cherry-pick this)
authorRoland Haeder <roland@mxchange.org>
Thu, 28 Jul 2016 19:08:26 +0000 (21:08 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 7 Aug 2016 10:39:35 +0000 (12:39 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java
src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java

index 34282bfd34141a2d5e9dc701a3fb35f40abe6571..6f8982e4424d674c928fe1a6135b244d7534e323 100644 (file)
@@ -42,6 +42,7 @@ import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jjobs.beans.BaseJobsController;
 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
+import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
@@ -53,7 +54,9 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
 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.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * A general contact bean (controller)
@@ -189,11 +192,22 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
         */
        private Long phoneNumber;
 
+       /**
+        * A list of all selectable contacts
+        */
+       private List<Contact> selectableContacts;
+
        /**
         * Street
         */
        private String street;
 
+       /**
+        * Regular user controller
+        */
+       @Inject
+       private JobsUserWebSessionController userController;
+
        /**
         * Login bean (controller)
         */
@@ -233,10 +247,10 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
                        throw new NullPointerException("event.addedContact is null"); //NOI18N
                } else if (event.getAddedContact().getContactId() == null) {
                        // ... and again
-                       throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
+                       throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
                } else if (event.getAddedContact().getContactId() < 1) {
                        // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
                }
 
                // Clear this bean
@@ -251,9 +265,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
 
        @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
@@ -271,16 +282,37 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
 
                // Clear all data
                this.clear();
+       }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
+       @Override
+       public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLinkedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.linkedUser is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
+               }
+
+               // Remove contact from list available contacts list
+               this.selectableContacts.remove(event.getLinkedUser().getUserContact());
+
+               // Clear all data
+               this.clear();
        }
 
        @Override
        public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
-
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -305,9 +337,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
 
        @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) {
                        // Throw NPE
@@ -326,9 +355,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
                // Get user instance
                Contact registeredContact = event.getRegisteredUser().getUserContact();
 
-               // Debug message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
-
                // Copy all data from registered->user
                this.copyContact(registeredContact);
 
@@ -340,16 +366,10 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
 
                // Clear all data
                this.clear();
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
        }
 
        @Override
        public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
-
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -371,9 +391,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
 
        @Override
        public void afterUserLogin (@Observes final UserLoggedInEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
-
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -391,9 +408,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
 
                // Copy all data to this bean
                this.copyContact(event.getLoggedInUser().getUserContact());
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
        }
 
        @Override
@@ -765,6 +779,40 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
 
                // Get full contact list
                this.contactList = this.contactBean.getAllContacts();
+
+               // Get all users
+               List<User> allUsers = this.userController.allUsers();
+
+               // Get all contacts
+               List<Contact> allContacts = this.contactBean.getAllContacts();
+
+               // Get iterator
+               Iterator<Contact> iterator = allContacts.iterator();
+
+               // Loop through it
+               while (iterator.hasNext()) {
+                       // Get next element
+                       Contact next = iterator.next();
+
+                       // Get iterator
+                       Iterator<User> userIterator = allUsers.iterator();
+
+                       // Loop through all users
+                       while (userIterator.hasNext()) {
+                               // Get user instance
+                               User nextUser = userIterator.next();
+
+                               // Is contact same?
+                               if (Objects.equals(next, nextUser.getUserContact())) {
+                                       // Found same
+                                       iterator.remove();
+                                       break;
+                               }
+                       }
+               }
+
+               // Set contact list
+               this.selectableContacts = allContacts;
        }
 
        @Override
@@ -848,6 +896,11 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
                return localContact;
        }
 
+       @Override
+       public List<Contact> selectableContacts () {
+               return Collections.unmodifiableList(this.selectableContacts);
+       }
+
        @Override
        public void updateContactDataFromController (final Contact contact) {
                // Is the instance valid?
@@ -888,7 +941,8 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
        private void clear () {
                // Clear all data
                // - personal data
-               this.setGender(Gender.UNKNOWN);
+               this.setGender(null);
+               // TODO: Unfinished this.setTitle(null);
                this.setFirstName(null);
                this.setFamilyName(null);
                this.setStreet(null);
index 4a3215007719599cbc9962f1aacc18dd9265d962..7e9561f141ff9d96f518ccbf51edc3d1fd2c0e56 100644 (file)
@@ -30,6 +30,7 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
 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.events.user.linked.AdminLinkedUserEvent;
 
 /**
  * An interface for user beans
@@ -48,7 +49,7 @@ public interface JobsContactWebSessionController extends Serializable {
         * <p>
         * @return A list of all contacts.
         */
-       List<Contact> allContacts();
+       List<Contact> allContacts ();
 
        /**
         * Checks whether there are contacts.
@@ -106,7 +107,15 @@ public interface JobsContactWebSessionController extends Serializable {
        void afterAdminAddedContact (final AdminAddedContactEvent event);
 
        /**
-        * Event observer for updated contact data by admins
+        * Observes events being fired when an administrator has linked a new user
+        * with existing contact data.
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminLinkedUser (final AdminLinkedUserEvent event);
+
+       /**
+        * Event observer for updated contact data by administrators
         * <p>
         * @param event Updated contact data event
         */