]> git.mxchange.org Git - jjobs-war.git/commitdiff
Continued with contact-cellphone unlink: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Mon, 15 Aug 2016 12:56:56 +0000 (14:56 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 19 Aug 2016 21:19:59 +0000 (23:19 +0200)
- implemented afterAdminUnlinkedCellphoneContactDataEvent() which observes events being fired after cellphone has been unlinked from contact
- also checked if contact and cellphone are really linked
- renamed message key to ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET as this reflects what is there
- added missing i18n message

Signed-off-by: Roland Häder <roland@mxchange.org>
13 files changed:
src/java/de/chotime/landingpage/beans/phone/JobsPhoneWebApplicationBean.java [deleted file]
src/java/de/chotime/landingpage/beans/phone/JobsPhoneWebApplicationController.java [deleted file]
src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java
src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java [new file with mode: 0644]
src/java/org/mxchange/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
web/WEB-INF/templates/admin/cellphone/admin_cellphone_data.tpl
web/WEB-INF/templates/admin/cellphone/admin_cellphone_links.tpl
web/WEB-INF/templates/admin/cellphone/admin_form_cellphone_data.tpl
web/admin/cellphone/admin_cellphone_delete.xhtml
web/admin/cellphone/admin_cellphone_edit.xhtml
web/admin/cellphone/admin_contact_cellphone_unlink.xhtml

diff --git a/src/java/de/chotime/landingpage/beans/phone/JobsPhoneWebApplicationBean.java b/src/java/de/chotime/landingpage/beans/phone/JobsPhoneWebApplicationBean.java
deleted file mode 100644 (file)
index 148f855..0000000
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * 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
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package de.chotime.landingpage.beans.phone;
-
-import java.text.MessageFormat;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
-import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-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.jjobs.beans.BaseJobsController;
-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.phone.PhoneSessionBeanRemote;
-import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
-
-/**
- * Regular controller (bean) for phone numbers
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Named ("phoneController")
-@ApplicationScoped
-public class JobsPhoneWebApplicationBean extends BaseJobsController implements JobsPhoneWebApplicationController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 491_058_674_675_690_105L;
-
-       /**
-        * All cell phone numbers
-        */
-       private final List<DialableCellphoneNumber> cellphoneNumbers;
-
-       /**
-        * All fax numbers
-        */
-       private final List<DialableFaxNumber> faxNumbers;
-
-       /**
-        * All land-line numbers
-        */
-       private final List<DialableLandLineNumber> landLineNumbers;
-
-       /**
-        * General EJB for phone numbers
-        */
-       private PhoneSessionBeanRemote phoneBean;
-
-       /**
-        * Default constructor
-        */
-       public JobsPhoneWebApplicationBean () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw it again
-                       throw new FaceletException(e);
-               }
-
-               // Init all lists
-               this.cellphoneNumbers = new LinkedList<>();
-               this.faxNumbers = new LinkedList<>();
-               this.landLineNumbers = new LinkedList<>();
-       }
-
-       @Override
-       public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
-               // The event must be valid
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getAddedContact() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("event.addedContact is null"); //NOI18N
-               } else if (event.getAddedContact().getContactId() == null) {
-                       // ... and again
-                       throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
-               } else if (event.getAddedContact().getContactId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
-               }
-
-               // Update contact's cellphone, land-line and fax number
-               this.updateContactPhoneNumbers(event.getAddedContact());
-
-               // Clear this bean
-               this.clear();
-       }
-
-       @Override
-       public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getAddedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.addedUser is null"); //NOI18N
-               } else if (event.getAddedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
-               } else if (event.getAddedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
-               }
-
-               // Update contact's cellphone, land-line and fax number
-               this.updateContactPhoneNumbers(event.getAddedUser().getUserContact());
-
-               // Clear all data
-               this.clear();
-       }
-
-       @Override
-       public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUpdatedContact() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.updatedContact is null"); //NOI18N
-               } else if (event.getUpdatedContact().getContactId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
-               } else if (event.getUpdatedContact().getContactId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
-               }
-
-               // Update contact's cellphone, land-line and fax number
-               this.updateContactPhoneNumbers(event.getUpdatedContact());
-
-               // Clear all data
-               this.clear();
-       }
-
-       @Override
-       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
-       public List<DialableCellphoneNumber> allCellphoneNumbers () {
-               return this.cellphoneNumbers;
-       }
-
-       @Override
-       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
-       public List<DialableFaxNumber> allFaxNumbers () {
-               return this.faxNumbers;
-       }
-
-       @Override
-       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
-       public List<DialableLandLineNumber> allLandLineNumbers () {
-               return this.landLineNumbers;
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // All phone numbers
-               this.cellphoneNumbers.addAll(this.phoneBean.allCellphoneNumbers());
-               this.faxNumbers.addAll(this.phoneBean.allFaxNumbers());
-               this.landLineNumbers.addAll(this.phoneBean.allLandLineNumbers());
-       }
-
-       /**
-        * Clears this bean
-        */
-       private void clear () {
-               // Clear all data
-       }
-
-       /**
-        * Uniquely add given cellphone number to this bean's list. First remove the
-        * old instance (by id number), then re-add it again.
-        * <p>
-        * @param cellphoneNumber Cellphone number to add
-        */
-       private void uniqueAddCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
-               // Make sure the parameter is valid
-               if (null == cellphoneNumber) {
-                       // Throw NPE
-                       throw new NullPointerException("cellphoneNumber is null");
-               } else if (cellphoneNumber.getPhoneId() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("cellphoneNumber.phoneId is null");
-               } else if (cellphoneNumber.getPhoneId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid.", cellphoneNumber.getPhoneId()));
-               }
-
-               // First remove it by object
-               if (!this.cellphoneNumbers.remove(cellphoneNumber)) {
-                       // Did not work, try by id number
-                       for (final DialableCellphoneNumber cell : this.cellphoneNumbers) {
-                               // Is id number the same?
-                               if (Objects.equals(cell.getPhoneId(), cellphoneNumber.getPhoneId())) {
-                                       // Found it
-                                       this.cellphoneNumbers.remove(cell);
-                                       break;
-                               }
-                       }
-               }
-
-               // ... then add it
-               this.cellphoneNumbers.add(cellphoneNumber);
-       }
-
-       /**
-        * Uniquely add given fax number to this bean's list. First remove the old
-        * instance (by id number), then re-add it again.
-        * <p>
-        * @param faxNumber number to add
-        */
-       private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
-               // Make sure the parameter is valid
-               if (null == faxNumber) {
-                       // Throw NPE
-                       throw new NullPointerException("faxNumber is null");
-               } else if (faxNumber.getPhoneId() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("faxNumber.phoneId is null");
-               } else if (faxNumber.getPhoneId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId()));
-               }
-
-               // First remove it
-               if (!this.faxNumbers.remove(faxNumber)) {
-                       // Did not work, try by id number
-                       for (final DialableFaxNumber fax : this.faxNumbers) {
-                               // Is id number the same?
-                               if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) {
-                                       // Found it
-                                       this.faxNumbers.remove(fax);
-                                       break;
-                               }
-                       }
-               }
-
-               // ... then add it
-               this.faxNumbers.add(faxNumber);
-       }
-
-       /**
-        * Uniquely add given land-line number to this bean's list. First remove the
-        * old instance (by id number), then re-add it again.
-        * <p>
-        * @param landLineNumber Land-line number to add
-        */
-       private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
-               // Make sure the parameter is valid
-               if (null == landLineNumber) {
-                       // Throw NPE
-                       throw new NullPointerException("landLineNumber is null");
-               } else if (landLineNumber.getPhoneId() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("landLineNumber.phoneId is null");
-               } else if (landLineNumber.getPhoneId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId()));
-               }
-
-               // First remove it
-               if (!this.landLineNumbers.remove(landLineNumber)) {
-                       // Did not work, try by id number
-                       for (final DialableLandLineNumber landLine : this.landLineNumbers) {
-                               // Is id number the same?
-                               if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) {
-                                       // Found it
-                                       this.landLineNumbers.remove(landLine);
-                                       break;
-                               }
-                       }
-               }
-
-               // ... then add it
-               this.landLineNumbers.add(landLineNumber);
-       }
-
-       /**
-        * Updates given contact's cellphone, land-line and fax number
-        * <p>
-        * @param contact Contact instance
-        */
-       private void updateContactPhoneNumbers (final Contact contact) {
-               // Parameter must be valid
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null");
-               } else if (contact.getContactId() == null) {
-                       // Throw again
-                       throw new NullPointerException("contact.contactId is null");
-               } else if (contact.getContactId() < 1) {
-                       // Id number is not valid
-               }
-
-               // Is cellphone set?
-               if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
-                       // Unique-add it
-                       this.uniqueAddCellphoneNumber(contact.getContactCellphoneNumber());
-               }
-
-               // Is land-line set?
-               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
-                       // Unique-add it
-                       this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
-               }
-
-               // Is fax set?
-               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
-                       // Unique-add it
-                       this.uniqueAddFaxNumber(contact.getContactFaxNumber());
-               }
-       }
-
-}
diff --git a/src/java/de/chotime/landingpage/beans/phone/JobsPhoneWebApplicationController.java b/src/java/de/chotime/landingpage/beans/phone/JobsPhoneWebApplicationController.java
deleted file mode 100644 (file)
index c99b942..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package de.chotime.landingpage.beans.phone;
-
-import java.io.Serializable;
-import java.util.List;
-import javax.ejb.Local;
-import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
-
-/**
- * An interface for a request web controller (bean) for administrative phone
- * number purposes.
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Local
-public interface JobsPhoneWebApplicationController extends Serializable {
-
-       /**
-        * Event observer for newly added users by administrator
-        * <p>
-        * @param event Event being fired
-        */
-       void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
-
-       /**
-        * Observes events being fired when an administrator has added a new
-        * contact.
-        * <p>
-        * @param event Event being fired
-        */
-       void afterAdminAddedContact (final AdminAddedContactEvent event);
-
-       /**
-        * Event observer for updated contact data by administrators
-        * <p>
-        * @param event Updated contact data event
-        */
-       void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event);
-
-       /**
-        * Returns a list of all cellphone numbers. For performance reasons, the
-        * controller (bean) should be application-scoped as from user to user
-        * nothing changes. And the controller's post-construct method should load
-        * all numbers and cache it in the controller.
-        * <p>
-        * @return List of all cell phone numbers
-        */
-       List<DialableCellphoneNumber> allCellphoneNumbers ();
-
-       /**
-        * Returns a list of all fax numbers. For performance reasons, the
-        * controller (bean) should be application-scoped as from user to user
-        * nothing changes. And the controller's post-construct method should load
-        * all numbers and cache it in the controller.
-        * <p>
-        * @return List of all fax numbers
-        */
-       List<DialableFaxNumber> allFaxNumbers ();
-
-       /**
-        * Returns a list of all land-line numbers. For performance reasons, the
-        * controller (bean) should be application-scoped as from user to user
-        * nothing changes. And the controller's post-construct method should load
-        * all numbers and cache it in the controller.
-        * <p>
-        * @return List of all land-line numbers
-        */
-       List<DialableLandLineNumber> allLandLineNumbers ();
-
-}
index baae0ac94991f5e107f44463d1570bf7a6ed21ab..2c25bb32bed84ed00a54a96e00ef41bcf638cf63 100644 (file)
@@ -17,9 +17,7 @@
 package org.mxchange.jjobs.beans.contact.phone;
 
 import java.io.Serializable;
