@Override @Transactional("blTransactionManager") public Customer deleteCustomerPaymentFromCustomer(Customer customer, CustomerPayment payment) { List<CustomerPayment> payments = customer.getCustomerPayments(); for (CustomerPayment customerPayment : payments) { if (customerPayment.getId().equals(payment.getId())) { customer.getCustomerPayments().remove(customerPayment); break; } } return customerService.saveCustomer(customer); }
@Override public void addCustomerAttributeToCustomer(Long customerId, String customerAttributeKey, String customerAttributeValue) throws PaymentException { Customer currentCustomer = CustomerState.getCustomer(); Long currentCustomerId = currentCustomer.getId(); if (customerId != null && !currentCustomerId.equals(customerId)) { logWarningIfCustomerMismatch(currentCustomerId, customerId); currentCustomer = customerService.readCustomerById(customerId); } CustomerAttribute customerAttribute = new CustomerAttributeImpl(); customerAttribute.setName(customerAttributeKey); customerAttribute.setValue(customerAttributeValue); customerAttribute.setCustomer(currentCustomer); currentCustomer.getCustomerAttributes().put(customerAttributeKey, customerAttribute); customerService.saveCustomer(currentCustomer); }
@Test(groups = { "getOrdersForCustomer" }, dependsOnGroups = { "readCustomer", "findCurrentCartForCustomer" }) @Transactional public void getOrdersForCustomer() { String username = "customer1"; Customer customer = customerService.readCustomerByUsername(username); List<Order> orders = orderService.findOrdersForCustomer(customer); assert orders != null; assert orders.size() > 0; }
@Test(groups = { "changeCustomerPassword" }, dependsOnGroups = { "readCustomer" }) @Transactional @Commit public void changeCustomerPasswords() { for (String userName : userNames) { Customer customer = customerService.readCustomerByUsername(userName); customer.setPassword(customer.getPassword() + "-Changed"); customerService.saveCustomer(customer); } }
Customer customer = customerService.readCustomerById(Long.valueOf(customerId)); if (customer != null) { CustomerState.setCustomer(customer); ServletWebRequest servletWebRequest = new ServletWebRequest(request, (HttpServletResponse)servletResponse); BroadleafRequestContext.getBroadleafRequestContext().setWebRequest(servletWebRequest); Customer customer = this.customerService.createCustomer(); CustomerState.setCustomer(customer); setupCustomerForRuleProcessing(customer, request);
@Test(groups = { "readCustomer" }, dependsOnGroups = { "createCustomers", "createCustomerIdGeneration" }) public void readCustomersById() { for (Long userId : userIds) { Customer customer = customerService.readCustomerById(userId); assert customer.getId() == userId; } }
@Test(groups = { "testNamedOrderForCustomer" }, dependsOnGroups = { "testOrderProperties" }) public void testNamedOrderForCustomer() throws PricingException { Customer customer = customerService.createCustomerFromId(null); customer = customerService.saveCustomer(customer); Order order = orderService.createNamedOrderForCustomer("Birthday Order", customer); Long orderId = order.getId(); assert order != null; assert order.getName().equals("Birthday Order"); assert order.getCustomer().equals(customer); orderService.cancelOrder(order); assert orderService.findOrderById(orderId) == null; }
.filter(customerName -> isNull(customerService.readCustomerByUsername(customerName))) .orElseThrow(() -> new ResourceNotFoundException("Username already taken, please try with other")); .filter(e -> isNull(customerService.readCustomerByEmail(e))) .orElseThrow(() -> new ResourceNotFoundException("Email address already taken, please try with other")); final Customer customer = customerService.readCustomerById(customerUserDetails.getId()); customer.setUsername(username); customer.setEmailAddress(email); customerService.registerCustomer(customer, password, passwordConfirm);
customer = customerService.readCustomerById(overrideId); if (customer != null && !customer.isRegistered() && !customer.isLoggedIn() && !customer.isCookied()) { customer.setAnonymous(true); if (userName != null && (customer == null || !userName.equals(customer.getUsername()))) { customer = customerService.readCustomerByUsername(userName); if (logger.isDebugEnabled() && customer != null) { logger.debug("Customer found by username " + userName);
public Customer createCustomer() { Customer customer = customerService.createCustomerFromId(null); return customer; }
@Override public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); Customer customer = customerService.readCustomerByUsername(entity.findProperty("username").getValue()); if (StringUtils.isEmpty(customer.getEmailAddress())) { throw new ServiceException("Unable to update password because an email address is not available for this customer. An email address is required to send the customer the new system generated password."); } PasswordReset passwordReset = new PasswordReset(); passwordReset.setUsername(entity.findProperty("username").getValue()); passwordReset.setPasswordChangeRequired(false); passwordReset.setEmail(customer.getEmailAddress()); passwordReset.setPasswordLength(22); passwordReset.setSendResetEmailReliableAsync(false); customer = customerService.resetPassword(passwordReset); return entity; }
public Customer createAnonymousCustomer() throws DataAccessException { Customer customer = customerService.createNewCustomer(); customer.setUsername(String.valueOf(customer.getId())); customer.setPassword(RandomStringUtils.randomAscii(8)); return customerService.saveCustomer(customer); }
@Override public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance(); adminInstance.setId(customerService.findNextCustomerId()); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); if (customerService.readCustomerByUsername(adminInstance.getUsername()) != null) { Entity error = new Entity(); error.addValidationError("username", "nonUniqueUsernameError"); return error; } adminInstance = (Customer) dynamicEntityDao.merge(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { LOG.error("Unable to execute persistence activity", e); throw new ServiceException("Unable to add entity for " + entity.getType()[0], e); } }
@RequestMapping(value="registerCustomer", method = { RequestMethod.POST }) public ModelAndView registerCustomer(@ModelAttribute("registerCustomerForm") RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response) { registerCustomerValidator.validate(registerCustomerForm, errors); if (! errors.hasErrors()) { customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm()); loginService.loginCustomer(registerCustomerForm.getCustomer()); return new ModelAndView(getRegistrationSuccessView()); } else { return new ModelAndView(getRegistrationErrorView()); } }
@ModelAttribute("registerCustomerForm") public RegisterCustomerForm initCustomerRegistrationForm() { RegisterCustomerForm customerRegistrationForm = new RegisterCustomerForm(); Customer customer = customerService.createNewCustomer(); customerRegistrationForm.setCustomer(customer); return customerRegistrationForm; }
public void validate(UpdateAccountForm form, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); if (!errors.hasErrors()) { //is this a valid email address? if (!GenericValidator.isEmail(form.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid"); } //check email address to see if it is already in use by another customer Customer customerMatchingNewEmail = customerService.readCustomerByEmail(form.getEmailAddress()); if (customerMatchingNewEmail != null && !CustomerState.getCustomer().getId().equals(customerMatchingNewEmail.getId())) { //customer found with new email entered, and it is not the current customer errors.rejectValue("emailAddress", "emailAddress.used"); } } }
@Override public Customer createEntity(final CustomerDto customerDto) { return updateEntity(customerService.createCustomer(), customerDto); }
@Override public String retrieveCustomerAttributeFromCustomer(Long customerId, String customerAttributeKey) { Customer currentCustomer = CustomerState.getCustomer(); Long currentCustomerId = currentCustomer.getId(); if (customerId != null && !currentCustomerId.equals(customerId)) { logWarningIfCustomerMismatch(currentCustomerId, customerId); currentCustomer = customerService.readCustomerById(customerId); } if (currentCustomer.getCustomerAttributes().containsKey(customerAttributeKey)) { return currentCustomer.getCustomerAttributes().get(customerAttributeKey).getValue(); } return null; }
@Test(groups = "createCustomers", dependsOnGroups="createCustomerIdGeneration", dataProvider = "setupCustomers", dataProviderClass = CustomerDataProvider.class) @Rollback(false) public void createCustomer(Customer customerInfo) { Customer customer = customerService.createCustomerFromId(null); customer.setPassword(customerInfo.getPassword()); customer.setUsername(customerInfo.getUsername()); Long customerId = customer.getId(); assert customerId != null; customer = customerService.saveCustomer(customer); assert customer.getId() == customerId; userIds.add(customer.getId()); userNames.add(customer.getUsername()); }
customer = customerService.readCustomerById(overrideId); } else { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (userName != null && (customer == null || !userName.equals(customer.getUsername()))) { customer = customerService.readCustomerByUsername(userName); if (logger.isDebugEnabled() && customer != null) { logger.debug("Customer found by username " + userName);