import javax.naming.NamingException;
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.update.AdminContactUpdatedEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
import org.mxchange.jcountry.data.Country;
+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.mobileprovider.MobileProvider;
import org.mxchange.pizzaapplication.beans.helper.PizzaAdminWebRequestController;
System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
}
+ @Override
+ public Contact createContactInstance () {
+ // User message
+ //this.getLogger().logTrace("createContactInstance: CALLED!");
+
+ // 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());
+
+ // 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());
+
+ // Set ownContact
+ contact.setContactOwnContact(Boolean.TRUE);
+
+ // 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)) {
+ // Now the number must be given
+ if (phone.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+ } else if (phone.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+ } else if (phone.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+ } else if (phone.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set phone number
+ contact.setContactLandLineNumber(phone);
+ }
+
+ // 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
+ contact.setContactFaxNumber(fax);
+ }
+
+ // Is the provider set?
+ if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
+ // Is the number set?
+ if (cellphone.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
+ } else if (cellphone.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set cellphone number
+ contact.setContactCellphoneNumber(cellphone);
+ }
+
+ // Trace message
+ //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
+
+ // Return it
+ return contact;
+ }
+
@Override
public Date getBirthday () {
return this.birthday;
// Required personal data must be set
assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
- // Create new contact instance
- Contact localContact = new UserContact();
-
// Generate phone number
DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
contact.setContactCity(this.getCity());
contact.setContactCountry(this.getCountry());
contact.setContactEmailAddress(this.getEmailAddress());
+ contact.setContactBirthday(this.getBirthday());
+ contact.setContactComment(this.getComment());
+
+ // Set ownContact
+ contact.setContactOwnContact(Boolean.TRUE);
// 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)) {
contact.setContactCellphoneNumber(cellphone);
}
- contact.setContactBirthday(this.getBirthday());
- contact.setContactComment(this.getComment());
-
- // Created timestamp and ownContact
- contact.setContactOwnContact(Boolean.TRUE);
-
// Trace message
//this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
// Return it
- return localContact;
+ return contact;
}
@Override
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.view.facelets.FaceletException;
+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.gender.Gender;
import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
+import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
import org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote;
/**
*/
private static final long serialVersionUID = 12_487_062_487_527_913L;
+ /**
+ * Administrative contact controller (for personal data)
+ */
+ @Inject
+ private PizzaAdminContactWebRequestController adminContactController;
+
/**
* Administrative customer EJB
*/
}
}
+ @Override
+ public String addCustomer () {
+ // Are at least some fields added?
+ if (!this.isCustomerDataSet()) {
+ // Not all customer data is set
+ throw new FaceletException("PLease provide minimum personal data: gender, first_name, family_name");
+ }
+
+ // Get contact instance
+ Contact contact = this.adminContactController.createContactInstance();
+
+ // Ask the EJB for a free customer number
+ String customerNumber = this.adminCustomerBean.createCustomerNumber();
+
+ // Create new customer instance
+ Customer customer = new PizzaCustomer(CustomerAccountStatus.CONFIRMED, contact, customerNumber);
+ }
+
@Override
public List<Customer> allCustomers () {
// Return it
this.customerList = this.adminCustomerBean.allCustomers();
}
+ /**
+ * Checks whether ther minimum customer data is set
+ * <p>
+ * @return Whether minimum data is set
+ */
+ private boolean isCustomerDataSet () {
+ // Check all
+ return ((this.adminContactController.getGender() instanceof Gender) &&
+ (this.adminContactController.getFirstName() != null) &&
+ (!this.adminContactController.getFirstName().isEmpty()) &&
+ (this.adminContactController.getFamilyName() != null) &&
+ (!this.adminContactController.getFamilyName().isEmpty()));
+ }
+
}