+ @Override
+ public boolean isEmailAddressRegistered (final String emailAddress) {
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N
+
+ // The email address should be valid
+ if (null == emailAddress) {
+ // Is null
+ throw new NullPointerException("emailAddress is null"); //NOI18N
+ } else if (emailAddress.isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
+ }
+
+ // Default is not found
+ boolean isFound = false;
+
+ try {
+ // Ask other method for contact instance
+ Contact contact = this.findContactByEmailAddress(emailAddress);
+
+ // Log debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: Found contact={1} for emailAddress={2}", this.getClass().getSimpleName(), contact, emailAddress)); //NOI18N
+
+ // It is found ...
+ isFound = true;
+ } catch (final ContactNotFoundException ex) {
+ // @TODO Was not found, log exception for spam check?
+ }
+
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N
+
+ // Return status
+ return isFound;
+ }
+
+ @Override
+ public Contact lookupContact (final Contact contact) {
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
+
+ // Parameter should be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() > 0) {
+ try {
+ // Id set, ask other method
+ return this.findContactById(contact.getContactId());
+ } catch (final ContactNotFoundException ex) {
+ // Not found, should not happen
+ throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is set, but not found.", contact.getContactId()), ex); //NOI18N
+ }
+ }
+
+ // Default is not found
+ Contact foundContact = null;
+
+ // Get whole list
+ List<Contact> contacts = this.getAllContacts();
+
+ // Is the list empty?
+ if (contacts.isEmpty()) {
+ // Then abort here
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: No contacts registered, returning NULL ...", this.getClass().getSimpleName())); //NOI18N
+ return null;
+ }
+
+ // Get iterator
+ Iterator<Contact> iterator = contacts.iterator();
+
+ // Loop through all
+ while (iterator.hasNext()) {
+ // Get contact
+ Contact next = iterator.next();
+
+ // Is same contact?
+ if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isContactFound: Found same contact: contactId={1}", this.getClass().getSimpleName(), next.getContactId())); //NOI18N
+
+ // Found it
+ foundContact = next;
+ break;
+ }
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: foundContact={1} - EXIT!", this.getClass().getSimpleName(), foundContact)); //NOI18N
+
+ // Return found contact
+ return foundContact;
+ }
+