/** * Method to check if given user exists for given username under given store. System treat * username as unique for a given store, customer is not allowed to use same username twice for a * given store, however it can be used for different stores. * * @param userName Customer slected userName * @param store store for which customer want to register * @return boolean flag indicating if user exists for given store or not * @throws Exception */ @Override public boolean checkIfUserExists(final String userName, final MerchantStore store) throws Exception { if (StringUtils.isNotBlank(userName) && store != null) { Customer customer = customerService.getByNick(userName, store.getId()); if (customer != null) { LOG.info( "Customer with userName {} already exists for store {} ", userName, store.getStorename()); return true; } LOG.info("No customer found with userName {} for store {} ", userName, store.getStorename()); return false; } LOG.info("Either userName is empty or we have not found any value for store"); return false; }
@RequestMapping( value = "/admin/options/remove.html", method = RequestMethod.POST, produces = "application/json") public @ResponseBody String deleteOption( HttpServletRequest request, HttpServletResponse response, Locale locale) { String sid = request.getParameter("optionId"); MerchantStore store = (MerchantStore) request.getAttribute("MERCHANT_STORE"); AjaxResponse resp = new AjaxResponse(); try { Long id = Long.parseLong(sid); ProductOption entity = productOptionService.getById(store, id); if (entity == null || entity.getMerchantSore().getId().intValue() != store.getId().intValue()) { resp.setStatusMessage(messages.getMessage("message.unauthorized", locale)); resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE); } else { productOptionService.delete(entity); resp.setStatus(AjaxResponse.RESPONSE_OPERATION_COMPLETED); } } catch (Exception e) { LOGGER.error("Error while deleting option", e); resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE); resp.setErrorMessage(e); } String returnString = resp.toJSONString(); return returnString; }
/** * Method responsible for adding content files to underlying Infinispan cache. It will add given * content file(s) for given merchant store in the cache. Following steps will be performed in * order to add files * * <pre> * 1. Validate form data * 2. Get Merchant Store based on merchant Id. * 3. Call {@link InputContentFile} to add file(s). * </pre> * * @param contentImages * @param bindingResult * @param model * @param request * @return * @throws Exception */ @PreAuthorize("hasRole('CONTENT')") @RequestMapping(value = "/admin/content/static/saveFiles.html", method = RequestMethod.POST) public String saveFiles( @ModelAttribute(value = "contentFiles") @Valid final ContentFiles contentFiles, final BindingResult bindingResult, final Model model, final HttpServletRequest request) throws Exception { this.setMenu(model, request); if (bindingResult.hasErrors()) { LOGGER.info("Found {} Validation errors", bindingResult.getErrorCount()); return ControllerConstants.Tiles.ContentFiles.contentFiles; } final List<InputContentFile> contentFilesList = new ArrayList<InputContentFile>(); final MerchantStore store = (MerchantStore) request.getAttribute(Constants.ADMIN_STORE); if (CollectionUtils.isNotEmpty(contentFiles.getFile())) { LOGGER.info( "Saving {} content files for merchant {}", contentFiles.getFile().size(), store.getId()); for (final MultipartFile multipartFile : contentFiles.getFile()) { if (!multipartFile.isEmpty()) { ByteArrayInputStream inputStream = new ByteArrayInputStream(multipartFile.getBytes()); InputContentFile cmsContentImage = new InputContentFile(); cmsContentImage.setFileName(multipartFile.getOriginalFilename()); cmsContentImage.setFileContentType(FileContentType.STATIC_FILE); cmsContentImage.setFile(inputStream); contentFilesList.add(cmsContentImage); } } if (CollectionUtils.isNotEmpty(contentFilesList)) { contentService.addContentFiles(store.getCode(), contentFilesList); } else { // show error message on UI } } return ControllerConstants.Tiles.ContentFiles.contentFiles; }
@Override public Customer getCustomerByUserName(String userName, MerchantStore store) throws Exception { return customerService.getByNick(userName, store.getId()); }