]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java
it is this way ...
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / contact / AddressbookAdminContactWebRequestBean.java
index 6c1a48310692ca83ccab29f192e2978acc030aa8..6b77e0c161e1c86c8756322c81a9f60cb7da119c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Cho-Time GmbH
+ * Copyright (C) 2016 Roland Haeder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -344,24 +344,6 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo
                this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
        }
 
-       @Override
-       public String editContactData () {
-               // Get contact instance
-               Contact contact = this.adminHelper.getContact();
-
-               // Is the land-line number set?
-               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
-                       // .. land-line data
-                       this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
-                       this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
-                       this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
-                       this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
-               }
-
-               // Log message
-               //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
-       }
-
        @Override
        public Contact createContactInstance () {
                // Generate phone number
@@ -400,6 +382,39 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo
                return contact;
        }
 
+       @Override
+       public String editContactData () {
+               // Get contact instance
+               Contact contact = this.adminHelper.getContact();
+
+               // Check if contact instance is in helper and valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("adminHelper.contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Invalid id
+                       throw new IllegalStateException(MessageFormat.format("adminHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+               }
+
+               // Update all data in contact
+               this.updateContactData(contact);
+
+               // Call EJB for updating contact data
+               Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+
+               // Fire event
+               this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
+
+               // Clear bean
+               this.clear();
+
+               // Return to contact list (for now)
+               return "admin_list_contact"; //NOI18N
+       }
+
        @Override
        @SuppressWarnings ("ReturnOfDateField")
        public Date getBirthday () {