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.context.FacesContext;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jcontacts.contact.utils.ContactUtils;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-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.jjobs.beans.helper.JobsWebRequestHelperController;
import org.mxchange.jphone.phonenumbers.DialableNumber;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
/**
* An administrative user controller (bean)
private AdminContactSessionBeanRemote adminContactBean;
/**
- * Bean helper
+ * Bean helper instance
*/
@Inject
private JobsWebRequestHelperController beanHelper;
private String comment;
/**
- * General contact EJB
+ * Remote contact bean
*/
private ContactSessionBeanRemote contactBean;
*/
private Country country;
- /**
- * Event being fired when contact data has been deleted
- */
- @Inject
- @Any
- private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
-
/**
* Email address
*/
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 boolean isLandLineUnlinked;
/**
- * Whether a mobile entry has been unlinked
+ * Whether a cellphone 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;
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;
return "admin_list_contact"; //NOI18N
}
- @Override
- public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent 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) {
+ // Log message
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
+
// 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
+ 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
this.setStreet(contact.getContactStreet());
this.setZipCode(contact.getContactZipCode());
- // ... mobile data
+ // Is the cell phone set?
if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- this.setMobileNumberId(contact.getContactMobileNumber().getPhoneId());
+ // ... cellphone data
+ this.setMobileId(contact.getContactMobileNumber().getPhoneId());
this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
}
- // ... fax data
+ // Is the fax set?
if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
- this.setFaxNumberId(contact.getContactFaxNumber().getPhoneId());
+ // ... 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
+ // Is the land-line number set?
if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // .. land-line data
this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
}
+
+ // Log message
+ //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
}
@Override
public Contact createContactInstance () {
+ // Are all minimum fields set?
+ if (this.getGender() == null) {
+ // Throw NPE
+ throw new NullPointerException("gender 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 = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+ DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+
// Create new instance
Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
- // Update all data in contact
- this.updateContactData(contact);
+ // Add all others
+ contact.setContactBirthday(this.getBirthday());
+ contact.setContactStreet(this.getStreet());
+ contact.setContactHouseNumber(this.getHouseNumber());
+ contact.setContactZipCode(this.getZipCode());
+ contact.setContactCity(this.getCity());
+ contact.setContactCountry(this.getCountry());
+ contact.setContactEmailAddress(this.getEmailAddress());
+ contact.setContactBirthday(this.getBirthday());
+ contact.setContactComment(this.getComment());
- // Return it
- return contact;
- }
+ // Set ownContact
+ contact.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
+ }
- @Override
- public String deleteContactData (final Contact contact) {
- // The instance must be valid
- if (null == contact) {
- // 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
+ // Set phone number
+ contact.setContactLandLineNumber(landLine);
}
- // Call EJB
- this.adminContactBean.deleteContactData(contact);
+ // 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
+ }
- // Fire event
- this.deletedContactEvent.fire(new AdminDeletedContactEvent(contact));
+ // Set fax number
+ contact.setContactFaxNumber(fax);
+ }
- // All fine
- return "admin_list_contact"; //NOI18N
+ // Is the provider set?
+ if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
+ // Is the number set?
+ if (mobile.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
+ } else if (mobile.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set cellphone number
+ contact.setContactMobileNumber(mobile);
+ }
+
+ // Return it
+ return contact;
}
@Override
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
+ throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
} else if (contact.getContactId() < 1) {
// Invalid id
throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
this.updateContactData(contact);
// Call EJB for updating contact data
- Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
// Fire event
this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
}
@Override
- public Long getFaxNumber () {
- return this.faxNumber;
+ public Long getFaxId () {
+ return this.faxId;
}
@Override
- public void setFaxNumber (final Long faxNumber) {
- this.faxNumber = faxNumber;
+ public void setFaxId (final Long faxId) {
+ this.faxId = faxId;
}
@Override
- public Long getFaxNumberId () {
- return this.faxNumberId;
+ public Long getFaxNumber () {
+ return this.faxNumber;
}
@Override
- public void setFaxNumberId (final Long faxNumberId) {
- this.faxNumberId = faxNumberId;
+ public void setFaxNumber (final Long faxNumber) {
+ this.faxNumber = faxNumber;
}
@Override
}
@Override
- public Long getMobileNumber () {
- return this.mobileNumber;
+ public Long getMobileId () {
+ return this.mobileId;
}
@Override
- public void setMobileNumber (Long mobileNumber) {
- this.mobileNumber = mobileNumber;
+ public void setMobileId (final Long mobileId) {
+ this.mobileId = mobileId;
}
@Override
- public Long getMobileNumberId () {
- return this.mobileNumberId;
+ public Long getMobileNumber () {
+ return this.mobileNumber;
}
@Override
- public void setMobileNumberId (final Long mobileNumberId) {
- this.mobileNumberId = mobileNumberId;
+ public void setMobileNumber (Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
}
@Override
// 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
+ this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-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
+ this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
}
}
+ @Override
+ public boolean isGenderRequired () {
+ // Get context parameter
+ String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_gender_enabled"); //NOI18N
+
+ // Is it set?
+ boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
+
+ // Return value
+ return isRequired;
+ }
+
/**
* Clears this bean
*/
private void clear () {
// Clear all data
// - personal data
- this.setGender(null);
this.setTitle(null);
this.setFirstName(null);
this.setFamilyName(null);
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
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 mobile number
- this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
+ // Update contact's cellphone number
+ this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
// Update contact's land-line number
this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
private boolean isMobileUnlinked;
/**
- * Mobile number's carrier
+ * Phone number area code
*/
- private MobileProvider mobileCarrier;
+ private Integer landLineAreaCode;
/**
- * Mobile number
+ * Country instance for phone number
*/
- private Long mobileNumber;
+ private Country landLineCountry;
/**
- * Phone number area code
+ * Phone number
*/
- private Integer phoneAreaCode;
+ private Long landLineNumber;
/**
- * Country instance for phone number
+ * Mobile number
*/
- private Country phoneCountry;
+ private Long mobileNumber;
/**
- * Phone number
+ * Mobile number's carrier
*/
- private Long phoneNumber;
+ private MobileProvider mobileProvider;
/**
* A list of all selectable contacts
assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
// Generate phone number
- DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
- DialableMobileNumber mobile = new MobileNumber(this.getMobileCarrier(), this.getMobileNumber());
+ DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
// Create new contact
contact.setContactComment(this.getComment());
// Don't set null or wrong references
- if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
+ if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
// Now the number must be given
if (phone.getPhoneAreaCode() == null) {
// Is null
}
// Is the provider set?
- if ((mobile instanceof DialableMobileNumber) && (this.getMobileCarrier() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
+ if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
// Is the number set?
if (mobile.getPhoneNumber() == null) {
// Is null
contact.setContactCountry(this.getCountry());
// Update contact's mobile number
- this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileCarrier(), this.getMobileNumber());
+ this.isMobileUnlinked = ContactUtils.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 = 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());
}
@Override
- public MobileProvider getMobileCarrier () {
- return this.mobileCarrier;
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
}
@Override
- public void setMobileCarrier (final MobileProvider mobileCarrier) {
- this.mobileCarrier = mobileCarrier;
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
}
@Override
- public Long getMobileNumber () {
- return this.mobileNumber;
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
}
@Override
- public void setMobileNumber (final Long mobileNumber) {
- this.mobileNumber = mobileNumber;
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
}
@Override
- public Integer getPhoneAreaCode () {
- return this.phoneAreaCode;
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
}
@Override
- public void setPhoneAreaCode (final Integer phoneAreaCode) {
- this.phoneAreaCode = phoneAreaCode;
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
}
@Override
- public Country getPhoneCountry () {
- return this.phoneCountry;
+ public Long getMobileNumber () {
+ return this.mobileNumber;
}
@Override
- public void setPhoneCountry (final Country phoneCountry) {
- this.phoneCountry = phoneCountry;
+ public void setMobileNumber (final Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
}
@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
// - contact data
this.setEmailAddress(null);
this.setEmailAddressRepeat(null);
- this.setPhoneAreaCode(null);
- this.setPhoneCountry(null);
- this.setPhoneNumber(null);
- this.setMobileCarrier(null);
+ this.setLandLineAreaCode(null);
+ this.setLandLineCountry(null);
+ this.setLandLineNumber(null);
+ this.setMobileProvider(null);
this.setMobileNumber(null);
this.setFaxAreaCode(null);
this.setFaxCountry(null);
// - contact data
if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
- this.setPhoneCountry(phone.getPhoneCountry());
- this.setPhoneAreaCode(phone.getPhoneAreaCode());
- this.setPhoneNumber(phone.getPhoneNumber());
+ this.setLandLineCountry(phone.getPhoneCountry());
+ this.setLandLineAreaCode(phone.getPhoneAreaCode());
+ this.setLandLineNumber(phone.getPhoneNumber());
}
if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
- this.setMobileCarrier(mobile.getMobileProvider());
+ this.setMobileProvider(mobile.getMobileProvider());
this.setMobileNumber(mobile.getPhoneNumber());
}