import javax.persistence.Query;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException;
import org.mxchange.jcustomercore.model.customer.Customer;
import org.mxchange.jcustomercore.utils.CustomerUtils;
import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
* Contact instance
*/
@EJB
- private ContactSessionBeanRemote customerBean;
+ private ContactSessionBeanRemote contactBean;
+
+ /**
+ * General customer bean
+ */
+ @EJB
+ private RateCalcCustomerSessionBeanRemote customerBean;
@Override
- public Customer addCustomer (final Customer customer) {
+ public Customer addCustomer (final Customer customer) throws CustomerAlreadyRegisteredException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("addCustomer: customer={0} - CALLED!", customer)); //NOI18N
} else if (customer.getCustomerNumber().length() < RateCalcAdminCustomerSessionBeanRemote.CUSTOMER_NUMBER_LENGTH) {
// To short number
throw new IllegalArgumentException(MessageFormat.format("customer.customerNumber.length={0} is shorter than expected: {1}", customer.getCustomerNumber().length(), RateCalcAdminCustomerSessionBeanRemote.CUSTOMER_NUMBER_LENGTH)); //NOI18N
+ } else if (this.customerBean.isReqistered(customer)) {
+ // Throw exception
+ throw new CustomerAlreadyRegisteredException(customer);
}
// Get contact instance
Contact updatedContact = null;
// Is a customer found?
- if (this.customerBean.isContactFound(contact)) {
+ if (this.contactBean.isContactFound(contact)) {
// Yes, then get updated version
- updatedContact = this.customerBean.updateContactData(contact);
+ updatedContact = this.contactBean.updateContactData(contact);
// Remove it from customer so it won't get persisted again
customer.setCustomerContact(null);