private void changeModel(List<Trole> l, List<Role> nl) { if (l != null && l.size() > 0) { for (Trole t : l) { Role u = new Role(); BeanUtils.copyProperties(t, u); Set<TroleTresource> s = t.getTroleTresources(); if (s != null && !s.isEmpty()) { String resourceIds = ""; String resourceNames = ""; for (TroleTresource rr : s) { Tresource r = rr.getTresource(); if (resourceIds.length() > 0) { resourceIds += ","; resourceNames += ","; } resourceIds += r.getId(); resourceNames += r.getText(); } u.setResourceIds(resourceIds); u.setResourceNames(resourceNames); } nl.add(u); } } }
@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; }