-import java.util.List;
 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.jusercore.events.user.add.AdminAddedUserEvent;
@@ -33,11 +31,11 @@ import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 public interface JobsAdminContactPhoneWebRequestController extends Serializable {
 
        /**
-        * Getter for all contacts having current cellphone instance linked
+        * Unlinks cellphone data with current contact
         * <p>
-        * @return List of all linked contacts
+        * @return Redirect outcome
         */
-       List<Contact> allCellphoneContacts ();
+       String unlinkCellphoneContactData ();
 
        /**
         * Event observer for newly added users by adminstrator
diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java
new file mode 100644 (file)
index 0000000..970c1fd
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2016 Cho-Time GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.contact.phone;
+
+import de.chotime.landingpage.beans.BaseLandingController;
+import de.chotime.landingpage.beans.contact.LandingContactWebSessionController;
+import de.chotime.landingpage.beans.helper.LandingWebRequestController;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.events.cellphone.unlinked.AdminUnlinkedCellphoneNumberEvent;
+import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jphone.phonenumbers.DialableNumber;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+
+/**
+ * An administrative contact phone controller (bean)
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@Named ("contactPhoneController")
+@SessionScoped
+public class JobsContactPhoneWebSessionBean extends BaseLandingController implements JobsContactPhoneWebSessionController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 542_145_347_916L;
+
+       /**
+        * Admin helper instance
+        */
+       @Inject
+       private LandingWebRequestController beanHelper;
+
+       /**
+        * General contact controller
+        */
+       @Inject
+       private LandingContactWebSessionController contactController;
+
+       /**
+        * "Cache" for contact's cellphone, land-line and fax numbers. Currently one
+        * one per each type is supported. Maybe later this will change into a
+        * OneToMany relationship (one contact, many numbers).
+        */
+       private final Map<DialableNumber, List<Contact>> contacts;
+
+       /**
+        * Default constructor
+        */
+       public JobsContactPhoneWebSessionBean () {
+               // Init lists/maps
+               this.contacts = new HashMap<>(10);
+       }
+
+       @Override
+       public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
+               // The event must be valid
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getAddedContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.addedContact is null"); //NOI18N
+               } else if (event.getAddedContact().getContactId() == null) {
+                       // ... and again
+                       throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
+               } else if (event.getAddedContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
+               }
+
+               // Clear this bean
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getAddedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.addedUser is null"); //NOI18N
+               } else if (event.getAddedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
+               } else if (event.getAddedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
+               }
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminUnlinkedCellphoneContactDataEvent (@Observes final AdminUnlinkedCellphoneNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlinkedCellphoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlinkedCellphoneNumber is null"); //NOI18N
+               } else if (event.getUnlinkedCellphoneNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlinkedCellphoneNumber.contactId is null"); //NOI18N
+               } else if (event.getUnlinkedCellphoneNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedCellphoneNumber(), event.getUnlinkedCellphoneNumber().getPhoneId())); //NOI18N
+               }
+
+               // Remove it from list
+               this.contacts.remove(event.getUnlinkedCellphoneNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedContact is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+               }
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public List<Contact> allCellphoneContacts () {
+               // Get id
+               DialableCellphoneNumber phone = this.beanHelper.getCellPhoneNumber();
+
+               // Is cache there?
+               if (this.contacts.containsKey(phone)) {
+                       // Return cached version
+                       return this.contacts.get(phone);
+               } else {
+                       // Ask bean
+                       List<Contact> list = new LinkedList<>();
+
+                       // "Walk" through all contacts
+                       for (final Contact contact : this.contactController.allContacts()) {
+                               // Is cellphone instance the same?
+                               if (Objects.equals(contact.getContactCellphoneNumber(), this.beanHelper.getCellPhoneNumber())) {
+                                       // Found one
+                                       list.add(contact);
+                               }
+                       }
+
+                       // Store result in cache
+                       this.contacts.put(phone, list);
+
+                       // Return now-cached list
+                       return list;
+               }
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all data
+       }
+
+}
diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionController.java
new file mode 100644 (file)
index 0000000..4273bf9
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2016 Cho-Time GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.contact.phone;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.ejb.Local;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.events.cellphone.unlinked.AdminUnlinkedCellphoneNumberEvent;
+import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@Local
+public interface JobsContactPhoneWebSessionController extends Serializable {
+
+       /**
+        * Getter for all contacts having current cellphone instance linked
+        * <p>
+        * @return List of all linked contacts
+        */
+       List<Contact> allCellphoneContacts ();
+
+       /**
+        * Event observer for newly added users by adminstrator
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
+
+       /**
+        * Observes events being fired when an administrator has added a new
+        * contact.
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminAddedContact (final AdminAddedContactEvent event);
+
+       /**
+        * Event observer for updated contact data by administrators
+        * <p>
+        * @param event Updated contact data event
+        */
+       void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event);
+
+       /**
+        * Event observer for unlinked cellphone-contact by administrators
+        * <p>
+        * @param event Unlinked cellphone-contact event
+        */
+       void afterAdminUnlinkedCellphoneContactDataEvent (final AdminUnlinkedCellphoneNumberEvent event);
+
+}
index c2b503af1606a1258eaad512a0a56eb93d396b21..a6e175c15b8b6b2555b461c47ee35824e461a929 100644 (file)
@@ -597,7 +597,7 @@ PAGE_TITLE_ADMIN_LOCK_USER=Benutzeraccount sperren
 CONTENT_TITLE_ADMIN_LOCK_USER=Benutzeraccount sperren:
 ERROR_BEAN_HELPER_USER_NOT_SET=Fehler: Instanz 'user' im Bean-Helper nicht gesetzt.
 ERROR_BEAN_HELPER_CONTACT_NOT_SET=Fehler: Instanz 'contact' im Bean-Helper nicht gesetzt.
-ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET=Fehler: Instanz 'cellPhone' in administrativer Bean nicht gesetzt.
+ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET=Fehler: Instanz 'cellPhone' in Bean-Helper nicht gesetzt.
 CONTENT_TITLE_ADMIN_LIST_CONTACT_CELLPHONE=Mobiltelefonnummern auflisten:
 ADMIN_LIST_CELLPHONE_EMPTY=Es sind keine Mobilfunknummern gespeichert.
 ADMIN_MENU_PHONE_NUMBERS_TITLE=Telefonnummern:
@@ -640,3 +640,4 @@ ERROR_USER_PASSWORD_MISMATCH=Ihr eingegebenes Passwort ist falsch.
 ERROR_USER_NAME_ALREADY_USED=Benutzername bereits verwendet. Bitte geben Sie einen anderen ein.
 ERROR_EMAIL_ADDRESSES_MISMATCHING=Die eingegebenen  Email-Addressen stimmen nicht \u00fcberein.
 ERROR_EMAIL_ADDRESS_ALREADY_USED=Die eingegebene Email-Adresse wird bereits verwendet und kann nicht erneut verwendet werden.
+ERROR_CELLPHONE_CONTACT_NOT_LINKED=Fehler: Mobilfunk-Id {0} ist nicht mit Kontakt-Id {1} verkn\u00fcpft.
index 4fdb2a2dd57232a74c8358367117fa3a68ef56ec..87c9a3e4a2b3c681aa1f904709bd740a671b254f 100644 (file)
@@ -597,7 +597,7 @@ PAGE_TITLE_ADMIN_LOCK_USER=Lock user account
 CONTENT_TITLE_ADMIN_LOCK_USER=Lock user account:
 ERROR_BEAN_HELPER_USER_NOT_SET=Error: Instance 'user' not set in bean helper.
 ERROR_BEAN_HELPER_CONTACT_NOT_SET=Error: Instance 'contact' not set in bean helper.
-ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET=Error: Instance 'cellPhone' in administrative bean not set.
+ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET=Error: Instance 'cellPhone' in bean helper not set.
 CONTENT_TITLE_ADMIN_LIST_CONTACT_CELLPHONE=List mobile phone numbers:
 ADMIN_LIST_CELLPHONE_EMPTY=No cell phone numbers are saved.
 ADMIN_MENU_PHONE_NUMBERS_TITLE=Phone numbers:
@@ -639,4 +639,5 @@ ERROR_USER_STATUS_UNCONFIRMED=You have not yet confirmed your user account.
 ERROR_USER_PASSWORD_MISMATCH=You have entered a wrong password.
 ERROR_USER_NAME_ALREADY_USED=User name already used. Please enter another name.
 ERROR_EMAIL_ADDRESSES_MISMATCHING=Both entered email addresses are not the same.
-ERROR_EMAIL_ADDRESS_ALREADY_USED=YOur entered email address is already used. Please enter another and try again.
+ERROR_EMAIL_ADDRESS_ALREADY_USED=Your entered email address is already used. Please enter another and try again.
+ERROR_CELLPHONE_CONTACT_NOT_LINKED=Error: Cell phone id {0} is not linked with contact id {1}.
index aa73fdb36be4864d0f27d3d96ef45fefb929d837..73bcaeb1269e8c57dbb2eab40adf07e4560c6126 100644 (file)
@@ -5,7 +5,7 @@
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
 
