/*
- * Copyright (C) 2016 - 2018 Free Software Foundation
+ * Copyright (C) 2016 - 2022 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
package org.mxchange.jcontacts.model.contact;
import java.text.MessageFormat;
-import java.util.Iterator;
import java.util.List;
-import java.util.Objects;
import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
-import org.mxchange.jjobs.beans.ejb.BaseJobsEnterpriseBean;
+import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
/**
* A contact EJB
@Override
@SuppressWarnings ("unchecked")
- public List<Contact> allContacts () {
+ public List<Contact> fetchAllContacts () {
// Log trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts - CALLED!", this.getClass().getSimpleName())); //NOI18N
return contacts;
}
- @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
- final List<Contact> contacts = this.allContacts();
-
- // 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
- final Iterator<Contact> iterator = contacts.iterator();
-
- // Loop through all
- while (iterator.hasNext()) {
- // Get contact
- final Contact next = iterator.next();
-
- // Is same contact?
- if ((Objects.equals(contact, next)) || (Contacts.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;
- }
-
@Override
public Contact updateContactData (final Contact contact, final boolean isCellphoneUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
// Log trace message