Skip to content

Commit

Permalink
fix: Analytics API returns invalid totalAggregationType [2.42-DHIS2-1…
Browse files Browse the repository at this point in the history
…8045] (#18569)

* fix: Analytics API returns invalid totalAggregationType [2.42-DHIS2-18045]

* QA issue
  • Loading branch information
d-bernat authored Sep 11, 2024
1 parent 98eaa91 commit 3f32483
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public String getDimensionItem(IdScheme idScheme) {

@Override
public TotalAggregationType getTotalAggregationType() {
return TotalAggregationType.SUM;
return getAggregationType() == AggregationType.NONE
? TotalAggregationType.NONE
: TotalAggregationType.SUM;
}

// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.hisp.dhis.common;

public enum TotalAggregationType {
NONE,
SUM,
AVERAGE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2004-2024, 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.
*/
package org.hisp.dhis.common;

import static org.junit.jupiter.api.Assertions.assertSame;

import org.hisp.dhis.analytics.AggregationType;
import org.junit.jupiter.api.Test;

class BaseDimensionalItemObjectTest {
@Test
void testWhenBaseDimensionalItemObjectAggregationTypeIsNoneTotalAggregationTypeIsNone() {
// given
BaseDimensionalItemObject baseDimensionalItemObject = new BaseDimensionalItemObject();

// when
baseDimensionalItemObject.setAggregationType(AggregationType.NONE);

// then
assertSame(TotalAggregationType.NONE, baseDimensionalItemObject.getTotalAggregationType());
}

@Test
void testWhenBaseDimensionalItemObjectAggregationTypeIsNotNoneTotalAggregationTypeIsSum() {
// given
BaseDimensionalItemObject baseDimensionalItemObject = new BaseDimensionalItemObject();

// when
baseDimensionalItemObject.setAggregationType(AggregationType.AVERAGE_SUM_ORG_UNIT);

// then
assertSame(TotalAggregationType.SUM, baseDimensionalItemObject.getTotalAggregationType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void queryAggregatedenrollmentsmacase1() throws JSONException {

// Assert metaData.
String expectedMetaData =
"{\"pager\":{\"page\":1,\"pageSize\":100,\"isLastPage\":true},\"items\":{\"lZGmxYbs97q\":{\"uid\":\"lZGmxYbs97q\",\"code\":\"MMD_PER_ID\",\"name\":\"Unique ID\",\"description\":\"Unique identiifer\",\"dimensionItemType\":\"PROGRAM_ATTRIBUTE\",\"valueType\":\"TEXT\",\"aggregationType\":\"NONE\",\"totalAggregationType\":\"SUM\"},\"Mnp3oXrpAbK\":{\"uid\":\"Mnp3oXrpAbK\",\"code\":\"Female\",\"name\":\"Female\"},\"rBvjJYbMCVx\":{\"uid\":\"rBvjJYbMCVx\",\"code\":\"Male\",\"name\":\"Male\"},\"IpHINAT79UW\":{\"uid\":\"IpHINAT79UW\",\"name\":\"Child Programme\"},\"ZzYYXq4fJie\":{\"uid\":\"ZzYYXq4fJie\",\"name\":\"Baby Postnatal\",\"description\":\"Baby Postnatal\"},\"ou\":{\"uid\":\"ou\",\"name\":\"Organisation unit\",\"dimensionType\":\"ORGANISATION_UNIT\"},\"202208\":{\"uid\":\"202208\",\"code\":\"202208\",\"name\":\"August 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-08-01T00:00:00.000\",\"endDate\":\"2022-08-31T00:00:00.000\"},\"202307\":{\"uid\":\"202307\",\"code\":\"202307\",\"name\":\"July 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-07-01T00:00:00.000\",\"endDate\":\"2023-07-31T00:00:00.000\"},\"202209\":{\"uid\":\"202209\",\"code\":\"202209\",\"name\":\"September 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-09-01T00:00:00.000\",\"endDate\":\"2022-09-30T00:00:00.000\"},\"a3kGcGDCuk6\":{\"uid\":\"a3kGcGDCuk6\",\"code\":\"DE_2006098\",\"name\":\"MCH Apgar Score\",\"description\":\"Apgar is a quick test performed on a baby at 1 and 5 minutes after birth. The 1-minute score determines how well the baby tolerated the birthing process. The 5-minute score tells the doctor how well the baby is doing outside the mother's womb.\",\"dimensionItemType\":\"DATA_ELEMENT\",\"valueType\":\"NUMBER\",\"aggregationType\":\"AVERAGE\",\"totalAggregationType\":\"SUM\"},\"202305\":{\"uid\":\"202305\",\"code\":\"202305\",\"name\":\"May 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-05-01T00:00:00.000\",\"endDate\":\"2023-05-31T00:00:00.000\"},\"202306\":{\"uid\":\"202306\",\"code\":\"202306\",\"name\":\"June 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-06-01T00:00:00.000\",\"endDate\":\"2023-06-30T00:00:00.000\"},\"202303\":{\"uid\":\"202303\",\"code\":\"202303\",\"name\":\"March 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-03-01T00:00:00.000\",\"endDate\":\"2023-03-31T00:00:00.000\"},\"202304\":{\"uid\":\"202304\",\"code\":\"202304\",\"name\":\"April 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-04-01T00:00:00.000\",\"endDate\":\"2023-04-30T00:00:00.000\"},\"202301\":{\"uid\":\"202301\",\"code\":\"202301\",\"name\":\"January 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-01-01T00:00:00.000\",\"endDate\":\"2023-01-31T00:00:00.000\"},\"202302\":{\"uid\":\"202302\",\"code\":\"202302\",\"name\":\"February 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-02-01T00:00:00.000\",\"endDate\":\"2023-02-28T00:00:00.000\"},\"cejWyOfXge6\":{\"uid\":\"cejWyOfXge6\",\"name\":\"Gender\",\"description\":\"Gender\",\"dimensionItemType\":\"PROGRAM_ATTRIBUTE\",\"valueType\":\"TEXT\",\"aggregationType\":\"NONE\",\"totalAggregationType\":\"SUM\"},\"202211\":{\"uid\":\"202211\",\"code\":\"202211\",\"name\":\"November 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-11-01T00:00:00.000\",\"endDate\":\"2022-11-30T00:00:00.000\"},\"202212\":{\"uid\":\"202212\",\"code\":\"202212\",\"name\":\"December 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-12-01T00:00:00.000\",\"endDate\":\"2022-12-31T00:00:00.000\"},\"202210\":{\"uid\":\"202210\",\"code\":\"202210\",\"name\":\"October 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-10-01T00:00:00.000\",\"endDate\":\"2022-10-31T00:00:00.000\"},\"pe\":{\"uid\":\"pe\",\"dimensionType\":\"PERIOD\"},\"A03MvHHogjR\":{\"uid\":\"A03MvHHogjR\",\"name\":\"Birth\",\"description\":\"Birth of the baby\"},\"lc3eMKXaEfw\":{\"uid\":\"lc3eMKXaEfw\",\"code\":\"OU_197385\",\"name\":\"Bonthe\",\"dimensionItemType\":\"ORGANISATION_UNIT\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\"}},\"dimensions\":{\"lZGmxYbs97q\":[],\"A03MvHHogjR.a3kGcGDCuk6\":[],\"pe\":[\"202208\",\"202209\",\"202210\",\"202211\",\"202212\",\"202301\",\"202302\",\"202303\",\"202304\",\"202305\",\"202306\",\"202307\"],\"ou\":[\"lc3eMKXaEfw\"],\"cejWyOfXge6\":[\"Mnp3oXrpAbK\"]}}";
"{\"pager\":{\"page\":1,\"pageSize\":100,\"isLastPage\":true},\"items\":{\"lZGmxYbs97q\":{\"uid\":\"lZGmxYbs97q\",\"code\":\"MMD_PER_ID\",\"name\":\"Unique ID\",\"description\":\"Unique identiifer\",\"dimensionItemType\":\"PROGRAM_ATTRIBUTE\",\"valueType\":\"TEXT\",\"aggregationType\":\"NONE\",\"totalAggregationType\":\"NONE\"},\"Mnp3oXrpAbK\":{\"uid\":\"Mnp3oXrpAbK\",\"code\":\"Female\",\"name\":\"Female\"},\"rBvjJYbMCVx\":{\"uid\":\"rBvjJYbMCVx\",\"code\":\"Male\",\"name\":\"Male\"},\"IpHINAT79UW\":{\"uid\":\"IpHINAT79UW\",\"name\":\"Child Programme\"},\"ZzYYXq4fJie\":{\"uid\":\"ZzYYXq4fJie\",\"name\":\"Baby Postnatal\",\"description\":\"Baby Postnatal\"},\"ou\":{\"uid\":\"ou\",\"name\":\"Organisation unit\",\"dimensionType\":\"ORGANISATION_UNIT\"},\"202208\":{\"uid\":\"202208\",\"code\":\"202208\",\"name\":\"August 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-08-01T00:00:00.000\",\"endDate\":\"2022-08-31T00:00:00.000\"},\"202307\":{\"uid\":\"202307\",\"code\":\"202307\",\"name\":\"July 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-07-01T00:00:00.000\",\"endDate\":\"2023-07-31T00:00:00.000\"},\"202209\":{\"uid\":\"202209\",\"code\":\"202209\",\"name\":\"September 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-09-01T00:00:00.000\",\"endDate\":\"2022-09-30T00:00:00.000\"},\"a3kGcGDCuk6\":{\"uid\":\"a3kGcGDCuk6\",\"code\":\"DE_2006098\",\"name\":\"MCH Apgar Score\",\"description\":\"Apgar is a quick test performed on a baby at 1 and 5 minutes after birth. The 1-minute score determines how well the baby tolerated the birthing process. The 5-minute score tells the doctor how well the baby is doing outside the mother's womb.\",\"dimensionItemType\":\"DATA_ELEMENT\",\"valueType\":\"NUMBER\",\"aggregationType\":\"AVERAGE\",\"totalAggregationType\":\"SUM\"},\"202305\":{\"uid\":\"202305\",\"code\":\"202305\",\"name\":\"May 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-05-01T00:00:00.000\",\"endDate\":\"2023-05-31T00:00:00.000\"},\"202306\":{\"uid\":\"202306\",\"code\":\"202306\",\"name\":\"June 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-06-01T00:00:00.000\",\"endDate\":\"2023-06-30T00:00:00.000\"},\"202303\":{\"uid\":\"202303\",\"code\":\"202303\",\"name\":\"March 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-03-01T00:00:00.000\",\"endDate\":\"2023-03-31T00:00:00.000\"},\"202304\":{\"uid\":\"202304\",\"code\":\"202304\",\"name\":\"April 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-04-01T00:00:00.000\",\"endDate\":\"2023-04-30T00:00:00.000\"},\"202301\":{\"uid\":\"202301\",\"code\":\"202301\",\"name\":\"January 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-01-01T00:00:00.000\",\"endDate\":\"2023-01-31T00:00:00.000\"},\"202302\":{\"uid\":\"202302\",\"code\":\"202302\",\"name\":\"February 2023\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2023-02-01T00:00:00.000\",\"endDate\":\"2023-02-28T00:00:00.000\"},\"cejWyOfXge6\":{\"uid\":\"cejWyOfXge6\",\"name\":\"Gender\",\"description\":\"Gender\",\"dimensionItemType\":\"PROGRAM_ATTRIBUTE\",\"valueType\":\"TEXT\",\"aggregationType\":\"NONE\",\"totalAggregationType\":\"NONE\"},\"202211\":{\"uid\":\"202211\",\"code\":\"202211\",\"name\":\"November 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-11-01T00:00:00.000\",\"endDate\":\"2022-11-30T00:00:00.000\"},\"202212\":{\"uid\":\"202212\",\"code\":\"202212\",\"name\":\"December 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-12-01T00:00:00.000\",\"endDate\":\"2022-12-31T00:00:00.000\"},\"202210\":{\"uid\":\"202210\",\"code\":\"202210\",\"name\":\"October 2022\",\"dimensionItemType\":\"PERIOD\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\",\"startDate\":\"2022-10-01T00:00:00.000\",\"endDate\":\"2022-10-31T00:00:00.000\"},\"pe\":{\"uid\":\"pe\",\"dimensionType\":\"PERIOD\"},\"A03MvHHogjR\":{\"uid\":\"A03MvHHogjR\",\"name\":\"Birth\",\"description\":\"Birth of the baby\"},\"lc3eMKXaEfw\":{\"uid\":\"lc3eMKXaEfw\",\"code\":\"OU_197385\",\"name\":\"Bonthe\",\"dimensionItemType\":\"ORGANISATION_UNIT\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\"}},\"dimensions\":{\"lZGmxYbs97q\":[],\"A03MvHHogjR.a3kGcGDCuk6\":[],\"pe\":[\"202208\",\"202209\",\"202210\",\"202211\",\"202212\",\"202301\",\"202302\",\"202303\",\"202304\",\"202305\",\"202306\",\"202307\"],\"ou\":[\"lc3eMKXaEfw\"],\"cejWyOfXge6\":[\"Mnp3oXrpAbK\"]}}";
String actualMetaData = new JSONObject((Map) response.extract("metaData")).toString();
assertEquals(expectedMetaData, actualMetaData, false);

Expand Down
Loading

0 comments on commit 3f32483

Please sign in to comment.