public int addCustomer(JSONObject jObj) {
    int cid = 0;
    String emailId = null;
    Customer customer = new Customer();
    customer.setCreatedAt(Utilities.getCurrentDateTime());
    customer.setUpdatedAt(Utilities.getCurrentDateTime());
    try {
      customer.setCustomerGroupId(jObj.getInt("customerGroup"));
      emailId = jObj.getString("email");
      System.out.println("EMAIL ID:" + emailId);
      customer.setEmail(emailId);
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (null == emailId) {
      return cid;
    } else if (isEmailAlreadyExists(emailId)) {
      return cid;
    }
    customerService.addcustomer(customer);
    cid = customer.getId();
    System.out.println("customer==>" + customer.toString());

    List<Entities> listAttributes = this.entitiesService.listAttributes();
    HashMap<Integer, String> attrs = getAttributesList(listAttributes, "Customer");
    System.out.println("attrs==>" + attrs.toString());

    for (Entry<Integer, String> entry : attrs.entrySet()) {
      Integer attrId = entry.getKey();
      String attrName = entry.getValue();

      String attrValue = null;
      try {
        attrValue = jObj.getString(attrName);
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (null != attrValue) {

        CustomerEntityValues custAttrValue = new CustomerEntityValues();
        custAttrValue.setCustomerId(cid);
        custAttrValue.setLanguage("enUS");
        custAttrValue.setAttributeId(attrId);
        custAttrValue.setValue(attrValue);
        customerEntityValuesService.addCustomerAttributeValues(custAttrValue);
        System.out.println("custAttrValue-->" + custAttrValue.toString());
      }
    }

    return cid;

    /* //Rest call
    final String SERVER_URI = "http://localhost:8080/jvoidattributes/listCustomerAttriburtes";
    RestTemplate restTemplate = new RestTemplate();

    String returnString = restTemplate.getForObject(SERVER_URI, String.class);
          JSONObject returnJsonObj = null;
    try {
    	returnJsonObj = new JSONObject(returnString);
    } catch (JSONException e) {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    }

          System.out.println("returnJsonObj=>"+returnJsonObj);

          JSONArray arr = null;
          try {
    	arr = returnJsonObj.getJSONArray("Attributes");
    } catch (JSONException e) {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    }

          for (int i=0; i<arr.length(); i++) {
        try {
    		String attrValue = arr.getJSONObject(i).getString("code");
    		Integer attrId = Integer.parseInt(arr.getJSONObject(i).getString("id"));
    		System.out.println("id = "+attrId+"   code = "+attrValue);

    		CustomerAttributeValues custAttrValue = new CustomerAttributeValues();
    	    custAttrValue.setCustomerId(customer.getId());//get it from customer table
    	    custAttrValue.setLanguage("enUS");
    	    custAttrValue.setAttributeId(attrId);
    	    custAttrValue.setValue(customerMaster.toAttributedHashMap().get(attrValue));
    	    customerAttributeValuesService.addCustomerAttributeValues(custAttrValue);
    	    System.out.println("custAttrValue-->"+custAttrValue.toString());
    	} catch (JSONException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	}
    }
    */

  }
  public int updateCustomer(JSONObject jObj) {
    int status = 0;
    Customer customer = null;
    int customerId = 0;
    try {
      customerId = jObj.getInt("id");
      customer = this.customerService.getcustomerById(customerId);
    } catch (JSONException e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }

    if (null != customer) {

      System.out.println("Date:" + Utilities.getCurrentDateTime());
      System.out.println("CO:" + customer.toString());
      customer.setUpdatedAt(Utilities.getCurrentDateTime());
      customer.setCreatedAt(customer.getCreatedAt());
      try {
        customer.setEmail(jObj.getString("email"));
        customer.setCustomerGroupId(jObj.getInt("customerGroup"));
      } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      this.customerService.updatecustomer(customer);

      List<Entities> listAttributes = this.entitiesService.listAttributes();
      HashMap<Integer, String> attrs = getAttributesList(listAttributes, "Customer");
      System.out.println("attrs==>" + attrs.toString());

      for (Entry<Integer, String> entry : attrs.entrySet()) {
        Integer attrId = entry.getKey();
        String attrName = entry.getValue();

        CustomerEntityValues customerEntityValue =
            this.customerEntityValuesService.getCustomerEntityValuesByCustomerIdAndAttributeId(
                customerId, attrId);

        String attrValue;
        try {
          attrValue = jObj.getString(attrName);
          if (null != attrValue) {

            CustomerEntityValues custAttrValue = new CustomerEntityValues();
            custAttrValue.setCustomerId(customerId);
            custAttrValue.setLanguage(customerEntityValue.getLanguage());
            custAttrValue.setAttributeId(attrId);
            custAttrValue.setValue(attrValue);
            custAttrValue.setId(customerEntityValue.getId());
            customerEntityValuesService.updateCustomerAttributeValues(custAttrValue);
            System.out.println("custAttrValue-->" + custAttrValue.toString());
          }
        } catch (JSONException e) {
          e.printStackTrace();
        }
      }
      status = 1;
    } else {
      status = 0;
    }
    return status;
  }