X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fcontact%2FJobsAdminContactWebRequestBean.java;h=f5f168a94f6a491b8565bf6be4915de5852e6627;hb=09d2137f89da9234cd2fed7af9021b24c3934662;hp=420ae887f41aa29503460a7df71b17e902553738;hpb=c5081875aa28935bb1a02e5c4713ed6209eee1f4;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 420ae887..f5f168a9 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java @@ -22,6 +22,7 @@ import java.util.Iterator; import javax.annotation.PostConstruct; 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.inject.Inject; @@ -29,6 +30,7 @@ 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; @@ -36,23 +38,23 @@ 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.add.AdminContactAddedEvent; +import org.mxchange.jcontacts.events.contact.deleted.AdminContactDeletedEvent; +import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent; 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.JobsWebRequestController; +import org.mxchange.jjobs.beans.helper.JobsWebViewHelperController; import org.mxchange.jphone.phonenumbers.DialableNumber; -import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; 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.mobileprovider.MobileProvider; +import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; /** - * An administrative user bean (controller) + * An administrative user controller (bean) *

* @author Roland Haeder */ @@ -73,30 +75,20 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private Event addedContactEvent; /** - * Admin helper instance + * Administrative contact EJB */ - @Inject - private JobsWebRequestController beanHelper; - - /** - * Birth day - */ - private Date birthday; - - /** - * Cellphone number's carrier - */ - private MobileProvider cellphoneCarrier; + private AdminContactSessionBeanRemote adminContactBean; /** - * Cellphone id number + * Bean helper */ - private Long cellphoneId; + @Inject + private JobsWebViewHelperController beanHelper; /** - * Cellphone number + * Birth day */ - private Long cellphoneNumber; + private Date birthday; /** * City @@ -109,7 +101,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private String comment; /** - * Remote contact bean + * General contact EJB */ private final ContactSessionBeanRemote contactBean; @@ -129,6 +121,13 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement */ private Country country; + /** + * Event being fired when contact data has been deleted + */ + @Inject + @Any + private Event deletedContactEvent; + /** * Email address */ @@ -150,14 +149,14 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement private Country faxCountry; /** - * Fax id number + * Fax number */ - private Long faxId; + private Long faxNumber; /** - * Fax number + * Fax id number */ - private Long faxNumber; + private Long faxNumberId; /** * First name @@ -179,11 +178,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement */ private String houseNumberExtension; - /** - * Whether a cellphone entry has been unlinked - */ - private boolean isCellphoneUnlinked; - /** * Whether a fax entry has been unlinked */ @@ -194,25 +188,45 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement */ private boolean isLandLineUnlinked; + /** + * Whether a mobile entry has been unlinked + */ + private boolean isMobileUnlinked; + + /** + * Land-line number area code + */ + private Integer landLineAreaCode; + + /** + * Country instance for land-line number + */ + private Country landLineCountry; + /** * Land-line id number */ private Long landLineId; /** - * Phone number area code + * Land-line number + */ + private Long landLineNumber; + + /** + * Mobile number */ - private Integer phoneAreaCode; + private Long mobileNumber; /** - * Country instance for phone number + * Mobile id number */ - private Country phoneCountry; + private Long mobileNumberId; /** - * Phone number + * Mobile provider */ - private Long phoneNumber; + private MobileProvider mobileProvider; /** * Street @@ -245,8 +259,11 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // Get initial context Context context = new InitialContext(); - // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + // 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); @@ -288,7 +305,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // Try to call EJB try { // Call EJB - updatedContact = this.contactBean.addContact(contact); + updatedContact = this.adminContactBean.addContact(contact); } catch (final ContactAlreadyAddedException ex) { // Throw again throw new FaceletException(ex); @@ -304,6 +321,27 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement return "admin_list_contact"; //NOI18N } + @Override + public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Clear all data + this.clear(); + } + @Override public void copyContactToController (final Contact contact) { // The contact instance must be valid @@ -312,7 +350,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement 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) { // Not valid throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N @@ -334,16 +372,16 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.setStreet(contact.getContactStreet()); this.setZipCode(contact.getContactZipCode()); - // ... cellphone data - if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) { - this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId()); - this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider()); - this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber()); + // ... mobile data + if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + this.setMobileNumberId(contact.getContactMobileNumber().getPhoneId()); + this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider()); + this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber()); } // ... fax data if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - this.setFaxId(contact.getContactFaxNumber().getPhoneId()); + this.setFaxNumberId(contact.getContactFaxNumber().getPhoneId()); this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode()); this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry()); this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber()); @@ -352,48 +390,46 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // .. land-line data if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { this.setLandLineId(contact.getContactLandLineNumber().getPhoneId()); - this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode()); - this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry()); - this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber()); + this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode()); + this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry()); + this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber()); } } @Override public Contact createContactInstance () { - // Generate phone number - DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber()); - DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); - // Create new instance Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); - // Check if contact instance is in helper and valid + // Update all data in contact + this.updateContactData(contact); + + // Return it + return contact; + } + + @Override + public String deleteContactData (final Contact contact) { + // The instance must be valid if (null == contact) { // Throw NPE - throw new NullPointerException("beanHelper.contact is null"); //NOI18N + throw new NullPointerException("contact is null"); //NOI18N } else if (contact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N + // Throw it again + throw new NullPointerException("contact.contactId is null"); //NOI18N } else if (contact.getContactId() < 1) { - // Invalid id - throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N } - // Update all data in contact - this.updateContactData(contact); - - // Call EJB for updating contact data - Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); + // Call EJB + this.adminContactBean.deleteContactData(contact); // Fire event - this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact)); + this.deletedContactEvent.fire(new AdminContactDeletedEvent(contact)); - // Clear bean - this.clear(); - - // Return it - return contact; + // All fine + return "admin_list_contact"; //NOI18N } @Override @@ -407,7 +443,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement throw new NullPointerException("beanHelper.contact is null"); //NOI18N } else if (contact.getContactId() == null) { // Throw NPE again - throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N + throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N } else if (contact.getContactId() < 1) { // Invalid id throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N @@ -417,7 +453,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.updateContactData(contact); // Call EJB for updating contact data - Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); + Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); // Fire event this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact)); @@ -430,9 +466,9 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement } @Override - public String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) { + public String generateMobileNumber (final DialableMobileNumber mobileNumber) { // Is it null? - if (null == cellphoneNumber) { + if (null == mobileNumber) { // Return null return null; } @@ -440,9 +476,9 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // Get all data String number = String.format( "%s%d%d", //NOI18N - cellphoneNumber.getCellphoneProvider().getProviderCountry().getCountryExternalDialPrefix(), - cellphoneNumber.getCellphoneProvider().getProviderDialPrefix(), - cellphoneNumber.getPhoneNumber() + mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(), + mobileNumber.getMobileProvider().getProviderDialPrefix(), + mobileNumber.getPhoneNumber() ); // Return it @@ -481,36 +517,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.birthday = birthday; } - @Override - public MobileProvider getCellphoneCarrier () { - return this.cellphoneCarrier; - } - - @Override - public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) { - this.cellphoneCarrier = cellphoneCarrier; - } - - @Override - public Long getCellphoneId () { - return this.cellphoneId; - } - - @Override - public void setCellphoneId (final Long cellphoneId) { - this.cellphoneId = cellphoneId; - } - - @Override - public Long getCellphoneNumber () { - return this.cellphoneNumber; - } - - @Override - public void setCellphoneNumber (Long cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - @Override public String getCity () { return this.city; @@ -541,6 +547,17 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.contactId = contactId; } + @Override + public String getControllerType () { + return "admin"; //NOI18N + } + + @Override + @Deprecated + public void setControllerType (final String controllerType) { + throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N + } + @Override public Country getCountry () { return this.country; @@ -592,23 +609,23 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement } @Override - public Long getFaxId () { - return this.faxId; + public Long getFaxNumber () { + return this.faxNumber; } @Override - public void setFaxId (final Long faxId) { - this.faxId = faxId; + public void setFaxNumber (final Long faxNumber) { + this.faxNumber = faxNumber; } @Override - public Long getFaxNumber () { - return this.faxNumber; + public Long getFaxNumberId () { + return this.faxNumberId; } @Override - public void setFaxNumber (final Long faxNumber) { - this.faxNumber = faxNumber; + public void setFaxNumberId (final Long faxNumberId) { + this.faxNumberId = faxNumberId; } @Override @@ -651,6 +668,26 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.houseNumberExtension = houseNumberExtension; } + @Override + public Integer getLandLineAreaCode () { + return this.landLineAreaCode; + } + + @Override + public void setLandLineAreaCode (final Integer landLineAreaCode) { + this.landLineAreaCode = landLineAreaCode; + } + + @Override + public Country getLandLineCountry () { + return this.landLineCountry; + } + + @Override + public void setLandLineCountry (final Country landLineCountry) { + this.landLineCountry = landLineCountry; + } + @Override public Long getLandLineId () { return this.landLineId; @@ -662,33 +699,43 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement } @Override - public Integer getPhoneAreaCode () { - return this.phoneAreaCode; + public Long getLandLineNumber () { + return this.landLineNumber; + } + + @Override + public void setLandLineNumber (final Long landLineNumber) { + this.landLineNumber = landLineNumber; + } + + @Override + public Long getMobileNumber () { + return this.mobileNumber; } @Override - public void setPhoneAreaCode (final Integer phoneAreaCode) { - this.phoneAreaCode = phoneAreaCode; + public void setMobileNumber (Long mobileNumber) { + this.mobileNumber = mobileNumber; } @Override - public Country getPhoneCountry () { - return this.phoneCountry; + public Long getMobileNumberId () { + return this.mobileNumberId; } @Override - public void setPhoneCountry (final Country phoneCountry) { - this.phoneCountry = phoneCountry; + public void setMobileNumberId (final Long mobileNumberId) { + this.mobileNumberId = mobileNumberId; } @Override - public Long getPhoneNumber () { - return this.phoneNumber; + public MobileProvider getMobileProvider () { + return this.mobileProvider; } @Override - public void setPhoneNumber (final Long phoneNumber) { - this.phoneNumber = phoneNumber; + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; } @Override @@ -747,11 +794,11 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // - contact data this.setEmailAddress(null); - this.setPhoneCountry(null); - this.setPhoneAreaCode(null); - this.setPhoneNumber(null); - this.setCellphoneCarrier(null); - this.setCellphoneNumber(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); @@ -802,12 +849,6 @@ 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 //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N } // Update all fields @@ -821,12 +862,15 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement contact.setContactZipCode(this.getZipCode()); contact.setContactCity(this.getCity()); contact.setContactCountry(this.getCountry()); + contact.setContactEmailAddress(this.getEmailAddress()); + contact.setContactBirthday(this.getBirthday()); + contact.setContactComment(this.getComment()); - // Update contact's cellphone number - this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber()); + // Update contact's mobile number + this.isMobileUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getMobileProvider(), this.getMobileNumber()); // Update contact's land-line number - this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); + this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); // Update contact's fax number this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());