/**
   * Perform a search over all child and sub orgs within the given organisation
   *
   * <p>If a search query is given it will be split by space and the key words searched in the
   * title, orgid, address, addressLine2 and postcode fields.
   *
   * @param q - search query, which is a space seperated list of key words. Optional
   * @param organisation - search is for orgs inside this
   * @param orgType - optional, if given results are limited to organisations of this type
   * @param session
   * @return
   */
  public static List<Organisation> search(
      String q, Organisation organisation, OrgType orgType, 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);

    if (q != null) {
      String[] arr = q.split(" ");
      Conjunction con = Restrictions.conjunction();
      for (String queryPart : arr) {
        Disjunction dis = Restrictions.disjunction();
        String s = "%" + queryPart + "%";
        dis.add(Restrictions.ilike("title", s));
        dis.add(Restrictions.ilike("orgId", s));
        dis.add(Restrictions.ilike("address", s));
        dis.add(Restrictions.ilike("addressLine2", s));
        dis.add(Restrictions.ilike("postcode", s));
        con.add(dis);
      }
      crit.add(con);
    }

    if (orgType != null) {
      crit.add(Restrictions.eq("orgType", orgType));
    }
    // TODO: add other properties like address
    Criteria critParentLink = crit.createCriteria("parentOrgLinks");
    critParentLink.add(Restrictions.eq("owner", organisation));
    crit.addOrder(Order.asc("title"));
    return DbUtils.toList(crit, Organisation.class);
  }
Beispiel #2
0
 public static List<Group> findByOrg(Organisation org, Session session) {
   Criteria crit = session.createCriteria(Group.class);
   crit.setCacheable(true);
   crit.add(Restrictions.eq("organisation", org));
   crit.addOrder(Order.asc("name"));
   return DbUtils.toList(crit, Group.class);
 }
 public static List<Organisation> findByOrgType(OrgType orgType, Session session) {
   Criteria crit = session.createCriteria(Organisation.class);
   crit.setCacheable(true);
   crit.add(Restrictions.eq("orgType", orgType));
   crit.addOrder(Order.asc("title"));
   return DbUtils.toList(crit, Organisation.class);
 }
Beispiel #4
0
 /**
  * Is the given entity a member of this group, regardless of organisation
  *
  * @param entity
  * @return
  */
 public boolean isMember(BaseEntity entity) {
   Criteria crit = SessionManager.session().createCriteria(GroupMembership.class);
   crit.setCacheable(true);
   crit.add(Restrictions.eq("member", entity));
   crit.add(Restrictions.eq("groupEntity", this));
   boolean b = !DbUtils.toList(crit, GroupMembership.class).isEmpty();
   return b;
 }
Beispiel #5
0
 public static List<Profile> findByGroup(Group group, Session session) {
   Criteria crit = session.createCriteria(Profile.class);
   crit.setCacheable(true);
   // join to group membership, then subordinate, then restrict on org
   Criteria critMembership = crit.createCriteria("memberships");
   critMembership.add(Restrictions.eq("groupEntity", group));
   return DbUtils.toList(crit, Profile.class);
 }
Beispiel #6
0
 public static List<Profile> findByBusinessUnit(Organisation organisation, Session session) {
   Criteria crit = session.createCriteria(Profile.class);
   crit.setCacheable(true);
   // join to group membership, then subordinate, then restrict on org
   Criteria critMembership = crit.createCriteria("memberships");
   critMembership.add(Restrictions.eq("withinOrg", organisation));
   return DbUtils.toList(crit, Profile.class);
 }
 public static Organisation getRootOrg(Session session) {
   Criteria crit = session.createCriteria(Organisation.class);
   crit.setCacheable(true);
   crit.add(Restrictions.isNull("organisation"));
   List<Organisation> list = DbUtils.toList(crit, Organisation.class);
   if (!list.isEmpty()) {
     return list.get(0);
   }
   return null;
 }
  public static List<Organisation> findListByOrgId(
      Organisation adminOrg, String orgId, Session session) {
    Criteria crit = session.createCriteria(Organisation.class);
    Criteria critSubOrg = crit.createCriteria("parentOrgLinks");

    crit.setCacheable(true);
    crit.add(Restrictions.eq("orgId", orgId));
    critSubOrg.add(Restrictions.eq("owner", adminOrg));
    return DbUtils.toList(crit, Organisation.class);
  }
Beispiel #9
0
 public static List<Commit> findByBranch(
     Branch branch, Date from, Date to, boolean orderReverseDate, Integer limit, Session session) {
   Criteria c = session.createCriteria(Commit.class);
   c.add(Restrictions.eq("branch", branch));
   if (from != null) {
     c.add(Restrictions.gt("createdDate", from));
   }
   if (to != null) {
     c.add(Restrictions.le("createdDate", to));
   }
   if (limit != null) {
     c.setMaxResults(limit);
   }
   if (orderReverseDate) {
     c.addOrder(Order.desc("createdDate"));
   } else {
     c.addOrder(Order.asc("createdDate"));
   }
   return DbUtils.toList(c, Commit.class);
 }
Beispiel #10
0
 public static List<Profile> findAll(Session session) {
   Criteria crit = session.createCriteria(Profile.class);
   crit.setCacheable(true);
   return DbUtils.toList(crit, Profile.class);
 }
Beispiel #11
0
 public static List<Commit> findByBranch(Branch branch, Session session) {
   Criteria c = session.createCriteria(Commit.class);
   c.add(Restrictions.eq("branch", branch));
   c.addOrder(Order.desc("createdDate"));
   return DbUtils.toList(c, Commit.class);
 }