@Override
    protected String doInBackground(String... params) {
      String result = "";

      try {
        String url = "http://listasupermercadows.apphb.com/api/listaws/";

        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httpPost = new HttpPost(url);

        String json = "";

        JSONObject jsonObject = new JSONObject();
        jsonObject.accumulate("Nome", produto.getNome());
        jsonObject.accumulate("Quantidade", produto.getQuantidade());
        jsonObject.accumulate("ContaId", produto.getContaId());

        json = jsonObject.toString();

        StringEntity se = new StringEntity(json, "UTF-8");

        httpPost.setEntity(se);

        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-type", "application/json");

        HttpResponse httpResponse = httpclient.execute(httpPost);

      } catch (Exception e) {
        Log.d("Erro", e.getLocalizedMessage());
      }
      return result;
    }
Example #2
0
    protected String doInBackground(String[]... attb) {
      String responce = "";

      try {
        JsonParse Obg = new JsonParse();
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        String[] data = attb[0];
        String url =
            "http://restaurants.base.pk/"; // {%22reservation%22:1,%22refresh%22:0,%22username%22:%22"+data[0]+"%22,%22password%22:%22"+data[1]+"%22}";
        JSONObject obg = new JSONObject();
        obg.accumulate("reservation", "1");
        obg.accumulate("refresh", "0");
        obg.accumulate("password", data[0]);
        obg.accumulate("username", data[1]);
        String jsonObjectInString = obg.toString();

        url =
            Uri.parse(url)
                .buildUpon()
                .appendQueryParameter("jason", jsonObjectInString)
                .build()
                .toString();

        responce = Obg.makeHttpRequest(url, "POST", params);
        Log.i("------ &*****", "ReservationService Do in bg = " + responce);

      } catch (Exception e) {
        e.printStackTrace();
      }

      return responce;
    }
  private JSONObject addToCart(HttpServletRequest request) throws RemoteException, JSONException {
    UserDTO user = (UserDTO) request.getSession().getAttribute(Constants.USER);

    ProductDTO[] productDTOs = new ProductDTO[1];
    ProductDTO product = new ProductDTO();
    product.setIdentifier(Integer.valueOf(request.getParameter("productId")));
    product.setQuantity(Integer.valueOf(request.getParameter("quantity")));
    productDTOs[0] = product;

    ShoppingCartDTO shoppingCartDTO = new ShoppingCartDTO();
    shoppingCartDTO.setUser(user);
    shoppingCartDTO.setProducts(productDTOs);
    shoppingCartDTO.setOrderStatus(Constants.PENDING);
    JSONObject jsonObject = new JSONObject();

    try {
      proxy.addToCart(shoppingCartDTO);
      jsonObject.accumulate(Constants.STATUS, Constants.SUCCESS);
      jsonObject.accumulate(Constants.MESSAGE, Constants.ADDED_TO_CART_SUCCESS);
    } catch (SQLException e) {
      jsonObject.accumulate(Constants.STATUS, Constants.ERROR);
      jsonObject.accumulate(Constants.MESSAGE, Constants.ERROR_ADDING_TO_CART);
      e.printStackTrace();
    }

    return jsonObject;
  }
  public String getPersonaggiStoriciJSON() {
    logger.info("ListaPersonaggi JSON");

    String res = "";

    Sparql sp = new Sparql(queryPersonaggiStorici, endpoint);
    JSONObject result = new JSONObject(sp.returnJSON());
    JSONArray jarray = result.getJSONObject("results").getJSONArray("bindings");
    JSONArray arrayRisultati = new JSONArray(); // riscrivamo i risultati in maniera piu bella
    for (int i = 0; i < jarray.length(); i++) {
      JSONObject row = new JSONObject();
      String uri = jarray.getJSONObject(i).getJSONObject("person").getString("value");
      String name = jarray.getJSONObject(i).getJSONObject("name").getString("value");
      String job = "";
      if (jarray.getJSONObject(i).has("job"))
        job = jarray.getJSONObject(i).getJSONObject("job").getString("value");
      row.accumulate("URI", uri);
      row.accumulate("name", name);
      row.accumulate("icona", Place.returnJobIcona(job));
      row.accumulate(
          "detailEndpoint",
          ServerTomcat
              + infoPersonaggio
              + uri.replace("http://www.trentinocultura.net/asp_cat/main.asp?", ""));
      arrayRisultati.put(row);
    }
    logger.info("Restituiti " + arrayRisultati.length() + " personaggi storici");

    // return sp.returnJSON();
    return arrayRisultati.toString();
  }
  // Register new user
  public static String POST(String url, User user) {
    InputStream inputStream = null;
    String result = "";
    int code = 0;
    try {

      // 1. create HttpClient
      HttpClient httpclient = new DefaultHttpClient();

      // 2. make POST request to the given URL
      HttpPost httpPost = new HttpPost(url);

      String json = "";

      // 3. build jsonObject
      JSONObject jsonObject = new JSONObject();
      jsonObject.accumulate("name", user.getName());
      jsonObject.accumulate("mail", user.getEmail());
      jsonObject.accumulate("password", user.getPassword());

      // 4. convert JSONObject to JSON to String
      json = jsonObject.toString();

      // ** Alternative way to convert Person object to JSON string usin Jackson Lib
      // ObjectMapper mapper = new ObjectMapper();
      // json = mapper.writeValueAsString(person);

      // 5. set json to StringEntity
      StringEntity se = new StringEntity(json);

      // 6. set httpPost Entity
      httpPost.setEntity(se);

      // 7. Set some headers to inform server about the type of the content
      httpPost.setHeader("Accept", "application/json");
      httpPost.setHeader("Content-type", "application/json");

      // 8. Execute POST request to the given URL
      HttpResponse httpResponse = httpclient.execute(httpPost);
      code = httpResponse.getStatusLine().getStatusCode();
      if (code == 500) {
        throw new Exception();
      }
      System.out.println("Status------------------> " + code);
      // 9. receive response as inputStream
      inputStream = httpResponse.getEntity().getContent();

      // 10. convert inputstream to string
      if (inputStream != null) result = convertInputStreamToString(inputStream);
      else result = "Did not work!";

    } catch (Exception e) {
      // Log.d("InputStream", e.getLocalizedMessage());
      return String.valueOf(code);
    }

    // 11. return result
    return String.valueOf(code);
  }
  public String POST(String url) {
    String tmp;
    if (result == null) {
      tmp = textViewDesc.getText().toString();
    } else {
      tmp = result;
    }
    ArrayList<String> items = new ArrayList<>();
    items.addAll(Arrays.asList(textViewTags.getText().toString().split("\\s*,\\s*")));
    NormalQuestion normalQuestion =
        new NormalQuestion(textViewTitle.getText().toString(), tmp, items, roomId);

    InputStream inputStream = null;
    String result = "";
    try {
      // 1. create HttpClient

      // 2. make POST request to the given URL
      HttpPost httpPost = new HttpPost(url);

      // 3. build jsonObject
      JSONObject jsonObject = new JSONObject();
      jsonObject.accumulate("head", normalQuestion.getTitle());
      jsonObject.accumulate("desc", normalQuestion.getDescription());
      jsonObject.accumulate("roomId", normalQuestion.getRoomId());
      jsonObject.accumulate("tags", new JSONArray(items));

      // 4. convert JSONObject to JSON to String
      String json = jsonObject.toString();

      // ** Alternative way to convert Person object to JSON string usin Jackson Lib
      // ObjectMapper mapper = new ObjectMapper();
      // json = mapper.writeValueAsString(person);

      // 5. set json to StringEntity
      StringEntity se = new StringEntity(json);

      // 6. set httpPost Entity
      httpPost.setEntity(se);

      // 7. Set some headers to inform server about the type of the content
      httpPost.setHeader("Accept", "application/json");
      httpPost.setHeader("Content-type", "application/json");
      // 8. Execute POST request to the given URL
      HttpResponse httpResponse = MainActivity.httpClient.execute(httpPost);

      // 9. receive response as inputStream
      inputStream = httpResponse.getEntity().getContent();

      // 10. convert inputstream to string
      if (inputStream != null) result = convertInputStreamToString(inputStream);
      else result = "Did not work!";
      Log.v("hehehehe", result);
    } catch (Exception e) {
      Log.d("InputStream", e.getLocalizedMessage());
    }
    return result;
  }
 public void getAllMessage() throws JSONException {
   List<Message> messageList = messageService.getMessageList((Long) session.get("id"));
   JSONObject result = new JSONObject();
   for (Message message : messageList) {
     JSONObject mjson = new JSONObject();
     mjson.accumulate("invitor_name", message.getInviter().getName());
     mjson.accumulate("invitor_email", message.getInviter().getEmail());
     mjson.accumulate("content", message.getContent());
     mjson.accumulate("create_date", message.getDateCreated());
     result.append("messageList", mjson);
   }
   sendMsg(result.toString());
 }
    @Override
    protected String doInBackground(String... urls) {

      JSONObject jsonObject = new JSONObject();
      try {
        jsonObject.accumulate("comment", urls[1]);
        jsonObject.accumulate("post_id", urls[2]);
        jsonObject.accumulate("username", UserDataHolder.getInstance().getUsername());
      } catch (JSONException e) {
        e.printStackTrace();
      }

      return JsonUtil.POST(urls[0], jsonObject);
    }
 private JSONObject removeFromCart(int productId, int userId)
     throws JSONException, RemoteException {
   JSONObject jsonObject = new JSONObject();
   try {
     proxy.removeFromCart(userId, productId);
     jsonObject.accumulate(Constants.STATUS, Constants.SUCCESS);
     jsonObject.accumulate(Constants.MESSAGE, Constants.SUCCESS_REMOVE_FROM_CART);
   } catch (SQLException e) {
     jsonObject.accumulate(Constants.STATUS, Constants.ERROR);
     jsonObject.accumulate(Constants.MESSAGE, Constants.ERROR_REMOVE_FROM_CART);
     e.printStackTrace();
   }
   return jsonObject;
 }
 private JSONObject checkout(HttpServletRequest request) throws JSONException, RemoteException {
   UserDTO user = (UserDTO) request.getSession().getAttribute(Constants.USER);
   JSONObject jsonObject = new JSONObject();
   try {
     proxy.checkout(user.getIdentifier());
     jsonObject.accumulate(Constants.STATUS, Constants.SUCCESS);
     jsonObject.accumulate(Constants.MESSAGE, Constants.TRANSACTION_COMPLETED_MSG);
   } catch (SQLException e) {
     jsonObject.accumulate(Constants.STATUS, Constants.ERROR);
     jsonObject.accumulate(Constants.MESSAGE, Constants.ERROR_SHOPPING_CART);
     e.printStackTrace();
   }
   return jsonObject;
 }
