--- /dev/null
+/*
+ * 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());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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 ();
+
+}
+++ /dev/null
-/*
- * 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 de.chotime.landingpage.beans.phone;
-
-import de.chotime.landingpage.beans.BaseLandingController;
-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.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<rhaeder@cho-time.de>
- */
-@Named ("phoneController")
-@ApplicationScoped
-public class LandingPhoneWebApplicationBean extends BaseLandingController implements LandingPhoneWebApplicationController {
-
- /**
- * 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 LandingPhoneWebApplicationBean () {
- // 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());
- }
- }
-
-}
+++ /dev/null
-/*
- * 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 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<rhaeder@cho-time.de>
- */
-@Local
-public interface LandingPhoneWebApplicationController extends Serializable {
-
- /**
- * 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);
-
- /**
- * 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 ();
-
-}
import java.io.Serializable;
import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
}
/**
- * Shows a faces message with given message.
+ * Shows a faces message with given message (i18n) key.
* <p>
* @param clientId Client id to send message to
- * @param message Causing exception
+ * @param i18nKey Message key
*/
- protected void showFacesMessage (final String clientId, final String message) {
+ protected void showFacesMessage (final String clientId, final String i18nKey) {
+ // Get faces context
+ FacesContext context = FacesContext.getCurrentInstance();
+
+ // Get bundle name
+ String messageBundleName = context.getApplication().getMessageBundle();
+
+ // Get locale
+ Locale locale = context.getViewRoot().getLocale();
+
+ // Init bundle variable
+ ResourceBundle bundle;
+
+ try {
+ // Get bundle
+ bundle = ResourceBundle.getBundle(messageBundleName, locale);
+ } catch (final MissingResourceException ex) {
+ // Call other method
+ this.showFacesMessage(clientId, ex);
+ return;
+ }
+
+ // Get message
+ String message = bundle.getString(i18nKey);
+
// Get context and add message
- FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
+ context.addMessage(clientId, new FacesMessage(message));
}
}
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
import org.mxchange.jusercore.model.user.User;
/**
throw new FaceletException("Not all required fields are set."); //NOI18N
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+ this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
return ""; //NOI18N
}
import org.mxchange.jjobs.beans.BaseJobsController;
import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
import org.mxchange.jusercore.model.email_address.EmailAddressChange;
import org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote;
throw new FaceletException("Email address 1/2 are mismatching."); //NOI18N
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- this.showFacesMessage("form_login_change_email_address:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+ this.showFacesMessage("form_login_change_email_address:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
return ""; //NOI18N
} else if (!this.featureController.isFeatureEnabled("edit_user_data")) { //NOI18N
// Editing is not allowed
// All fine
return "login"; //NOI18N
- } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) {
+ } catch (final UserNotFoundException ex) {
// Show JSF message
- this.showFacesMessage("form_user_login:userName", ex); //NOI18N
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
+ return ""; //NOI18N
+ } catch (final UserStatusLockedException ex) {
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+ return ""; //NOI18N
+ } catch (final UserStatusUnconfirmedException ex) {
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
return ""; //NOI18N
} catch (final UserPasswordMismatchException ex) {
// Show JSF message
- this.showFacesMessage("form_user_login:userPassword", ex); //NOI18N
+ this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
return ""; //NOI18N
}
}
// Is the provider already created?
if (this.isMobileProviderCreated(mobileProvider)) {
// Then throw exception
- this.showFacesMessage("form_add_mobile_provider:providerDialPrefix", new MobileProviderAlreadyAddedException(mobileProvider)); //NOI18N
+ this.showFacesMessage("form_add_mobile_provider:providerDialPrefix", "ERROR_ADMIN_MOBILE_PROVIDER_ALREADY_ADDED"); //NOI18N
return ""; //NOI18N
}
throw new NullPointerException(MessageFormat.format("this.beanHelper.cellphoneNumber.phoneNumber={0} is not valid.", this.beanHelper.getCellPhoneNumber().getPhoneNumber())); //NOI18N
} else if (this.getCellphoneProvider() == null) {
// Not provided
- this.showFacesMessage("form_edit_cellphone:cellphoneProvider", "No mobile provider selected"); //NOI18N
+ this.showFacesMessage("form_edit_cellphone:cellphoneProvider", "ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED"); //NOI18N
return ""; //NOI18N
} else if (this.getCellphoneProvider().getProviderId() == null) {
// Throw NPE again ...
throw new IllegalArgumentException(MessageFormat.format("this.cellphoneProvider.providerId={0} is not valid.", this.getCellphoneProvider().getProviderId())); //NOI18N
} else if (this.getPhoneNumber() == null) {
// Not provided
- this.showFacesMessage("form_edit_cellphone:cellphoneNumber", "No cell phone number selected"); //NOI18N
+ this.showFacesMessage("form_edit_cellphone:cellphoneNumber", "ERROR_ADMIN_EMPTY_MOBILE_NUMBER"); //NOI18N
return ""; //NOI18N
}
import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
-import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
this.clear();
// Then abort here
- this.showFacesMessage("form_resend_link:resendEmailAddress", new UserStatusConfirmedException(user)); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED"); //NOI18N
return ""; //NOI18N
} else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
// Always clear bean
this.clear();
// User account is locked
- this.showFacesMessage("form_resend_link:resendEmailAddress", new UserStatusLockedException(user)); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED"); //NOI18N
return ""; //NOI18N
} else if (user.getUserConfirmKey() == null) {
// Status is UNCONFIRMED but confirmation key is NULL
throw new IllegalStateException("User tried to change password."); //NOI18N
} else if (!UserUtils.ifPasswordMatches(this.getUserCurrentPassword(), this.userLoginController.getLoggedInUser())) {
// Password mismatches
- this.showFacesMessage("form_user_change_password:userCurrentPassword", "Entered current password does not matched stored password."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userCurrentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
// Clear bean
this.clear();
return ""; //NOI18N
} else if (!Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())) {
// Both entered passwords don't match
- this.showFacesMessage("form_user_change_password:userPasswordRepeat", "Entered new passwords mismatch."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userPasswordRepeat", "ERROR_USER_NEW_PASSWORDS_MISMATCH"); //NOI18N
// Clear bean
this.clear();
return ""; //NOI18N
} else if (Objects.equals(this.getUserCurrentPassword(), this.getUserPassword())) {
// New password matches current
- this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is same as current password."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userPassword", "ERROR_USER_NEW_PASSWORD_SAME_AS_CURRENT"); //NOI18N
// Clear bean
this.clear();
return ""; //NOI18N
} else if (this.userLoginController.isPasswordInHistory(this.getUserPassword())) {
// Is already in list (to old passwords are ignored)
- this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is has already been used some time ago."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userPassword", "ERROR_USER_NEW_PASSWORD_ALREADY_ENTERED"); //NOI18N
// Clear bean
this.clear();
LOGIN_ENTER_CURRENT_PASSWORD_CONFIRM=Derzeitiges Passwort:
BUTTON_CHANGE_PERSONAL_DATA=Pers\u00f6nliche Daten \u00e4ndern
LOGIN_CHANGE_PERSONAL_DATA_TITLE=Pers\u00f6nliche Daten \u00e4ndern:
-ERROR_CURRENT_PASSWORD_MISMATCHING=Ihr eingegebenes Passwort entspricht nicht dem aktuell gespeicherten Passwort.
+ERROR_USER_CURRENT_PASSWORD_MISMATCHING=Fehler: Ihr eingegebenes Passwort entspricht nicht dem aktuell gespeicherten Passwort.
MESSAGE_BOX_TITLE=Hinweis:
MESSAGE_BOX_PARAMETER_MESSAGE_EMPTY=Fehler: Parameter "message" nicht gesetzt.
LOGIN_MESSAGE_DATA_SAVED=Daten wurden gespeichert.
ADMIN_LOCK_USER_TITLE=Wollen Sie diesen Benutzer wirklich sperren?
ERROR_ADMIN_CANNOT_UNLOCK_USER_ACCOUNT_UNLOCKED=Kann den Benutzer {0} ({1}) nicht entsperren, da er bereits entsperrt ist.
ERROR_ADMIN_CANNOT_LOCK_USER_ACCOUNT_LOCKED=Kann den Benutzer {0} ({1}) nicht sperren, da er bereits gesperrt ist.
+ERROR_ADMIN_MOBILE_PROVIDER_ALREADY_ADDED=Fehler: Mobilfunkanbieter existiert bereits
+ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED=Fehler: Kein Mobilfunkanbieter ausgew\u00e4hlt.
+ERROR_ADMIN_EMPTY_MOBILE_NUMBER=Fehler: Keine Mobilfunknummer eingegeben.
+ERROR_USER_STATUS_ALREADY_CONFIRMED=Sie haben bereits Ihren Benutzeraccount best\u00e4tigt und k\u00f6nnen diesen ab sofort benutzen.
+ERROR_USER_STATUS_LOCKED=Ihr Benutzeraccount wurde gesperrt. Bitte melden Sie sich beim Webmaster.
+ERROR_USER_NEW_PASSWORDS_MISMATCH=Ihre eingebenen Passw\u00f6rter (Wiederholung) stimmen nicht \u00fcberein.
+ERROR_USER_NEW_PASSWORD_SAME_AS_CURRENT=Das eingegebene neue Passwort muss sich von Ihrem aktuellen Passwort unterscheiden.
+ERROR_USER_NEW_PASSWORD_ALREADY_ENTERED=Sie hatten vor kurzem das Passwort bereits eingegeben.
+ERROR_USER_NOT_FOUND=Benutzeraccount nicht gefunden.
+ERROR_USER_STATUS_UNCONFIRMED=Sie haben noch nicht Ihren Benutzeraccount best\u00e4tigt.
+ERROR_USER_PASSWORD_MISMATCH=Ihr eingegebenes Passwort ist falsch.
LOGIN_ENTER_CURRENT_PASSWORD_CONFIRM=Current password:
BUTTON_CHANGE_PERSONAL_DATA=Change personal data
LOGIN_CHANGE_PERSONAL_DATA_TITLE=Change personal data:
-ERROR_CURRENT_PASSWORD_MISMATCHING=Your entered password doesn't match the currently stored one.
+ERROR_USER_CURRENT_PASSWORD_MISMATCHING=Error: Your entered password doesn't match the currently stored one.
MESSAGE_BOX_TITLE=Notice:
MESSAGE_BOX_PARAMETER_MESSAGE_EMPTY=Error: Parameter "message" not set.
LOGIN_MESSAGE_DATA_SAVED=Data has been saved.
ADMIN_LOCK_USER_TITLE=Do You really want to lock this user?
ERROR_ADMIN_CANNOT_UNLOCK_USER_ACCOUNT_UNLOCKED=Cannot unlock user {0} ({1}) because he is already unlocked.
ERROR_ADMIN_CANNOT_LOCK_USER_ACCOUNT_LOCKED=Cannot lock user {0} ({1}) because he is already locked.
+ERROR_ADMIN_MOBILE_PROVIDER_ALREADY_ADDED=Error: Mobile provider does already exist.
+ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED=Error: No mobile provider selected.
+ERROR_ADMIN_EMPTY_MOBILE_NUMBER=Error: No mobile phone number provided.
+ERROR_USER_STATUS_ALREADY_CONFIRMED=You have already confirmed your user account and use it right away.
+ERROR_USER_STATUS_LOCKED=Your user account has been locked. Please contact the webmaster.
+ERROR_USER_NEW_PASSWORDS_MISMATCH=Your entered passwords (repeated) does not match.
+ERROR_USER_NEW_PASSWORD_SAME_AS_CURRENT=Your entered password must be different to your current password.
+ERROR_USER_NEW_PASSWORD_ALREADY_ENTERED=You have already entered this password some time ago.
+ERROR_USER_NOT_FOUND=User account not found.
+ERROR_USER_STATUS_UNCONFIRMED=You have not yet confirmed your user account.
+ERROR_USER_PASSWORD_MISMATCH=You have entered a wrong password.
>
<div class="table_row">
- <div class="table_left">
+ <div class="table_left_medium">
<h:outputLabel for="emailAddress" value="#{msg.GUEST_REGISTRATION_ENTER_EMAIL}" />
</div>
- <div class="table_right">
- <h:inputText styleClass="input" id="emailAddress" size="20" maxlength="255" value="#{contactController.emailAddress}" required="true" requiredMessage="#{msg.EMAIL_ADDRESS_NOT_ENTERED}">
+ <div class="table_right_medium">
+ <h:inputText styleClass="input" id="emailAddress" size="30" maxlength="255" value="#{contactController.emailAddress}" required="true" requiredMessage="#{msg.EMAIL_ADDRESS_NOT_ENTERED}">
<f:validator validatorId="EmailAddressValidator" />
</h:inputText>
</div>
</div>
<div class="table_row">
- <div class="table_left">
+ <div class="table_left_medium">
<h:outputLabel for="emailAddressRepeat" value="#{msg.GUEST_REGISTRATION_ENTER_EMAIL_REPEAT}" />
</div>
- <div class="table_right">
- <h:inputText styleClass="input" id="emailAddressRepeat" size="20" maxlength="255" value="#{contactController.emailAddressRepeat}" required="true" requiredMessage="#{msg.EMAIL_ADDRESS_REPEAT_NOT_ENTERED}" />
+ <div class="table_right_medium">
+ <h:inputText styleClass="input" id="emailAddressRepeat" size="30" maxlength="255" value="#{contactController.emailAddressRepeat}" required="true" requiredMessage="#{msg.EMAIL_ADDRESS_REPEAT_NOT_ENTERED}" />
</div>
<div class="clear"></div>
</div>
<div class="table_right">
- <h:inputSecret styleClass="input" id="currentPassword" size="10" maxlength="255" value="#{userLoginController.currentPassword}" required="true" validatorMessage="#{msg.ERROR_CURRENT_PASSWORD_MISMATCHING}">
- <h:message for="currentPassword" styleClass="errors" />
- <!-- <f:validator for="currentPassword" validatorId="UserPasswordValidator" /> //-->
+ <h:inputSecret styleClass="input" id="currentPassword" size="10" maxlength="255" value="#{userLoginController.currentPassword}" required="true" validatorMessage="#{msg.ERROR_USER_CURRENT_PASSWORD_MISMATCHING}">
+ <!-- <f:validator for="currentPassword" validatorId="RecruiterUserPasswordValidator" /> //-->
</h:inputSecret>
</div>