]> git.mxchange.org Git - jjobs-war.git/commitdiff
Cleanups:
authorRoland Häder <roland@mxchange.org>
Tue, 3 May 2016 08:29:18 +0000 (10:29 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 5 May 2016 16:59:02 +0000 (18:59 +0200)
- hasUsers/allUsers was redundant
- moved isContactFound to admin user controller to avoid redundant lists, too

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/helper/JobsAdminWebRequestHelper.java
src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java
src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestController.java

index 2e796f804bc767d34e96e3e7a296200131a5b0ec..9d469410badad9bc30880f211b445f17fc748161 100644 (file)
@@ -122,6 +122,36 @@ public class JobsAdminWebRequestHelper implements JobsAdminWebRequestController
                this.contact = contact;
        }
 
+       @Override
+       public String getContactUsageMessageKey (final Contact contact) {
+               // The contact must be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               }
+
+               // Default key is "unused"
+               String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
+
+               // Check user/customer
+               boolean isUserContact = this.adminUserController.isContactFound(contact);
+
+               // Check user first
+               if (isUserContact) {
+                       // Only user
+                       messageKey = "CONTACT_IS_USER"; //NOI18N
+               }
+
+               // Return message key
+               return messageKey;
+       }
+
        @Override
        public User getUser () {
                return this.user;
index 12fb82983b8cd7eb82c4418a252fc2d55c6b247e..194a85be12a0a90ea81c6a31769a2a92fbcbf20f 100644 (file)
@@ -395,6 +395,43 @@ public class JobsAdminUserWebRequestBean implements JobsAdminUserWebRequestContr
                this.userList = this.userBean.allUsers();
        }
 
+       @Override
+       public boolean isContactFound (final Contact contact) {
+               // The contact must be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               }
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Get iterator
+               Iterator<User> iterator = this.allUsers().iterator();
+
+               // Loop through all entries
+               while (iterator.hasNext()) {
+                       // Get user
+                       User next = iterator.next();
+
+                       // Compare both objects
+                       if (Objects.equals(contact, next.getUserContact())) {
+                               // Found it
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return status
+               return isFound;
+       }
+
        @Override
        public User lookupUserById (final Long userId) throws UserNotFoundException {
                // Parameter must be valid
index 3408cbf609e524ddaf40e18e76775b36d240e803..fe084f60dea0ec69149c9838620afd81a2868747 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.jjobs.beans.user;
 
 import java.io.Serializable;
 import java.util.List;
+import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.model.user.User;
@@ -36,6 +37,15 @@ public interface JobsAdminUserWebRequestController extends Serializable {
         */
        void afterUserUpdatedPersonalData (final UpdatedUserPersonalDataEvent event);
 
+       /**
+        * Checks whether the given contact is a user
+        * <p>
+        * @param contact Contact to check
+        * <p>
+        * @return Whether the contact is a user
+        */
+       boolean isContactFound (final Contact contact);
+
        /**
         * Tries to lookup user by given id number. If the user is not found or the
         * account status is not CONFIRMED proper exceptions are thrown.