]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Fri, 29 Apr 2016 13:43:26 +0000 (15:43 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 29 Apr 2016 19:09:46 +0000 (21:09 +0200)
- renamed method changeUserData() to editUserData() (members sorted)
- surpressed some warnings that are not being fixed
- clear() needs to be called

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestController.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java
web/admin/contact/admin_contact_edit.xhtml

index 415ba6cc51b3654b9d39d879c71734f46d3fb657..44a78a91aa74c2095dfd71310712987cef6b889c 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.addressbook.beans.contact;
 
 import java.text.MessageFormat;
 import java.util.Date;
+import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
@@ -35,9 +36,8 @@ import org.mxchange.jcontacts.contact.gender.Gender;
 import org.mxchange.jcontacts.contact.utils.ContactUtils;
 import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcountry.data.Country;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 
@@ -231,35 +231,43 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo
        }
 
        @Override
-       public String changeContactData () {
-               // Get contact instance
-               Contact contact = this.adminHelper.getContact();
+       public String addContact () {
+               // Create new contact instance
+               Contact contact = this.createContactInstance();
 
-               // 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
+               // Default is not same contact
+               if (this.isSameContactFound(contact)) {
+                       // Already registered
+                       throw new FaceletException(new ContactAlreadyAddedException(contact));
                }
 
-               // Update all data in contact
-               this.updateContactData(contact);
+               // Init contact
+               Contact updatedContact;
 
-               // Call EJB for updating contact data
-               Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+               // Try to call EJB
+               try {
+                       // Call EJB
+                       updatedContact = this.contactBean.addContact(contact);
+               } catch (final ContactAlreadyAddedException ex) {
+                       // Throw again
+                       throw new FaceletException(ex);
+               }
 
                // Fire event
-               this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
+               this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact));
 
-               // Return to contact list (for now)
+               // Clear this bean
+               this.clear();
+
+               // Return outcome
                return "admin_list_contact"; //NOI18N
        }
 
+       @Override
+       public List<Contact> allContacts () {
+               return this.contactController.allContacts();
+       }
+
        @Override
        public void copyContactToController (final Contact contact) {
                // The contact instance must be valid
@@ -307,11 +315,46 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo
        }
 
        @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 () {
                return this.birthday;
        }
 
        @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
        public void setBirthday (final Date birthday) {
                this.birthday = birthday;
        }
index b737bea28acd2819fe30b56b5b583b05117dd4ec..25fcfc5311003f9e91aea0bc0235179d7888142f 100644 (file)
@@ -42,7 +42,7 @@ public interface AddressbookAdminContactWebRequestController extends Serializabl
         * <p>
         * @return Redirect outcome
         */
-       String changeContactData ();
+       String editContactData ();
 
        /**
         * Getter for cellphone id
index 3f584aa6e042808e5574ebff0f6c45f79f98b945..e06149a3acbae6282612a4585f93843fb6bac0a3 100644 (file)
@@ -235,7 +235,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUpdatedContact()== null) {
+               } else if (event.getUpdatedContact() == null) {
                        // Throw NPE again
                        throw new NullPointerException("event.user is null"); //NOI18N
                } else if (event.getUpdatedContact().getContactId() == null) {
@@ -338,6 +338,11 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
                System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
        }
 
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+       public List<Contact> allContacts () {
+               return this.contactList;
+       }
+
        /**
         * Clears this bean
         */
@@ -456,7 +461,6 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
 
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
-
                // Return it
                return localContact;
        }
@@ -510,11 +514,13 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe
        }
 
        @Override
+       @SuppressWarnings ("ReturnOfDateField")
        public Date getBirthday () {
                return this.birthday;
        }
 
        @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
        public void setBirthday (final Date birthday) {
                this.birthday = birthday;
        }
index 9f608238f43ac19c311c024346acef08305b8446..11928a3ea82f3b4282d7065009c113c52d49ede6 100644 (file)
@@ -41,7 +41,7 @@
 
                                        <div class="table_footer">
                                                <h:commandButton class="reset" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
-                                               <h:commandButton class="submit" type="submit" id="register" value="#{msg.BUTTON_ADMIN_EDIT_CONTACT}" action="#{adminContactController.changeContactData()}" />
+                                               <h:commandButton class="submit" type="submit" id="register" value="#{msg.BUTTON_ADMIN_EDIT_CONTACT}" action="#{adminContactController.editContactData()}" />
                                        </div>
                                </div>
                        </h:form>