=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryComboStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryComboStore.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryComboStore.java 2014-06-25 12:34:42 +0000 @@ -30,7 +30,6 @@ import java.util.Collection; -import org.hibernate.criterion.Restrictions; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.dataelement.CategoryComboStore; import org.hisp.dhis.dataelement.DataElementCategoryCombo; @@ -45,8 +44,7 @@ @SuppressWarnings("unchecked") public Collection getCategoryCombosByDimensionType( String dimensionType ) { - return getCriteria( Restrictions.or( - Restrictions.eq( "dimensionType", dimensionType ), - Restrictions.eq( "name", "default" ) ) ).list(); + return getQueryWithSelect( "dimensionType = :dimensionType or name = :name" ). + setString( "dimensionType", dimensionType).setString( "name", "default" ).list(); } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryStore.java 2014-03-26 18:56:37 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryStore.java 2014-06-25 12:34:42 +0000 @@ -30,7 +30,6 @@ import java.util.Collection; -import org.hibernate.criterion.Restrictions; import org.hisp.dhis.common.hibernate.HibernateDimensionalObjectStore; import org.hisp.dhis.dataelement.CategoryStore; import org.hisp.dhis.dataelement.DataElementCategory; @@ -45,6 +44,6 @@ @SuppressWarnings("unchecked") public Collection getCategoriesByDimensionType( String dimensionType ) { - return getCriteria( Restrictions.eq( "dataDimensionType", dimensionType ) ).list(); + return getQueryWithSelect( "dataDimensionType = :dimensionType" ).setString( "dimensionType", dimensionType ).list(); } } === modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java' --- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2014-03-27 10:14:49 +0000 +++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2014-06-25 12:34:42 +0000 @@ -358,6 +358,44 @@ return query; } + /** + * Returns a Query instance. Allows for injecting a criteria part, such as + * "code = :code and name = :name". Note that the bound values must be set + * on the query before executing it. + * + * @param hqlCriteria the HQL criteria. + * @return a Query. + */ + protected Query getQueryWithSelect( String hqlCriteria ) + { + boolean sharingEnabled = sharingEnabled(); + + String hql = "select distinct c from " + clazz.getName() + " c"; + + if ( hqlCriteria != null ) + { + hql += " where " + hqlCriteria; + } + + if ( sharingEnabled ) + { + String criteria = hqlCriteria != null ? "and" : "where"; + + hql += " " + criteria + " ( c.publicAccess like 'r%' or c.user IS NULL or c.user=:user" + + " or exists " + + " (from c.userGroupAccesses uga join uga.userGroup ug join ug.members ugm where ugm = :user and uga.access like 'r%') )"; + } + + Query query = getQuery( hql ); + + if ( sharingEnabled ) + { + query.setEntity( "user", currentUserService.getCurrentUser() ); + } + + return query; + } + private Query getQueryAll() { return getQuery( "from " + clazz.getName() + " c" );