public void add(Auth auth) { Tauth t = new Tauth(); BeanUtils.copyProperties(auth, t); t.setCid(UUID.randomUUID().toString()); if (auth.getPid() != null && !auth.getPid().equals(auth.getCid())) { t.setTauth(authDao.get(Tauth.class, auth.getPid())); } authDao.save(t); }
private boolean isDown(Tauth t, Tauth pt) { if (pt.getTauth() != null) { if (pt.getTauth().getCid().equals(t.getCid())) { return true; } else { return isDown(t, pt.getTauth()); } } return false; }
private void del(String cid) { Tauth t = authDao.get(Tauth.class, cid); if (t != null) { roleauthDao.executeHql("delete Troletauth t where t.tauth = ?", new Object[] {t}); Set<Tauth> auths = t.getTauths(); if (auths != null && !auths.isEmpty()) { // there exists child auth under current auth for (Tauth tauth : auths) { del(tauth.getCid()); } } authDao.delete(t); } }
private List<Auth> changeModel(List<Tauth> tauths) { List<Auth> l = new ArrayList<Auth>(); if (tauths != null && tauths.size() > 0) { for (Tauth t : tauths) { Auth a = new Auth(); BeanUtils.copyProperties(t, a); if (t.getTauth() != null) { a.setPid(t.getTauth().getCid()); a.setPname(t.getTauth().getCname()); } if (countChildren(t.getCid()) > 0) { a.setState("closed"); } l.add(a); } } return l; }
public void edit(Auth auth) { Tauth t = authDao.get(Tauth.class, auth.getCid()); // authority to be edit BeanUtils.copyProperties(auth, t); if (auth.getPid() != null && !auth.getPid().equals(auth.getCid())) { Tauth pAuth = authDao.get(Tauth.class, auth.getPid()); // parent authority if (pAuth != null) { if (isDown(t, pAuth)) { Set<Tauth> tauths = t.getTauths(); // all child auth of current auth if (tauths != null && tauths.size() > 0) { for (Tauth tauth : tauths) { if (tauth != null) { tauth.setTauth(null); } } } } t.setTauth(pAuth); } } }
private TreeNode tree(Tauth t, boolean recursive) { TreeNode node = new TreeNode(); node.setId(t.getCid()); node.setText(t.getCname()); Map<String, Object> attributes = new HashMap<String, Object>(); node.setAttributes(attributes); if (t.getTauths() != null && t.getTauths().size() > 0) { node.setState("closed"); if (recursive) { // query child nodes recursively List<Tauth> l = new ArrayList<Tauth>(t.getTauths()); Collections.sort(l, new AuthComparator()); // sort List<TreeNode> children = new ArrayList<TreeNode>(); for (Tauth r : l) { TreeNode tn = tree(r, true); children.add(tn); } node.setChildren(children); node.setState("open"); } } return node; }
public User login(User user) { Tuser t = userDao.get( "from Tuser t where t.cname = ? and t.cpwd = ?", new Object[] {user.getCname(), Encrypt.e(user.getCpwd())}); if (t != null) { BeanUtils.copyProperties(t, user, new String[] {"cpwd"}); Map<String, String> authIdsMap = new HashMap<String, String>(); String authIds = ""; String authNames = ""; Map<String, String> authUrlsMap = new HashMap<String, String>(); String authUrls = ""; String roleIds = ""; String roleNames = ""; boolean b1 = false; Set<Tusertrole> tusertroles = t.getTusertroles(); if (tusertroles != null && tusertroles.size() > 0) { for (Tusertrole tusertrole : tusertroles) { Trole trole = tusertrole.getTrole(); if (b1) { roleIds += ","; roleNames += ","; } roleIds += trole.getCid(); roleNames += trole.getCname(); b1 = true; Set<Troletauth> troletauths = trole.getTroletauths(); if (troletauths != null && troletauths.size() > 0) { for (Troletauth troletauth : troletauths) { Tauth tauth = troletauth.getTauth(); authIdsMap.put(tauth.getCid(), tauth.getCname()); authUrlsMap.put(tauth.getCid(), tauth.getCurl()); } } } } boolean b2 = false; for (String id : authIdsMap.keySet()) { if (b2) { authIds += ","; authNames += ","; } authIds += id; authNames += authIdsMap.get(id); b2 = true; } user.setAuthIds(authIds); user.setAuthNames(authNames); user.setRoleIds(roleIds); user.setRoleNames(roleNames); boolean b3 = false; for (String id : authUrlsMap.keySet()) { if (b3) { authUrls += ","; } authUrls += authUrlsMap.get(id); b3 = true; } user.setAuthUrls(authUrls); return user; } return null; }