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
 @SuppressWarnings("unchecked")
 @Action(
     value = "customer-save",
     results = {
       @Result(name = "success", location = "/WEB-INF/content/ajax/customer/customer-result.jsp"),
       @Result(name = "input", location = "/WEB-INF/content/ajax/customer/customer-result.jsp")
     })
 public String customersave() {
   boolean check = true;
   try {
     imageList = (List<Image>) session.get("imageList");
     if (customer.getId() != null) {
       Customer c = (Customer) session.get("customer");
       customer.setConfirm(c.getConfirm());
     }
     customer.setImageOfList(imageList);
     if (customer.getCnumber().equals("")) {
       addFieldError("cnumber", Messages.getString("inputEmpty"));
       addFieldError("cnumberEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getColor().equals("")) {
       addFieldError("color", Messages.getString("inputEmpty"));
       addFieldError("colorEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       if (customer.getColor().matches("[0-9]{4}[А-ЯӨҮ]{3}")) {
         addFieldError("color", Messages.getString("cnumber"));
         check = false;
       }
     }
     if (customer.getVinNumber().equals("")) {
       addFieldError("vinNumber", Messages.getString("inputEmpty"));
       addFieldError("vinNumberEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getOwnerName().equals("")) {
       addFieldError("ownerName", Messages.getString("inputEmpty"));
       addFieldError("ownerNameEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getOwnerAddress().equals("")) {
       addFieldError("ownerAddress", Messages.getString("inputEmpty"));
       addFieldError("ownerAddressEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getOwnerPhoneNumber().equals("")) {
       addFieldError("ownerPhoneNumberEdit", Messages.getString("inputEmpty"));
       addFieldError("ownerPhoneNumber", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getEstPoint().equals("")) {
       addFieldError("estPointEdit", Messages.getString("inputEmpty"));
       addFieldError("estPoint", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getMarketPrice().equals("")) {
       addFieldError("marketPrice", Messages.getString("inputEmpty"));
       addFieldError("marketPriceEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getConsumer().equals("")) {
       addFieldError("consumer", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getDefendant().equals("")) {
       addFieldError("defendant", Messages.getString("inputEmpty"));
       addFieldError("defendantEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getAgentConsumer().equals("")) {
       addFieldError("agentConsumerEdit", Messages.getString("inputEmpty"));
       addFieldError("agentConsumer", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getEstimateMaterial().equals("")) {
       addFieldError("estimateMaterial", Messages.getString("inputEmpty"));
       addFieldError("estimateMaterialEdit", Messages.getString("inputEmpty"));
     }
     if (companyStr.trim().equals("")) {
       addFieldError("companyStrEdit", Messages.getString("inputEmpty"));
       addFieldError("companyStr", Messages.getString("inputEmpty"));
       check = false;
     } else {
       try {
         customer.setCompany(companyService.get(Long.parseLong(companyStr)));
       } catch (Exception e) {
         addFieldError("companyStrEdit", e.getMessage());
         addFieldError("companyStr", e.getMessage());
         check = false;
       }
     }
     if (!itypeStr.equals("")) {
       customer.setItype(InsuranceType.get(itypeStr));
     } else {
       addFieldError("itypeStr", Messages.getString("inputEmpty"));
       addFieldError("itypeStrEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (dateStr.equals("")) {
       addFieldError("dateStr", Messages.getString("inputEmpty"));
       addFieldError("dateStrEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       customer.setDate(EstimaterStaticFunctions.strToDate(dateStr));
     }
     if (factoryStr.equals("")) {
       addFieldError("factoryStr", Messages.getString("inputEmpty"));
       addFieldError("factoryStrEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       try {
         customer.setCarFactory(carFactoryService.get(Long.parseLong(factoryStr)));
       } catch (Exception e) {
         addFieldError("factoryStr", e.getMessage());
         addFieldError("factoryStrEdit", e.getMessage());
         check = false;
       }
     }
     if (markStr.equals("")) {
       addFieldError("markStr", Messages.getString("inputEmpty"));
       addFieldError("markStrEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       try {
         customer.setCarMark(carMarkService.get(Long.parseLong(markStr)));
       } catch (Exception e) {
         addFieldError("markStrEdit", e.getMessage());
         addFieldError("markStr", e.getMessage());
         check = false;
       }
     }
     if (customer.getFactoryDate().equals("")) {
       addFieldError("factoryDateEdit", Messages.getString("inputEmpty"));
       addFieldError("factoryDate", Messages.getString("inputEmpty"));
       check = false;
     }
     if (customer.getImportedDate().equals("")) {
       addFieldError("importedDate", Messages.getString("inputEmpty"));
       addFieldError("importedDateEdit", Messages.getString("inputEmpty"));
       check = false;
     }
     if (emp1Str.equals("")) {
       addFieldError("emp1Str", Messages.getString("inputEmpty"));
       addFieldError("emp1StrEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       customer.setEmp1(employeeService.get(Long.parseLong(emp1Str)));
     }
     if (emp2Str.equals("")) {
       addFieldError("emp2Str", Messages.getString("inputEmpty"));
       addFieldError("emp2StrEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       customer.setEmp2(employeeService.get(Long.parseLong(emp2Str)));
     }
     if (mainStr.equals("")) {
       addFieldError("mainStr", Messages.getString("inputEmpty"));
       addFieldError("mainStrEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       customer.setMainEmp(employeeService.get(Long.parseLong(mainStr)));
     }
     if (carTypeStr.equals("")) {
       addFieldError("carTypeStr", Messages.getString("inputEmpty"));
       addFieldError("carTypeStrEdit", Messages.getString("inputEmpty"));
       check = false;
     } else {
       customer.setCarType(CarType.get(carTypeStr));
     }
     if (!customer.getRegNumber().matches("[А-ЯӨҮ]{2}[0-9]{8}")) {
       addFieldError("regnumber", Messages.getString("cnumber"));
       addFieldError("regnumberEdit", Messages.getString("cnumber"));
       check = false;
     }
     if (check) {
       defectList = (List<Defect>) session.get("defectList");
       for (Defect d : defectList) {
         defectService.saveOrUpdate(d);
       }
       customer.setDefectList(defectList);
       costList = (List<Cost>) session.get("costList");
       for (Cost c : costList) {
         costService.saveOrUpdate(c);
       }
       customer.setCostList(costList);
       customerService.saveOrUpdate(customer);
       request.setAttribute("successMarkDialog", "true");
       return SUCCESS;
     }
     return INPUT;
   } catch (Exception e) {
     addFieldError("mainStr", e.getMessage());
   }
   return INPUT;
 }
Exemplo n.º 3
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;
    }
  }