@Override
public void assignPermissions(String dynamicRoleId, Set<IPermissionMetaInfo> permissions) throws ObjectNotFoundException {
DynamicRoleMetaInfo role = (DynamicRoleMetaInfo) getDynamicRole(dynamicRoleId);
if (role == null) {
throw new ObjectNotFoundException("Dynamic role is not found", dynamicRoleId);
}
String appId = role.getModelId();
Set<PermissionRole> perm = role.getPermissionRoles();
if (permissions == null) {
perm.clear();
save(role);
// getHibernateTemplate().save(role);
return;
}
Set<PermissionRole> permToDelete = new HashSet<PermissionRole>();
for (PermissionRole prole : perm) {
String permissionId = prole.getPermissionId();
boolean containsPermission = false;
for (IPermissionMetaInfo permission : permissions) {
if (permission.getId().equals(permissionId)) {
containsPermission = true;
break;
}
}
if (!containsPermission) {
permToDelete.add(prole);
}
}
perm.removeAll(permToDelete);
for (IPermissionMetaInfo permission : permissions) {
boolean permissionExists = permissionDAO.existsPermission(appId, permission.getId());
if (!permissionExists) {
throw new ObjectNotFoundException("Permission is not found", permission.getId());
}
PermissionRole prole = new PermissionRole();
prole.setRole(role);
prole.setPermissionId(permission.getId());
if (!perm.contains(prole)) {