=== 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-10-16 06:17:19 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryComboStore.java 2014-10-17 17:55:45 +0000 @@ -30,6 +30,7 @@ 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,7 +46,6 @@ @SuppressWarnings("unchecked") public Collection getCategoryCombosByDimensionType( String dimensionType ) { - return getQueryWithSelect( "dimensionType = :dimensionType or name = :name" ). - setString( "dimensionType", dimensionType).setString( "name", "default" ).list(); + return getSharingCriteria( Restrictions.or( Restrictions.eq( "dimensionType", dimensionType ), Restrictions.eq( "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-10-16 06:17:19 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryStore.java 2014-10-17 17:55:45 +0000 @@ -30,6 +30,7 @@ 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 +46,6 @@ @SuppressWarnings("unchecked") public Collection getCategoriesByDimensionType( String dimensionType ) { - return getQueryWithSelect( "dataDimensionType = :dimensionType" ).setString( "dimensionType", dimensionType ).list(); + return getSharingCriteria( Restrictions.eq( "dataDimensionType", 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-10-16 06:17:19 +0000 +++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2014-10-17 17:55:45 +0000 @@ -249,6 +249,25 @@ } /** + * Creates a sharing Criteria for the implementation Class type restricted by the + * given Criterions. + * + * @param expressions the Criterions for the Criteria. + * @return a Criteria instance. + */ + protected final Criteria getSharingCriteria( Criterion... expressions ) + { + Criteria criteria = getSharingCriteria(); + + for ( Criterion expression : expressions ) + { + criteria.add( expression ); + } + + criteria.setCacheable( cacheable ); + return criteria; + } + /** * Retrieves an object based on the given Criterions. * * @param expressions the Criterions for the Criteria. @@ -390,44 +409,6 @@ return getSharingCriteria().list(); } - /** - * 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; - } - @Override public int getCount() {