]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with contact data editing (admin):
authorRoland Häder <roland@mxchange.org>
Thu, 21 Apr 2016 16:02:05 +0000 (18:02 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 21 Apr 2016 18:25:37 +0000 (20:25 +0200)
- added instance to helper
- renamed editFooData() to changeFooData()
- added handling contactId
- added form (with include)
- added method copyContactToController()
- added admin helper injection

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java
src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java
src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java
web/admin/contact/admin_contact_edit.xhtml

index ead1e7eeed9137755fa9a774e86f416f4aa050c2..60e15ffa2788463f0e3af6de5e8ab3959dca7a9a 100644 (file)
@@ -1,4 +1,4 @@
-# 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
index 2ba083ec86310e1120ffb27adbc0f7b9189b8760..9ae8e50df17ab5af9f47cbcdee0a9b04769815aa 100644 (file)
@@ -1,4 +1,4 @@
-# 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
index 2cf0c9b6c51913bd492feeab667c1a0c7b07b69f..5635e2b5ccce2edc4be08061290f8c90dd468c22 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
@@ -31,12 +31,15 @@ import javax.naming.NamingException;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
 import org.mxchange.jcontacts.contact.gender.Gender;
+import org.mxchange.jcontacts.contact.utils.ContactUtils;
 import org.mxchange.jcontacts.events.contact.AdminAddedContactEvent;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 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.update.AdminUserDataUpdatedEvent;
+import org.mxchange.pizzaapplication.beans.helper.PizzaAdminWebRequestController;
 
 /**
  * A user bean (controller)
@@ -59,6 +62,12 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
        @Any
        private Event<AdminAddedContactEvent> addedContactEvent;
 
+       /**
+        * Admin helper instance
+        */
+       @Inject
+       private PizzaAdminWebRequestController adminHelper;
+
        /**
         * Birth day
         */
@@ -199,6 +208,39 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
                }
        }
 
+       @Override
+       public String changeContactData () {
+               // 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);
+
+               // Update list
+               this.updateList(updatedContact);
+
+               // Fire event
+               this.updatedContactDataEvent.fire(new AdminUserDataUpdatedEvent(updatedContact));
+
+               // Return to contact list (for now)
+               return "admin_list_contact"; //NOI18N
+       }
+
        @Override
        public void copyContactToController (final Contact contact) {
                // Log message
@@ -207,10 +249,10 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
                // The contact instance must be valid
                if (null == contact) {
                        // Throw NPE again
-                       throw new NullPointerException("this.user.userContact is null"); //NOI18N
+                       throw new NullPointerException("contact is null"); //NOI18N
                } else if (contact.getContactId() < 1) {
                        // Not valid
-                       throw new IllegalStateException(MessageFormat.format("this.user.userContact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
                }
 
                // Set all fields: contact
@@ -494,4 +536,56 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
        public void init () {
        }
 
+       /**
+        * Updates all data in contact instance.
+        * <p>
+        * @param contact Contact instance
+        */
+       private void updateContactData (final Contact contact) {
+               // Contact instance should be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Invalid id
+                       throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+               }
+
+               // Update all fields
+               contact.setContactGender(this.getGender());
+               contact.setContactFirstName(this.getFirstName());
+               contact.setContactFamilyName(this.getFamilyName());
+               contact.setContactStreet(this.getStreet());
+               contact.setContactHouseNumber(this.getHouseNumber());
+               contact.setContactZipCode(this.getZipCode());
+               contact.setContactCity(this.getCity());
+               contact.setContactCountry(this.getCountry());
+
+               // Update contact's cellphone number
+               ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
+
+               // Is there a phone number?
+               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+                       // Debug message
+                       System.out.println(MessageFormat.format("updateContactData: phoneId={0}", contact.getContactLandLineNumber().getPhoneId())); //NOI18N
+
+                       // Yes, then update as well
+                       contact.getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode());
+                       contact.getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber());
+               }
+
+               // Is there a fax number?
+               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+                       // Debug message
+                       System.out.println(MessageFormat.format("updateContactData: faxId={0}", contact.getContactFaxNumber().getPhoneId())); //NOI18N
+
+                       // Yes, then update as well
+                       contact.getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode());
+                       contact.getContactFaxNumber().setPhoneNumber(this.getFaxNumber());
+               }
+       }
+
 }
