public static Result create_save() {
    Form<CustomerForm> filledForm = customerForm.bindFromRequest();

    if (filledForm.hasErrors()) {
      System.out.println("in error");
      return badRequest(create.render(filledForm));
    }

    CustomerForm customerForm = filledForm.get();
    if (customerForm == null) {
      System.out.println("in form");
      return badRequest(create.render(filledForm));
    }

    Customer customer = new Customer();
    formToModel(customer, customerForm);
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart picture1 = body.getFile("signatureOne");
    FilePart picture2 = body.getFile("signatureTwo");
    if (picture1 != null && picture2 != null) {
      File file1 = picture1.getFile();
      File file2 = picture2.getFile();
      String path = "public/signatureimages/" + customer.accountNumber;
      File f = new File(path);
      f.mkdir();
      file1.renameTo(new File(path, customer.signatureOne));
      file2.renameTo(new File(path, customer.signatureTwo));
      System.out.println("File uploaded successfully...");
    } else {
      filledForm.reject("file", "Please select the image to uplaod");
    }

    String inputFile =
        "public/signatureimages/" + customer.accountNumber + "/" + customer.signatureOne;
    String smoothfilename =
        "public/signatureimages/" + customer.accountNumber + "/signatureOne_smooth.jpg";
    String binaryfilename =
        "public/signatureimages/" + customer.accountNumber + "/signatureOne_binary.jpg";
    String sizeNormalizeFileName =
        "public/signatureimages/" + customer.accountNumber + "/signatureOne_normalize.jpg";
    SigImgProcessingController.smoothing(inputFile, smoothfilename);
    SigImgProcessingController.binarization(smoothfilename, binaryfilename);
    SigImgProcessingController.sizeNormalization(binaryfilename, sizeNormalizeFileName);
    float[] sig1 = SigImgProcessingController.calculateAngles(sizeNormalizeFileName);
    StringBuffer angels = new StringBuffer();

    for (int i = 0; i < sig1.length; i++) {
      angels.append(sig1[i] + "|");
    }
    System.out.println("Angles: " + angels);
    customer.signOneAngles = angels.toString();

    customer.save();
    return redirect(controllers.routes.CustomerController.index());
  }
 private static void processUpdate(String type, String id, String att, String value) {
   if (type == null || type.trim().length() == 0) return;
   if ("Order".equals(type)) {
     PurchaseOrder order = PurchaseOrder.findById(new Long(id));
     if ("paid".equals(att)) {
       Boolean oldValue = order.paid;
       if (oldValue == null) oldValue = Boolean.FALSE;
       order.paid = !oldValue;
       if (oldValue) setCurrentUseCaseName("Order unpaid");
       else setCurrentUseCaseName("Order paid");
     } else if ("customer".equals(att)) {
       if (value == null
           || value.startsWith(
               "- ")) // Do nothing if somehow the "- select a customer -" item was selected
       return;
       Customer customer = Customer.findById(new Long(value));
       order.customer = customer;
       Flash.current().success("The order has been reassigned to customer " + customer.name);
       setCurrentUseCaseName("Order reassigned");
     } else if ("notes".equals(att)) {
       order.notes = value;
       setCurrentUseCaseName("Order notes updated");
     }
     order.save();
   } else if ("Customer".equals(type)) {
     Customer customer = Customer.findById(new Long(id));
     if ("creditLimit".equals(att)) {
       BigDecimal val = NumberFormat.parseMoney(value);
       customer.creditLimit = val;
       setCurrentUseCaseName("Customer credit limit updated");
     }
     customer.save();
   } else if ("LineItem".equals(type)) {
     LineItem lineitem = LineItem.findById(new Long(id));
     if ("quantity".equals(att)) {
       Integer val = NumberFormat.parseNumber(value);
       lineitem.qtyOrdered = val;
       setCurrentUseCaseName("Line Item quantity updated");
     } else if ("unitPrice".equals(att)) {
       BigDecimal val = NumberFormat.parseMoney(value);
       lineitem.productPrice = val;
       setCurrentUseCaseName("Line Item unit price updated");
     } else if ("product".equals(att)) {
       Product product = Product.findById(new Long(value));
       lineitem.product = product;
       setCurrentUseCaseName("Line Item product changed");
     }
     lineitem.save();
   }
 }
 /** @return */
 @BodyParser.Of(BodyParser.Json.class)
 public static Result create() {
   JsonNode jsonNode = request().body().asJson();
   if (jsonNode == null) {
     return badRequest(Messages.get("json.expecting"));
   }
   Customer customer = Json.fromJson(jsonNode, Customer.class);
   if (customer == null) {
     return badRequest(Messages.get("json.expecting"));
   }
   customer.save();
   ObjectNode result = Json.newObject();
   result.put("id", customer.id);
   return created(result);
 }