예제 #1
0
 /**
  * Check if the organisation ID on this org is unique within its administrative domain (ie first
  * parent org with a non-null adminDomain)
  *
  * @param session
  * @return
  */
 public boolean isOrgIdUniqueWithinAdmin(Session session) {
   log.info("isOrgIdUniqueWithinAdmin: My OrgID={}", getOrgId());
   Organisation admin = closestAdminOrg();
   for (Organisation withSameOrgId : Organisation.findListByOrgId(admin, getOrgId(), session)) {
     if (withSameOrgId.getId() != this.getId()) {
       log.warn(
           "Found same orgID on record: "
               + withSameOrgId.getId()
               + " matching this record "
               + getId()
               + " in admin org= "
               + admin.getAdminDomain()
               + " id="
               + admin.getId());
       return false;
     }
   }
   log.info("isOrgIdUniqueWithinAdmin: All good");
   return true;
 }
예제 #2
0
 public GroupMembership getGroupMembership(Group g, Organisation hasGroupInOrg, Session session) {
   if (getMemberships() != null) {
     for (GroupMembership gm : getMemberships()) {
       if (gm.getGroupEntity().getId() == g.getId()) {
         // same group
         if (gm.getWithinOrg().getId() == hasGroupInOrg.getId()) {
           // and same org, so its a duplicate
           return gm;
         }
       }
     }
   }
   return null;
 }
예제 #3
0
  public static long countChildOrgs(Organisation organisation, Session session) {
    Criteria crit = session.createCriteria(Organisation.class);
    crit.setCacheable(true);
    Disjunction notDeleted = Restrictions.disjunction();
    notDeleted.add(Restrictions.isNull("deleted"));
    notDeleted.add(Restrictions.eq("deleted", Boolean.FALSE));
    crit.add(notDeleted);
    crit.add(Restrictions.ne("id", organisation.getId()));

    Criteria critParentLink = crit.createCriteria("parentOrgLinks");
    critParentLink.add(Restrictions.eq("owner", organisation));
    crit.setProjection(Projections.count("id"));
    Object result = crit.uniqueResult();
    if (result == null) {
      return 0;
    } else if (result instanceof Integer) {
      Integer i = (Integer) result;
      return i.longValue();
    } else {
      return (long) result;
    }
  }