public Product toProduct() { Product p = new Product(); p.setId(id); p.setName(name); p.setDescription(description); p.setDisabled(disabled); p.setPrice(price); p.setSku(sku); Category category = new Category(); category.setId(categoryId); p.setCategory(category ); //p.setImageUrl(WebUtils.IMAGES_PREFIX+id+".jpg"); return p; }
public Product updateProduct(Product product) { Product persistedProduct = getProductById(product.getId()); if(persistedProduct == null){ throw new JCartException("Product "+product.getId()+" doesn't exist"); } persistedProduct.setDescription(product.getDescription()); persistedProduct.setDisabled(product.isDisabled()); persistedProduct.setPrice(product.getPrice()); persistedProduct.setCategory(getCategoryById(product.getCategory().getId())); return productRepository.save(persistedProduct); }
public static ProductForm fromProduct(Product product) { ProductForm p = new ProductForm(); p.setId(product.getId()); p.setName(product.getName()); p.setDescription(product.getDescription()); p.setDisabled(product.isDisabled()); p.setPrice(product.getPrice()); p.setSku(product.getSku()); p.setCategoryId(product.getCategory().getId()); //p.setImageUrl(WebUtils.IMAGES_PREFIX+product.getId()+".jpg"); return p; } }
protected void sendOrderConfirmationEmail(Order order) { try { emailService.sendEmail(order.getCustomer().getEmail(), "QuilCartCart - Order Confirmation", "Your order has been placed successfully.\n" + "Order Number : "+order.getOrderNumber()); } catch (JCartException e) { logger.error(e); } }
private static Collection<? extends GrantedAuthority> getAuthorities(User user) { Set<String> roleAndPermissions = new HashSet<>(); List<Role> roles = user.getRoles(); for (Role role : roles) { roleAndPermissions.add(role.getName()); List<Permission> permissions = role.getPermissions(); for (Permission permission : permissions) { roleAndPermissions.add("ROLE_"+permission.getName()); } } String[] roleNames = new String[roleAndPermissions.size()]; Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(roleAndPermissions.toArray(roleNames)); return authorities; } }
public Order updateOrder(Order order) { Order o = getOrder(order.getOrderNumber()); o.setStatus(order.getStatus()); Order savedOrder = orderRepository.save(o); return savedOrder; }
public BigDecimal getSubTotal() { return product.getPrice().multiply(new BigDecimal(quantity)); }
public AuthenticatedUser(Customer customer) { super(customer.getEmail(), customer.getPassword(), getAuthorities(customer)); this.customer = customer; } public Customer getCustomer()
public AuthenticatedUser(User user) { super(user.getEmail(), user.getPassword(), getAuthorities(user)); this.user = user; }
@Override public void validate(Object target, Errors errors) { Customer customer = (Customer) target; Customer customerByEmail = custmoerService.getCustomerByEmail(customer.getEmail()); if(customerByEmail != null){ errors.rejectValue("email", "error.exists", new Object[]{customer.getEmail()}, "Email "+customer.getEmail()+" already in use"); } }
@Override public void validate(Object target, Errors errors) { Category category = (Category) target; String name = category.getName(); Category categoryByName = catalogService.getCategoryByName(name); if(categoryByName != null){ errors.rejectValue("name", "error.exists", new Object[]{name}, "Category "+category.getName()+" already exists"); } }
@Override public void validate(Object target, Errors errors) { User user = (User) target; String email = user.getEmail(); User userByEmail = securityService.findUserByEmail(email); if(userByEmail != null){ errors.rejectValue("email", "error.exists", new Object[]{email}, "Email "+email+" already in use"); } }
public BigDecimal getTotalAmount() { BigDecimal amount = new BigDecimal("0.0"); for (OrderItem item : items) { amount = amount.add(item.getSubTotal()); } return amount; }
@RequestMapping(value="/register", method=RequestMethod.GET) protected String registerForm(Model model) { model.addAttribute("customer", new Customer()); return "register"; }
@RequestMapping(value="/roles/new", method=RequestMethod.GET) public String createRoleForm(Model model) { Role role = new Role(); model.addAttribute("role",role); //model.addAttribute("permissionsList",securityService.getAllPermissions()); return viewPrefix+"create_role"; }
@RequestMapping(value="/categories/new", method=RequestMethod.GET) public String createCategoryForm(Model model) { Category category = new Category(); model.addAttribute("category",category); return viewPrefix+"create_category"; }
@RequestMapping(value="/users/new", method=RequestMethod.GET) public String createUserForm(Model model) { User user = new User(); model.addAttribute("user",user); //model.addAttribute("rolesList",securityService.getAllRoles()); return viewPrefix+"create_user"; }
public BigDecimal getSubTotal() { return product.getPrice().multiply(new BigDecimal(quantity)); }