/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2022 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
import java.text.MessageFormat;
import java.util.Date;
-import java.util.Iterator;
-import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
import javax.enterprise.inject.Any;
-import javax.faces.context.FacesContext;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
import javax.inject.Inject;
import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.addressbook.beans.BaseAddressbookController;
-import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
-import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jcontacts.contact.ContactUtils;
-import org.mxchange.jcontacts.contact.UserContact;
-import org.mxchange.jcontacts.contact.title.PersonalTitle;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
-import org.mxchange.jcountry.data.Country;
-import org.mxchange.jphone.phonenumbers.DialableNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
-import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
+import org.mxchange.jcontacts.model.utils.ContactUtils;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jphone.model.phonenumbers.DialableNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
/**
* An administrative user bean (controller)
*/
@Named ("adminContactController")
@RequestScoped
-public class AddressbookAdminContactWebRequestBean extends BaseAddressbookController implements AddressbookAdminContactWebRequestController {
+public class AddressbookAdminContactWebRequestBean extends BaseAddressbookBean implements AddressbookAdminContactWebRequestController {
/**
* Serial number
*/
private static final long serialVersionUID = 542_145_347_916L;
+ /**
+ * Academic academicTitle
+ */
+ private String academicTitle;
+
/**
* An event fired when the administrator has added a new contact
*/
/**
* Administrative contact EJB
*/
+ @EJB (lookup = "java:global/addressbook-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
private AdminContactSessionBeanRemote adminContactBean;
- /**
- * Bean helper instance
- */
- @Inject
- private AddressbookWebRequestHelperController beanHelper;
-
/**
* Birth day
*/
private String comment;
/**
- * Remote contact bean
+ * Current contact instance
+ */
+ private Contact contact;
+
+ /**
+ * EJB for general contact purposes
*/
+ @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
private ContactSessionBeanRemote contactBean;
/**
- * General contact controller
+ * Country instance
*/
- @Inject
- private AddressbookContactWebSessionController contactController;
+ private Country contactCountry;
/**
* Contact id
private Long contactId;
/**
- * Country instance
+ * An instance of a contact list controller
*/
- private Country country;
+ @Inject
+ private AddressbookContactListWebViewController contactListController;
+
+ /**
+ * Event being fired when an administrator has deleted a contact
+ */
+ @Any
+ @Inject
+ private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
/**
* Email address
private boolean isLandLineUnlinked;
/**
- * Whether a cellphone entry has been unlinked
+ * Whether a mobile entry has been unlinked
*/
private boolean isMobileNumberUnlinked;
*/
private String street;
- /**
- * Academic academicTitle
- */
- private String academicTitle;
-
/**
* An event fired when the administrator has updated contact data
*/
super();
}
- @Override
- public String addContact () {
+ /**
+ * Adds contact data to database and redirects on success. If the contact is
+ * already found, a proper exception is thrown.
+ */
+ public void addContact () {
// Are all minimum fields set?
if (this.getPersonalTitle() == null) {
// Throw NPE
}
// Create new contact instance
- Contact contact = this.createContactInstance();
+ final Contact createdContact = this.createContactInstance();
// Default is not same contact
- if (this.isSameContactFound(contact)) {
+ if (this.contactListController.isContactFound(createdContact)) {
// Already registered
- throw new FaceletException(new ContactAlreadyAddedException(contact));
+ throw new FacesException(new ContactAlreadyAddedException(createdContact));
}
// Init contact
- Contact updatedContact;
+ final Contact updatedContact;
// Try to call EJB
try {
// Call EJB
- updatedContact = this.adminContactBean.addContact(contact);
+ updatedContact = this.adminContactBean.addContact(createdContact);
} catch (final ContactAlreadyAddedException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
// Clear this bean
this.clear();
-
- // Return outcome
- return "admin_list_contact"; //NOI18N
}
- @Override
- public void copyContactToController (final Contact contact) {
+ /**
+ * Observer for events being fired when a bean helper has successfully
+ * created a contact instance.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
// Log message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
- // The contact instance must be valid
- if (null == contact) {
+ // The event instance must be valid
+ if (null == event) {
// Throw NPE again
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getCreatedContact() == null) {
// Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
+ throw new NullPointerException("event.createdContact is null"); //NOI18N
+ } else if (event.getCreatedContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N
+ } else if (event.getCreatedContact().getContactId() < 1) {
// Not valid
- throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
}
+ // Set contact for e.g. delete method
+ this.setContact(event.getCreatedContact());
+
+ // Get contact instance from event
+ final Contact createdContact = event.getCreatedContact();
+
// Set all fields: contact
- this.setContactId(contact.getContactId());
- this.setAcademicTitle(contact.getContactTitle());
- this.setBirthday(contact.getContactBirthday());
- this.setCity(contact.getContactCity());
- this.setComment(contact.getContactComment());
- this.setCountry(contact.getContactCountry());
- this.setEmailAddress(contact.getContactEmailAddress());
- this.setFamilyName(contact.getContactFamilyName());
- this.setFirstName(contact.getContactFirstName());
- this.setPersonalTitle(contact.getContactPersonalTitle());
- this.setHouseNumber(contact.getContactHouseNumber());
- this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
- this.setStreet(contact.getContactStreet());
- this.setZipCode(contact.getContactZipCode());
+ this.setContactId(createdContact.getContactId());
+ this.setAcademicTitle(createdContact.getContactTitle());
+ this.setBirthday(createdContact.getContactBirthday());
+ this.setCity(createdContact.getContactCity());
+ this.setComment(createdContact.getContactComment());
+ this.setContactCountry(createdContact.getContactCountry());
+ this.setEmailAddress(createdContact.getContactEmailAddress());
+ this.setFamilyName(createdContact.getContactFamilyName());
+ this.setFirstName(createdContact.getContactFirstName());
+ this.setPersonalTitle(createdContact.getContactPersonalTitle());
+ this.setHouseNumber(createdContact.getContactHouseNumber());
+ this.setHouseNumberExtension(createdContact.getContactHouseNumberExtension());
+ this.setStreet(createdContact.getContactStreet());
+ this.setZipCode(createdContact.getContactZipCode());
// Is the cell phone set?
- if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // ... cellphone data
- this.setMobileId(contact.getContactMobileNumber().getPhoneId());
- this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
- this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
+ if (createdContact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ // ... cmobile data
+ this.setMobileId(createdContact.getContactMobileNumber().getMobileId());
+ this.setMobileProvider(createdContact.getContactMobileNumber().getMobileProvider());
+ this.setMobileNumber(createdContact.getContactMobileNumber().getMobileNumber());
}
// Is the fax set?
- if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ if (createdContact.getContactFaxNumber() instanceof DialableFaxNumber) {
// ... fax data
- this.setFaxId(contact.getContactFaxNumber().getPhoneId());
- this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
- this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
- this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
+ this.setFaxId(createdContact.getContactFaxNumber().getPhoneId());
+ this.setFaxAreaCode(createdContact.getContactFaxNumber().getPhoneAreaCode());
+ this.setFaxCountry(createdContact.getContactFaxNumber().getPhoneCountry());
+ this.setFaxNumber(createdContact.getContactFaxNumber().getPhoneNumber());
}
// Is the land-line number set?
- if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ if (createdContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
// .. land-line data
- this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
- this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
- this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
- this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
+ this.setLandLineId(createdContact.getContactLandLineNumber().getPhoneId());
+ this.setLandLineAreaCode(createdContact.getContactLandLineNumber().getPhoneAreaCode());
+ this.setLandLineCountry(createdContact.getContactLandLineNumber().getPhoneCountry());
+ this.setLandLineNumber(createdContact.getContactLandLineNumber().getPhoneNumber());
}
// Log message
- //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
}
@Override
} else if (this.getFamilyName().isEmpty()) {
// Empty string
throw new IllegalStateException("familyName is empty"); //NOI18N
+ } else if (this.getContactCountry() == null) {
+ // Throw NPE
+ throw new NullPointerException("contactCountry is null"); //NOI18N
+ } else if (this.getContactCountry().getCountryId() == null) {
+ // Throw it again
+ throw new NullPointerException("contactCountry.countryId is null"); //NOI18N
+ } else if (this.getContactCountry().getCountryId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is invalid", this.getContactCountry().getCountryId())); //NOI18N
}
// Generate phone number
- DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
- DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
- DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ DialableLandLineNumber landLine = null;
+ DialableMobileNumber mobile = null;
+ DialableFaxNumber fax = null;
+
+ // Are all fields set?
+ if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
+ // Init instance
+ landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ }
- // Create new instance
- Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
+ // Are all fields set?
+ if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
+ // Initialize instance
+ mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+ }
- // Add all others
- contact.setContactTitle(this.getAcademicTitle());
- contact.setContactBirthday(this.getBirthday());
- contact.setContactStreet(this.getStreet());
- contact.setContactHouseNumber(this.getHouseNumber());
- contact.setContactZipCode(this.getZipCode());
- contact.setContactCity(this.getCity());
- contact.setContactCountry(this.getCountry());
- contact.setContactEmailAddress(this.getEmailAddress());
- contact.setContactBirthday(this.getBirthday());
- contact.setContactComment(this.getComment());
+ // Are all fields set?
+ if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
+ // Initialize instance
+ fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ }
- // Set ownContact
- contact.setContactOwnContact(Boolean.TRUE);
+ // Create new instance
+ final Contact localContact = new UserContact(
+ this.getPersonalTitle(),
+ this.getFirstName(),
+ this.getFamilyName(),
+ this.getContactCountry(),
+ Boolean.FALSE,
+ this.getStreet(),
+ this.getHouseNumber(),
+ this.getHouseNumberExtension(),
+ this.getZipCode(),
+ this.getCity(),
+ this.getEmailAddress(),
+ this.getAcademicTitle(),
+ this.getBirthday(),
+ this.getComment()
+ );
+
+ // Add missing fields
+ localContact.setContactId(this.getContactId());
// Don't set null or wrong references
if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
} else if (landLine.getPhoneAreaCode() < 1) {
// Abort here
- throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+ throw new IllegalStateException("phone.phoneAreaCode is zero or below."); //NOI18N
} else if (landLine.getPhoneNumber() == null) {
// Is null
throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
} else if (landLine.getPhoneNumber() < 1) {
// Abort here
- throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+ throw new IllegalStateException("phone.phoneNumber is zero or below."); //NOI18N
}
// Set phone number
- contact.setContactLandLineNumber(landLine);
+ localContact.setContactLandLineNumber(landLine);
}
// Don't set null or wrong references
throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
} else if (fax.getPhoneAreaCode() < 1) {
// Abort here
- throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+ throw new IllegalStateException("fax.phoneAreaCode is zero or below."); //NOI18N
} else if (fax.getPhoneNumber() == null) {
// Is null
throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
} else if (fax.getPhoneNumber() < 1) {
// Abort here
- throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
+ throw new IllegalStateException("fax.phoneNumber is zero or below."); //NOI18N
}
// Set fax number
- contact.setContactFaxNumber(fax);
+ localContact.setContactFaxNumber(fax);
}
// Is the provider set?
if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
// Is the number set?
- if (mobile.getPhoneNumber() == null) {
+ if (mobile.getMobileNumber() == null) {
// Is null
- throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
- } else if (mobile.getPhoneNumber() < 1) {
+ throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
+ } else if (mobile.getMobileNumber() < 1) {
// Abort here
- throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
+ throw new IllegalStateException("cmobile.phoneNumber is zero or below."); //NOI18N
}
- // Set cellphone number
- contact.setContactMobileNumber(mobile);
+ // Set cmobile number
+ localContact.setContactMobileNumber(mobile);
}
// Return it
- return contact;
+ return localContact;
}
- @Override
- public String editContactData () {
+ /**
+ * Deletes currently chosen contact and returns to list view
+ *
+ * @return
+ */
+ public String deleteContactData () {
+ // Is contact set?
+ if (this.getContact() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.contact is null");
+ } else if (this.getContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.contact.contactId is null");
+ } else if (this.getContact().getContactId() < 1) {
+ // Throw IAE
+ throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
+ }
+
+ try {
+ // Invoke EJB
+ this.adminContactBean.deleteContactData(this.getContact());
+ } catch (final ContactNotFoundException ex) {
+ // Throw it again
+ throw new FacesException(ex);
+ }
+
+ // Fire event
+ this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
+
+ // Return to list view
+ return "admin_list_contacts";
+ }
+
+ /**
+ * Edits currently loaded contact's data in database.
+ */
+ public void editContactData () {
// Get contact instance
- Contact contact = this.beanHelper.getContact();
+ final Contact createdContact = this.createContactInstance();
// Check if contact instance is in helper and valid
- if (null == contact) {
+ if (null == createdContact) {
// Throw NPE
throw new NullPointerException("beanHelper.contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
+ } else if (createdContact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
+ throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
+ } else if (createdContact.getContactId() < 1) {
// Invalid id
- throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+ throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
}
// Update all data in contact
- this.updateContactData(contact);
+ this.updateContactData(createdContact);
- // Call EJB for updating contact data
- Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ // Init updated contact instance
+ final Contact updatedContact;
+
+ try {
+ // Call EJB for updating contact data
+ updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ } catch (final ContactNotFoundException ex) {
+ // Throw as a cause
+ throw new FacesException(ex);
+ }
// Fire event
this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
// Clear bean
this.clear();
-
- // Return to contact list (for now)
- return "admin_list_contact"; //NOI18N
}
- @Override
+ /**
+ * Returns a text representation of given mobile number or null if not set.
+ * <p>
+ * @param mobileNumber Mobile number
+ * <p>
+ * @return Text representation or null
+ */
public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
// Is it null?
if (null == mobileNumber) {
}
// Get all data
- String number = String.format(
- "%s%d%d", //NOI18N
- mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
- mobileNumber.getMobileProvider().getProviderDialPrefix(),
- mobileNumber.getPhoneNumber()
- );
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
+ mobileNumber.getMobileProvider().getProviderDialPrefix(),
+ mobileNumber.getMobileNumber()
+ );
// Return it
return number;
}
- @Override
+ /**
+ * Returns a text representation of given land-line or fax number or null if
+ * not set.
+ * <p>
+ * @param phoneNumber Land-line or fax number
+ * <p>
+ * @return Text representation or null
+ */
public String generatePhoneNumber (final DialableNumber phoneNumber) {
// Is it null?
if (null == phoneNumber) {
}
// Generate it
- String number = String.format(
- "%s%d%d", //NOI18N
- phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
- phoneNumber.getPhoneAreaCode(),
- phoneNumber.getPhoneNumber()
- );
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
+ phoneNumber.getPhoneAreaCode(),
+ phoneNumber.getPhoneNumber()
+ );
// Return it
return number;
}
- @Override
+ /**
+ * Getter for academic title
+ * <p>
+ * @return Academic title
+ */
+ public String getAcademicTitle () {
+ return this.academicTitle;
+ }
+
+ /**
+ * Setter for academic title
+ * <p>
+ * @param academicTitle Academic title
+ */
+ public void setAcademicTitle (final String academicTitle) {
+ this.academicTitle = academicTitle;
+ }
+
+ /**
+ * Getter for birth day
+ * <p>
+ * @return Birth day
+ */
@SuppressWarnings ("ReturnOfDateField")
public Date getBirthday () {
return this.birthday;
}
- @Override
+ /**
+ * Setter for birth day
+ * <p>
+ * @param birthday Birth day
+ */
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
public void setBirthday (final Date birthday) {
this.birthday = birthday;
}
- @Override
+ /**
+ * Getter for city name
+ * <p>
+ * @return City name
+ */
public String getCity () {
return this.city;
}
- @Override
+ /**
+ * Setter for city name
+ * <p>
+ * @param city City name
+ */
public void setCity (final String city) {
this.city = city;
}
- @Override
+ /**
+ * Getter for comments
+ * <p>
+ * @return Comments
+ */
public String getComment () {
return this.comment;
}
- @Override
+ /**
+ * Setter for comment
+ * <p>
+ * @param comment Comments
+ */
public void setComment (final String comment) {
this.comment = comment;
}
- @Override
- public Long getContactId () {
- return this.contactId;
+ /**
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
+ */
+ public Contact getContact () {
+ return this.contact;
}
- @Override
- public void setContactId (final Long contactId) {
- this.contactId = contactId;
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact) {
+ this.contact = contact;
}
- @Override
- public String getControllerType () {
- return "admin"; //NOI18N
+ /**
+ * Getter for contactCountry instance
+ * <p>
+ * @return Country instance
+ */
+ public Country getContactCountry () {
+ return this.contactCountry;
}
- @Override
- @Deprecated
- public void setControllerType (final String controllerType) {
- throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
+ /**
+ * Setter for contactCountry instance
+ * <p>
+ * @param contactCountry Country instance
+ */
+ public void setContactCountry (final Country contactCountry) {
+ this.contactCountry = contactCountry;
}
- @Override
- public Country getCountry () {
- return this.country;
+ /**
+ * Getter for contact id
+ * <p>
+ * @return Contact id
+ */
+ public Long getContactId () {
+ return this.contactId;
}
- @Override
- public void setCountry (final Country country) {
- this.country = country;
+ /**
+ * Setter for contact id
+ * <p>
+ * @param contactId Contact id
+ */
+ public void setContactId (final Long contactId) {
+ this.contactId = contactId;
}
@Override
+ public String getControllerType () {
+ return "admin"; //NOI18N
+ }
+
+ /**
+ * Getter for email address
+ * <p>
+ * @return Email address
+ */
public String getEmailAddress () {
return this.emailAddress;
}
- @Override
+ /**
+ * Setter for email address
+ * <p>
+ * @param emailAddress Email address
+ */
public void setEmailAddress (final String emailAddress) {
this.emailAddress = emailAddress;
}
- @Override
+ /**
+ * Family name
+ * <p>
+ * @return the familyName
+ */
public String getFamilyName () {
return this.familyName;
}
- @Override
+ /**
+ * Family name
+ * <p>
+ * @param familyName the familyName to set
+ */
public void setFamilyName (final String familyName) {
this.familyName = familyName;
}
- @Override
+ /**
+ * Getter for fax number's area code
+ * <p>
+ * @return Fax number's area code
+ */
public Integer getFaxAreaCode () {
return this.faxAreaCode;
}
- @Override
+ /**
+ * Setter for fax number's area code
+ * <p>
+ * @param faxAreaCode Fax number's area code
+ */
public void setFaxAreaCode (final Integer faxAreaCode) {
this.faxAreaCode = faxAreaCode;
}
- @Override
+ /**
+ * Getter for fax's country instance
+ * <p>
+ * @return Fax' country instance
+ */
public Country getFaxCountry () {
return this.faxCountry;
}
- @Override
+ /**
+ * Setter for fax's country instance
+ * <p>
+ * @param faxCountry Fax' country instance
+ */
public void setFaxCountry (final Country faxCountry) {
this.faxCountry = faxCountry;
}
- @Override
+ /**
+ * Getter for fax id
+ * <p>
+ * @return Fax id
+ */
public Long getFaxId () {
return this.faxId;
}
- @Override
+ /**
+ * Setter for fax id
+ * <p>
+ * @param faxId Fax id
+ */
public void setFaxId (final Long faxId) {
this.faxId = faxId;
}
- @Override
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
public Long getFaxNumber () {
return this.faxNumber;
}
- @Override
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
public void setFaxNumber (final Long faxNumber) {
this.faxNumber = faxNumber;
}
- @Override
+ /**
+ * Getter for first name
+ * <p>
+ * @return First name
+ */
public String getFirstName () {
return this.firstName;
}
- @Override
+ /**
+ * Setter for first name
+ * <p>
+ * @param firstName First name
+ */
public void setFirstName (final String firstName) {
this.firstName = firstName;
}
- @Override
+ /**
+ * Getter for house number
+ * <p>
+ * @return House number
+ */
public Short getHouseNumber () {
return this.houseNumber;
}
- @Override
+ /**
+ * Setter for house number
+ * <p>
+ * @param houseNumber House number
+ */
public void setHouseNumber (final Short houseNumber) {
this.houseNumber = houseNumber;
}
- @Override
+ /**
+ * Getter for house number extension. Example: 123a, 'a' is the extension
+ * and 123 is the house number.
+ * <p>
+ * @return House number extension
+ */
public String getHouseNumberExtension () {
return this.houseNumberExtension;
}
- @Override
+ /**
+ * Setter for house number extension
+ * <p>
+ * @param houseNumberExtension House number extension
+ */
public void setHouseNumberExtension (final String houseNumberExtension) {
this.houseNumberExtension = houseNumberExtension;
}
- @Override
+ /**
+ * Getter for land-line number's area code
+ * <p>
+ * @return Land-line number's area code
+ */
public Integer getLandLineAreaCode () {
return this.landLineAreaCode;
}
- @Override
+ /**
+ * Setter for land-line number's area code
+ * <p>
+ * @param landLineAreaCode Land-line number's area code
+ */
public void setLandLineAreaCode (final Integer landLineAreaCode) {
this.landLineAreaCode = landLineAreaCode;
}
- @Override
+ /**
+ * Getter for land-line number's country instance
+ * <p>
+ * @return Land-line number's country instance
+ */
public Country getLandLineCountry () {
return this.landLineCountry;
}
- @Override
+ /**
+ * Setter for land-line number's country instance
+ * <p>
+ * @param landLineCountry Land-line number's country instance
+ */
public void setLandLineCountry (final Country landLineCountry) {
this.landLineCountry = landLineCountry;
}
- @Override
+ /**
+ * Getter for land-line id
+ * <p>
+ * @return Land-line id
+ */
public Long getLandLineId () {
return this.landLineId;
}
- @Override
+ /**
+ * Setter for land-line id
+ * <p>
+ * @param landLineId Land-line id
+ */
public void setLandLineId (final Long landLineId) {
this.landLineId = landLineId;
}
- @Override
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
public Long getLandLineNumber () {
return this.landLineNumber;
}
- @Override
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
public void setLandLineNumber (final Long landLineNumber) {
this.landLineNumber = landLineNumber;
}
- @Override
+ /**
+ * Getter for mobile id
+ * <p>
+ * @return Mobile id
+ */
public Long getMobileId () {
return this.mobileId;
}
- @Override
+ /**
+ * Setter for mobile id
+ * <p>
+ * @param mobileId Mobile id
+ */
public void setMobileId (final Long mobileId) {
this.mobileId = mobileId;
}
- @Override
+ /**
+ * Getter for mobile number
+ * <p>
+ * @return Mobile number
+ */
public Long getMobileNumber () {
return this.mobileNumber;
}
- @Override
- public void setMobileNumber (Long mobileNumber) {
+ /**
+ * Setter for mobile number
+ * <p>
+ * @param mobileNumber Mobile number
+ */
+ public void setMobileNumber (final Long mobileNumber) {
this.mobileNumber = mobileNumber;
}
- @Override
+ /**
+ * Getter for mobile number's carrier
+ * <p>
+ * @return Mobile number's carrier
+ */
public MobileProvider getMobileProvider () {
return this.mobileProvider;
}
- @Override
+ /**
+ * Setter for mobile number's carrier prefix
+ * <p>
+ * @param mobileProvider Mobile number's carrier prefix
+ */
public void setMobileProvider (final MobileProvider mobileProvider) {
this.mobileProvider = mobileProvider;
}
- @Override
+ /**
+ * Getter for personal title
+ * <p>
+ * @return Personal title
+ */
public PersonalTitle getPersonalTitle () {
return this.personalTitle;
}
- @Override
+ /**
+ * Setter for personal title
+ * <p>
+ * @param personalTitle Personal title
+ */
public void setPersonalTitle (final PersonalTitle personalTitle) {
this.personalTitle = personalTitle;
}
- @Override
+ /**
+ * Getter for street name
+ * <p>
+ * @return Street name
+ */
public String getStreet () {
return this.street;
}
- @Override
+ /**
+ * Setter for street name
+ * <p>
+ * @param street Street name
+ */
public void setStreet (final String street) {
this.street = street;
}
- @Override
- public String getAcademicTitle () {
- return this.academicTitle;
- }
-
- @Override
- public void setAcademicTitle (final String academicTitle) {
- this.academicTitle = academicTitle;
- }
-
- @Override
+ /**
+ * Getter for ZIP code
+ * <p>
+ * @return ZIP code
+ */
public Integer getZipCode () {
return this.zipCode;
}
- @Override
- public void setZipCode (final Integer zipCode) {
- this.zipCode = zipCode;
- }
-
/**
- * Post-initialization of this class
+ * Setter for ZIP code
+ * <p>
+ * @param zipCode ZIP code
*/
- @PostConstruct
- public void init () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
-
- // Try to lookup (administative)
- this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw again
- throw new FaceletException(e);
- }
+ public void setZipCode (final Integer zipCode) {
+ this.zipCode = zipCode;
}
@Override
- public boolean isPersonalTitleRequired () {
- // Get context parameter
- String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_personal_title_enabled"); //NOI18N
-
- // Is it set?
- boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
-
- // Return value
- return isRequired;
+ public void validateContactData () {
+ if (this.getPersonalTitle() == null) {
+ // Throw NPE again
+ throw new NullPointerException("contactController.gender is null"); //NOI18N
+ } else if (this.getFirstName() == null) {
+ // ... and again
+ throw new NullPointerException("contactController.firstName is null"); //NOI18N
+ } else if (this.getFirstName().isEmpty()) {
+ // ... and again
+ throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
+ } else if (this.getFamilyName() == null) {
+ // ... and again
+ throw new NullPointerException("contactController.familyName is null"); //NOI18N
+ } else if (this.getFamilyName().isEmpty()) {
+ // ... and again
+ throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
+ } else if (this.getEmailAddress() == null) {
+ // ... and again
+ throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
+ } else if (this.getEmailAddress().isEmpty()) {
+ // ... and again
+ throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
+ }
}
/**
*/
private void clear () {
// Clear all data
+ this.setContact(null);
+
// - personal data
this.setAcademicTitle(null);
this.setFirstName(null);
this.setHouseNumberExtension(null);
this.setZipCode(null);
this.setCity(null);
- this.setCountry(null);
+ this.setContactCountry(null);
// - contact data
this.setEmailAddress(null);
this.setComment(null);
}
- /**
- * Checks whether the given contact is found
- * <p>
- * @param contact Contact inastance
- *
- * @return Wether contact has been found
- */
- private boolean isSameContactFound (final Contact contact) {
- // Default is not found
- boolean IsFound = false;
-
- // Get iterator
- Iterator<Contact> iterator = this.contactController.allContacts().iterator();
-
- // Loop through all
- while (iterator.hasNext()) {
- // Get next contact
- Contact next = iterator.next();
-
- // Is the same?
- if (ContactUtils.isSameContact(contact, next)) {
- // Yes, then abort loop
- IsFound = false;
- break;
- }
- }
-
- // Return status
- return IsFound;
- }
-
/**
* Updates all data in contact instance.
* <p>
throw new NullPointerException("contact is null"); //NOI18N
} else if (contact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
} else if (contact.getContactId() < 1) {
// Invalid id
throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
contact.setContactZipCode(this.getZipCode());
contact.setContactCity(this.getCity());
- contact.setContactCountry(this.getCountry());
+ contact.setContactCountry(this.getContactCountry());
- // Update contact's cellphone number
+ // Update contact's cmobile number
this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
// Update contact's land-line number