@Test(groups = { "readCustomer" }, dependsOnGroups = { "createCustomers", "createCustomerIdGeneration" }) public void readCustomersById() { for (Long userId : userIds) { Customer customer = customerService.readCustomerById(userId); assert customer.getId() == userId; } }
@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; }
Customer customer = customerService.readCustomerById(Long.valueOf(customerId)); if (customer != null) { CustomerState.setCustomer(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); }
customer = customerService.readCustomerById(overrideId); if (customer != null && !customer.isRegistered() && !customer.isLoggedIn() && !customer.isCookied()) { customer.setAnonymous(true);
Customer customer = customerService.readCustomerById(customerId); if (Status.class.isAssignableFrom(customer.getClass())) { ((Status) customer).setArchived('Y');
@Override public Long createCustomerPaymentFromResponseDTO(PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) throws IllegalArgumentException { validateResponseAndConfig(responseDTO, config); Long customerId = Long.parseLong(responseDTO.getCustomer().getCustomerId()); Customer customer = customerService.readCustomerById(customerId); if (customer != null) { if (isNewDefaultPaymentMethod(responseDTO)) { customerPaymentService.clearDefaultPaymentStatus(customer); } CustomerPayment customerPayment = customerPaymentService.create(); populateCustomerPayment(customerPayment, responseDTO, config); customerPayment.setCustomer(customer); customerPayment = customerPaymentService.saveCustomerPayment(customerPayment); customer.getCustomerPayments().add(customerPayment); return customerPayment.getId(); } return null; }
anonymousCustomer = customerService.readCustomerById(customerId);
Customer customer = customerService.readCustomerById(Long.valueOf(customerId)); if (customer != null) { CustomerState.setCustomer(customer);
@Transactional @RequestMapping(value = "/merge", method = RequestMethod.POST) @ApiOperation( value = "Merge carts", notes = "Merges anonymous cart with a logged in customer's cart", response = Void.class ) @ApiResponses(value = { @ApiResponse(code = 200, message = "Carts have been successfully merged", response = Void.class) }) public void mergeWithAnonymous( @ApiIgnore @AuthenticationPrincipal final CustomerUserDetails userDetails, @RequestBody final String anonymousToken) throws RemoveFromCartException, PricingException { final Customer loggedUser = customerService.readCustomerById(userDetails.getId()); final CustomerUserDetails anonymousUserDetails = (CustomerUserDetails) tokenServices.loadAuthentication (anonymousToken).getPrincipal(); final Customer anonymousUser = customerService.readCustomerById(anonymousUserDetails.getId()); final Order anonymousCart = orderService.findCartForCustomer(anonymousUser); mergeCartService.mergeCart(loggedUser, anonymousCart); }
.orElseThrow(() -> new ResourceNotFoundException("Email address already taken, please try with other")); final Customer customer = customerService.readCustomerById(customerUserDetails.getId()); customer.setUsername(username); customer.setEmailAddress(email);
@PostAuthorize("permitAll") @Transactional public List<Order> getOrdersByCustomer(final UserDetails userDetails) throws CustomerNotFoundException { return Match.of(userDetails) .whenType(AdminUserDetails.class).then(this::getAllOrders) .whenType(CustomerUserDetails.class).then(() -> { final Long id = ((CustomerUserDetails) userDetails).getId(); return Optional.ofNullable(customerService.readCustomerById(id)) .map(c -> orderService.findOrdersForCustomer(c)) .orElseThrow(() -> new CustomerNotFoundException(format("Cannot find customer with ID: %d", id))); }).otherwise(Collections::emptyList) .get(); }
customer = customerService.readCustomerById(overrideId); } else { Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
/** * Returns the anonymous customer that was saved in session. This first checks for a full customer in session (meaning * that the customer has not already been persisted) and returns that. If there is no full customer in session (and * there is instead just an anonymous customer ID) then this will look up the customer from the database using that and * return it. * * @param request the current request * @return the anonymous customer in session or null if there is no anonymous customer represented in session * @see {@link #getAnonymousCustomerSessionAttributeName()} * @see {@link #getAnonymousCustomerIdSessionAttributeName()} */ public Customer getAnonymousCustomer(WebRequest request) { if (BLCRequestUtils.isOKtoUseSession(request)) { Customer anonymousCustomer = (Customer) request.getAttribute(getAnonymousCustomerSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION); if (anonymousCustomer == null) { //Customer is not in session, see if we have just a customer ID in session (the anonymous customer might have //already been persisted) Long customerId = (Long) request.getAttribute(getAnonymousCustomerIdSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION); if (customerId != null) { //we have a customer ID in session, look up the customer from the database to ensure we have an up-to-date //customer to store in CustomerState anonymousCustomer = customerService.readCustomerById(customerId); } } return anonymousCustomer; } return null; }
protected void forceNewAuthenticationIfPrincipalIsNotValidForScope(User principal, Set<String> scopeSet) { for(String scope : scopeSet) { if (Scope.CUSTOMER.matches(scope)) { if ( !(principal instanceof CustomerUserDetails) ) { throw new InsufficientAuthenticationException("Not logged in as a customer"); } Customer customer = customerService.readCustomerById(((CustomerUserDetails) principal).getId()); if (Scope.CUSTOMER_REGISTERED.matches(scope)) { if (!customer.isRegistered()) { throw new InsufficientAuthenticationException("Not logged in as a registered customer"); } } } else if (Scope.STAFF.matches(scope) && ( !(principal instanceof AdminUserDetails) )) { throw new InsufficientAuthenticationException("Not logged in as an admin user"); } } }