示例#1
0
 protected static void findChildCountryByAccessCriteria(Criteria criteria) {
   Integer country = SecurityUtil.getInstance().getCountry();
   if (country != null && country != 0) {
     // have just country access to restrict to all centres in that country
     criteria.createCriteria("child.country").add(Restrictions.eq("id", new Long(country)));
   }
 }
 public static void findChildCentreByAccessCriteria(Criteria criteria) {
   Integer centre = SecurityUtil.getInstance().getCentre();
   if (centre != null && centre != 0) {
     // have just country access to restrict to all centres in that country
     criteria.createCriteria("child.centre").add(Restrictions.eq("id", new Long(centre)));
   }
 }
 public static void findReportCentreByAccessCriteria(Criteria criteria) {
   Integer centre = SecurityUtil.getInstance().getCentre();
   if (centre != null && centre != 0) {
     // have just country access to restrict to all centres in that country
     criteria
         .createCriteria("centre", CriteriaSpecification.LEFT_JOIN)
         .add(Restrictions.or(Restrictions.eq("id", new Long(centre)), Restrictions.isNull("id")));
   }
 }
示例#4
0
 /**
  * Return hibernate criteria to determine which countries a user has access to based on the
  * country set in their user record. If no country is set, the user has access to all countries,
  * otherwise restrict to the particular country the user is in.
  */
 public Criteria findByAccessCriteria(EntityManager entityManager) {
   Criteria criteria = ((Session) entityManager.getDelegate()).createCriteria(Country.class);
   Integer country = SecurityUtil.getInstance().getCountry();
   if (country != null && country != 0)
     // restrict to country of user
     criteria.add(Restrictions.eq("id", new Long(country)));
   criteria.addOrder(Order.asc("name"));
   // else can access all countries as no country set
   return criteria;
 }
 /**
  * Return hibernate criteria to determine which centres a user has access to based on the centre
  * set in their user record. If no centre is set, the user has access to all centres in the given
  * country, otherwise restrict to the particular centre the user is in.
  */
 public Criteria findByAccessCriteria(EntityManager entityManager, Long countryId) {
   Criteria criteria =
       ((Session) entityManager.getDelegate()).createCriteria(DiabetesCentre.class);
   Integer centre = SecurityUtil.getInstance().getCentre();
   if (countryId != null && countryId != 0) {
     // have just country access to restrict to all centres in that country
     criteria.createCriteria("country").add(Restrictions.eq("id", countryId));
   }
   if (centre != null && centre != 0) {
     // have specific centre access so restrict to that centre
     criteria.add(Restrictions.eq("id", new Long(centre)));
   }
   criteria.addOrder(Order.asc("name"));
   // else can access all centres as no centre set
   return criteria;
 }