Example #1
0
 public OrgType orgType(String name) {
   if (getOrgTypes() != null) {
     for (OrgType ot : getOrgTypes()) {
       if (ot.getName().equals(name)) {
         return ot;
       }
     }
   }
   return null;
 }
Example #2
0
  /**
   * Sets the new org type on this group, updating collections in the old and new org type objects
   * if they're not null
   *
   * @param newOrgType
   * @param session
   */
  public void setRegoOrgType(OrgType newOrgType, Session session) {
    OrgType oldOrgType = getRegoOrgType();
    if (oldOrgType != null) {
      oldOrgType.getGroups().remove(this);
      session.save(oldOrgType);
    }

    setRegoOrgType(newOrgType);

    if (newOrgType != null) {
      if (newOrgType.getGroups() == null) {
        newOrgType.setGroups(new ArrayList<Group>());
      }
      newOrgType.getGroups().add(this);
    }
  }
Example #3
0
 /**
  * Find all memberships of this user to organisations of the given type, which are within the
  * given parent org. If the orgtype is null returns all memberships withint the given parent org
  *
  * @param ot
  * @param parentOrg
  * @return
  */
 public List<GroupMembership> membershipsForOrgType(OrgType ot, Organisation parentOrg) {
   List<GroupMembership> list = new ArrayList<>();
   if (ot == null) {
     // use any membership from within the awarding org
     if (getMemberships() != null) {
       getMemberships()
           .stream()
           .filter((m) -> (m.getWithinOrg().isWithin(parentOrg)))
           .forEach(
               (m) -> {
                 list.add(m);
               });
     }
   } else {
     // find a membership to an org of type pointsOrgType
     if (getMemberships() != null) {
       getMemberships()
           .stream()
           .filter((m) -> (m.getWithinOrg().isWithin(parentOrg)))
           .filter(
               (m) ->
                   (m.getWithinOrg().getOrgType() != null
                       && ot.getId() == m.getWithinOrg().getOrgType().getId()))
           .forEach(
               (m) -> {
                 list.add(m);
               });
     }
   }
   return list;
 }
Example #4
0
 public OrgType orgType(String name, boolean autoCreate, Session session) {
   OrgType ot = orgType(name);
   if (ot == null) {
     if (autoCreate) {
       if (getOrgTypes() == null) {
         setOrgTypes(new ArrayList<>());
       }
       ot = new OrgType();
       ot.setName(name);
       ot.setDisplayName(name);
       ot.setOrganisation(this);
       getOrgTypes().add(ot);
       session.save(this);
       session.save(ot);
     }
   }
   return ot;
 }
Example #5
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;
 }
Example #6
0
 @Factory("orgTypes")
 public OrgType[] getOrgTypes() {
   return OrgType.values();
 }