index 0e8e7668279f21d13e86a04d7b1694b3e9ffc822..8b7f93fabdf7871c6e68cb7cadcf20a45c95c4f3 100644 (file)
@@ -37,6 +37,13 @@ public interface PizzaAdminContactWebRequestController extends Serializable {
         */
        void copyContactToController (final Contact contact);
 
+       /**
+        * Edits cuirrently loaded contact's data in database.
+        * <p>
+        * @return Redirect outcome
+        */
+       String changeContactData ();
+
        /**
         * Getter for cellphone id
         * <p>
index e678c5f26dc4943d818148eaf5b24d77e3869165..1ff3f0b611f793f8882d4fb3f172a2f696a713e9 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.pizzaapplication.beans.helper;
 
 import java.io.Serializable;
+import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jusercore.model.user.User;
 
 /**
@@ -45,4 +46,23 @@ public interface PizzaAdminWebRequestController extends Serializable {
         */
        void copyUserToController ();
 
+       /**
+        * Getter for contact instance
+        * <p>
+        * @return Contact instance
+        */
+       Contact getContact ();
+
+       /**
+        * Setter for contact instance
+        * <p>
+        * @param contact Contact instance
+        */
+       void setContact (final Contact contact);
+
+       /**
+        * Copies currently set contact instance's data to adminContactController
+        */
+       void copyContactToController ();
+
 }
index 4ca5964e06d395a40eb59e0c9dad78dfc82e62a9..41e629e4a6b60069791fa4b3d259b2af0ebfa2b5 100644 (file)
@@ -51,6 +51,11 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle
        @Inject
        private PizzaAdminUserWebRequestController adminUserController;
 
+       /**
+        * Contact instance
+        */
+       private Contact contact;
+
        /**
         * User instance
         */
@@ -62,6 +67,30 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle
        public PizzaAdminWebRequestHelper () {
        }
 
+       @Override
+       public void copyContactToController () {
+               // Log message
+               System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
+
+               // Validate user instance
+               if (this.getContact() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.contact is null"); //NOI18N
+               } else if (this.getContact().getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+               } else if (this.getContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
+               }
+
+               // Set all fields: user
+               this.adminContactController.copyContactToController(this.getContact());
+
+               // Log message
+               System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
+       }
+
        @Override
        public void copyUserToController () {
                // Log message
@@ -82,16 +111,20 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle
                // Set all fields: user
                this.adminUserController.setUserName(this.getUser().getUserName());
 
-               // Get contact instance (shortens stuff)
-               Contact contact = this.getUser().getUserContact();
-
-               // Call contact controller
-               this.adminContactController.copyContactToController(contact);
-
                // Log message
                System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
        }
 
+       @Override
+       public Contact getContact () {
+               return this.contact;
+       }
+
+       @Override
+       public void setContact (final Contact contact) {
+               this.contact = contact;
+       }
+
        @Override
        public User getUser () {
                return this.user;
index 1ee1b060d0db2a234008aae3c5a755eb5630d73c..4c77b0ee50607ddb0673ef2303d35aee3cd9bf89 100644 (file)
@@ -237,7 +237,7 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon
        }
 
        @Override
-       public String editUserData () {
+       public String changeUserData () {
                // Get user instance
                User user = this.adminHelper.getUser();
 
index 2d242c94f18e7ea885224b3a05996af8bf808c7c..9d787b11ed074ba7443521c82d07f1d67dad6a9b 100644 (file)
@@ -76,7 +76,7 @@ public interface PizzaAdminUserWebRequestController extends Serializable {
         * <p>
         * @return Redirect outcome
         */
-       String editUserData();
+       String changeUserData ();
 
        /**
         * Getter for user name
index 9397ecfd73e9a1892e450d5c499a3e468acc77e9..1df661ecc4d9664bd7db15933883a771e840fb18 100644 (file)
@@ -8,6 +8,11 @@
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        >
 
+       <f:metadata>
+               <f:viewParam name="contactId" value="#{adminHelper.contact}" converter="UserConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CONTACT_ID_NOT_SET}" />
+               <f:viewAction action="#{adminHelper.copyContactToController()}" />
+       </f:metadata>
+
        <ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
                <ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_EDIT_CONTACT}</ui:define>
 
                </ui:define>
 
                <ui:define name="content">
-                       Here goes your content.
+                       <h:outputText styleClass="errors" value="#{msg.ERROR_CONTACT_ID_NOT_FOUND}" rendered="#{empty adminHelper.contact}" />
+
+                       <h:form id="admin_edit_user" rendered="#{not empty adminHelper.user}">
+                               <div class="table">
+                                       <div class="table_header">
+                                               #{msg.ADMIN_EDIT_CONTACT_TITLE}
+                                       </div>
+
+                                       <div class="para notice">
+                                               #{msg.ADMIN_PERSONAL_DATA_MINIMUM_NOTICE}
+                                       </div>
+
+                                       <ui:include src="/WEB-INF/templates/admin/contact/admin_form_contact_data.tpl">
+                                               <ui:param name="mode" value="edit" />
+                                       </ui:include>
+
+                                       <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="#{adminUserController.changeContactData()}" />
+                                       </div>
+                               </div>
+                       </h:form>
                </ui:define>
        </ui:composition>
 </html>