dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34791
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17844: Fix approvals for default option combo
------------------------------------------------------------
revno: 17844
committer: jimgrace@xxxxxxxxx
branch nick: dhis2
timestamp: Tue 2014-12-30 11:25:53 -0500
message:
Fix approvals for default option combo
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.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-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2014-11-14 20:34:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2014-12-30 16:25:53 +0000
@@ -445,11 +445,10 @@
dataSets.add( da.getDataSet() );
}
- Period period = dataApprovals.get(0).getPeriod();
-
- OrganisationUnit orgUnit = dataApprovals.get(0).getOrganisationUnit();
-
- List<DataApprovalStatus> statuses = dataApprovalStore.getDataApprovals( dataSets, period, orgUnit, null );
+ DataApproval da0 = dataApprovals.get( 0 );
+
+ List<DataApprovalStatus> statuses = dataApprovalStore.getDataApprovals( dataSets,
+ da0.getPeriod(), da0.getOrganisationUnit(), da0.getAttributeOptionCombo() );
for ( DataApprovalStatus status : statuses )
{
@@ -469,7 +468,9 @@
}
/**
- * Returns an indexed map where the key is based on organisation unit and period.
+ * Returns an indexed map where the key is based on each distinct
+ * combination of organisation unit, period, and attributeOptionCombo.
+ * (attributeOptionCombo may be null.)
*/
private ListMap<String, DataApproval> getIndexedListMap( List<DataApproval> dataApprovalList )
{
@@ -477,7 +478,9 @@
for ( DataApproval approval : dataApprovalList )
{
- String key = approval == null ? null : approval.getOrganisationUnit().getId() + "-" + approval.getPeriod().getId();
+ String key = approval == null ? null : approval.getOrganisationUnit().getId()
+ + "-" + approval.getPeriod().getId()
+ + "-" + ( approval.getAttributeOptionCombo() == null ? "null" : approval.getAttributeOptionCombo().getId() );
map.putValue( key, approval );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java 2014-12-29 02:05:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java 2014-12-30 16:25:53 +0000
@@ -237,24 +237,35 @@
final String dataSetIds = getCommaDelimitedString( getIdentifiers( DataSet.class, dataSets ) );
- Set<Integer> categoryComboIds = new HashSet<>();
-
- for ( DataSet ds : dataSets )
- {
- if ( ds.isApproveData() && ( maySeeDefaultCategoryCombo || ds.getCategoryCombo() != defaultCategoryCombo ) )
- {
- categoryComboIds.add( ds.getCategoryCombo().getId() );
- }
- }
-
- if ( categoryComboIds.isEmpty() )
- {
- log.warn( "No dataset categorycombos to check for approval, user " + ( user == null ? "(null)" : user.getUsername() ) + " datasetIds " + dataSetIds );
-
- return new ArrayList<>();
- }
-
- final String dataSetCcIds = TextUtils.getCommaDelimitedString( categoryComboIds );
+ boolean isDefaultCombo = ( attributeOptionCombo == categoryService.getDefaultDataElementCategoryOptionCombo() );
+
+ final String categoryComboIds;
+
+ if ( isDefaultCombo )
+ {
+ categoryComboIds = Integer.toString( categoryService.getDefaultDataElementCategoryCombo().getId() );
+ }
+ else
+ {
+ Set<Integer> catComboIds = new HashSet<>();
+
+ for ( DataSet ds : dataSets )
+ {
+ if ( ds.isApproveData() && ( maySeeDefaultCategoryCombo || ds.getCategoryCombo() != defaultCategoryCombo ) )
+ {
+ catComboIds.add( ds.getCategoryCombo().getId() );
+ }
+ }
+
+ if ( catComboIds.isEmpty() )
+ {
+ log.warn( "No dataset categorycombos to check for approval, user " + ( user == null ? "(null)" : user.getUsername() ) + " datasetIds " + dataSetIds );
+
+ return new ArrayList<>();
+ }
+
+ categoryComboIds = TextUtils.getCommaDelimitedString( catComboIds );
+ }
int orgUnitLevel = 1;
String orgUnitJoinOn;
@@ -291,6 +302,8 @@
testAncestors += "or o" + i + ".organisationunitid is not null ";
}
+ final String dsCategoryComboIdMatches = isDefaultCombo ? "" : "and ds.categorycomboid = a.categorycomboid "; // Default option combo matches any data set.
+
String readyBelowSubquery = "true"; // Ready below if this is the lowest (highest number) approval orgUnit level.
int orgUnitLevelAbove = 0;
@@ -314,9 +327,10 @@
boolean acceptanceRequiredForApproval = (Boolean) systemSettingManager.getSystemSetting( KEY_ACCEPTANCE_REQUIRED_FOR_APPROVAL, false );
readyBelowSubquery = "not exists (select 1 from _orgunitstructure ous " +
+ "join dataset ds on ds.datasetid in (" + dataSetIds + ") " + dsCategoryComboIdMatches +
"left join dataapproval da on da.organisationunitid = ous.organisationunitid " +
- "and da.dataapprovallevelid = " + dal.getLevel() + " and da.periodid in (" + periodIds + ") " +
- "and da.datasetid in (" + dataSetIds + ") " +
+ "and da.dataapprovallevelid = " + dal.getId() + " and da.periodid in (" + periodIds + ") " +
+ "and da.datasetid = ds.datasetid " +
"and da.attributeoptioncomboid = a.categoryoptioncomboid " +
"where ous.idlevel" + orgUnitLevel + " = a.organisationunitid " +
"and ous.level = " + dal.getOrgUnitLevel() + " " +
@@ -331,7 +345,7 @@
{
approvedAboveSubquery = "exists(select 1 from dataapproval da " +
"join dataapprovallevel dal on dal.dataapprovallevelid = da.dataapprovallevelid " +
- "join dataset ds on ds.datasetid in (" + dataSetIds + ") and ds.categorycomboid = a.categorycomboid " +
+ "join dataset ds on ds.datasetid = da.datasetid and ds.datasetid in (" + dataSetIds + ") " + dsCategoryComboIdMatches +
"join _orgunitstructure ou on ou.organisationunitid = a.organisationunitid and ou.idlevel" + orgUnitLevelAbove + " = da.organisationunitid " +
"where da.periodid in (" + periodIds + ") and da.attributeoptioncomboid = a.categoryoptioncomboid) ";
}
@@ -339,14 +353,14 @@
final String sql =
"select a.categoryoptioncomboid, a.organisationunitid, " +
"(select min(coalesce(dal.level, 0)) from period p " +
- "join dataset ds on ds.datasetid in (" + dataSetIds + ") and ds.categorycomboid = a.categorycomboid " +
+ "join dataset ds on ds.datasetid in (" + dataSetIds + ") " + dsCategoryComboIdMatches +
"left join dataapproval da on da.datasetid = ds.datasetid and da.periodid = p.periodid " +
"and da.attributeoptioncomboid = a.categoryoptioncomboid and da.organisationunitid = a.organisationunitid " +
"left join dataapprovallevel dal on dal.dataapprovallevelid = da.dataapprovallevelid " +
"where p.periodid in (" + periodIds + ") " +
") as highest_approved_level, " +
"(select substring(min(concat(100000 + coalesce(dal.level, 0), coalesce(da.accepted, FALSE))) from 7) from period p " +
- "join dataset ds on ds.datasetid in (" + dataSetIds + ") and ds.categorycomboid = a.categorycomboid " +
+ "join dataset ds on ds.datasetid in (" + dataSetIds + ") " + dsCategoryComboIdMatches +
"left join dataapproval da on da.datasetid = ds.datasetid and da.periodid = p.periodid " +
"and da.attributeoptioncomboid = a.categoryoptioncomboid and da.organisationunitid = a.organisationunitid " +
"left join dataapprovallevel dal on dal.dataapprovallevelid = da.dataapprovallevelid " +
@@ -357,7 +371,7 @@
"from ( " + // subquery to get combinations of organisation unit and category option combo
"select distinct cocco.categoryoptioncomboid, ccoc.categorycomboid, o.organisationunitid " +
"from categoryoptioncombos_categoryoptions cocco " +
- "join categorycombos_optioncombos ccoc on ccoc.categoryoptioncomboid = cocco.categoryoptioncomboid and ccoc.categorycomboid in (" + dataSetCcIds + ") " +
+ "join categorycombos_optioncombos ccoc on ccoc.categoryoptioncomboid = cocco.categoryoptioncomboid and ccoc.categorycomboid in (" + categoryComboIds + ") " +
"join dataelementcategoryoption co on co.categoryoptionid = cocco.categoryoptionid " +
"and (co.startdate is null or co.startdate <= '" + maxDate + "') and (co.enddate is null or co.enddate >= '" + minDate + "') " +
"join _orgunitstructure o on " + orgUnitJoinOn + " " +
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java 2014-11-26 15:21:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java 2014-12-30 16:25:53 +0000
@@ -167,8 +167,10 @@
return;
}
+ DataElementCategoryOptionCombo combo = categoryService.getDefaultDataElementCategoryOptionCombo();
+
DataApprovalStatus status = dataApprovalService
- .getDataApprovalStatusAndPermissions( dataSet, period, organisationUnit, null );
+ .getDataApprovalStatusAndPermissions( dataSet, period, organisationUnit, combo );
DataApprovalPermissions permissions = status.getPermissions();
permissions.setState( status.getState().toString() );
@@ -238,8 +240,10 @@
private DataApprovalStateResponse getDataApprovalStateResponse( DataSet dataSet,
OrganisationUnit organisationUnit, Period period )
{
+ DataElementCategoryOptionCombo combo = categoryService.getDefaultDataElementCategoryOptionCombo();
+
DataApprovalStatus status = dataApprovalService.getDataApprovalStatusAndPermissions( dataSet, period,
- organisationUnit, null );
+ organisationUnit, combo );
DataApproval dataApproval = status.getDataApproval();
Date createdDate = dataApproval == null ? null : dataApproval.getCreated();