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;
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
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;
*/
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.