Example #1
0
 /**
  * Find the closest parent organisation with a non-null admin domain, or this org if it has a
  * non-null admin domain
  *
  * @return
  */
 public Organisation closestAdminOrg() {
   Organisation p = this;
   while (p.getAdminDomain() == null && p.getOrganisation() != null) {
     p = p.getOrganisation();
   }
   return p;
 }
Example #2
0
  /**
   * Create a GroupMembership linking this profile to the given group, within the given
   * organisation. Is immediately saved
   *
   * <p>If a duplicate membership exists an exception is thrown
   *
   * <p>Check for existing membership by calling getGroupMembership(group, hasGruopInOrg, session)
   *
   * @param g
   * @param hasGroupInOrg
   * @param session
   * @return
   */
  public GroupMembership createGroupMembership(
      Group g, Organisation hasGroupInOrg, Session session) {
    GroupMembership gm = getGroupMembership(g, hasGroupInOrg, session);
    if (gm != null) {
      return gm;
    }
    gm = new GroupMembership();
    gm.setCreatedDate(new Date());
    gm.setGroupEntity(g);
    gm.setMember(this);
    gm.setWithinOrg(hasGroupInOrg);
    gm.setModifiedDate(new Date());
    session.save(gm);

    if (g.getGroupMemberships() == null) {
      g.setGroupMemberships(new ArrayList<GroupMembership>());
    }
    g.getGroupMemberships().add(gm);

    // Need to create a subordinate record for each parent organisation
    Organisation subordinateTo = hasGroupInOrg;
    while (subordinateTo != null) {
      createSubordinate(subordinateTo, gm, session);
      subordinateTo = subordinateTo.getOrganisation();
    }

    if (getMemberships() == null) {
      setMemberships(new ArrayList<GroupMembership>());
    }
    getMemberships().add(gm);
    return gm;
  }
Example #3
0
 public OrgType createOrgType(String name, Session session) {
   OrgType existing = orgType(name);
   if (existing != null) {
     throw new RuntimeException("An organisation type with that name already exists");
   }
   Organisation parent = getOrganisation();
   while (parent != null) {
     if (parent.orgType(name) != null) {
       throw new RuntimeException(
           "An organisation type with that name exists in a parent organisation: "
               + parent.getOrgId());
     }
     parent = parent.getOrganisation();
   }
   OrgType ot = new OrgType();
   ot.setName(name);
   ot.setDisplayName(name);
   ot.setOrganisation(this);
   getOrgTypes().add(ot);
   session.save(this);
   session.save(ot);
   return ot;
 }