예제 #1
0
  @Override
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Post
  public Representation post(Representation entity) {

    Form form = new Form(entity);
    String operation = null;
    int start = 0;
    int limit = 50;
    try {
      operation = URLDecoder.decode(form.getQueryString(), "utf-8");
      operation = new String(operation.getBytes("iso-8859-1"), "utf-8");
      JSONObject json = JSONObject.fromObject(operation);
      start =
          json.containsKey("start") == false ? start : Integer.parseInt(json.getString("start"));
      limit =
          json.containsKey("limit") == false ? limit : Integer.parseInt(json.getString("limit"));
    } catch (Exception e) {
      // e.printStackTrace();
    }
    List<Role> list = service.getAllRole(start, limit);
    Page page = new Page(list);
    page.setStart(start);
    page.setPageSize(limit);
    int totalCount = service.getCountRole();
    page.setTotalCount(totalCount);
    return new JsonRepresentation(JSONObject.fromObject(page));
  }
예제 #2
0
  public Handler(Query query, Form form) throws ResourceException {
    this.query = query;
    this.queryString = form.getQueryString();
    for (QueryParameter p : query.getParameters()) {

      String name = p.getName();
      String svalue = form.getFirstValue(name, true);

      switch (p.getType()) {
        case DATE:
          parameters.put(p, readParameterValue(Date.class, p, svalue));
          break;

        case NUMBER:
          parameters.put(p, readParameterValue(BigDecimal.class, p, svalue));
          break;

        case STRING:
          parameters.put(p, readParameterValue(String.class, p, svalue));
          break;

        case CLOB:
        case BLOB:
          throw new ClientErrorException(
              Status.CLIENT_ERROR_BAD_REQUEST,
              String.format("LOBs are not supported as parameters: %s", name));
      }
    }

    if (log.isDebugEnabled()) {
      for (QueryParameter qp : parameters.keySet()) {
        log.debug(qp.toString(parameters.get(qp)));
      }
    }
  }
예제 #3
0
 @Override
 @SuppressWarnings("unchecked")
 @Put
 public Representation put(Representation entity) {
   Form form = new Form(entity);
   String name = (String) getRequestAttributes().get("name");
   String operation = null;
   boolean flag = true;
   String message = "操作成功!";
   try {
     operation = URLDecoder.decode(form.getQueryString(), "utf-8");
     operation = new String(operation.getBytes("iso-8859-1"), "utf-8");
     JSONObject json = JSONObject.fromObject(operation);
     String roleName = json.getString("roleName");
     Role role = new Role();
     String moduels = json.containsKey("modules") == false ? "" : json.getString("modules");
     String roleDesc = json.containsKey("roleDesc") == false ? "" : json.getString("roleDesc");
     role.setRoleName(roleName);
     role.setModules(moduels);
     role.setRoleDesc(roleDesc);
     if (name != null && name.equals("update")) {
       flag = service.updateRole(role);
       if (!flag) message = "操作失败!";
     } else {
       if (service.getRoleByName(roleName) == null) {
         flag = service.saveRole(role);
         if (!flag) message = "操作失败!";
       } else {
         message = "此角色已经存在,请重新填写!";
         flag = false;
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     message = e.getMessage();
   }
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("message", message);
   map.put("success", flag);
   if (!flag) getResponse().setStatus(new Status(600), message);
   return new JsonRepresentation(JSONObject.fromObject(map));
 }