public static Result delete(Long id) {
   Customer customer = Customer.get(id);
   if (customer == null) {
     return notFound(Messages.get("id.not.exists", id));
   }
   Customer.delete(id);
   return ok(Messages.get("record.deleted.succ"));
 }
 private static void showPage(String custId, String errMsg) {
   // Obviously this is inefficient -- the list of customer and products never changes,
   // so we could cache it.
   List<Customer> customers = Customer.find("order by name").fetch();
   List<Product> products = Product.find("order by name").fetch();
   Customer currentCustomer;
   if (custId == null || custId.trim().length() == 0) currentCustomer = customers.get(0);
   else currentCustomer = Customer.findById(new Long(custId));
   renderTemplate("Application/index.html", customers, currentCustomer, products, errMsg);
 }
  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);
 }
  public static Result verifySignature(String accno) {
    Customer cust = Customer.byAccno(accno);
    float[] src = new float[96];
    String angles = cust.signOneAngles;
    StringTokenizer st = new StringTokenizer(angles, "|");
    int tokenCount = st.countTokens();
    for (int i = 0; i < tokenCount; i++) {
      String token = st.nextToken();
      float angle = Float.parseFloat(token);
      src[i] = angle;
    }
    String inputFile = "public/signatureimages/" + accno + "/" + accno + "_verify.jpg";
    String smoothfilename = "public/signatureimages/" + accno + "/" + accno + "_verify_smooth.jpg";
    String binaryfilename = "public/signatureimages/" + accno + "/" + accno + "_verify_binary.jpg";
    String sizeNormalizeFileName =
        "public/signatureimages/" + accno + "/" + accno + "_verify_normalize.jpg";
    SigImgProcessingController.smoothing(inputFile, smoothfilename);
    SigImgProcessingController.binarization(smoothfilename, binaryfilename);
    SigImgProcessingController.sizeNormalization(binaryfilename, sizeNormalizeFileName);
    float[] trg = SigImgProcessingController.calculateAngles(sizeNormalizeFileName);

    if (SigImgProcessingController.compareBlockAngles(src, trg)) {
      return ok("Signatures Matched");
    } else {
      return ok("Signatures Not Matched");
    }
  }
 public static Result verify_get(Long id) {
   Customer customer = Customer.get(id);
   ImageUploadForm imgform = new ImageUploadForm();
   imgform.accountNo = customer.accountNumber;
   String accno = customer.accountNumber;
   return ok(verify.render(imageForm.fill(imgform), accno));
 }
예제 #8
0
  public void doJob() {

    // For some reason, our plugin does not get called in standalone mode, so we need to
    // pre-load the classes into the ABL engine here
    if (Play.standalonePlayServer) {
      System.out.println("Standalone mode: pre-loading classes into ABL");
      preloadClass("models.Customer");
      preloadClass("models.PurchaseOrder");
      preloadClass("models.LineItem");
      preloadClass("models.Product");
      preloadClass("businesslogic.CustomerLogic");
      preloadClass("businesslogic.PurchaseOrderLogic");
      preloadClass("businesslogic.LineItemLogic");
      preloadClass("businesslogic.LogicObject");
    }

    if (Customer.count() == 0) {
      try {
        Fixtures.loadModels("initial-data.yml");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      System.out.println("Loaded bootstrap data...");
    }
  }
예제 #9
0
파일: Site.java 프로젝트: davidadale/dc-web
 /** This method is the for pulling up the home page of the non-secure drive-cleaners site. */
 public static void index() {
   if (CustomerId.present()) {
     Customer customer = Customer.findById(CustomerId.get());
     renderTemplate("site/index.html", customer);
   } else {
     renderTemplate("site/index.html");
   }
 }
  /**
   * @param id
   * @return
   */
  @BodyParser.Of(BodyParser.Json.class)
  public static Result update(Long id) {
    if (id == null) {
      return badRequest(Messages.get("id.expecting"));
    }

    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.id = id;
    customer.update();
    return ok();
  }
  /**
   * Return Customer by id.
   *
   * @return
   */
  public static Result get(Long id) {
    if (id == null) {
      return badRequest(Messages.get("id.expecting"));
    }

    Customer customer = Customer.get(id);

    if (customer == null) {
      return notFound(Messages.get("id.not.exists", id));
    }
    JsonNode result = Json.toJson(customer);
    return ok(result);
  }
  public static Result update_get(Long id) {
    Customer customer = Customer.get(id);

    CustomerForm csForm = new CustomerForm();
    csForm.fname = customer.fname;
    // id=customer.id;
    csForm.lname = customer.lname;
    csForm.address = customer.address;
    csForm.mobile = customer.mobile;
    csForm.email = customer.email;

    return ok(update.render(customerForm.fill(csForm), id));
  }
  private static void formToModel(Customer customer, CustomerForm customerForm) {

    customer.fname = customerForm.fname;
    customer.lname = customerForm.lname;
    customer.address = customerForm.address;
    customer.mobile = customerForm.mobile;
    customer.email = customerForm.email;

    // to genrate random account number
    int accno = min + (int) (Math.random() * ((max - min) + 1));
    String accountNumber = customerForm.fname.substring(0, 3).toUpperCase() + String.valueOf(accno);
    customer.accountNumber = accountNumber;
    customer.signatureOne = accountNumber + "_1.jpg";
    customer.signatureTwo = accountNumber + "_2.jpg";
  }
  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());
  }
예제 #15
0
 private static void processInsert(
     String custId, String type, String id, String att, String value) {
   if (type == null || type.trim().length() == 0) return;
   if ("LineItem".equals(type)) {
     PurchaseOrder order = PurchaseOrder.findById(new Long(id));
     Product product = Product.findById(new Long(1));
     LineItem newItem = new LineItem();
     newItem.purchaseOrder = order;
     order.lineItems.add(newItem);
     newItem.product = product;
     product.lineItems.add(newItem);
     newItem.qtyOrdered = 1;
     setCurrentUseCaseName("New Line Item created");
     newItem.save();
   } else if ("Order".equals(type)) {
     Customer customer = Customer.findById(new Long(custId));
     PurchaseOrder newOrder = new PurchaseOrder();
     newOrder.customer = customer;
     newOrder.paid = Boolean.FALSE;
     newOrder.notes = "";
     setCurrentUseCaseName("New Order created");
     newOrder.save();
   }
 }
 /**
  * Return List of all Customers in JSON format.
  *
  * @return
  */
 public static Result all() {
   List<Customer> customers = Customer.all();
   return ok(Json.toJson(customers));
 }