Ejemplo n.º 1
0
  @Test
  public void createStoreLogo() throws ServiceException, FileNotFoundException, IOException {

    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    final File file1 = new File("/Users/csamson777/Pictures/peavey.jpg");

    if (!file1.exists() || !file1.canRead()) {
      throw new ServiceException("Can't read" + file1.getAbsolutePath());
    }

    byte[] is = IOUtils.toByteArray(new FileInputStream(file1));
    ByteArrayInputStream inputStream = new ByteArrayInputStream(is);
    InputContentFile cmsContentImage = new InputContentFile();

    cmsContentImage.setFileName(file1.getName());
    cmsContentImage.setFile(inputStream);

    // logo as a content
    contentService.addLogo(store.getCode(), cmsContentImage);

    store.setStoreLogo(file1.getName());
    merchantService.update(store);

    // query the store
    store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);

    // get the logo
    String logo = store.getStoreLogo();

    OutputContentFile image =
        contentService.getContentFile(store.getCode(), FileContentType.LOGO, logo);

    // print image
    OutputStream outputStream =
        new FileOutputStream("/Users/csamson777/Pictures/mexique" + image.getFileName());

    ByteArrayOutputStream baos = image.getFile();
    baos.writeTo(outputStream);

    // remove image
    contentService.removeFile(store.getCode(), FileContentType.LOGO, store.getStoreLogo());
  }
  /**
   * 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;
  }
Ejemplo n.º 3
0
  @PreAuthorize("hasRole('STORE')")
  @RequestMapping(value = "/admin/store/saveBranding.html", method = RequestMethod.POST)
  public String saveStoreBranding(
      @ModelAttribute(value = "contentImages") @Valid final ContentFiles contentImages,
      BindingResult result,
      Model model,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    setMenu(model, request);

    MerchantStore store = (MerchantStore) request.getAttribute(Constants.ADMIN_STORE);

    if (contentImages.getFile() != null && contentImages.getFile().size() > 0) {

      String imageName = contentImages.getFile().get(0).getOriginalFilename();
      InputStream inputStream = contentImages.getFile().get(0).getInputStream();
      InputContentFile cmsContentImage = new InputContentFile();
      cmsContentImage.setFileName(imageName);
      cmsContentImage.setMimeType(contentImages.getFile().get(0).getContentType());
      cmsContentImage.setFile(inputStream);
      contentService.addLogo(store.getCode(), cmsContentImage);

      // Update store
      store.setStoreLogo(imageName);
      merchantStoreService.update(store);
      request.getSession().setAttribute(Constants.ADMIN_STORE, store);
    }

    // display templates
    model.addAttribute("templates", templates);

    model.addAttribute("success", "success");
    model.addAttribute("store", store);

    return "admin-store-branding";
  }