Пример #1
0
 @Override
 public void handlePut(ActionParameters params) throws ActionException {
   log.debug("handlePut");
   User user = new User();
   getUserParams(user, params);
   String password = params.getRequiredParam(PARAM_PASSWORD);
   String[] roles = params.getRequest().getParameterValues("roles");
   User retUser = null;
   try {
     retUser = userService.createUser(user, roles);
     userService.setUserPassword(retUser.getScreenname(), password);
   } catch (ServiceException se) {
     throw new ActionException(se.getMessage(), se);
   }
   JSONObject response = null;
   try {
     response = user2Json(retUser);
   } catch (JSONException je) {
     throw new ActionException(je.getMessage(), je);
   }
   ResponseHelper.writeResponse(params, response);
 }
Пример #2
0
  @Override
  public void handlePost(ActionParameters params) throws ActionException {
    log.debug("handlePost");
    User user = new User();
    getUserParams(user, params);
    String[] roles = params.getRequest().getParameterValues("roles");
    String password = params.getHttpParam(PARAM_PASSWORD);
    User retUser = null;
    try {
      if (user.getId() > -1) {
        // retUser = userService.modifyUser(user);
        log.debug("roles size: " + roles.length);
        retUser = userService.modifyUserwithRoles(user, roles);
        log.debug("done modifying user");
        if (password != null && !"".equals(password.trim())) {
          userService.updateUserPassword(retUser.getScreenname(), password);
        }
      } else {
        log.debug("NOW IN POST and creating a new user!!!!!!!!!!!!!");
        if (password == null || password.trim().isEmpty()) {
          throw new ActionException("Parameter 'password' not found.");
        }
        retUser = userService.createUser(user);
        userService.setUserPassword(retUser.getScreenname(), password);
      }

    } catch (ServiceException se) {
      throw new ActionException(se.getMessage(), se);
    }
    JSONObject response = null;
    try {
      response = user2Json(retUser);
    } catch (JSONException je) {
      throw new ActionException(je.getMessage(), je);
    }
    ResponseHelper.writeResponse(params, response);
  }