コード例 #1
0
  @RequestMapping(value = "/save")
  @ResponseBody
  public JSONObject saveLanguage(HttpServletRequest request) {
    AjaxResponse R = new AjaxResponse(request);
    UserSecurity me = R.getUser();
    AccessManager manager = null;

    boolean create, update, error = false;
    if (me == null || (manager = me.getAccessManager()) == null) error = true;

    if (!(create = manager.has("LANGUAGE", "ADD"))) error = true;

    if (!(update = manager.has("LANGUAGE", "MODIFY"))) error = true;

    if (error) R.addError(AccessErrors._NAME, AccessErrors.NOT_HAS_PERMISSIONS);

    if (!R.hasError()) {
      String tmp = request.getParameter("languageId"),
          name = request.getParameter("name"),
          code = request.getParameter("code");
      int languageId = tmp != null ? Integer.parseInt(tmp) : 0;
      boolean enabled = Boolean.parseBoolean(request.getParameter("enabled"));
      Language languageById, languageByCode;

      if (code == null || code.isEmpty())
        R.addError(DataModifyErrors._NAME, DataModifyErrors.SECONDARY_KEY_EMPTY);

      languageByCode = Languages.getLanguage(code);

      if (!R.hasError())
        if (languageId > 0 && update) {
          languageById = Languages.getLanguage(languageId);

          if (languageByCode != null && languageById != languageByCode)
            R.addError(DataModifyErrors._NAME, DataModifyErrors.SECONDARY_KEY_EXISTS);
          else core.languageUpdate(languageId, name, code, enabled);
        } else if (create) {
          if (languageByCode != null)
            R.addError(DataModifyErrors._NAME, DataModifyErrors.SECONDARY_KEY_EXISTS);
          else core.languageCreate(name, code, enabled);
        }
    }

    return R.getReturn();
  }
コード例 #2
0
  @RequestMapping(value = "/delete/{languageId}")
  @ResponseBody
  public JSONObject deleteLanguage(HttpServletRequest request, @PathVariable int languageId) {
    AjaxResponse R = new AjaxResponse(request);
    UserSecurity me = R.getUser();
    AccessManager manager;

    if (me == null
        || (manager = me.getAccessManager()) == null
        || !manager.has("LANGUAGE", "REMOVE"))
      R.addError(AccessErrors._NAME, AccessErrors.NOT_HAS_PERMISSIONS);

    if (!R.hasError()) core.languageDelete(languageId);

    return R.getReturn();
  }