dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32672
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16655: wip, moving from hql to criteria in genericStores. Merged SharingTests with IdentifiableObjectMan...
------------------------------------------------------------
revno: 16655
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-09-08 20:02:43 +0700
message:
wip, moving from hql to criteria in genericStores. Merged SharingTests with IdentifiableObjectManagerTest. Extended idObjectManager with several new methods.
removed:
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/SharingTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nUtils.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/relationship/DefaultRelationshipTypeService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeGroupService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2014-09-08 12:34:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2014-09-08 13:02:43 +0000
@@ -132,6 +132,16 @@
List<T> getAllLikeName( String name );
/**
+ * Retrieves a List of objects where the name is like the given name.
+ *
+ * @param name the name.
+ * @param first the first result object to return.
+ * @param max the max number of result objects to return.
+ * @return a List of objects.
+ */
+ List<T> getAllLikeName( String name, int first, int max );
+
+ /**
* Retrieves a List of objects where the shortName is like the given shortName.
*
* @param shortName the shortName.
@@ -157,17 +167,6 @@
List<T> getAllOrderedLastUpdated( int first, int max );
/**
- * Retrieves the objects determined by the given first result and max result
- * which name is like the given name.
- *
- * @param name the name which result object names must be like.
- * @param first the first result object to return.
- * @param max the max number of result objects to return.
- * @return List of objects.
- */
- List<T> getAllLikeNameOrderedName( String name, int first, int max );
-
- /**
* Gets the count of objects which name is like the given name.
*
* @param name the name which result object names must be like.
@@ -176,6 +175,14 @@
int getCountLikeName( String name );
/**
+ * Gets the count of objects which shortName is like the given shortName.
+ *
+ * @param shortName the shortName which result object shortNames must be like.
+ * @return the count of objects.
+ */
+ int getCountLikeShortName( String shortName );
+
+ /**
* Retrieves a list of objects referenced by the given List of uids.
*
* @param uids a List of uids.
@@ -184,7 +191,7 @@
List<T> getByUid( Collection<String> uids );
/**
- * Retrieves a list of objects referenced by the given List of uids.
+ * Retrieves a list of objects referenced by the given List of uids.
* Bypasses the ACL system.
*
* @param uids a List of uids.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2014-09-08 12:34:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2014-09-08 13:02:43 +0000
@@ -108,6 +108,8 @@
<T extends IdentifiableObject> int getCountByName( Class<T> clazz, String name );
+ <T extends IdentifiableObject> int getCountByShortName( Class<T> clazz, String shortName );
+
// -------------------------------------------------------------------------
// NO ACL
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java 2014-08-27 12:50:13 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java 2014-09-08 13:02:43 +0000
@@ -125,7 +125,7 @@
@Override
public Collection<SqlView> getSqlViewsBetweenByName( String name, int first, int max )
{
- return sqlViewStore.getAllLikeNameOrderedName( name, first, max );
+ return sqlViewStore.getAllLikeName( name, first, max );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java 2014-09-08 13:02:43 +0000
@@ -201,7 +201,7 @@
@Override
public Set<Attribute> getAttributesBetweenByName( String name, int first, int max )
{
- return new HashSet<>( i18n( i18nService, attributeStore.getAllLikeNameOrderedName( name, first, max ) ));
+ return new HashSet<>( i18n( i18nService, attributeStore.getAllLikeName( name, first, max ) ));
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2014-09-08 12:34:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2014-09-08 13:02:43 +0000
@@ -298,7 +298,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> Collection<T> getAllSortedByLastUpdated( Class<T> clazz )
{
GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
@@ -339,6 +339,19 @@
}
@Override
+ public <T extends IdentifiableObject> int getCountByShortName( Class<T> clazz, String shortName )
+ {
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+ if ( store != null )
+ {
+ return store.getCountLikeShortName( shortName );
+ }
+
+ return 0;
+ }
+
+ @Override
@SuppressWarnings("unchecked")
public <T extends IdentifiableObject> Collection<T> getLikeName( Class<T> clazz, String name )
{
@@ -391,7 +404,7 @@
return new ArrayList<>();
}
- return (List<T>) store.getAllLikeNameOrderedName( name, first, max );
+ return (List<T>) store.getAllLikeName( name, first, max );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2014-09-08 12:34:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2014-09-08 13:02:43 +0000
@@ -32,6 +32,7 @@
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.AuditLogUtil;
import org.hisp.dhis.common.BaseIdentifiableObject;
@@ -228,6 +229,18 @@
@Override
@SuppressWarnings( "unchecked" )
+ public List<T> getAllLikeName( String name, int first, int max )
+ {
+ return getSharingCriteria()
+ .add( Restrictions.like( "name", "%" + name + "%" ).ignoreCase() )
+ .addOrder( Order.asc( "name" ) )
+ .setFirstResult( first )
+ .setMaxResults( max )
+ .list();
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
public List<T> getAllLikeShortName( String shortName )
{
if ( NameableObject.class.isAssignableFrom( clazz ) )
@@ -280,69 +293,21 @@
}
@Override
- @SuppressWarnings( "unchecked" )
- public List<T> getAllLikeNameOrderedName( String name, int first, int max )
- {
- Query query = sharingEnabled() ? getQueryAllLikeNameOrderedNameAcl( name ) : getQueryAllLikeNameOrderedName( name );
-
- query.setFirstResult( first );
- query.setMaxResults( max );
-
- return query.list();
- }
-
- private Query getQueryAllLikeNameOrderedNameAcl( String name )
- {
- String hql = "select distinct c from " + clazz.getName() + " c"
- + " where lower(c.name) like :name and ( 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%')"
- + " ) order by c.name";
-
- Query query = getQuery( hql );
- query.setString( "name", "%" + name.toLowerCase() + "%" );
- query.setEntity( "user", currentUserService.getCurrentUser() );
-
- return query;
- }
-
- private Query getQueryAllLikeNameOrderedName( String name )
- {
- Query query = getQuery( "from " + clazz.getName() + " c where lower(name) like :name order by name" );
- query.setString( "name", "%" + name.toLowerCase() + "%" );
-
- return query;
- }
-
- @Override
public int getCountLikeName( String name )
{
- Query query = sharingEnabled() ? getQueryCountLikeNameAcl( name ) : getQueryCountLikeName( name );
-
- return ((Long) query.uniqueResult()).intValue();
- }
-
- private Query getQueryCountLikeNameAcl( String name )
- {
- String hql = "select count(distinct c) from " + clazz.getName() + " c"
- + " where lower(name) like :name and (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 );
- query.setEntity( "user", currentUserService.getCurrentUser() );
- query.setString( "name", "%" + name.toLowerCase() + "%" );
-
- return query;
- }
-
- private Query getQueryCountLikeName( String name )
- {
- Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where lower(name) like :name" );
- query.setString( "name", "%" + name.toLowerCase() + "%" );
-
- return query;
+ return ((Number) getSharingCriteria()
+ .add( Restrictions.like( "name", "%" + name + "%" ).ignoreCase() )
+ .setProjection( Projections.countDistinct( "id" ) )
+ .uniqueResult()).intValue();
+ }
+
+ @Override
+ public int getCountLikeShortName( String shortName )
+ {
+ return ((Number) getSharingCriteria()
+ .add( Restrictions.like( "shortName", "%" + shortName + "%" ).ignoreCase() )
+ .setProjection( Projections.countDistinct( "id" ) )
+ .uniqueResult()).intValue();
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java 2014-09-08 13:02:43 +0000
@@ -114,6 +114,6 @@
@Override
public Collection<Concept> getConceptsBetweenByName( String name, int first, int max )
{
- return conceptStore.getAllLikeNameOrderedName( name, first, max );
+ return conceptStore.getAllLikeName( name, first, max );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java 2014-09-08 13:02:43 +0000
@@ -137,6 +137,6 @@
public Collection<Constant> getConstantsBetweenByName( String name, int first, int max )
{
- return constantStore.getAllLikeNameOrderedName( name, first, max );
+ return constantStore.getAllLikeName( name, first, max );
}
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java 2014-09-08 13:02:43 +0000
@@ -131,6 +131,6 @@
public List<DataDictionary> getDataDictionariesBetweenByName( String name, int first, int max )
{
- return new ArrayList<>( i18n( i18nService, dataDictionaryStore.getAllLikeNameOrderedName( name, first, max ) ) );
+ return new ArrayList<>( i18n( i18nService, dataDictionaryStore.getAllLikeName( name, first, max ) ) );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2014-09-08 13:02:43 +0000
@@ -256,7 +256,7 @@
@Override
public Collection<DataElementCategory> getDataElementCategoryBetweenByName( String name, int first, int max )
{
- return i18n( i18nService, categoryStore.getAllLikeNameOrderedName( name, first, max ) );
+ return i18n( i18nService, categoryStore.getAllLikeName( name, first, max ) );
}
public Collection<DataElementCategory> getDataElementCategoriesBetween( int first, int max )
@@ -266,7 +266,7 @@
public Collection<DataElementCategory> getDataElementCategoriesBetweenByName( String name, int first, int max )
{
- return i18n( i18nService, categoryStore.getAllLikeNameOrderedName( name, first, max ) );
+ return i18n( i18nService, categoryStore.getAllLikeName( name, first, max ) );
}
public int getDataElementCategoryCount()
@@ -352,7 +352,7 @@
public Collection<DataElementCategoryOption> getDataElementCategoryOptionsBetweenByName( String name, int first,
int max )
{
- return i18n( i18nService, categoryOptionStore.getAllLikeNameOrderedName( name, first, max ) );
+ return i18n( i18nService, categoryOptionStore.getAllLikeName( name, first, max ) );
}
@Override
@@ -449,7 +449,7 @@
public Collection<DataElementCategoryCombo> getDataElementCategoryCombosBetweenByName( String name, int first,
int max )
{
- return i18n( i18nService, categoryComboStore.getAllLikeNameOrderedName( name, first, max ) );
+ return i18n( i18nService, categoryComboStore.getAllLikeName( name, first, max ) );
}
public Collection<DataElementCategoryCombo> getDisaggregationCategoryCombos()
@@ -815,7 +815,7 @@
public Collection<CategoryOptionGroup> getCategoryOptionGroupsBetweenByName( int first, int max, String name )
{
- return categoryOptionGroupStore.getAllLikeNameOrderedName( name, first, max );
+ return categoryOptionGroupStore.getAllLikeName( name, first, max );
}
public Collection<CategoryOptionGroup> getAllCategoryOptionGroups()
@@ -902,7 +902,7 @@
public Collection<CategoryOptionGroupSet> getCategoryOptionGroupSetsBetweenByName( int first, int max, String name )
{
- return categoryOptionGroupSetStore.getAllLikeNameOrderedName( name, first, max );
+ return categoryOptionGroupSetStore.getAllLikeName( name, first, max );
}
public Collection<CategoryOptionGroupSet> getAllCategoryOptionGroupSets()
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java 2014-09-08 13:02:43 +0000
@@ -179,7 +179,7 @@
public Collection<I18nLocale> getI18nLocalesBetweenLikeName( String name, int first, int max )
{
- return localeStore.getAllLikeNameOrderedName( name, first, max );
+ return localeStore.getAllLikeName( name, first, max );
}
public List<Locale> getAllLocales()
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nUtils.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nUtils.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nUtils.java 2014-09-08 13:02:43 +0000
@@ -84,7 +84,7 @@
I18nService i18nService, GenericIdentifiableObjectStore<T> store, String name, int first, int max )
{
return i18nService.currentLocaleIsBase() ?
- i18n( i18nService, store.getAllLikeNameOrderedName( name, first, max ) ) :
+ i18n( i18nService, store.getAllLikeName( name, first, max ) ) :
Paging.getObjectsBetweenByName( i18n( i18nService, store.getAll() ), name, first, max );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2014-09-08 13:02:43 +0000
@@ -277,7 +277,7 @@
public List<Map> getMapsBetweenLikeName( String name, int first, int max )
{
- return mapStore.getAllLikeNameOrderedName( name, first, max );
+ return mapStore.getAllLikeName( name, first, max );
}
// -------------------------------------------------------------------------
@@ -374,7 +374,7 @@
public Collection<MapView> getMapViewsBetweenByName( String name, int first, int max )
{
- return mapViewStore.getAllLikeNameOrderedName( name, first, max );
+ return mapViewStore.getAllLikeName( name, first, max );
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2014-08-29 15:27:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2014-09-08 13:02:43 +0000
@@ -121,7 +121,7 @@
public Collection<OptionSet> getOptionSetsBetweenByName( String name, int first, int max )
{
- return new HashSet<>( i18n( i18nService, optionSetStore.getAllLikeNameOrderedName( name, first, max ) ) );
+ return new HashSet<>( i18n( i18nService, optionSetStore.getAllLikeName( name, first, max ) ) );
}
public Collection<OptionSet> getOptionSetsBetween( int first, int max )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2014-09-08 13:02:43 +0000
@@ -643,7 +643,7 @@
public Collection<OrganisationUnit> getOrganisationUnitsBetweenByName( String name, int first, int max )
{
- return i18n( i18nService, organisationUnitStore.getAllLikeNameOrderedName( name, first, max ) );
+ return i18n( i18nService, organisationUnitStore.getAllLikeName( name, first, max ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java 2014-09-08 13:02:43 +0000
@@ -116,6 +116,6 @@
@Override
public List<UserGroup> getUserGroupsBetweenByName( String name, int first, int max )
{
- return userGroupStore.getAllLikeNameOrderedName( name, first, max );
+ return userGroupStore.getAllLikeName( name, first, max );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2014-09-08 13:02:43 +0000
@@ -223,7 +223,7 @@
@Override
public List<User> getAllUsersBetweenByName( String name, int first, int max )
{
- return userStore.getAllLikeNameOrderedName( name, first, max );
+ return userStore.getAllLikeName( name, first, max );
}
@Override
@@ -317,7 +317,7 @@
users.add( uidUser );
}
- users.addAll( userStore.getAllLikeNameOrderedName( query, 0, 1000 ) ); //TODO
+ users.addAll( userStore.getAllLikeName( query, 0, 1000 ) ); //TODO
return users;
}
@@ -418,7 +418,7 @@
public Collection<UserAuthorityGroup> getUserRolesBetweenByName( String name, int first, int max )
{
- return userAuthorityGroupStore.getAllLikeNameOrderedName( name, first, max );
+ return userAuthorityGroupStore.getAllLikeName( name, first, max );
}
public int getUserRoleCount()
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2014-09-08 13:02:43 +0000
@@ -67,7 +67,7 @@
@Override
@SuppressWarnings("unchecked")
- public List<User> getAllLikeNameOrderedName( String name, int first, int max )
+ public List<User> getAllLikeName( String name, int first, int max )
{
Criteria criteria = getCriteria();
criteria.add( Restrictions.or( Restrictions.ilike( "surname", "%" + name + "%" ),
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java 2014-09-08 13:02:43 +0000
@@ -28,43 +28,353 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.google.common.collect.Sets;
+import org.hibernate.SessionFactory;
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.acl.AccessStringHelper;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.hibernate.exception.CreateAccessDeniedException;
+import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserGroup;
+import org.hisp.dhis.user.UserGroupAccess;
+import org.hisp.dhis.user.UserService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
public class IdentifiableObjectManagerTest
extends DhisSpringTest
{
@Autowired
+ private SessionFactory sessionFactory;
+
+ @Autowired
private DataElementService dataElementService;
-
- @Autowired
- private IdentifiableObjectManager identifiableObjectManager;
-
+
+ @Override
+ protected void setUpTest() throws Exception
+ {
+ identifiableObjectManager = (IdentifiableObjectManager) getBean( IdentifiableObjectManager.ID );
+ userService = (UserService) getBean( UserService.ID );
+ }
+
@Test
public void testGetObject()
{
DataElement dataElementA = createDataElement( 'A' );
DataElement dataElementB = createDataElement( 'B' );
-
+
int dataElementIdA = dataElementService.addDataElement( dataElementA );
int dataElementIdB = dataElementService.addDataElement( dataElementB );
-
+
DataElementGroup dataElementGroupA = createDataElementGroup( 'A' );
DataElementGroup dataElementGroupB = createDataElementGroup( 'B' );
-
+
int dataElementGroupIdA = dataElementService.addDataElementGroup( dataElementGroupA );
int dataElementGroupIdB = dataElementService.addDataElementGroup( dataElementGroupB );
-
+
assertEquals( dataElementA, identifiableObjectManager.getObject( dataElementIdA, DataElement.class.getSimpleName() ) );
assertEquals( dataElementB, identifiableObjectManager.getObject( dataElementIdB, DataElement.class.getSimpleName() ) );
-
+
assertEquals( dataElementGroupA, identifiableObjectManager.getObject( dataElementGroupIdA, DataElementGroup.class.getSimpleName() ) );
assertEquals( dataElementGroupB, identifiableObjectManager.getObject( dataElementGroupIdB, DataElementGroup.class.getSimpleName() ) );
}
+
+ @Test
+ public void publicAccessSetIfNoUser()
+ {
+ DataElement dataElement = createDataElement( 'A' );
+ identifiableObjectManager.save( dataElement );
+
+ assertNotNull( dataElement.getPublicAccess() );
+ assertFalse( AccessStringHelper.canRead( dataElement.getPublicAccess() ) );
+ assertFalse( AccessStringHelper.canWrite( dataElement.getPublicAccess() ) );
+ }
+
+ @Test
+ public void getCount()
+ {
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ assertEquals( 4, identifiableObjectManager.getCount( DataElement.class ) );
+ }
+
+ @Test
+ public void getCountByName()
+ {
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementA" ) );
+ assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementB" ) );
+ assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementC" ) );
+ assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementD" ) );
+ }
+
+ @Test
+ public void getEqualToName()
+ {
+ DataElement dataElement = createDataElement( 'A' );
+ identifiableObjectManager.save( dataElement );
+
+ assertNotNull( identifiableObjectManager.getByName( DataElement.class, "DataElementA" ) );
+ assertNull( identifiableObjectManager.getByName( DataElement.class, "DataElementB" ) );
+ assertEquals( dataElement, identifiableObjectManager.getByName( DataElement.class, "DataElementA" ) );
+ }
+
+ @Test
+ public void getAllEqualToName()
+ {
+ OrganisationUnit organisationUnitA1 = createOrganisationUnit( 'A' );
+ organisationUnitA1.setCode( null );
+ identifiableObjectManager.save( organisationUnitA1 );
+
+ OrganisationUnit organisationUnitA2 = createOrganisationUnit( 'B' );
+ organisationUnitA2.setName( "OrganisationUnitA" );
+ organisationUnitA2.setCode( null );
+ identifiableObjectManager.save( organisationUnitA2 );
+
+ assertEquals( 2, identifiableObjectManager.getAllByName( OrganisationUnit.class, "OrganisationUnitA" ).size() );
+ assertEquals( 0, identifiableObjectManager.getAllByName( OrganisationUnit.class, "organisationunita" ).size() );
+ }
+
+ @Test
+ public void getAllEqualToNameIgnoreCase()
+ {
+ OrganisationUnit organisationUnitA1 = createOrganisationUnit( 'A' );
+ organisationUnitA1.setCode( null );
+ identifiableObjectManager.save( organisationUnitA1 );
+
+ OrganisationUnit organisationUnitA2 = createOrganisationUnit( 'B' );
+ organisationUnitA2.setName( "OrganisationUnitA" );
+ organisationUnitA2.setCode( null );
+ identifiableObjectManager.save( organisationUnitA2 );
+
+ assertEquals( 2, identifiableObjectManager.getAllByNameIgnoreCase( OrganisationUnit.class, "OrganisationUnitA" ).size() );
+ assertEquals( 2, identifiableObjectManager.getAllByNameIgnoreCase( OrganisationUnit.class, "organisationunita" ).size() );
+ }
+
+ @Test
+ public void getAllLikeName()
+ {
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ assertEquals( 4, identifiableObjectManager.getCountByName( DataElement.class, "DataElement" ) );
+ assertEquals( 4, identifiableObjectManager.getCountByName( DataElement.class, "dataElement" ) );
+
+ assertEquals( 4, identifiableObjectManager.getLikeName( DataElement.class, "DataElement" ).size() );
+ assertEquals( 4, identifiableObjectManager.getLikeName( DataElement.class, "dataElement" ).size() );
+ }
+
+ @Test
+ public void getAllLikeShortName()
+ {
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ assertEquals( 4, identifiableObjectManager.getCountByShortName( DataElement.class, "DataElementShort" ) );
+ assertEquals( 4, identifiableObjectManager.getCountByShortName( DataElement.class, "dataElementSHORT" ) );
+
+ assertEquals( 4, identifiableObjectManager.getLikeShortName( DataElement.class, "DataElementShort" ).size() );
+ assertEquals( 4, identifiableObjectManager.getLikeShortName( DataElement.class, "dataElementSHORT" ).size() );
+ }
+
+ @Test
+ public void getAllOrderedName()
+ {
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+
+ List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAllSorted( DataElement.class ) );
+
+ assertEquals( 4, dataElements.size() );
+ assertEquals( "DataElementA", dataElements.get( 0 ).getName() );
+ assertEquals( "DataElementB", dataElements.get( 1 ).getName() );
+ assertEquals( "DataElementC", dataElements.get( 2 ).getName() );
+ assertEquals( "DataElementD", dataElements.get( 3 ).getName() );
+ }
+
+ @Test
+ public void getAllOrderedLastUpdated()
+ {
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAllSortedByLastUpdated( DataElement.class ) );
+
+ assertEquals( 4, dataElements.size() );
+ assertEquals( "DataElementD", dataElements.get( 0 ).getName() );
+ assertEquals( "DataElementC", dataElements.get( 1 ).getName() );
+ assertEquals( "DataElementB", dataElements.get( 2 ).getName() );
+ assertEquals( "DataElementA", dataElements.get( 3 ).getName() );
+ }
+
+ @Test
+ public void userIsCurrentIfNoUserSet()
+ {
+ User user = createUserAndInjectSecurityContext( true );
+
+ DataElement dataElement = createDataElement( 'A' );
+ identifiableObjectManager.save( dataElement );
+
+ assertNotNull( dataElement.getUser() );
+ assertEquals( user, dataElement.getUser() );
+ }
+
+ @Test
+ public void userCanCreatePublic()
+ {
+ createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD" );
+
+ DataElement dataElement = createDataElement( 'A' );
+ identifiableObjectManager.save( dataElement );
+
+ assertNotNull( dataElement.getPublicAccess() );
+ assertTrue( AccessStringHelper.canRead( dataElement.getPublicAccess() ) );
+ assertTrue( AccessStringHelper.canWrite( dataElement.getPublicAccess() ) );
+ }
+
+ @Test
+ public void userCanCreatePrivate()
+ {
+ createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PRIVATE_ADD" );
+
+ DataElement dataElement = createDataElement( 'A' );
+ identifiableObjectManager.save( dataElement );
+
+ assertNotNull( dataElement.getPublicAccess() );
+ assertFalse( AccessStringHelper.canRead( dataElement.getPublicAccess() ) );
+ assertFalse( AccessStringHelper.canWrite( dataElement.getPublicAccess() ) );
+ }
+
+ @Test( expected = CreateAccessDeniedException.class )
+ public void userDeniedCreateObject()
+ {
+ createUserAndInjectSecurityContext( false );
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ }
+
+ @Test( expected = DeleteAccessDeniedException.class )
+ public void userDeniedDeleteObject()
+ {
+ createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD", "F_USER_ADD" );
+
+ User user = createUser( 'B' );
+ identifiableObjectManager.save( user );
+
+ DataElement dataElement = createDataElement( 'A' );
+ identifiableObjectManager.save( dataElement );
+
+ dataElement.setUser( user );
+ dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
+ sessionFactory.getCurrentSession().update( dataElement );
+
+ identifiableObjectManager.delete( dataElement );
+ }
+
+ @Test
+ public void objectsWithNoUser()
+ {
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ Collection<DataElement> all = identifiableObjectManager.getAll( DataElement.class );
+
+ assertEquals( 4, all.size() );
+ }
+
+ @Test
+ public void readPrivateObjects()
+ {
+ createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD", "F_USER_ADD" );
+
+ User user = createUser( 'B' );
+ identifiableObjectManager.save( user );
+
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ assertEquals( 4, identifiableObjectManager.getAll( DataElement.class ).size() );
+
+ List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAll( DataElement.class ) );
+
+ for ( DataElement dataElement : dataElements )
+ {
+ dataElement.setUser( user );
+ dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
+
+ sessionFactory.getCurrentSession().update( dataElement );
+ }
+
+ assertEquals( 0, identifiableObjectManager.getAll( DataElement.class ).size() );
+ }
+
+ @Test
+ public void readUserGroupSharedObjects()
+ {
+ User loginUser = createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD", "F_USER_ADD", "F_USERGROUP_PUBLIC_ADD" );
+
+ User user = createUser( 'B' );
+ identifiableObjectManager.save( user );
+
+ UserGroup userGroup = createUserGroup( 'A', Sets.newHashSet( loginUser ) );
+ identifiableObjectManager.save( userGroup );
+
+ identifiableObjectManager.save( createDataElement( 'A' ) );
+ identifiableObjectManager.save( createDataElement( 'B' ) );
+ identifiableObjectManager.save( createDataElement( 'C' ) );
+ identifiableObjectManager.save( createDataElement( 'D' ) );
+
+ assertEquals( 4, identifiableObjectManager.getAll( DataElement.class ).size() );
+
+ List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAll( DataElement.class ) );
+
+ for ( DataElement dataElement : dataElements )
+ {
+ dataElement.setUser( user );
+ dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
+
+ UserGroupAccess userGroupAccess = new UserGroupAccess();
+ userGroupAccess.setAccess( AccessStringHelper.newInstance().enable( AccessStringHelper.Permission.READ ).build() );
+ userGroupAccess.setUserGroup( userGroup );
+
+ sessionFactory.getCurrentSession().save( userGroupAccess );
+
+ dataElement.getUserGroupAccesses().add( userGroupAccess );
+ sessionFactory.getCurrentSession().update( dataElement );
+ }
+
+ assertEquals( 4, identifiableObjectManager.getAll( DataElement.class ).size() );
+ }
}
=== removed file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/SharingTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/SharingTest.java 2014-09-08 12:34:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/SharingTest.java 1970-01-01 00:00:00 +0000
@@ -1,346 +0,0 @@
-package org.hisp.dhis.common;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.Sets;
-import org.hibernate.SessionFactory;
-import org.hisp.dhis.DhisSpringTest;
-import org.hisp.dhis.acl.AccessStringHelper;
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.hibernate.exception.CreateAccessDeniedException;
-import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.UserGroup;
-import org.hisp.dhis.user.UserGroupAccess;
-import org.hisp.dhis.user.UserService;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class SharingTest
- extends DhisSpringTest
-{
- @Autowired
- private SessionFactory sessionFactory;
-
- @Override
- protected void setUpTest() throws Exception
- {
- identifiableObjectManager = (IdentifiableObjectManager) getBean( IdentifiableObjectManager.ID );
- userService = (UserService) getBean( UserService.ID );
- }
-
- @Test
- public void publicAccessSetIfNoUser()
- {
- DataElement dataElement = createDataElement( 'A' );
- identifiableObjectManager.save( dataElement );
-
- assertNotNull( dataElement.getPublicAccess() );
- assertFalse( AccessStringHelper.canRead( dataElement.getPublicAccess() ) );
- assertFalse( AccessStringHelper.canWrite( dataElement.getPublicAccess() ) );
- }
-
- @Test
- public void getCount()
- {
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- assertEquals( 4, identifiableObjectManager.getCount( DataElement.class ) );
- }
-
- @Test
- public void getCountByName()
- {
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementA" ) );
- assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementB" ) );
- assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementC" ) );
- assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementD" ) );
- }
-
- @Test
- public void getEqualToName()
- {
- DataElement dataElement = createDataElement( 'A' );
- identifiableObjectManager.save( dataElement );
-
- assertNotNull( identifiableObjectManager.getByName( DataElement.class, "DataElementA" ) );
- assertNull( identifiableObjectManager.getByName( DataElement.class, "DataElementB" ) );
- assertEquals( dataElement, identifiableObjectManager.getByName( DataElement.class, "DataElementA" ) );
- }
-
- @Test
- public void getAllEqualToName()
- {
- OrganisationUnit organisationUnitA1 = createOrganisationUnit( 'A' );
- organisationUnitA1.setCode( null );
- identifiableObjectManager.save( organisationUnitA1 );
-
- OrganisationUnit organisationUnitA2 = createOrganisationUnit( 'B' );
- organisationUnitA2.setName( "OrganisationUnitA" );
- organisationUnitA2.setCode( null );
- identifiableObjectManager.save( organisationUnitA2 );
-
- assertEquals( 2, identifiableObjectManager.getAllByName( OrganisationUnit.class, "OrganisationUnitA" ).size() );
- assertEquals( 0, identifiableObjectManager.getAllByName( OrganisationUnit.class, "organisationunita" ).size() );
- }
-
- @Test
- public void getAllEqualToNameIgnoreCase()
- {
- OrganisationUnit organisationUnitA1 = createOrganisationUnit( 'A' );
- organisationUnitA1.setCode( null );
- identifiableObjectManager.save( organisationUnitA1 );
-
- OrganisationUnit organisationUnitA2 = createOrganisationUnit( 'B' );
- organisationUnitA2.setName( "OrganisationUnitA" );
- organisationUnitA2.setCode( null );
- identifiableObjectManager.save( organisationUnitA2 );
-
- assertEquals( 2, identifiableObjectManager.getAllByNameIgnoreCase( OrganisationUnit.class, "OrganisationUnitA" ).size() );
- assertEquals( 2, identifiableObjectManager.getAllByNameIgnoreCase( OrganisationUnit.class, "organisationunita" ).size() );
- }
-
- @Test
- public void getAllLikeName()
- {
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- assertEquals( 4, identifiableObjectManager.getLikeName( DataElement.class, "DataElement" ).size() );
- assertEquals( 4, identifiableObjectManager.getLikeName( DataElement.class, "dataElement" ).size() );
- }
-
- @Test
- public void getAllLikeShortName()
- {
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- assertEquals( 4, identifiableObjectManager.getLikeShortName( DataElement.class, "DataElementShort" ).size() );
- assertEquals( 4, identifiableObjectManager.getLikeShortName( DataElement.class, "dataElementSHORT" ).size() );
- }
-
- @Test
- public void getAllOrderedName()
- {
- identifiableObjectManager.save( createDataElement( 'D' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'A' ) );
-
- List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAllSorted( DataElement.class ) );
-
- assertEquals( 4, dataElements.size() );
- assertEquals( "DataElementA", dataElements.get( 0 ).getName() );
- assertEquals( "DataElementB", dataElements.get( 1 ).getName() );
- assertEquals( "DataElementC", dataElements.get( 2 ).getName() );
- assertEquals( "DataElementD", dataElements.get( 3 ).getName() );
- }
-
- @Test
- public void getAllOrderedLastUpdated()
- {
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAllSortedByLastUpdated( DataElement.class ) );
-
- assertEquals( 4, dataElements.size() );
- assertEquals( "DataElementD", dataElements.get( 0 ).getName() );
- assertEquals( "DataElementC", dataElements.get( 1 ).getName() );
- assertEquals( "DataElementB", dataElements.get( 2 ).getName() );
- assertEquals( "DataElementA", dataElements.get( 3 ).getName() );
- }
-
- @Test
- public void userIsCurrentIfNoUserSet()
- {
- User user = createUserAndInjectSecurityContext( true );
-
- DataElement dataElement = createDataElement( 'A' );
- identifiableObjectManager.save( dataElement );
-
- assertNotNull( dataElement.getUser() );
- assertEquals( user, dataElement.getUser() );
- }
-
- @Test
- public void userCanCreatePublic()
- {
- createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD" );
-
- DataElement dataElement = createDataElement( 'A' );
- identifiableObjectManager.save( dataElement );
-
- assertNotNull( dataElement.getPublicAccess() );
- assertTrue( AccessStringHelper.canRead( dataElement.getPublicAccess() ) );
- assertTrue( AccessStringHelper.canWrite( dataElement.getPublicAccess() ) );
- }
-
- @Test
- public void userCanCreatePrivate()
- {
- createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PRIVATE_ADD" );
-
- DataElement dataElement = createDataElement( 'A' );
- identifiableObjectManager.save( dataElement );
-
- assertNotNull( dataElement.getPublicAccess() );
- assertFalse( AccessStringHelper.canRead( dataElement.getPublicAccess() ) );
- assertFalse( AccessStringHelper.canWrite( dataElement.getPublicAccess() ) );
- }
-
- @Test( expected = CreateAccessDeniedException.class )
- public void userDeniedCreateObject()
- {
- createUserAndInjectSecurityContext( false );
- identifiableObjectManager.save( createDataElement( 'A' ) );
- }
-
- @Test( expected = DeleteAccessDeniedException.class )
- public void userDeniedDeleteObject()
- {
- createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD", "F_USER_ADD" );
-
- User user = createUser( 'B' );
- identifiableObjectManager.save( user );
-
- DataElement dataElement = createDataElement( 'A' );
- identifiableObjectManager.save( dataElement );
-
- dataElement.setUser( user );
- dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
- sessionFactory.getCurrentSession().update( dataElement );
-
- identifiableObjectManager.delete( dataElement );
- }
-
- @Test
- public void objectsWithNoUser()
- {
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- Collection<DataElement> all = identifiableObjectManager.getAll( DataElement.class );
-
- assertEquals( 4, all.size() );
- }
-
- @Test
- public void readPrivateObjects()
- {
- createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD", "F_USER_ADD" );
-
- User user = createUser( 'B' );
- identifiableObjectManager.save( user );
-
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- assertEquals( 4, identifiableObjectManager.getAll( DataElement.class ).size() );
-
- List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAll( DataElement.class ) );
-
- for ( DataElement dataElement : dataElements )
- {
- dataElement.setUser( user );
- dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
-
- sessionFactory.getCurrentSession().update( dataElement );
- }
-
- assertEquals( 0, identifiableObjectManager.getAll( DataElement.class ).size() );
- }
-
- @Test
- public void readUserGroupSharedObjects()
- {
- User loginUser = createUserAndInjectSecurityContext( false, "F_DATAELEMENT_PUBLIC_ADD", "F_USER_ADD", "F_USERGROUP_PUBLIC_ADD" );
-
- User user = createUser( 'B' );
- identifiableObjectManager.save( user );
-
- UserGroup userGroup = createUserGroup( 'A', Sets.newHashSet( loginUser ) );
- identifiableObjectManager.save( userGroup );
-
- identifiableObjectManager.save( createDataElement( 'A' ) );
- identifiableObjectManager.save( createDataElement( 'B' ) );
- identifiableObjectManager.save( createDataElement( 'C' ) );
- identifiableObjectManager.save( createDataElement( 'D' ) );
-
- assertEquals( 4, identifiableObjectManager.getAll( DataElement.class ).size() );
-
- List<DataElement> dataElements = new ArrayList<>( identifiableObjectManager.getAll( DataElement.class ) );
-
- for ( DataElement dataElement : dataElements )
- {
- dataElement.setUser( user );
- dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
-
- UserGroupAccess userGroupAccess = new UserGroupAccess();
- userGroupAccess.setAccess( AccessStringHelper.newInstance().enable( AccessStringHelper.Permission.READ ).build() );
- userGroupAccess.setUserGroup( userGroup );
-
- sessionFactory.getCurrentSession().save( userGroupAccess );
-
- dataElement.getUserGroupAccesses().add( userGroupAccess );
- sessionFactory.getCurrentSession().update( dataElement );
- }
-
- assertEquals( 4, identifiableObjectManager.getAll( DataElement.class ).size() );
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2014-09-02 18:14:13 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2014-09-08 13:02:43 +0000
@@ -885,7 +885,7 @@
public List<Chart> getChartsBetweenByName( String name, int first, int max )
{
- return chartStore.getAllLikeNameOrderedName( name, first, max );
+ return chartStore.getAllLikeName( name, first, max );
}
public Collection<Chart> getChartsByUser( User user )
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java 2014-09-08 13:02:43 +0000
@@ -105,7 +105,7 @@
public List<Document> getDocumentsBetweenByName( String name, int first, int max )
{
- return documentStore.getAllLikeNameOrderedName( name, first, max );
+ return documentStore.getAllLikeName( name, first, max );
}
public List<Document> getDocumentsByUid( List<String> uids )
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2014-09-08 13:02:43 +0000
@@ -315,7 +315,7 @@
@Override
public List<Report> getReportsBetweenByName( String name, int first, int max )
{
- return reportStore.getAllLikeNameOrderedName( name, first, max );
+ return reportStore.getAllLikeName( name, first, max );
}
public List<Report> getReportByName( String name )
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2014-09-08 13:02:43 +0000
@@ -214,7 +214,7 @@
public List<ReportTable> getReportTablesBetweenByName( String name, int first, int max )
{
- return reportTableStore.getAllLikeNameOrderedName( name, first, max );
+ return reportTableStore.getAllLikeName( name, first, max );
}
public int getReportTableCount()
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2014-08-26 12:43:04 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2014-09-08 13:02:43 +0000
@@ -183,7 +183,7 @@
@Override
public Collection<Program> getProgramBetweenByName( String name, int min, int max )
{
- return i18n( i18nService, programStore.getAllLikeNameOrderedName( name, min, max ));
+ return i18n( i18nService, programStore.getAllLikeName( name, min, max ));
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/relationship/DefaultRelationshipTypeService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/relationship/DefaultRelationshipTypeService.java 2014-04-14 15:59:05 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/relationship/DefaultRelationshipTypeService.java 2014-09-08 13:02:43 +0000
@@ -110,7 +110,7 @@
@Override
public Collection<? extends RelationshipType> getRelationshipTypesBetweenByName( String name, int min, int max )
{
- return relationshipTypeStore.getAllLikeNameOrderedName( name, min, max );
+ return relationshipTypeStore.getAllLikeName( name, min, max );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeGroupService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeGroupService.java 2014-05-16 15:26:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeGroupService.java 2014-09-08 13:02:43 +0000
@@ -117,7 +117,7 @@
@Override
public Collection<TrackedEntityAttributeGroup> getTrackedEntityAttributeGroupsBetweenByName( String name, int min, int max )
{
- return attributeGroupStore.getAllLikeNameOrderedName( name, min, max );
+ return attributeGroupStore.getAllLikeName( name, min, max );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java 2014-09-08 13:02:43 +0000
@@ -151,7 +151,7 @@
public Collection<TrackedEntityAttribute> getTrackedEntityAttributesBetweenByName( String name, int min, int max )
{
- return attributeStore.getAllLikeNameOrderedName( name, min, max );
+ return attributeStore.getAllLikeName( name, min, max );
}
public int getTrackedEntityAttributeCount()
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java 2014-04-15 14:30:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java 2014-09-08 13:02:43 +0000
@@ -107,7 +107,7 @@
@Override
public Collection<TrackedEntity> getTrackedEntityBetweenByName( String name, int min, int max )
{
- return trackedEntityStore.getAllLikeNameOrderedName( name, min, max );
+ return trackedEntityStore.getAllLikeName( name, min, max );
}
@Override
=== 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-09-08 12:34:18 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2014-09-08 13:02:43 +0000
@@ -436,7 +436,9 @@
@Override
public int getCount()
{
- return ((Number) getSharingCriteria().setProjection( Projections.countDistinct( "id" ) ).uniqueResult()).intValue();
+ return ((Number) getSharingCriteria()
+ .setProjection( Projections.countDistinct( "id" ) )
+ .uniqueResult()).intValue();
}
//----------------------------------------------------------------------------------------------------------------