-       <h:outputText styleClass="errors" value="#{msg.ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
+       <h:outputText styleClass="errors" value="#{msg.ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
 
        <h:panelGrid id="cellphone_data" summary="#{msg.ADMIN_TABLE_SUMMARY_SHOW_CELLPHONE_DATA}" headerClass="table_header_column" styleClass="table_big" columns="2" rendered="#{not empty beanHelper.cellPhoneNumber}">
                <f:facet name="header">
index 071b7fe6488e7132103b0ff20775062621e13557..925188ce677f07ff8020ebcfe83e65c6db1ab995 100644 (file)
@@ -5,7 +5,7 @@
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
 
-       <h:outputText styleClass="errors" value="#{msg.ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
+       <h:outputText styleClass="errors" value="#{msg.ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
 
        <ui:fragment rendered="#{not empty beanHelper.cellPhoneNumber}">
                <ul class="mini_nav">
index 0440290508924c0f2cd7bfbb64c8c4f919ee4d5d..1fa52a28307f366e21120000d5431243635eda12 100644 (file)
@@ -5,7 +5,7 @@
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
 
-       <h:outputText styleClass="errors" value="#{msg.ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
+       <h:outputText styleClass="errors" value="#{msg.ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
 
        <div class="para">
                <fieldset class="fieldset" id="phone_data">
