Ejemplo n.º 1
0
  private GroupRole grantRole(
      Repository repo, Organisation withinOrg, String roleName, Session session) {
    if (getGroupRoles() == null) {
      setGroupRoles(new ArrayList<GroupRole>());
    }

    // Check if this role already exists
    for (GroupRole gr : getGroupRoles()) {
      if (gr.getRoleName().equals(roleName)) {
        if (gr.getWithinOrg() != null && gr.getWithinOrg() == withinOrg) {
          // nothing to do
          return null;
        } else if (gr.getRepository() != null && gr.getRepository() == repo) {
          // nothing to do
          return null;
        } else if (withinOrg == null
            && repo == null
            && gr.getRepository() == null
            && gr.getWithinOrg() == null) {
          return null;
        }
      }
    }
    GroupRole gr = new GroupRole();
    gr.setGrantee(this);
    gr.setRoleName(roleName);
    gr.setRepository(repo);
    gr.setWithinOrg(withinOrg);
    session.save(gr);
    getGroupRoles().add(gr);
    return gr;
  }