Example #11
0
 @Override
 protected Void doInBackground(Void... params) {
   try {
     DefaultHttpClient httpclient = new DefaultHttpClient();
     String reqURL = Constants.BASE_URL + Constants.MESSAGE_COUNT;
     HttpPost httpPost = new HttpPost(reqURL);
     String json = "";
     JSONObject reqparams = new JSONObject();
     reqparams.accumulate("appId", "1966477342111");
     reqparams.accumulate("secret", Constants.secret);
     reqparams.accumulate("access_token", AppController.getToken(AfterLoginActivity.this));
     reqparams.accumulate("device_id", AppController.getRegistrationId(AfterLoginActivity.this));
     reqparams.accumulate("os_type", "android");
     json = reqparams.toString();
     StringEntity se = new StringEntity(json);
     httpPost.setEntity(se);
     httpPost.setHeader("Accept", "application/json");
     httpPost.setHeader("Content-type", "application/json");
     HttpResponse httpResponse = httpclient.execute(httpPost);
     inputStream = httpResponse.getEntity().getContent();
     if (inputStream != null) result = AppController.convertInputStreamToString(inputStream);
     else result = "Did not work!";
   } catch (Exception e) {
     Log.d("InputStream", e.getLocalizedMessage());
   }
   try {
     JSONObject object = new JSONObject(result);
     JSONArray array = object.getJSONArray("data");
     message_count = array.length();
     runOnUiThread(
         new Runnable() {
           @Override
           public void run() {
             actionBarMessagesTV.setText(String.valueOf(message_count));
             Log.v("XXXXXXXXXXXX", "data sayısını bastı");
           }
         });
   } catch (JSONException e) {
     e.printStackTrace();
     runOnUiThread(
         new Runnable() {
           @Override
           public void run() {
             actionBarMessagesTV.setText("0");
             Log.v("XXXXXXXXXXXX", "data sayısını basamaıd");
           }
         });
   }
   return null;
 }
    @Override
    protected String doInBackground(String... urls) {
      if (isCancelled()) return null;

      JSONObject jsonObject = new JSONObject();
      try {
        jsonObject.accumulate("post_id", "" + post_id);
        jsonObject.accumulate("current_page", "" + current_page);
        jsonObject.accumulate("num_comments", "" + num_comments);
      } catch (JSONException e) {
        e.printStackTrace();
      }

      return JsonUtil.POST(urls[0], jsonObject);
    }
  @RequestMapping("/json/console/app/(*:appId)/(~:appVersion)/builder/actions")
  public void getBuilderDataActionList(
      ModelMap map,
      Writer writer,
      @RequestParam("appId") String appId,
      @RequestParam(required = false) String appVersion,
      HttpServletRequest request)
      throws Exception {
    appService.getAppDefinition(appId, appVersion);
    JSONObject jsonObject = new JSONObject();

    // get available binders
    DataListAction[] actions = dataListService.getAvailableActions();

    Collection<Object> collection = new ArrayList<Object>();
    for (DataListAction action : actions) {
      Plugin p = (Plugin) action;
      HashMap hm = new HashMap();
      hm.put("name", p.getName());
      hm.put("label", action.getLinkLabel());
      hm.put("className", action.getClassName());
      if (action instanceof PropertyEditable) {
        String propertyOptions = ((PropertyEditable) action).getPropertyOptions();
        if (propertyOptions != null && !propertyOptions.isEmpty()) {
          hm.put("propertyOptions", propertyOptions);
        }
      }
      hm.put("type", "text");
      collection.add(hm);
    }
    jsonObject.accumulate("actions", collection);
    jsonObject.write(writer);
  }
