/*
- * Copyright (C) 2016 Roland Haeder
+ * 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 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.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.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jcontacts.contact.gender.Gender;
-import org.mxchange.jcontacts.contact.utils.ContactUtils;
-import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent;
+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.jcountry.data.Country;
-import org.mxchange.jjobs.beans.helper.JobsAdminWebRequestController;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
+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.Contacts;
+import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jjobs.beans.BaseJobsBean;
+import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewController;
+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)
+ * An administrative user controller (bean)
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Hรคder<roland@mxchange.org>
*/
@Named ("adminContactController")
@RequestScoped
-public class JobsAdminContactWebRequestBean implements JobsAdminContactWebRequestController {
+public class JobsAdminContactWebRequestBean extends BaseJobsBean implements JobsAdminContactWebRequestController {
/**
* Serial number
private static final long serialVersionUID = 542_145_347_916L;
/**
- * An event fired when the administrator has added a new user
+ * Academic academicTitle
+ */
+ private String academicTitle;
+
+ /**
+ * An event fired when the administrator has added a new contact
*/
@Inject
@Any
- private Event<AdminAddedUserEvent> addedUserEvent;
+ private Event<ObservableAdminAddedContactEvent> addedContactEvent;
/**
- * Admin helper instance
+ * Administrative contact EJB
*/
- @Inject
- private JobsAdminWebRequestController adminHelper;
+ @EJB (lookup = "java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
+ private AdminContactSessionBeanRemote adminContactBean;
/**
* Birth day
private Date birthday;
/**
- * Cellphone number's carrier
+ * City
*/
- private MobileProvider cellphoneCarrier;
+ private String city;
/**
- * Cellphone id number
+ * Optional comments
*/
- private Long cellphoneId;
+ private String comment;
/**
- * Cellphone number
+ * Current contact instance
*/
- private Long cellphoneNumber;
+ private Contact contact;
/**
- * City
+ * EJB for general contact purposes
*/
- private String city;
+ @EJB (lookup = "java:global/jjobs-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
+ private ContactSessionBeanRemote contactBean;
/**
- * Optional comments
+ * General contact controller
*/
- private String comment;
+ @Inject
+ private JobsContactWebRequestController contactController;
/**
- * Remote contact bean
+ * Country instance
*/
- private final ContactSessionBeanRemote contactBean;
+ private Country contactCountry;
/**
* Contact id
private Long contactId;
/**
- * Country instance
+ * An instance of a contact list controller
+ */
+ @Inject
+ private JobsContactListWebViewController contactListController;
+
+ /**
+ * Event being fired when an administrator has deleted a contact
*/
- private Country country;
+ @Any
+ @Inject
+ private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
/**
* Email address
*/
private String firstName;
- /**
- * Gender instance
- */
- private Gender gender;
-
/**
* House number
*/
private Short houseNumber;
/**
- * Whether a cellphone entry has been unlinked
+ * House number extension
*/
- private boolean isCellphoneUnlinked;
+ private String houseNumberExtension;
/**
* Whether a fax entry has been unlinked
private boolean isLandLineUnlinked;
/**
- * Land-line id number
+ * Whether a cmobile entry has been unlinked
*/
- private Long landLineId;
+ private boolean isMobileNumberUnlinked;
/**
* Phone number area code
*/
- private Integer phoneAreaCode;
+ private Integer landLineAreaCode;
/**
* Country instance for phone number
*/
- private Country phoneCountry;
+ private Country landLineCountry;
+
+ /**
+ * Land-line id number
+ */
+ private Long landLineId;
/**
* Phone number
*/
- private Long phoneNumber;
+ private Long landLineNumber;
+
+ /**
+ * Mobile id number
+ */
+ private Long mobileId;
+
+ /**
+ * Mobile number
+ */
+ private Long mobileNumber;
+
+ /**
+ * Mobile number's provider
+ */
+ private MobileProvider mobileProvider;
+
+ /**
+ * PersonalTitle instance
+ */
+ private PersonalTitle personalTitle;
/**
* Street
*/
@Inject
@Any
- private Event<AdminUpdatedContactEvent> updatedContactEvent;
+ private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
/**
* ZIP code
* Default constructor
*/
public JobsAdminContactWebRequestBean () {
- // Set gender to UNKNOWN
- this.gender = Gender.UNKNOWN;
+ // Call super constructor
+ super();
+ }
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
+ /**
+ * 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
+ throw new NullPointerException("personalTitle is null"); //NOI18N
+ } else if (this.getFirstName() == null) {
+ // Throw NPE
+ throw new NullPointerException("firstName is null"); //NOI18N
+ } else if (this.getFirstName().isEmpty()) {
+ // Empty string
+ throw new IllegalStateException("firstName is empty"); //NOI18N
+ } else if (this.getFamilyName() == null) {
+ // Throw NPE
+ throw new NullPointerException("familyName is null"); //NOI18N
+ } else if (this.getFamilyName().isEmpty()) {
+ // Empty string
+ throw new IllegalStateException("familyName is empty"); //NOI18N
+ }
+
+ // Create new contact instance
+ final Contact createdContact = this.createContactInstance();
+
+ // Default is not same contact
+ if (this.contactListController.isContactFound(createdContact)) {
+ // Already registered
+ throw new FacesException(new ContactAlreadyAddedException(createdContact));
+ }
- // Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
+ // Init contact
+ final Contact updatedContact;
+
+ // Try to call EJB
+ try {
+ // Call EJB
+ updatedContact = this.adminContactBean.addContact(createdContact);
+ } catch (final ContactAlreadyAddedException ex) {
// Throw again
- throw new FaceletException(e);
+ throw new FacesException(ex);
}
+
+ // Fire event
+ this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
+
+ // Clear this bean
+ this.clear();
+ }
+
+ /**
+ * 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::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
+
+ // The event instance must be valid
+ if (null == event) {
+ // Throw NPE again
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getCreatedContact() == null) {
+ // Throw NPE again
+ 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("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(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 (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 (createdContact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // ... fax data
+ 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 (createdContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // .. land-line data
+ 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::afterCreatedContactEvent(): EXIT!"); //NOI18N
}
@Override
- public String changeContactData () {
+ public Contact createContactInstance () {
+ // Are all minimum fields set?
+ if (this.getPersonalTitle() == null) {
+ // Throw NPE
+ throw new NullPointerException("personalTitle is null"); //NOI18N
+ } else if (this.getFirstName() == null) {
+ // Throw NPE
+ throw new NullPointerException("firstName is null"); //NOI18N
+ } else if (this.getFirstName().isEmpty()) {
+ // Empty string
+ throw new IllegalStateException("firstName is empty"); //NOI18N
+ } else if (this.getFamilyName() == null) {
+ // Throw NPE
+ throw new NullPointerException("familyName is null"); //NOI18N
+ } else if (this.getFamilyName().isEmpty()) {
+ // Empty string
+ throw new IllegalStateException("familyName is empty"); //NOI18N
+ }
+
+ // Generate phone number
+ 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());
+ }
+
+ // Are all fields set?
+ if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
+ // Initialize instance
+ mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+ }
+
+ // 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());
+ }
+
+ // Create new instance
+ final Contact localContact = new UserContact(
+ this.getPersonalTitle(),
+ this.getFirstName(),
+ this.getFamilyName()
+ );
+
+ // Add all others
+ localContact.setContactBirthday(this.getBirthday());
+ localContact.setContactCity(this.getCity());
+ localContact.setContactComment(this.getComment());
+ localContact.setContactCountry(this.getContactCountry());
+ localContact.setContactEmailAddress(this.getEmailAddress());
+ localContact.setContactHouseNumber(this.getHouseNumber());
+ localContact.setContactId(this.getContactId());
+ localContact.setContactStreet(this.getStreet());
+ localContact.setContactTitle(this.getAcademicTitle());
+ localContact.setContactZipCode(this.getZipCode());
+
+ // Set ownContact
+ localContact.setContactOwnContact(Boolean.TRUE);
+
+ // 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)) {
+ // Now the number must be given
+ if (landLine.getPhoneAreaCode() == null) {
+ // Is null
+ 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
+ } 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
+ }
+
+ // Set phone number
+ localContact.setContactLandLineNumber(landLine);
+ }
+
+ // Don't set null or wrong references
+ if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+ // Now the number must be given
+ if (fax.getPhoneAreaCode() == null) {
+ // Is null
+ 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
+ } 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
+ }
+
+ // Set fax number
+ 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.getMobileNumber() == null) {
+ // Is null
+ throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
+ } else if (mobile.getMobileNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set cmobile number
+ localContact.setContactMobileNumber(mobile);
+ }
+
+ // Return it
+ return localContact;
+ }
+
+ /**
+ * 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.adminHelper.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("adminHelper.contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
+ throw new NullPointerException("beanHelper.contact is null"); //NOI18N
+ } else if (createdContact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("adminHelper.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("adminHelper.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.isCellphoneUnlinked, 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 AdminContactUpdatedEvent(updatedContact));
+ this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
- // Return to contact list (for now)
- return "admin_list_contact"; //NOI18N
+ // Clear bean
+ this.clear();
}
- @Override
- public void copyContactToController (final Contact contact) {
- // The contact instance must be valid
- if (null == contact) {
- // Throw NPE again
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ /**
+ * 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) {
+ // Return null
+ return null;
}
- // Set all fields: contact
- this.setContactId(contact.getContactId());
- 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.setGender(contact.getContactGender());
- this.setHouseNumber(contact.getContactHouseNumber());
- this.setStreet(contact.getContactStreet());
- this.setZipCode(contact.getContactZipCode());
-
- // ... cellphone data
- this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
- this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
- this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
-
- // ... fax data
- this.setFaxId(contact.getContactFaxNumber().getPhoneId());
- this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
- this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
- this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
-
- // .. land-line data
- this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
- this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
- this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
- this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
- }
+ // Get all data
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
+ mobileNumber.getMobileProvider().getProviderDialPrefix(),
+ mobileNumber.getMobileNumber()
+ );
- @Override
- public Date getBirthday () {
- return this.birthday;
+ // Return it
+ return number;
}
- @Override
- public void setBirthday (final Date birthday) {
- this.birthday = birthday;
- }
+ /**
+ * 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) {
+ // Return null
+ return null;
+ }
- @Override
- public MobileProvider getCellphoneCarrier () {
- return this.cellphoneCarrier;
- }
+ // Generate it
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
+ phoneNumber.getPhoneAreaCode(),
+ phoneNumber.getPhoneNumber()
+ );
- @Override
- public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
- this.cellphoneCarrier = cellphoneCarrier;
+ // Return it
+ return number;
}
- @Override
- public Long getCellphoneId () {
- return this.cellphoneId;
+ /**
+ * Getter for academic title
+ * <p>
+ * @return Academic title
+ */
+ public String getAcademicTitle () {
+ return this.academicTitle;
}
- @Override
- public void setCellphoneId (final Long cellphoneId) {
- this.cellphoneId = cellphoneId;
+ /**
+ * Setter for academic title
+ * <p>
+ * @param academicTitle Academic title
+ */
+ public void setAcademicTitle (final String academicTitle) {
+ this.academicTitle = academicTitle;
}
- @Override
- public Long getCellphoneNumber () {
- return this.cellphoneNumber;
+ /**
+ * Getter for birth day
+ * <p>
+ * @return Birth day
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getBirthday () {
+ return this.birthday;
}
- @Override
- public void setCellphoneNumber (Long cellphoneNumber) {
- this.cellphoneNumber = cellphoneNumber;
+ /**
+ * 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
+ /**
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
+ */
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact) {
+ this.contact = contact;
+ }
+
+ /**
+ * Getter for contactCountry instance
+ * <p>
+ * @return Country instance
+ */
+ public Country getContactCountry () {
+ return this.contactCountry;
+ }
+
+ /**
+ * Setter for contactCountry instance
+ * <p>
+ * @param contactCountry Country instance
+ */
+ public void setContactCountry (final Country contactCountry) {
+ this.contactCountry = contactCountry;
+ }
+
+ /**
+ * Getter for contact id
+ * <p>
+ * @return Contact id
+ */
public Long getContactId () {
return this.contactId;
}
- @Override
+ /**
+ * Setter for contact id
+ * <p>
+ * @param contactId Contact id
+ */
public void setContactId (final Long contactId) {
this.contactId = contactId;
}
@Override
- public Country getCountry () {
- return this.country;
- }
-
- @Override
- public void setCountry (final Country country) {
- this.country = country;
+ public String getControllerType () {
+ return "admin"; //NOI18N
}
- @Override
+ /**
+ * 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
- public Gender getGender () {
- return this.gender;
- }
-
- @Override
- public void setGender (final Gender gender) {
- this.gender = gender;
- }
-
- @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;
+ }
+
+ /**
+ * Setter for house number extension
+ * <p>
+ * @param houseNumberExtension House number extension
+ */
+ public void setHouseNumberExtension (final String houseNumberExtension) {
+ this.houseNumberExtension = houseNumberExtension;
+ }
+
+ /**
+ * Getter for land-line number's area code
+ * <p>
+ * @return Land-line number's area code
+ */
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Getter for land-line number's country instance
+ * <p>
+ * @return Land-line number's country instance
+ */
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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
- public Integer getPhoneAreaCode () {
- return this.phoneAreaCode;
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
}
- @Override
- public void setPhoneAreaCode (final Integer phoneAreaCode) {
- this.phoneAreaCode = phoneAreaCode;
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
}
- @Override
- public Country getPhoneCountry () {
- return this.phoneCountry;
+ /**
+ * Getter for mobile id
+ * <p>
+ * @return Mobile id
+ */
+ public Long getMobileId () {
+ return this.mobileId;
}
- @Override
- public void setPhoneCountry (final Country phoneCountry) {
- this.phoneCountry = phoneCountry;
+ /**
+ * Setter for mobile id
+ * <p>
+ * @param mobileId Mobile id
+ */
+ public void setMobileId (final Long mobileId) {
+ this.mobileId = mobileId;
}
- @Override
- public Long getPhoneNumber () {
- return this.phoneNumber;
+ /**
+ * Getter for mobile number
+ * <p>
+ * @return Mobile number
+ */
+ public Long getMobileNumber () {
+ return this.mobileNumber;
}
- @Override
- public void setPhoneNumber (final Long phoneNumber) {
- this.phoneNumber = phoneNumber;
+ /**
+ * 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;
+ }
+
+ /**
+ * Setter for mobile number's carrier prefix
+ * <p>
+ * @param mobileProvider Mobile number's carrier prefix
+ */
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
+ }
+
+ /**
+ * Getter for personal title
+ * <p>
+ * @return Personal title
+ */
+ public PersonalTitle getPersonalTitle () {
+ return this.personalTitle;
+ }
+
+ /**
+ * Setter for personal title
+ * <p>
+ * @param personalTitle Personal title
+ */
+ public void setPersonalTitle (final PersonalTitle personalTitle) {
+ this.personalTitle = personalTitle;
+ }
+
+ /**
+ * 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
+ /**
+ * Getter for ZIP code
+ * <p>
+ * @return ZIP code
+ */
public Integer getZipCode () {
return this.zipCode;
}
- @Override
+ /**
+ * Setter for ZIP code
+ * <p>
+ * @param zipCode ZIP code
+ */
public void setZipCode (final Integer zipCode) {
this.zipCode = zipCode;
}
+ @Override
+ 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
+ }
+ }
+
/**
- * Post-initialization of this class
+ * Clears this bean
*/
- @PostConstruct
- public void init () {
+ private void clear () {
+ // Clear all data
+ this.setContact(null);
+
+ // - personal data
+ this.setAcademicTitle(null);
+ this.setFirstName(null);
+ this.setFamilyName(null);
+ this.setStreet(null);
+ this.setHouseNumber(null);
+ this.setHouseNumberExtension(null);
+ this.setZipCode(null);
+ this.setCity(null);
+ this.setContactCountry(null);
+
+ // - contact data
+ this.setEmailAddress(null);
+ this.setLandLineCountry(null);
+ this.setLandLineAreaCode(null);
+ this.setLandLineNumber(null);
+ this.setMobileProvider(null);
+ this.setMobileNumber(null);
+ this.setFaxCountry(null);
+ this.setFaxAreaCode(null);
+ this.setFaxNumber(null);
+
+ // - other data
+ this.setBirthday(null);
+ this.setComment(null);
}
/**
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
}
// Update all fields
- contact.setContactGender(this.getGender());
+ contact.setContactPersonalTitle(this.getPersonalTitle());
+ contact.setContactTitle(this.getAcademicTitle());
contact.setContactFirstName(this.getFirstName());
contact.setContactFamilyName(this.getFamilyName());
contact.setContactStreet(this.getStreet());
contact.setContactHouseNumber(this.getHouseNumber());
+ 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
- this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
+ // Update contact's cmobile number
+ this.isMobileNumberUnlinked = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
// Update contact's land-line number
- this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+ this.isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
// Update contact's fax number
- this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ this.isFaxUnlinked = Contacts.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
}
}