]> git.mxchange.org Git - jjobs-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:40:33 +0000 (21:40 +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/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java
src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java
web/admin/contact/admin_contact_edit.xhtml

index 7b0a40ba29b03169d69eab861ccb430d422a4464..2362342448ad25887aedaaf83475d5eecc25489c 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.jjobs.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;
@@ -34,10 +35,9 @@ 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.jjobs.beans.helper.JobsAdminWebRequestController;
-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 JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
        }
 
        @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 JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
        }
 
        @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 493aefbd4d49b07b37dea8cef59e665a252f9ee3..aa33a93eeccc0c299d1119939ef957de3564729e 100644 (file)
@@ -42,7 +42,7 @@ public interface JobsAdminContactWebRequestController extends Serializable {
         * <p>
         * @return Redirect outcome
         */
-       String changeContactData ();
+       String editContactData ();
 
        /**
         * Getter for cellphone id
index 86cbc631d24334df0b235e5187d0fd688f6e8d0c..324bd1a96b81d34d74820d4745a97d1c3eb91474 100644 (file)
@@ -235,7 +235,7 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
                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 JobsContactWebSessionBean implements JobsContactWebSessionControlle
                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 JobsContactWebSessionBean implements JobsContactWebSessionControlle
 
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
-
                // Return it
                return localContact;
        }
@@ -510,11 +514,13 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle
        }
 
        @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>