dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29395
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14842: Analytics, implemented data approval constraints on queries
------------------------------------------------------------
revno: 14842
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-14 13:23:57 +0200
message:
Analytics, implemented data approval constraints on queries
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.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-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2014-04-14 08:42:46 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2014-04-14 11:23:57 +0000
@@ -179,7 +179,7 @@
/**
* Mapping of organisation unit sub-hierarchy roots and lowest available data approval levels.
*/
- private Map<OrganisationUnit, Integer> approvalLevels = new HashMap<OrganisationUnit, Integer>();
+ private Map<OrganisationUnit, Integer> dataApprovalLevels = new HashMap<OrganisationUnit, Integer>();
// -------------------------------------------------------------------------
// Constructors
@@ -207,7 +207,7 @@
params.dataPeriodType = this.dataPeriodType;
params.skipPartitioning = this.skipPartitioning;
params.organisationUnits = new ArrayList<OrganisationUnit>( this.organisationUnits );
- params.approvalLevels = new HashMap<OrganisationUnit, Integer>( this.approvalLevels );
+ params.dataApprovalLevels = new HashMap<OrganisationUnit, Integer>( this.dataApprovalLevels );
return params;
}
@@ -875,7 +875,15 @@
*/
public boolean isDataApproval()
{
- return approvalLevels != null && !approvalLevels.isEmpty();
+ return dataApprovalLevels != null && !dataApprovalLevels.isEmpty();
+ }
+
+ /**
+ * Ignore data approval constraints for this query.
+ */
+ public void ignoreDataApproval()
+ {
+ this.dataApprovalLevels = new HashMap<OrganisationUnit, Integer>();
}
// -------------------------------------------------------------------------
@@ -1144,14 +1152,14 @@
this.skipPartitioning = skipPartitioning;
}
- public Map<OrganisationUnit, Integer> getApprovalLevels()
+ public Map<OrganisationUnit, Integer> getDataApprovalLevels()
{
- return approvalLevels;
+ return dataApprovalLevels;
}
- public void setApprovalLevels( Map<OrganisationUnit, Integer> approvalLevels )
+ public void setDataApprovalLevels( Map<OrganisationUnit, Integer> dataApprovalLevels )
{
- this.approvalLevels = approvalLevels;
+ this.dataApprovalLevels = dataApprovalLevels;
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2014-04-14 10:12:23 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2014-04-14 11:23:57 +0000
@@ -337,6 +337,7 @@
// -----------------------------------------------------------------
DataQueryParams dataSourceParams = params.instance();
+ dataSourceParams.ignoreDataApproval(); // No approval for reporting rates
dataSourceParams.removeDimension( INDICATOR_DIM_ID );
dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
dataSourceParams.setAggregationType( AggregationType.COUNT );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2014-04-14 10:24:27 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2014-04-14 11:23:57 +0000
@@ -45,6 +45,7 @@
import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
import static org.hisp.dhis.system.util.TextUtils.removeLastOr;
import static org.hisp.dhis.system.util.TextUtils.trimEnd;
+import static org.hisp.dhis.analytics.DataQueryParams.LEVEL_PREFIX;
import java.util.Collection;
import java.util.HashMap;
@@ -64,6 +65,7 @@
import org.hisp.dhis.common.ListMap;
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.jdbc.StatementBuilder;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.system.util.MathUtils;
@@ -92,6 +94,8 @@
private static final Log log = LogFactory.getLog( JdbcAnalyticsManager.class );
+ private static final String COL_APPROVALLEVEL = "approvallevel";
+
@Autowired
private JdbcTemplate jdbcTemplate;
@@ -284,7 +288,7 @@
if ( DimensionalObjectUtils.anyDimensionHasItems( filters ) )
{
- sql += sqlHelper.whereAnd() + " (";
+ sql += sqlHelper.whereAnd() + " ( ";
for ( DimensionalObject filter : filters )
{
@@ -300,6 +304,21 @@
}
}
+ if ( params.isDataApproval() )
+ {
+ sql += sqlHelper.whereAnd() + " ( ";
+
+ for ( OrganisationUnit unit : params.getDataApprovalLevels().keySet() )
+ {
+ String ouCol = LEVEL_PREFIX + unit.getLevel();
+ Integer level = params.getDataApprovalLevels().get( unit );
+
+ sql += "(" + ouCol + " = '" + unit.getUid() + "' and " + COL_APPROVALLEVEL + " <= " + level + ") or ";
+ }
+
+ sql = removeLastOr( sql ) + ") ";
+ }
+
return sql;
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.java 2014-04-14 10:12:23 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.java 2014-04-14 11:23:57 +0000
@@ -123,7 +123,7 @@
unit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( unit.getId() ) );
}
- params.setApprovalLevels( approvalLevels );
+ params.setDataApprovalLevels( approvalLevels );
log.info( "User: " + user.getUsername() + " constrained by data approval levels: " + approvalLevels.values() );
}