Exemplo n.º 1
0
  @Action(
      value = "images-save",
      results = {
        @Result(
            name = "success",
            location = "/WEB-INF/content/ajax/customer/ajax-error-response.jsp"),
        @Result(
            name = "input",
            location = "/WEB-INF/content/ajax/customer/ajax-error-response.jsp"),
        @Result(name = "error", location = "/WEB-INF/content/ajax/customer/ajax-error-response.jsp")
      })
  public String ImagesaveAction() throws IOException {
    try {
      if (files.size() <= 0) {
        request.setAttribute("imageResult", Messages.getString("emptyError"));
        return INPUT;
      }

      String filePathd = request.getSession().getServletContext().getRealPath("/") + "\\uploads";
      String filePath = "c:/temp/";
      imageList = new LinkedList<Image>();
      for (int i = 0; i < files.size(); i++) {
        if (files.get(i).length() > 5500000) {
          request.setAttribute("imageResult", Messages.getString("maxSizeLimitError"));
          return INPUT;
        }
        Image image = new Image();
        String name = imFileName.get(i);
        image.setName(name);
        image.setContentType(imContentType.get(i));
        if (i != 0) {
          image.setIsMain(false);
        } else {
          image.setIsMain(true);
        }
        File fileToCreate = new File(filePath, name);
        FileUtils.copyFile(files.get(i), fileToCreate);
        File fileToCreated = new File(filePathd, name);
        FileUtils.copyFile(files.get(i), fileToCreated);
        imageService.saveOrUpdate(image);
        imageList.add(image);
      }
      session.put("imageList", imageList);
      request.setAttribute("imageResult", "success");
      return SUCCESS;
    } catch (Exception e) {
      request.setAttribute("imageResult", Messages.getString("somethingWrong"));
      return ERROR;
    }
  }
Exemplo n.º 2
0
  @Action(
      value = "delete-pm-images",
      results = {
        @Result(
            name = "success",
            location = "/WEB-INF/content/ajax/customer/ajax-image-list-response.jsp"),
        @Result(
            name = "input",
            location = "/WEB-INF/content/ajax/customer/ajax-image-input-error-response.jsp"),
        @Result(name = "error", location = "/WEB-INF/content/ajax/customer/ajax-error-response.jsp")
      })
  public String deleteImagesAction() {
    try {
      if (customer.getId() == null || customer.getId() == 0l) {
        addFieldError("id", Messages.getString("emptyError"));
        return INPUT;
      }

      String[] imageIds = request.getParameterValues("imageIds[]");
      if (imageIds == null || imageIds.length <= 0) {
        addFieldError("imageIds", Messages.getString("emptyError"));
        return INPUT;
      }

      Customer cust = new Customer();
      cust = customerService.get(customer.getId());
      if (cust == null) {
        addFieldError("id", Messages.getString("wrongIdError"));
        return INPUT;
      }
      String filePathd = request.getSession().getServletContext().getRealPath("/") + "\\uploads";
      String filePath = "c:/temp/";
      for (int j = 0; j < imageIds.length; j++) {
        Long imageId = 0l;
        try {
          imageId = Long.parseLong(imageIds[j]);
        } catch (NumberFormatException e) {
          addFieldError("imageIds", Messages.getString("numberIdError"));
          return INPUT;
        }

        Image image = new Image();
        image = imageService.get(imageId);
        if (image == null) {
          addFieldError("imageIds", Messages.getString("wrongIdError"));
          return INPUT;
        }

        for (int i = 0; i < cust.getImageOfList().size(); i++) {
          if (cust.getImageOfList().get(i).getId() == image.getId()) {
            cust.getImageOfList().remove(i);
            imageService.delete(image);
            FileUtils.deleteQuietly(new File(filePath + "\\" + image.getName()));
            FileUtils.deleteQuietly(new File(filePathd + "\\" + image.getName()));
          }
        }
        session.put("imageList", cust.getImageOfList());
      }
      return SUCCESS;
    } catch (Exception e) {
      addFieldError("exception", Messages.getString("somethingWrong"));
      return ERROR;
    }
  }