Example #14
0
 public JSONObject toJSONObject() throws JSONException {
   JSONObject jsonObject = new JSONObject().put("name", name).put("dataNodes", new JSONArray());
   for (DataNode dataNode : dataNodes) {
     jsonObject.accumulate("dataNodes", dataNode.toJSONObject());
   }
   return jsonObject;
 }
    @Override
    protected String doInBackground(String... params) {
      String response = null;

      try {

        ServerCommunicator serverCommunicator = new ServerCommunicator();

        String requestURL = Configuration.GET_CATEGORIES;

        System.out.println("the getting url is++" + requestURL);
        try {
          // 3. build jsonObject
          JSONObject jsonObject = new JSONObject();
          jsonObject.accumulate("category", "All");

          // 4. convert JSONObject to JSON to String
          reqParams = jsonObject.toString();
          Log.d("Login request params:", reqParams);

        } catch (JSONException e) {
          e.getLocalizedMessage();
        }
        response = serverCommunicator.postJSONData(reqParams, requestURL);
      } catch (Exception e) {
        e.printStackTrace();
      }
      System.out.println("responseresponse responseresponse--" + response);
      return response;
    }
Example #16
0
  public String createLoginJSON(String unm, String passwwd) {
    JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.accumulate("loginId", unm);
      jsonObject.accumulate("password", passwwd);

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    // 4. convert JSONObject to JSON to String
    String inputjson = jsonObject.toString();
    logger.info("login json =" + inputjson);
    return inputjson;
  }
  private JSONObject exportImageInfo(ImageInfoModel info) throws JSONException {
    JSONObject obj = new JSONObject();
    obj.put("file", info.getImageFile());
    if (info.isBallVisible()) {
      obj.put(
          "ball",
          new JSONObject()
              .put("x", info.getBallCenter().x)
              .put("y", info.getBallCenter().y)
              .put("radius", info.getBallRadius())
              .put("entirely-visible", info.isBallEntirelyVisible()));
    }

    if (info.isCyanTeamMarkerVisible()) {
      obj.put("cyan-team-marker", exportRectangle(info.getCyanTeamMarkerRectangle()));
    }

    if (info.isMagentaTeamMarkerVisible()) {
      obj.put("magenta-team-marker", exportRectangle(info.getMagentaTeamMarkerRectangle()));
    }

    if (info.isYellowGoalLeftVisible()) {
      obj.put("yellow-goal-left", exportRectangle(info.getYellowGoalLeftRectangle()));
    }

    if (info.isYellowGoalRightVisible()) {
      obj.put("yellow-goal-right", exportRectangle(info.getYellowGoalRightRectangle()));
    }

    if (info.isCarpetVisible()) {
      obj.put("carpet", exportRectangle(info.getCarpetRectangle()));
    }

    if (info.hasFloorPlanePoints()) {
      for (Point point : info.getFloorPlanePoints()) {
        obj.accumulate("floor", new JSONObject(point, new String[] {"x", "y"}));
      }
    }

    if (info.hasLinePoints()) {
      for (Point point : info.getLinePoints()) {
        obj.accumulate("field-line", new JSONObject(point, new String[] {"x", "y"}));
      }
    }

    return obj;
  }
    @Override
    protected String doInBackground(String... urls) {

      JSONObject jsonObject = new JSONObject();
      try {
        // 1India-1, 2Economy-2, 3Politics-3,	4world-4, 5business-5, 6Sc&T-6,	7sports-7,
        // 8miscellaneous-8
        position = etCategory.getSelectedItemPosition();
        category = position + 1; // position starts from 0
        jsonObject.accumulate("link", etUrl.getText().toString());
        jsonObject.accumulate("cat", "" + category);
        jsonObject.accumulate("tags", etTags.getText().toString());
        jsonObject.accumulate("username", UserDataHolder.getInstance().getUsername());
      } catch (JSONException e) {
        e.printStackTrace();
      }

      return JsonUtil.POST(urls[0], jsonObject);
    }
