@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;
  }
  @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;
  }
Beispiel #3
0
 @Override
 public User save(User user) {
   Tuser t = new Tuser();
   BeanUtils.copyProperties(user, t, new String[] {"pwd"});
   t.setId(UUID.randomUUID().toString());
   t.setCreatedatetime(new Date());
   t.setPwd(Encrypt.e(user.getPwd()));
   userDao.save(t);
   BeanUtils.copyProperties(t, user);
   return user;
 }
 @Override
 public Menu add(Menu menu) {
   Tmenu t = new Tmenu();
   BeanUtils.copyProperties(menu, t);
   t.setId(UUID.randomUUID().toString());
   if (menu.getPid() != null) {
     Tmenu p = menuDao.get(Tmenu.class, menu.getPid());
     if (p != null) {
       t.setTmenu(p);
     }
   }
   t.setIconcls(menu.getIconCls());
   menuDao.save(t);
   BeanUtils.copyProperties(t, menu);
   return menu;
 }