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()); }
public static Result update_save(Long id) { Form<CustomerForm> filledForm = customerForm.bindFromRequest(); if (filledForm.hasErrors()) { return badRequest(update.render(filledForm, id)); } CustomerForm customerForm = filledForm.get(); if (customerForm == null) { return badRequest(update.render(filledForm, id)); } Customer customer = Customer.get(id); if (customer == null) { filledForm.reject(Messages.get("id.not.exists", id)); return badRequest(update.render(filledForm, id)); } formToModel(customer, customerForm); customer.update(); return redirect(controllers.routes.CustomerController.index()); }