コード例 #1
0
  @PreAuthorize("hasRole('STORE')")
  @RequestMapping(
      value = "/admin/store/removeImage.html",
      method = RequestMethod.POST,
      produces = "application/json")
  public @ResponseBody String removeImage(
      HttpServletRequest request, HttpServletResponse response, Locale locale) {

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

    AjaxResponse resp = new AjaxResponse();

    try {

      contentService.removeFile(store.getCode(), FileContentType.LOGO, store.getStoreLogo());

      store.setStoreLogo(null);
      merchantStoreService.update(store);

    } catch (Exception e) {
      LOGGER.error("Error while deleting product", e);
      resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
      resp.setErrorMessage(e);
    }

    String returnString = resp.toJSONString();

    return returnString;
  }
コード例 #2
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());
  }