public Organisation childOrg(Long orgId, Session session) { Organisation child = get(orgId, session); if (child == null) { return null; } if (child.isWithin(this)) { return child; } return null; }
/** * Find out if this user is associated with the group in an organisation which is within the * membership group * * @param groupName * @param org * @return */ public boolean isInGroup(String groupName, Organisation org) { if (getMemberships() != null) { for (GroupMembership m : getMemberships()) { if (m.getGroupEntity().getName().equals(groupName)) { if (org.isWithin(m.getWithinOrg())) { return true; } } } } return false; }
/** * Check if this organisation is within, or is, the given org * * @param withinOrg * @return */ public boolean isWithin(Organisation withinOrg) { if (withinOrg == null) { return false; } if (withinOrg == this) { return true; } Organisation parent = getOrganisation(); if (parent != null) { return parent.isWithin(withinOrg); } return false; }
public boolean hasRole(String roleName, Organisation org) { if (getMemberships() != null) { for (GroupMembership m : getMemberships()) { if (org.isWithin(m.getWithinOrg())) { for (GroupRole r : m.getGroupEntity().getGroupRoles()) { if (r.getRoleName().equals(roleName)) { return true; } } } } } return false; }
/** * Remove all memberships of this profile within this organiosation or subordinate organisations * * @param profile * @param session */ public void removeMember(Profile profile, Session session) { log.info("removeMember: profileid=" + profile.getId() + " org=" + getOrgId()); List<GroupMembership> toDelete = new ArrayList<>(); if (profile.getMemberships() != null) { for (GroupMembership m : profile.getMemberships()) { Organisation memberWithin = m.getWithinOrg(); if (memberWithin.isWithin(this)) { log.info( "Remove membership of user: "******" from org: " + memberWithin.getOrgId()); toDelete.add(m); } } } for (GroupMembership m : toDelete) { m.delete(session); } }