From 175360101be5db79c050f79939cd36c3d8d28bce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 21 Apr 2016 18:02:05 +0200 Subject: [PATCH] Continued with contact data editing (admin): - added instance to helper - renamed editFooData() to changeFooData() - added handling contactId - added form (with include) - added method copyContactToController() - added admin helper injection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../localization/bundle_de_DE.properties | 2 +- .../localization/bundle_en_US.properties | 2 +- .../PizzaAdminContactWebRequestBean.java | 100 +++++++++++++++++- ...PizzaAdminContactWebRequestController.java | 7 ++ .../PizzaAdminWebRequestController.java | 20 ++++ .../helper/PizzaAdminWebRequestHelper.java | 45 ++++++-- .../user/PizzaAdminUserWebRequestBean.java | 2 +- .../PizzaAdminUserWebRequestController.java | 2 +- web/admin/contact/admin_contact_edit.xhtml | 28 ++++- 9 files changed, 194 insertions(+), 14 deletions(-) diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index ead1e7ee..60e15ffa 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -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 diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 2ba083ec..9ae8e50d 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -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 diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java index 2cf0c9b6..5635e2b5 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java @@ -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 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. + *

+ * @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()); + } + } + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java index 0e8e7668..8b7f93fa 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java @@ -37,6 +37,13 @@ public interface PizzaAdminContactWebRequestController extends Serializable { */ void copyContactToController (final Contact contact); + /** + * Edits cuirrently loaded contact's data in database. + *

+ * @return Redirect outcome + */ + String changeContactData (); + /** * Getter for cellphone id *

diff --git a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java index e678c5f2..1ff3f0b6 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java @@ -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 + *

+ * @return Contact instance + */ + Contact getContact (); + + /** + * Setter for contact instance + *

+ * @param contact Contact instance + */ + void setContact (final Contact contact); + + /** + * Copies currently set contact instance's data to adminContactController + */ + void copyContactToController (); + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java index 4ca5964e..41e629e4 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java +++ b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java @@ -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; diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index 1ee1b060..4c77b0ee 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -237,7 +237,7 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon } @Override - public String editUserData () { + public String changeUserData () { // Get user instance User user = this.adminHelper.getUser(); diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java index 2d242c94..9d787b11 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java @@ -76,7 +76,7 @@ public interface PizzaAdminUserWebRequestController extends Serializable { *

* @return Redirect outcome */ - String editUserData(); + String changeUserData (); /** * Getter for user name diff --git a/web/admin/contact/admin_contact_edit.xhtml b/web/admin/contact/admin_contact_edit.xhtml index 9397ecfd..1df661ec 100644 --- a/web/admin/contact/admin_contact_edit.xhtml +++ b/web/admin/contact/admin_contact_edit.xhtml @@ -8,6 +8,11 @@ xmlns:f="http://xmlns.jcp.org/jsf/core" > + + + + + #{msg.PAGE_TITLE_ADMIN_EDIT_CONTACT} @@ -16,7 +21,28 @@ - Here goes your content. + + + +

+
+ #{msg.ADMIN_EDIT_CONTACT_TITLE} +
+ +
+ #{msg.ADMIN_PERSONAL_DATA_MINIMUM_NOTICE} +
+ + + + + + +
+ -- 2.39.5