From 1100d920618a139a6a6cd6c2e00c8e8a9f97bc85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 26 Apr 2016 13:11:35 +0200 Subject: [PATCH] updated code logic to latest changes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../contact/JobsContactSessionBean.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java index 9756345..77f8dcf 100644 --- a/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java @@ -19,10 +19,10 @@ package org.mxchange.jcontacts.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.addressbook.database.BaseAddressbookDatabaseBean; import org.mxchange.jcontacts.contact.utils.ContactUtils; import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; @@ -33,7 +33,6 @@ import org.mxchange.jcontacts.exceptions.ContactNotFoundException; * @author Roland Haeder */ @Stateless (name = "contact", description = "A bean handling contact data") -@Stateless (name = "contact", description = "A bean handling contact data") public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean implements ContactSessionBeanRemote { /** @@ -133,7 +132,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i } @Override - public boolean isContactFound (final Contact contact) { + public Contact lookupContact (final Contact contact) { // Log trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("isContactFound: contact={0} - CALLED!", contact)); //NOI18N @@ -144,7 +143,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i } else if (contact.getContactId() > 0) { try { // Id set, ask other method - return (this.findContactById(contact.getContactId()) instanceof Contact); + 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 @@ -152,7 +151,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i } // Default is not found - boolean isFound = false; + Contact foundContact = null; // Get whole list List contacts = this.getAllContacts(); @@ -161,7 +160,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i if (contacts.isEmpty()) { // Then abort here this.getLoggerBeanLocal().logTrace("isContactFound: No contacts registered, returning 'false' ..."); //NOI18N - return false; + return null; } // Get iterator @@ -173,20 +172,21 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i Contact next = iterator.next(); // Is same contact? - if (ContactUtils.isSameContact(contact, next)) { + if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("isContactFound: Found same contact, id={0}", next.getContactId())); //NOI18N + // Found it - isFound = true; + foundContact = next; break; } } - // Return status - return isFound; - } + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("isContactFound: foundContact={0} - EXIT!", foundContact)); //NOI18N - @Override - public Contact lookupContact (Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + // Return status + return foundContact; } @Override -- 2.39.5