index 440c8bd1aa41625b10fb33bb5f2ab33a391f9b7e..38166fb148a5edcac11a33aa90dfe1d45c39ba8a 100644 (file)
@@ -42,7 +42,7 @@
                                </div>
                        </h:form>
 
-                       <h:outputText styleClass="errors" value="#{msg.ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
+                       <h:outputText styleClass="errors" value="#{msg.ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
                </ui:define>
        </ui:composition>
 </html>
index 2474727c31abc2ddf0cb0b8fd8e32f76f4c3f2bc..192a2914af93567d2483be14599240c0412f32f8 100644 (file)
@@ -35,7 +35,7 @@
                                </div>
                        </h:form>
 
-                       <h:outputText styleClass="errors" value="#{msg.ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
+                       <h:outputText styleClass="errors" value="#{msg.ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
                </ui:define>
        </ui:composition>
 </html>
index 4d6a5012a60a7271d4920c011c3641f2a30e0c82..f39b1e2b5810107825a7ecc426e29bf699604da7 100644 (file)
@@ -20,7 +20,7 @@
                </ui:define>
 
                <ui:define name="content">
-                       <h:form id="form_unlink_contact_cellphone" rendered="#{not empty beanHelper.cellPhoneNumber and not empty beanHelper.contact}">
+                       <h:form id="form_unlink_contact_cellphone" rendered="#{not empty beanHelper.cellPhoneNumber and not empty beanHelper.contact and beanHelper.contact.contactCellphoneNumber == beanHelper.cellPhoneNumber}">
                                <div class="table">
                                        <div class="table_header">
                                                <h:outputText value="#{msg.ADMIN_UNLINK_CONTACT_CELLPHONE_TITLE}" />
                                </div>
                        </h:form>
 
-                       <h:outputText styleClass="errors" value="#{msg.ERROR_ADMIN_BEAN_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
+                       <h:outputText styleClass="errors" value="#{msg.ERROR_BEAN_HELPER_CELLPHONE_NUMBER_NOT_SET}" rendered="#{empty beanHelper.cellPhoneNumber}" />
 
                        <h:outputText styleClass="errors" value="#{msg.ERROR_BEAN_HELPER_CONTACT_NOT_SET}" rendered="#{empty beanHelper.contact}" />
+
+                       <h:outputFormat styleClass="errors" value="#{msg.ERROR_CELLPHONE_CONTACT_NOT_LINKED}" rendered="#{not empty beanHelper.cellPhoneNumber and not empty beanHelper.contact and beanHelper.contact.contactCellphoneNumber != beanHelper.cellPhoneNumber}">
+                               <f:param value="#{beanHelper.cellPhoneNumber.phoneId}" />
+                               <f:param value="#{beanHelper.contact.contactId}" />
+                       </h:outputFormat>
                </ui:define>
        </ui:composition>
 </html>