Ejemplo n.º 1
0
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  @Path("select")
  public String getUserData(String json) {
    JSONObject jObj = null;
    try {
      jObj = new JSONObject(json);
      Integer userID = Integer.parseInt(jObj.getString("userID"));
      User user = dbManager.getUserbyAccountId(userID);

      jObj.put("middle_name", user.getMiddleName());
      jObj.put("last_name", user.getLastName());
      jObj.put("street", user.getStreet());
      jObj.put("house_number", user.getHouseNumber());
      jObj.put("city", user.getCity());
      jObj.put("postal_code", user.getPostalCode());
      jObj.put("country", user.getCountry());
      Account account = user.getAccountId();
      jObj.put("email", account.getUserName());

    } catch (JSONException ex) {
      Logger.getLogger(ChangeAccount.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      return jObj.toString();
    }
  }
Ejemplo n.º 2
0
  @POST
  @Path("update")
  @Consumes(MediaType.APPLICATION_JSON)
  public String updateUserData(String json)
      throws JSONException, IOException, NonexistentEntityException, RollbackFailureException,
          Exception {
    JSONObject jObj = new JSONObject(json);
    try {
      int userId = jObj.getInt("userID");
      String email = jObj.getString("email");
      String password = jObj.getString("password");

      String middleName = jObj.optString("middle_name");
      String lastName = jObj.optString("last_name");
      String street = jObj.optString("street");
      String houseNumber = jObj.optString("house_number");
      String postalCode = jObj.optString("postal_code");
      String city = jObj.optString("city");
      String country = jObj.optString("country");

      Account account = dbManager.findById(Account.class, userId);
      account.setUserName(email);
      account.setPassword(password);
      User user = account.getUser();
      user.setCity(city);
      user.setCountry(country);
      user.setHouseNumber(houseNumber);
      user.setLastName(lastName);
      user.setPostalCode(postalCode);
      user.setStreet(street);

      if (password != null && !password.isEmpty()) {
        dbManager.save(account);
      }
      dbManager.save(user);

    } catch (Exception ex) {
      Logger.getLogger(ChangeAccount.class.getName()).log(Level.SEVERE, null, ex);
      return jObj.put("result", true).toString();
    }
    jObj = new JSONObject();

    return jObj.put("result", true).toString();
  }