diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java index 00e13a1c4e4..e33ad0454aa 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java @@ -251,12 +251,12 @@ private String getInputSql(Program program) { \sfrom (\ select h.trackedentityid, '${historyTableId}' as startdate, h.enddate as enddate, h.organisationunitid \ from ${programownershiphistory} h \ - where h.programid=${programId} \ + where h.programid = ${programId} \ and h.organisationunitid is not null \ union \ select o.trackedentityid, '${trackedEntityOwnTableId}' as startdate, null as enddate, o.organisationunitid \ from ${trackedentityprogramowner} o \ - where o.programid=${programId} \ + where o.programid = ${programId} \ and exists (\ select 1 from ${programownershiphistory} p \ where o.trackedentityid = p.trackedentityid \ diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java index b399999ff37..62de96dba85 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java @@ -278,14 +278,16 @@ void testPopulateTable() throws SQLException { select te.uid,a.startdate,a.enddate,ou.uid from (\ select h.trackedentityid, '1001-01-01' as startdate, h.enddate as enddate, h.organisationunitid \ from "programownershiphistory" h \ - where h.programid=0 and h.organisationunitid is not null \ + where h.programid = 0 \ + and h.organisationunitid is not null \ union \ select o.trackedentityid, '2002-02-02' as startdate, null as enddate, o.organisationunitid \ from "trackedentityprogramowner" o \ - where o.programid=0 \ + where o.programid = 0 \ and exists (select 1 from "programownershiphistory" p \ where o.trackedentityid = p.trackedentityid \ - and p.programid=0 and p.organisationunitid is not null)\ + and p.programid = 0 \ + and p.organisationunitid is not null)\ ) a \ inner join "trackedentity" te on a.trackedentityid = te.trackedentityid \ inner join "organisationunit" ou on a.organisationunitid = ou.organisationunitid \