use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class CommonSetupBaseTest method createCustomerWithBasicOrderAndAddresses.
/**
* Create a state, country, and customer with a basic order and some addresses
*/
public Customer createCustomerWithBasicOrderAndAddresses() {
Customer customer = createCustomerWithAddresses();
Order order = new OrderImpl();
order.setStatus(OrderStatus.IN_PROCESS);
order.setTotal(new Money(BigDecimal.valueOf(1000)));
assert order.getId() == null;
order.setCustomer(customer);
order = orderDao.save(order);
assert order.getId() != null;
return customer;
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class RegisterCustomerValidator method validate.
public void validate(Object obj, Errors errors, boolean useEmailForUsername) {
RegisterCustomerForm form = (RegisterCustomerForm) obj;
Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername());
if (customerFromDb != null && customerFromDb.isRegistered()) {
if (useEmailForUsername) {
errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null);
} else {
errors.rejectValue("customer.username", "username.used", null, null);
}
}
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required");
errors.pushNestedPath("customer");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
errors.popNestedPath();
if (!errors.hasErrors()) {
if (!form.getPassword().matches(getValidatePasswordExpression())) {
errors.rejectValue("password", "password.invalid", null, null);
}
if (!form.getPassword().equals(form.getPasswordConfirm())) {
errors.rejectValue("password", "passwordConfirm.invalid", null, null);
}
if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) {
errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null);
}
}
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class CustomerStateRefresher method onApplicationEvent.
/**
* Removes the complete {@link Customer} stored in session and adds a new session variable for just the customer ID. This
* should occur once the session-based {@link Customer} (all anonymous Customers start out this way) has been persisted.
*
* <p>Also updates {@link CustomerState} with the persisted {@link Customer} so that it will always represent the most
* up-to-date version that is in the database</p>
*
* @param request
* @param databaseCustomer
*/
@Override
public void onApplicationEvent(final CustomerPersistedEvent event) {
Customer dbCustomer = event.getCustomer();
// if there is an active request, remove the session-based customer if it exists and update CustomerState
WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
if (request != null) {
String customerAttribute = CustomerStateRequestProcessor.getAnonymousCustomerSessionAttributeName();
String customerIdAttribute = CustomerStateRequestProcessor.getAnonymousCustomerIdSessionAttributeName();
if (BLCRequestUtils.isOKtoUseSession(request)) {
Customer sessionCustomer = (Customer) request.getAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
// persisted
if (sessionCustomer != null && sessionCustomer.getId().equals(dbCustomer.getId())) {
request.removeAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
request.setAttribute(customerIdAttribute, dbCustomer.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
}
}
// Update CustomerState if the persisted Customer ID is the same
if (CustomerState.getCustomer() != null && CustomerState.getCustomer().getId().equals(dbCustomer.getId())) {
// Copy transient fields from the customer that existed in CustomerState, prior to the DB refresh,
// to the customer that has been saved (merged) in the DB....
Customer preMergedCustomer = CustomerState.getCustomer();
resetTransientFields(preMergedCustomer, dbCustomer);
CustomerState.setCustomer(dbCustomer);
}
}
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class RegisterCustomerControllerTest method createCustomerFromController.
@Test(groups = "createCustomerFromController", dataProvider = "setupCustomerControllerData", dataProviderClass = RegisterCustomerDataProvider.class, enabled = false)
@Transactional
@Rollback(false)
public void createCustomerFromController(RegisterCustomerForm registerCustomer) {
BindingResult errors = new BeanPropertyBindingResult(registerCustomer, "registerCustomer");
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
registerCustomerController.registerCustomer(registerCustomer, errors, request, response);
assert (errors.getErrorCount() == 0);
Customer customerFromDb = customerService.readCustomerByUsername(registerCustomer.getCustomer().getUsername());
assert (customerFromDb != null);
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class RegisterCustomerDataProvider method createCustomer.
@DataProvider(name = "setupCustomerControllerData")
public static Object[][] createCustomer() {
Customer customer = new CustomerImpl();
customer.setEmailAddress("testCase@test.com");
customer.setFirstName("TestFirstName");
customer.setLastName("TestLastName");
customer.setUsername("TestCase");
ChallengeQuestion question = new ChallengeQuestionImpl();
question.setId(1L);
customer.setChallengeQuestion(question);
customer.setChallengeAnswer("Challenge CandidateItemOfferAnswer");
RegisterCustomerForm registerCustomer = new RegisterCustomerForm();
registerCustomer.setCustomer(customer);
registerCustomer.setPassword("TestPassword");
registerCustomer.setPasswordConfirm("TestPassword");
return new Object[][] { new Object[] { registerCustomer } };
}
Aggregations