dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38173
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19491: Centralized logic for getting data sets for current user. Added i18n.
------------------------------------------------------------
revno: 19491
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-06-22 17:17:36 +0200
message:
Centralized logic for getting data sets for current user. Added i18n.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/CurrentUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedOrgUnitDataValueService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetMetaDataAction.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/user/CurrentUserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/CurrentUserService.java 2015-06-01 19:49:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/CurrentUserService.java 2015-06-22 15:17:36 +0000
@@ -28,8 +28,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.List;
import java.util.Set;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
/**
@@ -78,4 +80,10 @@
* Indicates whether the current user has been granted the given authority.
*/
boolean currenUserIsAuthorized( String auth );
+
+ /**
+ * Returns the data sets associated with the current user. If the current
+ * user has the ALL authority then all data sets are returned.
+ */
+ List<DataSet> getCurrentUserDataSets();
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedOrgUnitDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedOrgUnitDataValueService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedOrgUnitDataValueService.java 2015-06-22 15:17:36 +0000
@@ -37,6 +37,9 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
import org.hisp.dhis.period.Period;
+/**
+ * @author Lars Helge Overland
+ */
public class DefaultAggregatedOrgUnitDataValueService
implements AggregatedOrgUnitDataValueService
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java 2015-06-01 19:49:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java 2015-06-22 15:17:36 +0000
@@ -29,15 +29,22 @@
*/
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.security.spring.AbstractSpringSecurityCurrentUserService;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.collect.Lists;
+
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
/**
* @author Torgeir Lorange Ostby
- * @version $Id: DefaultCurrentUserService.java 5708 2008-09-16 14:28:32Z larshelg $
*/
@Transactional
public class DefaultCurrentUserService
@@ -54,6 +61,20 @@
this.userService = userService;
}
+ private DataSetService dataSetService;
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+ private I18nService i18nService;
+
+ public void setI18nService( I18nService service )
+ {
+ i18nService = service;
+ }
+
// -------------------------------------------------------------------------
// CurrentUserService implementation
// -------------------------------------------------------------------------
@@ -81,21 +102,9 @@
@Override
public boolean currentUserIsSuper()
{
- String username = getCurrentUsername();
-
- if ( username == null )
- {
- return false;
- }
-
- UserCredentials userCredentials = userService.getUserCredentialsByUsername( username );
-
- if ( userCredentials == null )
- {
- return false;
- }
-
- return userCredentials.isSuper();
+ User user = getCurrentUser();
+
+ return user != null && user.isSuper();
}
@Override
@@ -113,4 +122,24 @@
return user != null && user.getUserCredentials().isAuthorized( auth );
}
+
+ @Override
+ public List<DataSet> getCurrentUserDataSets()
+ {
+ User user = getCurrentUser();
+
+ if ( user == null )
+ {
+ return Lists.newArrayList();
+ }
+
+ if ( user.isSuper() )
+ {
+ return dataSetService.getAllDataSets();
+ }
+ else
+ {
+ return i18n( i18nService, Lists.newArrayList( user.getUserCredentials().getAllDataSets() ) );
+ }
+ }
}
=== 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 2015-06-12 20:22:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2015-06-22 15:17:36 +0000
@@ -585,6 +585,8 @@
<bean id="org.hisp.dhis.user.CurrentUserService" class="org.hisp.dhis.user.DefaultCurrentUserService">
<property name="userService" ref="org.hisp.dhis.user.UserService" />
+ <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+ <property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
</bean>
<bean id="org.hisp.dhis.user.UserSettingService" class="org.hisp.dhis.user.DefaultUserSettingService">
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetMetaDataAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetMetaDataAction.java 2015-06-15 13:44:20 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetMetaDataAction.java 2015-06-22 15:17:36 +0000
@@ -239,15 +239,8 @@
expressionService.substituteExpressions( indicators, null );
- if ( currentUserService.currentUserIsSuper() )
- {
- dataSets = new ArrayList<>( dataSetService.getAllDataSets() );
- }
- else if ( user != null )
- {
- dataSets = new ArrayList<>( user.getUserCredentials().getAllDataSets() );
- }
-
+ dataSets = currentUserService.getCurrentUserDataSets();
+
Set<DataElementCategoryCombo> categoryComboSet = new HashSet<>();
Set<DataElementCategory> categorySet = new HashSet<>();