X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fcontact%2FJobsAdminContactWebRequestBean.java;h=6d06039f05b06c205426e8c70e19e3437c083d62;hb=164ba221de68d0ae673f411bd84aae8880f4aaa9;hp=b4c598255ede6a5548dfa57fa312e33b8e723f95;hpb=d5fda2ab63061743d025611b5751a8346e11c698;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java index b4c59825..6d06039f 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 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 @@ -18,40 +18,40 @@ package org.mxchange.jjobs.beans.contact; 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.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.AdminContactSessionBeanRemote; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.contact.UserContact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.contact.utils.ContactUtils; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent; -import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jjobs.beans.BaseJobsController; -import org.mxchange.jjobs.beans.helper.JobsWebViewHelperController; -import org.mxchange.jphone.phonenumbers.DialableNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; 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.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 controller (bean) @@ -60,13 +60,18 @@ import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContac */ @Named ("adminContactController") @RequestScoped -public class JobsAdminContactWebRequestBean extends BaseJobsController implements JobsAdminContactWebRequestController { +public class JobsAdminContactWebRequestBean extends BaseJobsBean implements JobsAdminContactWebRequestController { /** * 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 */ @@ -77,14 +82,9 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement /** * Administrative contact EJB */ + @EJB (lookup = "java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote") private AdminContactSessionBeanRemote adminContactBean; - /** - * Bean helper - */ - @Inject - private JobsWebViewHelperController beanHelper; - /** * Birth day */ @@ -101,15 +101,26 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private String comment; /** - * General contact EJB + * Current contact instance */ - private final ContactSessionBeanRemote contactBean; + private Contact contact; + + /** + * EJB for general contact purposes + */ + @EJB (lookup = "java:global/jjobs-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote") + private ContactSessionBeanRemote contactBean; /** * General contact controller */ @Inject - private JobsContactWebSessionController contactController; + private JobsContactWebRequestController contactController; + + /** + * Country instance + */ + private Country contactCountry; /** * Contact id @@ -117,15 +128,16 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private Long contactId; /** - * Country instance + * An instance of a contact list controller */ - private Country country; + @Inject + private JobsContactListWebViewController contactListController; /** - * Event being fired when contact data has been deleted + * Event being fired when an administrator has deleted a contact */ - @Inject @Any + @Inject private Event deletedContactEvent; /** @@ -149,25 +161,20 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private Country faxCountry; /** - * Fax number + * Fax id number */ - private Long faxNumber; + private Long faxId; /** - * Fax id number + * Fax number */ - private Long faxNumberId; + private Long faxNumber; /** * First name */ private String firstName; - /** - * Gender instance - */ - private Gender gender; - /** * House number */ @@ -189,17 +196,17 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private boolean isLandLineUnlinked; /** - * Whether a mobile entry has been unlinked + * Whether a cmobile entry has been unlinked */ - private boolean isMobileUnlinked; + private boolean isMobileNumberUnlinked; /** - * Land-line number area code + * Phone number area code */ private Integer landLineAreaCode; /** - * Country instance for land-line number + * Country instance for phone number */ private Country landLineCountry; @@ -209,34 +216,34 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private Long landLineId; /** - * Land-line number + * Phone number */ private Long landLineNumber; /** - * Mobile number + * Mobile id number */ - private Long mobileNumber; + private Long mobileId; /** - * Mobile id number + * Mobile number */ - private Long mobileNumberId; + private Long mobileNumber; /** - * Mobile provider + * Mobile number's provider */ private MobileProvider mobileProvider; /** - * Street + * PersonalTitle instance */ - private String street; + private PersonalTitle personalTitle; /** - * Title + * Street */ - private String title; + private String street; /** * An event fired when the administrator has updated contact data @@ -254,28 +261,19 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement * Default constructor */ public JobsAdminContactWebRequestBean () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup (general) - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N - - // Try to lookup (administative) - this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } + // Call super constructor + 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.getGender() == null) { + if (this.getPersonalTitle() == null) { // Throw NPE - throw new NullPointerException("gender is null"); //NOI18N + throw new NullPointerException("personalTitle is null"); //NOI18N } else if (this.getFirstName() == null) { // Throw NPE throw new NullPointerException("firstName is null"); //NOI18N @@ -291,24 +289,24 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement } // 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 @@ -316,156 +314,291 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // Clear this bean this.clear(); - - // Return outcome - return "admin_list_contact"; //NOI18N } - @Override - public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { - // event should not be null + /** + * Observer for events being fired when a bean helper has successfully + * created a contact instance. + *

+ * @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 - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedUser() == null) { // Throw NPE again - throw new NullPointerException("event.addedUser is null"); //NOI18N - } else if (event.getAddedUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.addedUser.userId is null"); //NOI18N - } else if (event.getAddedUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N - } - - // Clear all data - this.clear(); - } - - @Override - public void copyContactToController (final Contact contact) { - // The contact instance must be valid - if (null == contact) { + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getCreatedContact() == null) { // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { + throw new NullPointerException("event.createdContact is null"); //NOI18N + } else if (event.getCreatedContact().getContactId() == null) { // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { + 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.setTitle(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.setGender(contact.getContactGender()); - this.setHouseNumber(contact.getContactHouseNumber()); - this.setHouseNumberExtension(contact.getContactHouseNumberExtension()); - this.setStreet(contact.getContactStreet()); - this.setZipCode(contact.getContactZipCode()); - - // ... mobile data - if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - this.setMobileNumberId(contact.getContactMobileNumber().getPhoneId()); - this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider()); - this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber()); + 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()); } - // ... fax data - if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - this.setFaxNumberId(contact.getContactFaxNumber().getPhoneId()); - this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode()); - this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry()); - this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber()); + // 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()); } - // .. land-line data - if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - this.setLandLineId(contact.getContactLandLineNumber().getPhoneId()); - this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode()); - this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry()); - this.setLandLineNumber(contact.getContactLandLineNumber().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 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 - Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); + 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 + } - // Update all data in contact - this.updateContactData(contact); + // 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 contact; + return localContact; } - @Override - public String deleteContactData (final Contact contact) { - // The instance must be valid - if (null == contact) { + /** + * 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("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw it again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + 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())); } - // Call EJB - this.adminContactBean.deleteContactData(contact); + 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(contact)); + this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact())); - // All fine - return "admin_list_contact"; //NOI18N + // Return to list view + return "admin_list_contacts"; } - @Override - public String editContactData () { + /** + * 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 - } else if (contact.getContactId() < 1) { + } 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); + + // Init updated contact instance + final Contact updatedContact; - // Call EJB for updating contact data - Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); + 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. + *

+ * @param mobileNumber Mobile number + *

+ * @return Text representation or null + */ public String generateMobileNumber (final DialableMobileNumber mobileNumber) { // Is it null? if (null == mobileNumber) { @@ -474,18 +607,25 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement } // 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. + *

+ * @param phoneNumber Land-line or fax number + *

+ * @return Text representation or null + */ public String generatePhoneNumber (final DialableNumber phoneNumber) { // Is it null? if (null == phoneNumber) { @@ -494,285 +634,517 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement } // 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 + *

+ * @return Academic title + */ + public String getAcademicTitle () { + return this.academicTitle; + } + + /** + * Setter for academic title + *

+ * @param academicTitle Academic title + */ + public void setAcademicTitle (final String academicTitle) { + this.academicTitle = academicTitle; + } + + /** + * Getter for birth day + *

+ * @return Birth day + */ @SuppressWarnings ("ReturnOfDateField") public Date getBirthday () { return this.birthday; } - @Override + /** + * Setter for birth day + *

+ * @param birthday Birth day + */ @SuppressWarnings ("AssignmentToDateFieldFromParameter") public void setBirthday (final Date birthday) { this.birthday = birthday; } - @Override + /** + * Getter for city name + *

+ * @return City name + */ public String getCity () { return this.city; } - @Override + /** + * Setter for city name + *

+ * @param city City name + */ public void setCity (final String city) { this.city = city; } - @Override + /** + * Getter for comments + *

+ * @return Comments + */ public String getComment () { return this.comment; } - @Override + /** + * Setter for comment + *

+ * @param comment Comments + */ public void setComment (final String comment) { this.comment = comment; } - @Override - public Long getContactId () { - return this.contactId; + /** + * Getter for contact instance + *

+ * @return Contact instance + */ + public Contact getContact () { + return this.contact; } - @Override - public void setContactId (final Long contactId) { - this.contactId = contactId; + /** + * Setter for contact instance + *

+ * @param contact Contact instance + */ + public void setContact (final Contact contact) { + this.contact = contact; } - @Override - public String getControllerType () { - return "admin"; //NOI18N + /** + * Getter for contactCountry instance + *

+ * @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 + *

+ * @param contactCountry Country instance + */ + public void setContactCountry (final Country contactCountry) { + this.contactCountry = contactCountry; } - @Override - public Country getCountry () { - return this.country; + /** + * Getter for contact id + *

+ * @return Contact id + */ + public Long getContactId () { + return this.contactId; } - @Override - public void setCountry (final Country country) { - this.country = country; + /** + * Setter for contact id + *

+ * @param contactId Contact id + */ + public void setContactId (final Long contactId) { + this.contactId = contactId; } @Override + public String getControllerType () { + return "admin"; //NOI18N + } + + /** + * Getter for email address + *

+ * @return Email address + */ public String getEmailAddress () { return this.emailAddress; } - @Override + /** + * Setter for email address + *

+ * @param emailAddress Email address + */ public void setEmailAddress (final String emailAddress) { this.emailAddress = emailAddress; } - @Override + /** + * Family name + *

+ * @return the familyName + */ public String getFamilyName () { return this.familyName; } - @Override + /** + * Family name + *

+ * @param familyName the familyName to set + */ public void setFamilyName (final String familyName) { this.familyName = familyName; } - @Override + /** + * Getter for fax number's area code + *

+ * @return Fax number's area code + */ public Integer getFaxAreaCode () { return this.faxAreaCode; } - @Override + /** + * Setter for fax number's area code + *

+ * @param faxAreaCode Fax number's area code + */ public void setFaxAreaCode (final Integer faxAreaCode) { this.faxAreaCode = faxAreaCode; } - @Override + /** + * Getter for fax's country instance + *

+ * @return Fax' country instance + */ public Country getFaxCountry () { return this.faxCountry; } - @Override + /** + * Setter for fax's country instance + *

+ * @param faxCountry Fax' country instance + */ public void setFaxCountry (final Country faxCountry) { this.faxCountry = faxCountry; } - @Override - public Long getFaxNumber () { - return this.faxNumber; + /** + * Getter for fax id + *

+ * @return Fax id + */ + public Long getFaxId () { + return this.faxId; } - @Override - public void setFaxNumber (final Long faxNumber) { - this.faxNumber = faxNumber; + /** + * Setter for fax id + *

+ * @param faxId Fax id + */ + public void setFaxId (final Long faxId) { + this.faxId = faxId; } - @Override - public Long getFaxNumberId () { - return this.faxNumberId; + /** + * Getter for fax number + *

+ * @return Fax number + */ + public Long getFaxNumber () { + return this.faxNumber; } - @Override - public void setFaxNumberId (final Long faxNumberId) { - this.faxNumberId = faxNumberId; + /** + * Setter for fax number + *

+ * @param faxNumber Fax number + */ + public void setFaxNumber (final Long faxNumber) { + this.faxNumber = faxNumber; } - @Override + /** + * Getter for first name + *

+ * @return First name + */ public String getFirstName () { return this.firstName; } - @Override + /** + * Setter for first name + *

+ * @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 + *

+ * @return House number + */ public Short getHouseNumber () { return this.houseNumber; } - @Override + /** + * Setter for house number + *

+ * @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. + *

+ * @return House number extension + */ public String getHouseNumberExtension () { return this.houseNumberExtension; } - @Override + /** + * Setter for house number extension + *

+ * @param houseNumberExtension House number extension + */ public void setHouseNumberExtension (final String houseNumberExtension) { this.houseNumberExtension = houseNumberExtension; } - @Override + /** + * Getter for land-line number's area code + *

+ * @return Land-line number's area code + */ public Integer getLandLineAreaCode () { return this.landLineAreaCode; } - @Override + /** + * Setter for land-line number's area code + *

+ * @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 + *

+ * @return Land-line number's country instance + */ public Country getLandLineCountry () { return this.landLineCountry; } - @Override + /** + * Setter for land-line number's country instance + *

+ * @param landLineCountry Land-line number's country instance + */ public void setLandLineCountry (final Country landLineCountry) { this.landLineCountry = landLineCountry; } - @Override + /** + * Getter for land-line id + *

+ * @return Land-line id + */ public Long getLandLineId () { return this.landLineId; } - @Override + /** + * Setter for land-line id + *

+ * @param landLineId Land-line id + */ public void setLandLineId (final Long landLineId) { this.landLineId = landLineId; } - @Override + /** + * Getter for land-line number + *

+ * @return Land-line number + */ public Long getLandLineNumber () { return this.landLineNumber; } - @Override + /** + * Setter for land-line number + *

+ * @param landLineNumber Land-line number + */ public void setLandLineNumber (final Long landLineNumber) { this.landLineNumber = landLineNumber; } - @Override - public Long getMobileNumber () { - return this.mobileNumber; + /** + * Getter for mobile id + *

+ * @return Mobile id + */ + public Long getMobileId () { + return this.mobileId; } - @Override - public void setMobileNumber (Long mobileNumber) { - this.mobileNumber = mobileNumber; + /** + * Setter for mobile id + *

+ * @param mobileId Mobile id + */ + public void setMobileId (final Long mobileId) { + this.mobileId = mobileId; } - @Override - public Long getMobileNumberId () { - return this.mobileNumberId; + /** + * Getter for mobile number + *

+ * @return Mobile number + */ + public Long getMobileNumber () { + return this.mobileNumber; } - @Override - public void setMobileNumberId (final Long mobileNumberId) { - this.mobileNumberId = mobileNumberId; + /** + * Setter for mobile number + *

+ * @param mobileNumber Mobile number + */ + public void setMobileNumber (final Long mobileNumber) { + this.mobileNumber = mobileNumber; } - @Override + /** + * Getter for mobile number's carrier + *

+ * @return Mobile number's carrier + */ public MobileProvider getMobileProvider () { return this.mobileProvider; } - @Override + /** + * Setter for mobile number's carrier prefix + *

+ * @param mobileProvider Mobile number's carrier prefix + */ public void setMobileProvider (final MobileProvider mobileProvider) { this.mobileProvider = mobileProvider; } - @Override - public String getStreet () { - return this.street; + /** + * Getter for personal title + *

+ * @return Personal title + */ + public PersonalTitle getPersonalTitle () { + return this.personalTitle; } - @Override - public void setStreet (final String street) { - this.street = street; + /** + * Setter for personal title + *

+ * @param personalTitle Personal title + */ + public void setPersonalTitle (final PersonalTitle personalTitle) { + this.personalTitle = personalTitle; } - @Override - public String getTitle () { - return this.title; + /** + * Getter for street name + *

+ * @return Street name + */ + public String getStreet () { + return this.street; } - @Override - public void setTitle (final String title) { - this.title = title; + /** + * Setter for street name + *

+ * @param street Street name + */ + public void setStreet (final String street) { + this.street = street; } - @Override + /** + * Getter for ZIP code + *

+ * @return ZIP code + */ public Integer getZipCode () { return this.zipCode; } - @Override + /** + * Setter for ZIP code + *

+ * @param zipCode ZIP code + */ public void setZipCode (final Integer zipCode) { this.zipCode = zipCode; } - /** - * Post-initialization of this class - */ - @PostConstruct - public void init () { + @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 + } } /** @@ -780,9 +1152,10 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement */ private void clear () { // Clear all data + this.setContact(null); + // - personal data - this.setGender(null); - this.setTitle(null); + this.setAcademicTitle(null); this.setFirstName(null); this.setFamilyName(null); this.setStreet(null); @@ -790,7 +1163,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.setHouseNumberExtension(null); this.setZipCode(null); this.setCity(null); - this.setCountry(null); + this.setContactCountry(null); // - contact data this.setEmailAddress(null); @@ -808,37 +1181,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.setComment(null); } - /** - * Checks whether the given contact is found - *

- * @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 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. *

@@ -849,11 +1191,17 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement if (null == contact) { // Throw NPE throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE again + 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.setContactTitle(this.getTitle()); + contact.setContactPersonalTitle(this.getPersonalTitle()); + contact.setContactTitle(this.getAcademicTitle()); contact.setContactFirstName(this.getFirstName()); contact.setContactFamilyName(this.getFamilyName()); contact.setContactStreet(this.getStreet()); @@ -861,19 +1209,16 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement contact.setContactHouseNumberExtension(this.getHouseNumberExtension()); contact.setContactZipCode(this.getZipCode()); contact.setContactCity(this.getCity()); - contact.setContactCountry(this.getCountry()); - contact.setContactEmailAddress(this.getEmailAddress()); - contact.setContactBirthday(this.getBirthday()); - contact.setContactComment(this.getComment()); + contact.setContactCountry(this.getContactCountry()); - // Update contact's mobile number - this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber()); + // 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.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); + 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()); } }