From 5816d6a53a597ed6f249df017148cd94c7323a61 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 3 Aug 2017 21:43:01 +0200 Subject: [PATCH] WIP: Please cherry-pick: - renamed methods to make them more clear (current fax/land-line/mobile number) - these methods and also getter/setter in bean helper are for JSF views only and should not be callable by other beans - so this change breaks a lot again and I again need to rewrite it - so more controller interfaces are now empty, maybe one day some methods will come back, but ... - anyway, doing a lot CDI calls (in some methods +10 calls each) is really not good as CDI does take some time - better reimplement it in CDI events which are more flexible as more beans can be reached than only those which are hard-coded in - sorted members again MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminContactWebRequestBean.java | 87 +++-- .../JobsAdminContactWebRequestController.java | 7 - .../phone/JobsContactPhoneWebSessionBean.java | 30 +- .../JobsContactPhoneWebSessionController.java | 23 -- .../helper/JobsWebRequestHelperBean.java | 142 +++++-- .../JobsWebRequestHelperController.java | 110 ------ .../phone/JobsAdminPhoneWebRequestBean.java | 352 ++++++++++++------ .../beans/user/JobsUserWebSessionBean.java | 4 +- .../JobsConfirmationLinkWebRequestBean.java | 11 +- web/admin/fax/admin_fax_show.xhtml | 2 +- web/admin/landline/admin_landline_show.xhtml | 2 +- web/admin/mobile/admin_mobile_show.xhtml | 2 +- 12 files changed, 429 insertions(+), 343 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java index 2ae355e7..3edd3bdc 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java @@ -22,6 +22,7 @@ import java.util.Iterator; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; +import javax.enterprise.event.Observes; import javax.enterprise.inject.Any; import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; @@ -38,6 +39,7 @@ import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcontacts.contact.title.PersonalTitle; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.helper.created.ObservableHelperCreatedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; @@ -117,14 +119,14 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private JobsContactWebSessionController contactController; /** - * Contact id + * Country instance */ - private Long contactId; + private Country contactCountry; /** - * Country instance + * Contact id */ - private Country contactCountry; + private Long contactId; /** * Email address @@ -307,23 +309,34 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement return "admin_list_contact"; //NOI18N } - @Override - public void copyContactToController (final Contact contact) { + /** + * Observer for events being fired when a bean helper has successfully + * created a contact instance. + *

+ * @param event Event being fired + */ + public void afterHelperCreatedContactEvent (@Observes final ObservableHelperCreatedContactEvent event) { // Log message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterHelperCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N - // The contact instance must be valid - if (null == contact) { + // The event instance must be valid + if (null == event) { // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getCreatedContact() == null) { // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N - } else if (contact.getContactId() < 1) { + throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N + } else if (event.getCreatedContact().getContactId() == null) { + // Throw NPE again + throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N + } else if (event.getCreatedContact().getContactId() < 1) { // Not valid - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N } + // Get contact instance from event + Contact contact = event.getCreatedContact(); + // Set all fields: contact this.setContactId(contact.getContactId()); this.setAcademicTitle(contact.getContactTitle()); @@ -367,7 +380,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement } // Log message - //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterHelperCreatedContactEvent(): EXIT!"); //NOI18N } @Override @@ -398,6 +411,12 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // Create new instance Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName()); + // Is contact id set? + if (this.getContactId() instanceof Long) { + // Set it, too + contact.setContactId(this.getContactId()); + } + // Add all others contact.setContactTitle(this.getAcademicTitle()); contact.setContactBirthday(this.getBirthday()); @@ -481,7 +500,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement */ public String editContactData () { // Get contact instance - Contact contact = this.beanHelper.getContact(); + Contact contact = this.createContactInstance(); // Check if contact instance is in helper and valid if (null == contact) { @@ -638,6 +657,24 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.comment = comment; } + /** + * Getter for contactCountry instance + *

+ * @return Country instance + */ + public Country getContactCountry () { + return this.contactCountry; + } + + /** + * Setter for contactCountry instance + *

+ * @param contactCountry Country instance + */ + public void setContactCountry (final Country contactCountry) { + this.contactCountry = contactCountry; + } + /** * Getter for contact id *

@@ -667,24 +704,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N } - /** - * Getter for contactCountry instance - *

- * @return Country instance - */ - public Country getContactCountry () { - return this.contactCountry; - } - - /** - * Setter for contactCountry instance - *

- * @param contactCountry Country instance - */ - public void setContactCountry (final Country contactCountry) { - this.contactCountry = contactCountry; - } - /** * Getter for email address *

diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java index cd88e08e..38104e42 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java @@ -38,13 +38,6 @@ public interface JobsAdminContactWebRequestController extends Serializable { */ Contact createContactInstance (); - /** - * Copies given contact's data to this controller - *

- * @param contact Contact instance - */ - void copyContactToController (final Contact contact); - /** * Getter for controller type *

diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java index b583c799..63dcc3b4 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java @@ -245,8 +245,12 @@ public class JobsContactPhoneWebSessionBean extends BaseJobsController implement this.clear(); } - @Override - public List allFaxNumberContacts () { + /** + * Getter for all contacts having current fax number linked + *

+ * @return List of all linked contacts + */ + public List allCurrentFaxNumberContacts () { // Get id DialableFaxNumber faxNumber = this.beanHelper.getFaxNumber(); @@ -261,7 +265,7 @@ public class JobsContactPhoneWebSessionBean extends BaseJobsController implement // "Walk" through all contacts for (final Contact contact : this.contactController.allContacts()) { // Is mobile instance the same? - if (Objects.equals(contact.getContactFaxNumber(), this.beanHelper.getFaxNumber())) { + if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) { // Found one list.add(contact); } @@ -275,8 +279,12 @@ public class JobsContactPhoneWebSessionBean extends BaseJobsController implement } } - @Override - public List allLandLineNumberContacts () { + /** + * Getter for all contacts having current land-line number linked + *

+ * @return List of all linked contacts + */ + public List allCurrentLandLineNumberContacts () { // Get id DialableLandLineNumber landLineNumber = this.beanHelper.getLandLineNumber(); @@ -291,7 +299,7 @@ public class JobsContactPhoneWebSessionBean extends BaseJobsController implement // "Walk" through all contacts for (final Contact contact : this.contactController.allContacts()) { // Is mobile instance the same? - if (Objects.equals(contact.getContactLandLineNumber(), this.beanHelper.getLandLineNumber())) { + if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) { // Found one list.add(contact); } @@ -305,8 +313,12 @@ public class JobsContactPhoneWebSessionBean extends BaseJobsController implement } } - @Override - public List allMobileNumberContacts () { + /** + * Getter for all contacts having current mobile number linked + *

+ * @return List of all linked contacts + */ + public List allCurrentMobileNumberContacts () { // Get id DialableMobileNumber mobileNumber = this.beanHelper.getMobileNumber(); @@ -321,7 +333,7 @@ public class JobsContactPhoneWebSessionBean extends BaseJobsController implement // "Walk" through all contacts for (final Contact contact : this.contactController.allContacts()) { // Is mobile instance the same? - if (Objects.equals(contact.getContactMobileNumber(), this.beanHelper.getMobileNumber())) { + if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) { // Found one list.add(contact); } diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java index d3b2cd92..09375960 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java @@ -17,8 +17,6 @@ package org.mxchange.jjobs.beans.contact.phone; import java.io.Serializable; -import java.util.List; -import org.mxchange.jcontacts.contact.Contact; /** * An interface for user beans @@ -27,25 +25,4 @@ import org.mxchange.jcontacts.contact.Contact; */ public interface JobsContactPhoneWebSessionController extends Serializable { - /** - * Getter for all contacts having current fax number linked - *

- * @return List of all linked contacts - */ - List allFaxNumberContacts (); - - /** - * Getter for all contacts having current land-line number linked - *

- * @return List of all linked contacts - */ - List allLandLineNumberContacts (); - - /** - * Getter for all contacts having current mobile number linked - *

- * @return List of all linked contacts - */ - List allMobileNumberContacts (); - } diff --git a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java index 06d6cd84..52f109d5 100644 --- a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java +++ b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java @@ -23,6 +23,8 @@ import javax.enterprise.inject.Any; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.events.contact.helper.created.HelperCreatedContactEvent; +import org.mxchange.jcontacts.events.contact.helper.created.ObservableHelperCreatedContactEvent; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController; import org.mxchange.jjobs.beans.phone.JobsAdminPhoneWebRequestController; @@ -83,59 +85,66 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs */ private Contact contact; + /** + * Event for when a contact instance was created + */ + @Any + @Inject + private Event contactCreatedEvent; + /** * Fax number */ private DialableFaxNumber faxNumber; /** - * Land-line number + * Event for when a fax number instance was created */ - private DialableLandLineNumber landLineNumber; + @Any + @Inject + private Event faxNumberCreatedEvent; /** - * Mobile number + * Land-line number */ - private DialableMobileNumber mobileNumber; + private DialableLandLineNumber landLineNumber; /** - * User instance + * Event for when a land-line number instance was created */ - private User user; + @Any + @Inject + private Event landLineNumberCreatedEvent; /** - * Regular user controller + * Mobile number */ - @Inject - private JobsUserWebSessionController userController; + private DialableMobileNumber mobileNumber; /** - * Event for when a user instance was created + * Event for when a mobile number instance was created */ @Any @Inject - private Event userCreatedEvent; + private Event mobileNumberCreatedEvent; /** - * Event for when a fax number instance was created + * User instance */ - @Any - @Inject - private Event faxNumberCreatedEvent; + private User user; /** - * Event for when a land-line number instance was created + * Regular user controller */ - @Any @Inject - private Event landLineNumberCreatedEvent; + private JobsUserWebSessionController userController; /** - * Event for when a mobile number instance was created + * Event for when a user instance was created */ @Any @Inject - private Event mobileNumberCreatedEvent; + private Event userCreatedEvent; /** * Default constructor @@ -148,7 +157,9 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller)); } - @Override + /** + * Copies currently set contact instances data to adminContactController + */ public void copyContactToController () { // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); // System.out.println(MessageFormat.format("{0}.copyContactToController: CALLED, caller: {2}", this.getClass().getSimpleName(), this.contact, caller)); @@ -169,10 +180,12 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs this.setPhoneInstances(this.getContact()); // Set all fields: user - this.adminContactController.copyContactToController(this.getContact()); + this.contactCreatedEvent.fire(new HelperCreatedContactEvent(this.getContact())); } - @Override + /** + * Copies currently set fax number's data to admin phone controller + */ public void copyFaxNumberToController () { // Validate fax instance if (this.getFaxNumber() == null) { @@ -211,7 +224,9 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs this.faxNumberCreatedEvent.fire(new HelperCreatedFaxNumberEvent(this.getFaxNumber())); } - @Override + /** + * Copies currently set land-line number's data to admin phone controller + */ public void copyLandLineNumberToController () { // Validate land-line instance if (this.getLandLineNumber() == null) { @@ -250,7 +265,9 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs this.landLineNumberCreatedEvent.fire(new HelperCreatedLandLineNumberEvent(this.getLandLineNumber())); } - @Override + /** + * Copies currently set mobile number's data to admin phone controller + */ public void copyMobileNumberToController () { // Validate mobile instance if (this.getMobileNumber() == null) { @@ -283,7 +300,9 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs this.mobileNumberCreatedEvent.fire(new HelperCreatedMobileNumberEvent(this.getMobileNumber())); } - @Override + /** + * Copies currently set user instances data to adminUserController + */ public void copyUserToController () { // Log message //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N @@ -313,21 +332,34 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs this.userCreatedEvent.fire(new HelperCreatedUserEvent(this.getUser())); } - @Override + /** + * Getter for contact instance + *

+ * @return Contact instance + */ public Contact getContact () { - // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); - // System.out.println(MessageFormat.format("{0}: Returning this.contact={1}, caller: {2}", this.getClass().getSimpleName(), this.contact, caller)); return this.contact; } - @Override + /** + * Setter for contact instance + *

+ * @param contact Contact instance + */ public void setContact (final Contact contact) { // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller)); this.contact = contact; } - @Override + /** + * Returns a message key depending on if this contact is a user and/or a + * contact. If this contact is unused, a default key is returned. + *

+ * @param contact Contact instance to check + *

+ * @return Message key + */ public String getContactUsageMessageKey (final Contact contact) { // The contact must be valid if (null == contact) { @@ -357,42 +389,74 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs return messageKey; } - @Override + /** + * Getter for dialable fax number + *

+ * @return Dialable fax number + */ public DialableFaxNumber getFaxNumber () { return this.faxNumber; } - @Override + /** + * Setter for dialable fax number + *

+ * @param faxNumber Dialable fax number + */ public void setFaxNumber (final DialableFaxNumber faxNumber) { this.faxNumber = faxNumber; } - @Override + /** + * Getter for dialable land-line number + *

+ * @return Dialable land-line number + */ public DialableLandLineNumber getLandLineNumber () { return this.landLineNumber; } - @Override + /** + * Setter for dialable land-line number + *

+ * @param landLineNumber Dialable land-line number + */ public void setLandLineNumber (final DialableLandLineNumber landLineNumber) { this.landLineNumber = landLineNumber; } - @Override + /** + * Getter for dialable mobile number + *

+ * @return Dialable mobile number + */ public DialableMobileNumber getMobileNumber () { return this.mobileNumber; } - @Override + /** + * Setter for dialable mobile number + *

+ * @param mobileNumber Dialable mobile number + */ public void setMobileNumber (final DialableMobileNumber mobileNumber) { this.mobileNumber = mobileNumber; } - @Override + /** + * Getter for user instance + *

+ * @return User instance + */ public User getUser () { return this.user; } - @Override + /** + * Setter for user instance + *

+ * @param user User instance + */ public void setUser (final User user) { this.user = user; } diff --git a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperController.java b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperController.java index ed404894..3fd3b517 100644 --- a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperController.java +++ b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperController.java @@ -17,11 +17,6 @@ package org.mxchange.jjobs.beans.helper; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jusercore.model.user.User; /** * An interface for general bean helper @@ -30,109 +25,4 @@ import org.mxchange.jusercore.model.user.User; */ public interface JobsWebRequestHelperController extends Serializable { - /** - * Copies currently set fax number's data to admin phone controller - */ - void copyFaxNumberToController (); - - /** - * Copies currently set land-line number's data to admin phone controller - */ - void copyLandLineNumberToController (); - - /** - * Copies currently set mobile number's data to admin phone controller - */ - void copyMobileNumberToController (); - - /** - * Copies currently set contact instance's data to adminContactController - */ - void copyContactToController (); - - /** - * Copies currently set user instance's data to adminUserController - */ - void copyUserToController (); - - /** - * Returns a message key depending on if this contact is a user and/or a - * contact. If this contact is unused, a default key is returned. - *

- * @param contact Contact instance to check - *

- * @return Message key - */ - String getContactUsageMessageKey (final Contact contact); - - /** - * Getter for contact instance - *

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

- * @param contact Contact instance - */ - void setContact (final Contact contact); - - /** - * Getter for user instance - *

- * @return User instance - */ - User getUser (); - - /** - * Setter for user instance - *

- * @param user User instance - */ - void setUser (final User user); - - /** - * Getter for dialable mobile number - *

- * @return Dialable mobile number - */ - DialableMobileNumber getMobileNumber (); - - /** - * Setter for dialable mobile number - *

- * @param mobileNumber Dialable mobile number - */ - void setMobileNumber (final DialableMobileNumber mobileNumber); - - /** - * Getter for dialable land-line number - *

- * @return Dialable land-line number - */ - DialableLandLineNumber getLandLineNumber (); - - /** - * Setter for dialable land-line number - *

- * @param landLine Dialable land-line number - */ - void setLandLineNumber (final DialableLandLineNumber landLine); - - /** - * Getter for dialable fax number - *

- * @return Dialable fax number - */ - DialableFaxNumber getFaxNumber (); - - /** - * Setter for dialable fax number - *

- * @param faxNumber Dialable fax number - */ - void setFaxNumber (final DialableFaxNumber faxNumber); - } diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java index dc89c8dc..a8493ef5 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java @@ -17,17 +17,14 @@ package org.mxchange.jjobs.beans.phone; import java.text.MessageFormat; +import java.util.Calendar; import java.util.List; -import java.util.Locale; -import java.util.MissingResourceException; import java.util.Objects; -import java.util.ResourceBundle; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; +import javax.enterprise.event.Observes; import javax.enterprise.inject.Any; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -43,6 +40,9 @@ import org.mxchange.jphone.events.fax.removed.AdminFaxNumberRemovedFromListEvent import org.mxchange.jphone.events.fax.removed.AdminRemoveFaxNumberFromListEvent; import org.mxchange.jphone.events.fax.updated.AdminFaxNumberUpdatedEvent; import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; +import org.mxchange.jphone.events.helper.fax.created.ObservableHelperCreatedFaxNumberEvent; +import org.mxchange.jphone.events.helper.landline.created.ObservableHelperCreatedLandLineNumberEvent; +import org.mxchange.jphone.events.helper.mobile.created.ObservableHelperCreatedMobileNumberEvent; import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; import org.mxchange.jphone.events.landline.deleted.AdminLandLineNumberDeletedEvent; import org.mxchange.jphone.events.landline.removed.AdminLandLineNumberRemovedFromListEvent; @@ -56,8 +56,11 @@ import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListE import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent; import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote; @@ -169,6 +172,21 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ private Country phoneCountry; + /** + * When the phone entry has been created (persisted) + */ + private Calendar phoneEntryCreated; + + /** + * When the phone entry has been updated + */ + private Calendar phoneEntryUpdated; + + /** + * Phone id (aka primary key) + */ + private Long phoneId; + /** * Phone number */ @@ -208,6 +226,107 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller)); } + /** + * Observes events being fired when a bean helper has successfully created a + * fax number instance. + *

+ * @param event Event being fired + */ + public void afterHelperCreatedFaxNumberEvent (@Observes final ObservableHelperCreatedFaxNumberEvent event) { + // The event instance must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getFaxNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.faxNumber is null"); //NOI18N + } else if (event.getFaxNumber().getPhoneId() == null) { + // Throw NPE yet again + throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N + } else if (event.getFaxNumber().getPhoneId() < 1) { + // Throw NPE yet again + throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N + } + + // Get fax number from event + DialableFaxNumber number = event.getFaxNumber(); + + // Copy all data to this bean + this.setPhoneId(number.getPhoneId()); + this.setPhoneCountry(number.getPhoneCountry()); + this.setPhoneAreaCode(number.getPhoneAreaCode()); + this.setPhoneNumber(number.getPhoneNumber()); + this.setPhoneEntryCreated(number.getPhoneEntryCreated()); + this.setPhoneEntryUpdated(number.getPhoneEntryUpdated()); + } + + /** + * Observes events being fired when a bean helper has successfully created a + * land-line number instance. + *

+ * @param event Event being fired + */ + public void afterHelperCreatedLandLineNumberEvent (@Observes final ObservableHelperCreatedLandLineNumberEvent event) { + // The event instance must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLandLineNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.landLineNumber is null"); //NOI18N + } else if (event.getLandLineNumber().getPhoneId() == null) { + // Throw NPE yet again + throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N + } else if (event.getLandLineNumber().getPhoneId() < 1) { + // Throw NPE yet again + throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N + } + + // Get fax number from event + DialableLandLineNumber number = event.getLandLineNumber(); + + // Copy all data to this bean + this.setPhoneId(number.getPhoneId()); + this.setPhoneCountry(number.getPhoneCountry()); + this.setPhoneAreaCode(number.getPhoneAreaCode()); + this.setPhoneNumber(number.getPhoneNumber()); + this.setPhoneEntryCreated(number.getPhoneEntryCreated()); + this.setPhoneEntryUpdated(number.getPhoneEntryUpdated()); + } + + /** + * Observes events being fired when a bean helper has successfully created a + * mobile number instance. + *

+ * @param event Event being fired + */ + public void afterHelperCreatedMobileNumberEvent (@Observes final ObservableHelperCreatedMobileNumberEvent event) { + // The event instance must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.mobileNumber is null"); //NOI18N + } else if (event.getMobileNumber().getPhoneId() == null) { + // Throw NPE yet again + throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N + } else if (event.getMobileNumber().getPhoneId() < 1) { + // Throw NPE yet again + throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N + } + + // Get fax number from event + DialableMobileNumber number = event.getMobileNumber(); + + // Copy all data to this bean + this.setPhoneId(number.getPhoneId()); + this.setMobileProvider(number.getMobileProvider()); + this.setPhoneNumber(number.getPhoneNumber()); + this.setPhoneEntryCreated(number.getPhoneEntryCreated()); + this.setPhoneEntryUpdated(number.getPhoneEntryUpdated()); + } + /** * Returns a list of all unused ("non-linked") land-line numbers *

@@ -263,7 +382,7 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ public String deleteFaxData () { // Get fax number from bean helper - DialableFaxNumber number = this.beanHelper.getFaxNumber(); + DialableFaxNumber number = this.createFaxNumber(); // Is all data set if (number == null) { @@ -315,7 +434,7 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ public String deleteLandLineData () { // Get land-line number from helper - DialableLandLineNumber number = this.beanHelper.getLandLineNumber(); + DialableLandLineNumber number = this.createLandLineNumber(); // Is all data set if (number == null) { @@ -367,7 +486,7 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ public String deleteMobileData () { // Get mobile number from helper - DialableMobileNumber number = this.beanHelper.getMobileNumber(); + DialableMobileNumber number = this.createMobileNumber(); // Is all data set if (number == null) { @@ -413,7 +532,7 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ public String doChangeFaxNumber () { // Get fax number from bean helper - DialableFaxNumber number = this.beanHelper.getFaxNumber(); + DialableFaxNumber number = this.createFaxNumber(); // Is all data set if (number == null) { @@ -479,7 +598,7 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ public String doChangeLandLineNumber () { // Get land-line number from helper - DialableLandLineNumber number = this.beanHelper.getLandLineNumber(); + DialableLandLineNumber number = this.createLandLineNumber(); // Is all data set if (number == null) { @@ -545,7 +664,7 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ public String doUpdateMobileNumber () { // Get mobile number from helper - DialableMobileNumber number = this.beanHelper.getMobileNumber(); + DialableMobileNumber number = this.createMobileNumber(); // Is all data set if (number == null) { @@ -719,6 +838,64 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im this.phoneCountry = phoneCountry; } + /** + * Getter for phone entry created timestamp + *

+ * @return Phone entry created timestamp + */ + @SuppressWarnings ("ReturnOfDateField") + public Calendar getPhoneEntryCreated () { + return this.phoneEntryCreated; + } + + /** + * Setter for phone entry created timestamp + *

+ * @param phoneEntryCreated Phone entry created timestamp + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setPhoneEntryCreated (final Calendar phoneEntryCreated) { + this.phoneEntryCreated = phoneEntryCreated; + } + + /** + * Getter for phone entry updated timestamp + *

+ * @return Phone entry updated timestamp + */ + @SuppressWarnings ("ReturnOfDateField") + public Calendar getPhoneEntryUpdated () { + return this.phoneEntryUpdated; + } + + /** + * Setter for phone entry updated timestamp + *

+ * @param phoneEntryUpdated Phone entry updated timestamp + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) { + this.phoneEntryUpdated = phoneEntryUpdated; + } + + /** + * Getter for phone id + *

+ * @return Phone id + */ + public Long getPhoneId () { + return this.phoneId; + } + + /** + * Setter for phone id + *

+ * @param phoneId Phone id + */ + public void setPhoneId (final Long phoneId) { + this.phoneId = phoneId; + } + /** * Getter for dial number without prefix *

@@ -756,130 +933,75 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im } /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value + * Returns an instance of a DialableFaxNumber from all fields stored in this + * bean. *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter + * @return An instance of a DialableFaxNumber class */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } + private DialableFaxNumber createFaxNumber () { + // Initialize it + DialableFaxNumber number = new FaxNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N + // Add all other data + number.setPhoneEntryCreated(this.getPhoneEntryCreated()); + number.setPhoneEntryUpdated(this.getPhoneEntryUpdated()); + + // Is id number set? + if (this.getPhoneId() instanceof Long) { + // Set it + number.setPhoneId(this.getPhoneId()); } + // Return it - return contextValue; + return number; } /** - * Checks whether debug mode is enabled for given controller + * Returns an instance of a DialableLandLineNumber from all fields stored in + * this bean. *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled + * @return An instance of a DialableLandLineNumber class */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N + private DialableLandLineNumber createLandLineNumber () { + // Initialize it + DialableLandLineNumber number = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); + + // Add all other data + number.setPhoneEntryCreated(this.getPhoneEntryCreated()); + number.setPhoneEntryUpdated(this.getPhoneEntryUpdated()); + + // Is id number set? + if (this.getPhoneId() instanceof Long) { + // Set it + number.setPhoneId(this.getPhoneId()); } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; + // Return it - return isEnabled; + return number; } /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext + * Returns an instance of a DialableMobileNumber from all fields stored in + * this bean. *

- * @return Initialized and loaded resource bundle + * @return An instance of a DialableMobileNumber class */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); + private DialableMobileNumber createMobileNumber () { + // Initialize it + DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getPhoneNumber()); - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } + // Add all other data + number.setPhoneEntryCreated(this.getPhoneEntryCreated()); + number.setPhoneEntryUpdated(this.getPhoneEntryUpdated()); - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored + // Is id number set? + if (this.getPhoneId() instanceof Long) { + // Set it + number.setPhoneId(this.getPhoneId()); } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); + + // Return it + return number; } } diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index d07f7c6a..a09df30f 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -42,7 +42,6 @@ import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent; import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent; import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent; -import org.mxchange.jusercore.events.user.helper.created.ObservableHelperCreatedUserEvent; import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent; import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent; @@ -61,6 +60,7 @@ import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredE import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent; import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException; import org.mxchange.juserlogincore.login.UserLoginUtils; +import org.mxchange.jusercore.events.user.helper.created.ObservableHelperCreatedContactEvent; /** * A user controller (bean) @@ -338,7 +338,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs *

* @param event User created event */ - public void afterHelperCreatedUserEvent (@Observes final ObservableHelperCreatedUserEvent event) { + public void afterHelperCreatedUserEvent (@Observes final ObservableHelperCreatedContactEvent event) { // Is the instance valid? if (null == event) { // Throw NPE diff --git a/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java index 40adc257..1d8021e4 100644 --- a/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java @@ -30,6 +30,8 @@ import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.mxchange.jcoreee.events.helper.clear.HelperCleanupEvent; +import org.mxchange.jcoreee.events.helper.clear.ObservableHelperCleanupEvent; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.helper.JobsWebRequestHelperController; @@ -62,6 +64,13 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple @Inject private JobsWebRequestHelperController beanHelper; + /** + * Event being fired when a bean helper should be cleaned + */ + @Inject + @Any + private Event cleanHelperEvent; + /** * Confirmation key */ @@ -172,7 +181,7 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple // Is the user instance null? if ((null == user) || (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED)) { // Then clear this bean and the helper - this.beanHelper.setUser(null); + this.cleanHelperEvent.fire(new HelperCleanupEvent()); } else { // Try to confirm it this.confirmUserAccount(user); diff --git a/web/admin/fax/admin_fax_show.xhtml b/web/admin/fax/admin_fax_show.xhtml index 9b28b3fa..376c04b9 100644 --- a/web/admin/fax/admin_fax_show.xhtml +++ b/web/admin/fax/admin_fax_show.xhtml @@ -25,7 +25,7 @@ - + diff --git a/web/admin/landline/admin_landline_show.xhtml b/web/admin/landline/admin_landline_show.xhtml index dd860e22..ee7fe755 100644 --- a/web/admin/landline/admin_landline_show.xhtml +++ b/web/admin/landline/admin_landline_show.xhtml @@ -25,7 +25,7 @@ - + diff --git a/web/admin/mobile/admin_mobile_show.xhtml b/web/admin/mobile/admin_mobile_show.xhtml index fa622389..f4119d9d 100644 --- a/web/admin/mobile/admin_mobile_show.xhtml +++ b/web/admin/mobile/admin_mobile_show.xhtml @@ -25,7 +25,7 @@ - + -- 2.39.5