dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33575
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17161: UserService, using hibernate query to speed up retrival of readable category option groups
------------------------------------------------------------
revno: 17161
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-10-17 20:44:58 +0200
message:
UserService, using hibernate query to speed up retrival of readable category option groups
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionGroupStore.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.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/user/DefaultUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
--
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
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupStore.java 2014-10-17 18:44:58 +0000
@@ -0,0 +1,11 @@
+package org.hisp.dhis.dataelement;
+
+import java.util.List;
+
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+
+public interface CategoryOptionGroupStore
+ extends GenericIdentifiableObjectStore<CategoryOptionGroup>
+{
+ List<CategoryOptionGroup> getCategoryOptionGroups( CategoryOptionGroupSet groupSet );
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2014-09-12 14:17:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2014-10-17 18:44:58 +0000
@@ -602,6 +602,8 @@
Collection<CategoryOptionGroup> getCategoryOptionGroupsBetweenByName( int first, int max, String name );
Collection<CategoryOptionGroup> getAllCategoryOptionGroups();
+
+ List<CategoryOptionGroup> getCategoryOptionGroups( CategoryOptionGroupSet groupSet );
CategoryOptionGroup getCategoryOptionGroupByName( String name );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 2014-10-17 18:44:58 +0000
@@ -320,8 +320,6 @@
return dimensions;
}
-
-
@Override
public void mergeAnalyticalObject( BaseAnalyticalObject object )
{
=== 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-10-16 06:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2014-10-17 18:44:58 +0000
@@ -90,9 +90,9 @@
this.categoryOptionComboStore = categoryOptionComboStore;
}
- private GenericNameableObjectStore<CategoryOptionGroup> categoryOptionGroupStore;
+ private CategoryOptionGroupStore categoryOptionGroupStore;
- public void setCategoryOptionGroupStore( GenericNameableObjectStore<CategoryOptionGroup> categoryOptionGroupStore )
+ public void setCategoryOptionGroupStore( CategoryOptionGroupStore categoryOptionGroupStore )
{
this.categoryOptionGroupStore = categoryOptionGroupStore;
}
@@ -924,6 +924,12 @@
}
@Override
+ public List<CategoryOptionGroup> getCategoryOptionGroups( CategoryOptionGroupSet groupSet )
+ {
+ return categoryOptionGroupStore.getCategoryOptionGroups( groupSet );
+ }
+
+ @Override
public CategoryOptionGroup getCategoryOptionGroupByName( String name )
{
return i18n( i18nService, categoryOptionGroupStore.getByName( name ) );
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionGroupStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionGroupStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionGroupStore.java 2014-10-17 18:44:58 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.dataelement.hibernate;
+
+/*
+ * 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 java.util.List;
+
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.dataelement.CategoryOptionGroup;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
+import org.hisp.dhis.dataelement.CategoryOptionGroupStore;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class HibernateCategoryOptionGroupStore
+ extends HibernateIdentifiableObjectStore<CategoryOptionGroup>
+ implements CategoryOptionGroupStore
+{
+ @SuppressWarnings("unchecked")
+ public List<CategoryOptionGroup> getCategoryOptionGroups( CategoryOptionGroupSet groupSet )
+ {
+ return getSharingCriteria( Restrictions.eq( "groupSet", groupSet ) ).list();
+ }
+}
=== 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-10-16 06:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2014-10-17 18:44:58 +0000
@@ -49,6 +49,7 @@
import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
import org.hisp.dhis.dataelement.DataElementCategory;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.PeriodType;
@@ -108,8 +109,15 @@
this.currentUserService = currentUserService;
}
+ private DataElementCategoryService categoryService;
+
+ public void setCategoryService( DataElementCategoryService categoryService )
+ {
+ this.categoryService = categoryService;
+ }
+
private SecurityService securityService;
-
+
public void setSecurityService( SecurityService securityService )
{
this.securityService = securityService;
@@ -362,15 +370,9 @@
{
groups = new HashSet<>();
- for ( CategoryOptionGroupSet set : cogsConstraints )
+ for ( CategoryOptionGroupSet cogs : cogsConstraints )
{
- for ( CategoryOptionGroup g : set.getMembers() )
- {
- if ( securityService.canRead( g ) )
- {
- groups.add( g );
- }
- }
+ groups.addAll( categoryService.getCategoryOptionGroups( cogs ) );
}
}
@@ -835,11 +837,11 @@
*/
private boolean hasGroupsToUpdateUser( UserCredentials userCredentials )
{
- UserCredentials currentUserCredentials = currentUserService.getCurrentUser().getUserCredentials();
+ User user = currentUserService.getCurrentUser();
boolean onlyManageWithinUserGroups = (Boolean) systemSettingManager.getSystemSetting( KEY_ONLY_MANAGE_WITHIN_USER_GROUPS, false );
- if ( onlyManageWithinUserGroups && !currentUserCredentials.getAllAuthorities().contains( UserAuthorityGroup.AUTHORITY_ALL ) )
+ if ( onlyManageWithinUserGroups && !user.getUserCredentials().getAllAuthorities().contains( UserAuthorityGroup.AUTHORITY_ALL ) )
{
if ( userCredentials.getUser().getGroups() != null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-10-15 13:58:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-10-17 18:44:58 +0000
@@ -190,7 +190,7 @@
<property name="cacheable" value="true" />
</bean>
- <bean id="org.hisp.dhis.dataelement.CategoryOptionGroupStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
+ <bean id="org.hisp.dhis.dataelement.CategoryOptionGroupStore" class="org.hisp.dhis.dataelement.hibernate.HibernateCategoryOptionGroupStore">
<property name="clazz" value="org.hisp.dhis.dataelement.CategoryOptionGroup" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
@@ -594,6 +594,7 @@
<property name="userAuthorityGroupStore" ref="org.hisp.dhis.user.UserAuthorityGroupStore" />
<property name="userSettingStore" ref="org.hisp.dhis.user.UserSettingStore" />
<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+ <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="securityService" ref="org.hisp.dhis.security.SecurityService" />
<property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
</bean>