]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
implemented addContact()
authorRoland Häder <roland@mxchange.org>
Mon, 6 Jun 2016 12:13:15 +0000 (14:13 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 27 Jul 2016 19:59:15 +0000 (21:59 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jcontacts/contact/PizzaContactSessionBean.java

index 29b765a93f8db868619c798945059256ee099286..a7dc1b7e1734b81cf5263f2b0e36b0aa3192e84b 100644 (file)
@@ -49,34 +49,34 @@ public class PizzaContactSessionBean extends BasePizzaDatabaseBean implements Co
 
        @Override
        public Contact addContact (final Contact contact) throws ContactAlreadyAddedException {
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("addContact: contact={0} - CALLED!", contact)); //NOI18N
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("addContact: contact={0} - CALLED!", contact));
 
-               // The contact instance must be valid
+               // Is the instance set?
                if (null == contact) {
-                       // Throw NPE again
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() instanceof Long) {
-                       // Throw NPE again
-                       throw new NullPointerException("contact.contactId is not null"); //NOI18N //NOI18N
-               } else if (this.lookupContact(contact) instanceof Contact) {
-                       // Already found
-                       throw new ContactAlreadyAddedException(contact);
+                       // Throw NPE
+                       throw new NullPointerException("contact is null");
+               } else if (contact.getContactId() != null) {
+                       // Should be null
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId()));
                }
 
                // Set created timestamp
                contact.setContactCreated(new GregorianCalendar());
 
-               // Set all created timestamps in cellphone, land-line and fax number(s)
+               // Set all created timestamps, if instance is there
                this.setAllContactPhoneEntriesCreated(contact);
 
                // Persist it
                this.getEntityManager().persist(contact);
 
-               // Flush it
+               // Flush it to get contactId set
                this.getEntityManager().flush();
 
-               // Return updated instance
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("addContact: contact.contactId={0} after persisting - EXIT!", contact.getContactId()));
+
+               // Return it
                return contact;
        }