Example #19
0
  public String createChangePasswdJSON(
      String name, String oldPasswd, String newPasswd, String confirmNewPaswd) {
    JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.accumulate("loginId", name);
      jsonObject.accumulate("currentPassword", oldPasswd);
      jsonObject.accumulate("password", newPasswd);
      jsonObject.accumulate("confirmPassword", confirmNewPaswd);

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    // 4. convert JSONObject to JSON to String
    String inputjson = jsonObject.toString();
    logger.info("changePasswd json =" + inputjson);
    return inputjson;
  }
Example #20
0
  public String createBetOkJSON(
      String gameId, String currentGameId, String userId, HashMap<String, Integer> currentbetMap) {
    JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.accumulate("gameId", gameId);
      jsonObject.accumulate("currentGameId", currentGameId);
      jsonObject.accumulate("userId", userId);
      jsonObject.accumulate("finalBet", BetUtility.getInstance().convertBetToString(currentbetMap));

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    // 4. convert JSONObject to JSON to String
    String inputjson = jsonObject.toString();
    logger.info("bet ok json =" + inputjson);
    return inputjson;
  }
Example #21
0
 public JSONObject toJSONObject() throws JSONException {
   JSONObject jsonObject =
       new JSONObject()
           .put("clusterName", hardwareLayout.getClusterName())
           .put("version", version)
           .put("partitions", new JSONArray());
   for (Partition partition : partitionMap.values()) {
     jsonObject.accumulate("partitions", partition.toJSONObject());
   }
   return jsonObject;
 }
