]> git.mxchange.org Git - jjobs-war.git/commitdiff
Continued a bit: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Wed, 17 Aug 2016 13:50:59 +0000 (15:50 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 21 Aug 2016 18:44:23 +0000 (20:44 +0200)
- implemented unlinkFaxContactData(), unlinkLandLineContactData()
- added observer methods for fired events
- renamed cellphone -> mobile

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java
src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java
src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java
src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java

index 77c204204bde1463cbcf24e1802404a34b396074..fcbed56e5612de81f20e30e56b7ee9d57ce18b4c 100644 (file)
@@ -30,11 +30,17 @@ import javax.naming.NamingException;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminFaxNumberUnlinkedEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminLandLineNumberUnlinkedEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
 import org.mxchange.jcontacts.events.mobile.unlinked.AdminMobileNumberUnlinkedEvent;
 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
 import org.mxchange.jjobs.beans.BaseJobsController;
 import org.mxchange.jjobs.beans.helper.JobsWebRequestController;
+import org.mxchange.jphone.exceptions.FaxNumberNotLinkedException;
+import org.mxchange.jphone.exceptions.LandLineNumberNotLinkedException;
 import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 
@@ -63,12 +69,26 @@ public class JobsAdminContactPhoneWebRequestBean extends BaseJobsController impl
        @Inject
        private JobsWebRequestController beanHelper;
 
+       /**
+        * Event being fired when a fax number has been unlinked
+        */
+       @Inject
+       @Any
+       private Event<AdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
+
+       /**
+        * Event being fired when a land-line number has been unlinked
+        */
+       @Inject
+       @Any
+       private Event<AdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
+
        /**
         * Event being fired when admin unlinks mobile from contact
         */
        @Inject
        @Any
-       private Event<AdminUnlinkedMobileNumberEvent> mobileDataUnlinkedEvent;
+       private Event<AdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
 
        /**
         * Default constructor
@@ -150,6 +170,102 @@ public class JobsAdminContactPhoneWebRequestBean extends BaseJobsController impl
                this.clear();
        }
 
+       @Override
+       public String unlinkFaxContactData () {
+               // Is all data set
+               if (this.beanHelper.getFaxNumber() == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
+                       // Throw it again ...
+                       throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
+               } else if (this.beanHelper.getContact() == null) {
+                       // ... and throw again
+                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+               }
+
+               // Init contact instance
+               Contact updatedContact;
+
+               try {
+                       // Unlink it and return contact without fax instance
+                       updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
+               } catch (final FaxNumberNotLinkedException ex) {
+                       // Did not work
+                       this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.faxNumberUnlinkedEvent.fire(new AdminFaxNumberUnlinkedEvent(updatedContact, this.beanHelper.getFaxNumber()));
+
+               // All fine here
+               return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N
+       }
+
+       @Override
+       public String unlinkLandLineContactData () {
+               // Is all data set
+               if (this.beanHelper.getLandLineNumber() == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
+                       // Throw it again ...
+                       throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
+               } else if (this.beanHelper.getContact() == null) {
+                       // ... and throw again
+                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+               }
+
+               // Init contact instance
+               Contact updatedContact;
+
+               try {
+                       // Unlink it and return contact without landLine instance
+                       updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
+               } catch (final LandLineNumberNotLinkedException ex) {
+                       // Did not work
+                       this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.landLineNumberUnlinkedEvent.fire(new AdminLandLineNumberUnlinkedEvent(updatedContact, this.beanHelper.getLandLineNumber()));
+
+               // All fine here
+               return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N
+       }
+
        @Override
        public String unlinkMobileContactData () {
                // Is all data set
@@ -201,7 +317,7 @@ public class JobsAdminContactPhoneWebRequestBean extends BaseJobsController impl
                }
 
                // Fire event
-               this.mobileDataUnlinkedEvent.fire(new AdminMobileNumberUnlinkedEvent(updatedContact, this.beanHelper.getMobileNumber()));
+               this.mobileNumberUnlinkedEvent.fire(new AdminMobileNumberUnlinkedEvent(updatedContact, this.beanHelper.getMobileNumber()));
 
                // All fine here
                return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N
index 2328c19cbf1313256e30bafec8646be3d854cc7d..e72aad95f11401a88119b3a0825a3087ee2d5e14 100644 (file)
@@ -31,6 +31,20 @@ import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 @Local
 public interface JobsAdminContactPhoneWebRequestController extends Serializable {
 
+       /**
+        * Unlinks fax data with current contact
+        * <p>
+        * @return Redirect outcome
+        */
+       String unlinkFaxContactData ();
+
+       /**
+        * Unlinks land-line data with current contact
+        * <p>
+        * @return Redirect outcome
+        */
+       String unlinkLandLineContactData ();
+
        /**
         * Unlinks mobile data with current contact
         * <p>
index 6065ddccf7d41c4614c5ab50c326d57733b0efac..f8f554cf70cb85a2467f01cddfdc6513d0168c5c 100644 (file)
@@ -32,6 +32,8 @@ import javax.inject.Named;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
 import org.mxchange.jphone.phonenumbers.DialableNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
@@ -123,24 +125,72 @@ public class JobsContactPhoneWebSessionBean extends BaseLandingController implem
        }
 
        @Override
-       public void afterAdminUnlinkedCellphoneContactDataEvent (@Observes final AdminUnlinkedMobileNumberEvent event) {
+       public void afterAdminUnlinkedFaxContactDataEvent (@Observes final AdminUnlinkedFaxNumberEvent event) {
                // event should not be null
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUnlinkedCellphoneNumber() == null) {
+               } else if (event.getUnlinkedFaxNumber() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("event.unlinkedCellphoneNumber is null"); //NOI18N
-               } else if (event.getUnlinkedCellphoneNumber().getPhoneId() == null) {
+                       throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
+               } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
                        // userId is null
-                       throw new NullPointerException("event.unlinkedCellphoneNumber.contactId is null"); //NOI18N
-               } else if (event.getUnlinkedCellphoneNumber().getPhoneId() < 1) {
+                       throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
+               } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
                        // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedCellphoneNumber(), event.getUnlinkedCellphoneNumber().getPhoneId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
                }
 
                // Remove it from list
-               this.contacts.remove(event.getUnlinkedCellphoneNumber());
+               this.contacts.remove(event.getUnlinkedFaxNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final AdminUnlinkedLandLineNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlinkedLandLineNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
+               } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
+               } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
+               }
+
+               // Remove it from list
+               this.contacts.remove(event.getUnlinkedLandLineNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminUnlinkedMobileContactDataEvent (@Observes final AdminUnlinkedMobileNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlinkedMobileNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
+               } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
+               } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
+               }
+
+               // Remove it from list
+               this.contacts.remove(event.getUnlinkedMobileNumber());
 
                // Clear all data
                this.clear();
index 9fb14699b353a33c41b7e16ad179696d0bfc21e7..7c2451830762d3e508fbf840df08d4ef2b92eb7c 100644 (file)
@@ -22,6 +22,8 @@ import javax.ejb.Local;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 
@@ -77,10 +79,24 @@ public interface JobsContactPhoneWebSessionController extends Serializable {
        void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event);
 
        /**
-        * Event observer for unlinked mobile-contact by administrators
+        * Event observer for unlinked fax contact by administrators
         * <p>
-        * @param event Unlinked mobile-contact event
+        * @param event Unlinked fax contact event
         */
-       void afterAdminUnlinkedCellphoneContactDataEvent (final AdminUnlinkedMobileNumberEvent event);
+       void afterAdminUnlinkedFaxContactDataEvent (final AdminUnlinkedFaxNumberEvent event);
+
+       /**
+        * Event observer for unlinked land-line contact by administrators
+        * <p>
+        * @param event Unlinked land-line contact event
+        */
+       void afterAdminUnlinkedLandLineContactDataEvent (final AdminUnlinkedLandLineNumberEvent event);
+
+       /**
+        * Event observer for unlinked mobile contact by administrators
+        * <p>
+        * @param event Unlinked mobile contact event
+        */
+       void afterAdminUnlinkedMobileContactDataEvent (final AdminUnlinkedMobileNumberEvent event);
 
 }