Пример #1
0
  @Override
  public Role edit(Role role) {
    Trole t = roleDao.get(Trole.class, role.getId());
    if (t != null) {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("trole", t);
      roleResourceDao.executeHql("delete TroleTresource t where t.trole=:trole", params);

      BeanUtils.copyProperties(role, t);
      if (role.getResourceIds() != null) {
        String resourceNames = "";
        for (String id : role.getResourceIds().split(",")) {
          Tresource r = resourceDao.get(Tresource.class, id);
          if (r != null) {
            TroleTresource rr = new TroleTresource();
            rr.setId(UUID.randomUUID().toString());
            rr.setTresource(r);
            rr.setTrole(t);
            roleResourceDao.save(rr);

            if (resourceNames.length() > 0) {
              resourceNames += ",";
            }
            resourceNames += r.getText();
          }
        }
        role.setResourceNames(resourceNames);
      }
    }
    return role;
  }
Пример #2
0
  @Override
  public Role save(Role role) {
    Trole t = new Trole();
    BeanUtils.copyProperties(role, t);
    t.setId(UUID.randomUUID().toString());
    roleDao.save(t);
    if (role.getResourceIds() != null) {
      String resourceNames = "";
      for (String id : role.getResourceIds().split(",")) {
        Tresource r = resourceDao.get(Tresource.class, id);
        if (r != null) {
          TroleTresource rr = new TroleTresource();
          rr.setId(UUID.randomUUID().toString());
          rr.setTresource(r);
          rr.setTrole(t);
          roleResourceDao.save(rr);

          if (resourceNames.length() > 0) {
            resourceNames += ",";
          }
          resourceNames += r.getText();
        }
      }
      role.setResourceNames(resourceNames);
    }
    role.setId(t.getId());
    return role;
  }