Example #22
0
 public JSONObject toJSONObject() throws JSONException {
   JSONObject jsonObject =
       new JSONObject()
           .put("clusterName", clusterName)
           .put("version", version)
           .put("datacenters", new JSONArray());
   for (Datacenter datacenter : datacenters) {
     jsonObject.accumulate("datacenters", datacenter.toJSONObject());
   }
   return jsonObject;
 }
Example #23
0
  public String createTransferPointsJSON(
      String transferTo, String amount, String fromUserId, String actionType) {
    JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.accumulate("frmUserId", fromUserId);
      if (transferTo != null) {
        jsonObject.accumulate("toUserId", transferTo);
      }
      jsonObject.accumulate("actionType", actionType);
      jsonObject.accumulate("transferPoints", amount);

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    // 4. convert JSONObject to JSON to String
    String inputjson = jsonObject.toString();
    logger.info("xfer json=" + inputjson);
    return inputjson;
  }
  public String POST(String url) {

    InputStream inputStream = null;
    String result = "";
    try {

      // 1. create HttpClient
      HttpClient httpclient = new DefaultHttpClient();

      // 2. make POST request to the given URL
      HttpPost httpPost = new HttpPost(url);

      String json = "";

      // 3. build jsonObject
      JSONObject jsonObject = new JSONObject();
      jsonObject.accumulate("reg_name", name);
      jsonObject.accumulate("reg_contact", phone);
      jsonObject.accumulate("reg_veh_no", vehicle);
      jsonObject.accumulate("reg_id", regId);
      jsonObject.accumulate("reg_email", email);
      jsonObject.accumulate("lati", lati);
      jsonObject.accumulate("longi", longi);

      // 4. convert JSONObject to JSON to String
      json = jsonObject.toString();

      // 5. set json to StringEntity
      StringEntity se = new StringEntity(json);

      // 6. set httpPost Entity
      httpPost.setEntity(se);

      // 7. Set some headers to inform server about the type of the content
      httpPost.setHeader("Accept", "application/json");
      httpPost.setHeader("Content-type", "application/json");

      // 8. Execute POST request to the given URL
      HttpResponse httpResponse = httpclient.execute(httpPost);

      // 9. receive response as inputStream
      inputStream = httpResponse.getEntity().getContent();
      // 10. convert inputstream to string
      if (inputStream != null) {
        result = convertInputStreamToString(inputStream);

      } else result = "Did not work!";

    } catch (Exception e) {
      Log.d("InputStream", e.getLocalizedMessage());
    }

    // 11. return result
    return result;
  }
  public static String DELETE(String url, allTransactionsM model) {
    InputStream inputStream = null;
    String result = "";
    try {

      HttpClient httpclient = new DefaultHttpClient();

      HttpDeleteWithBody delete = new HttpDeleteWithBody(url);

      String json = "";

      JSONObject jsonObject = new JSONObject();
      jsonObject.accumulate("id", model.getId());
      jsonObject.accumulate("productGroup", model.getProductGroup());
      jsonObject.accumulate("productName", model.getProductName());
      jsonObject.accumulate("transaction", model.getTransaction());
      jsonObject.accumulate("date", model.getDate());

      json = jsonObject.toString();

      StringEntity se = new StringEntity(json);

      delete.setEntity(se);

      delete.setHeader("Accept", "application/json");
      delete.setHeader("Content-type", "application/json");

      HttpResponse httpResponse = httpclient.execute(delete);

      inputStream = httpResponse.getEntity().getContent();

      if (inputStream != null) result = convertInputStreamToString(inputStream);
      else result = "Did not work!";

    } catch (Exception e) {
      Log.w("InputStream", e.toString());
    }
    return result;
  }
Example #26
0
  public static void main(String[] args) {
    CommandLine jct = new CommandLine();
    new JCommander(jct, args);

    ClientSocket socket = new ClientSocket();
    WorldModel wm = new WorldModel();
    PlayerAI ai = new PlayerAI();
    NetworkHandler clientNetworkHandler = new NetworkHandler(socket, wm, ai);
    socket.connect(jct.host, jct.port.intValue());
    JSONObject object = new JSONObject();
    object.accumulate("name", "Pouya");
    socket.response(object.toString());
  }
Example #27
0
  public String createUser(
      String userId,
      String firstName,
      String lastname,
      String passwd,
      String contactNo,
      String email,
      String parentRole,
      String parentUserId,
      String clientId) {
    JSONObject jsonObject = new JSONObject();
    try {

      String createdUserRole = "";
      if (parentRole.equalsIgnoreCase("Admin")) {
        createdUserRole = "broker";
        parentUserId = "";
      } else if (parentRole.equalsIgnoreCase("broker")) {
        createdUserRole = "user";
      }

      jsonObject.accumulate("userId", userId);
      jsonObject.accumulate("password", passwd);
      jsonObject.accumulate("clientId", clientId);
      jsonObject.accumulate("firstName", firstName);
      jsonObject.accumulate("lastName", lastname);
      jsonObject.accumulate("contactNo", contactNo);
      jsonObject.accumulate("parentUserId", parentUserId);
      if (email != null) {
        jsonObject.accumulate("email", email);
      }
      jsonObject.accumulate("userRole", createdUserRole);

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    // 4. convert JSONObject to JSON to String
    String inputjson = jsonObject.toString();
    Log.d(TAG, "create user json=" + inputjson);
    return inputjson;
  }
 /** @return all allowed cards to transfer money */
 public String getTransferCards() {
   JSONObject j = new JSONObject();
   try {
     for (Card card : transferCards) {
       JSONObject json = new JSONObject();
       json.put("card", card.getId());
       j.accumulate("cards", json);
     }
   } catch (JSONException e) {
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
   return j.toString();
 }
 /**
  * Get billing history
  *
  * @param card
  * @param limit
  * @param start
  * @return
  */
 public String getHistory(Card card, Integer limit, Integer start) {
   this.currentCard = card;
   JSONObject json = new JSONObject();
   List<Invoice> history = invoiceService.getIncome(currentCard);
   history.addAll(invoiceService.getOutcome(currentCard));
   try {
     json.put("total", history.size());
     for (int i = start; i <= start + limit && i < history.size(); i++) {
       json.accumulate("history", history.get(i).toJson());
     }
   } catch (JSONException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return json.toString();
 }
Example #30
0
 public String getDatasFromServer(Integer row_id) {
   try {
     ODomain domain = new ODomain();
     domain.add("id", "=", selectServerId(row_id));
     JSONObject fields = new JSONObject();
     fields.accumulate("fields", "datas");
     JSONObject result =
         getServerDataHelper().getOdoo().search_read(getModelName(), fields, domain.get());
     if (result.getJSONArray("records").length() > 0) {
       JSONObject row = result.getJSONArray("records").getJSONObject(0);
       return row.getString("datas");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return "false";
 }