Skip to content

Commit 15e6124

Browse files
committed
AMP-31091: The disaggregation order doesnt match
1 parent 86b7d86 commit 15e6124

4 files changed

Lines changed: 41 additions & 9 deletions

File tree

amp/src/main/java/org/digijava/kernel/ampapi/endpoints/indicator/manager/MEIndicatorDTO.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class MEIndicatorDTO {
9292
private String dataSource;
9393

9494
@JsonProperty("disaggregation")
95-
private Set<Long> disaggregation = new HashSet<>();
95+
private List<Long> disaggregation = new ArrayList<>();
9696

9797
@JsonProperty("unitOfMeasure")
9898
private Long unitOfMeasure;
@@ -131,7 +131,7 @@ public MEIndicatorDTO(final AmpIndicator indicator) {
131131
this.logframeLinks = indicator.getLogframeLinks();
132132
this.data = indicator.getData();
133133
this.dataSource = indicator.getDataSource();
134-
this.disaggregation = indicator.getDisaggregation()!=null ? indicator.getDisaggregation().stream().map(AmpCategoryValue::getId).collect(Collectors.toSet()) : null;
134+
this.disaggregation = indicator.getDisaggregation()!=null ? indicator.getDisaggregation().stream().map(AmpCategoryValue::getId).collect(Collectors.toList()) : null;
135135
this.unitOfMeasure = indicator.getUnitOfMeasure()!=null ? indicator.getUnitOfMeasure().getId() : null;
136136
this.calculationMethod = indicator.getCalculationMethod();
137137
this.responsibleOrganizations = indicator.getResponsibleOrganizations()!=null ? indicator.getResponsibleOrganizations().stream().map(AmpOrganisation::getAmpOrgId).collect(Collectors.toSet()) : null;
@@ -288,8 +288,8 @@ public void setOutcomeId(Long outcomeId) {
288288
public String getDataSource() { return dataSource; }
289289
public void setDataSource(String dataSource) { this.dataSource = dataSource; }
290290

291-
public Set<Long> getDisaggregation() { return disaggregation; }
292-
public void setDisaggregation(Set<Long> disaggregation) { this.disaggregation = disaggregation; }
291+
public List<Long> getDisaggregation() { return disaggregation; }
292+
public void setDisaggregation(List<Long> disaggregation) { this.disaggregation = disaggregation; }
293293

294294
public Long getUnitOfMeasure() { return unitOfMeasure; }
295295
public void setUnitOfMeasure(Long unitOfMeasure) { this.unitOfMeasure = unitOfMeasure; }

amp/src/main/java/org/digijava/module/aim/dbentity/AmpIndicator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import org.digijava.module.categorymanager.dbentity.AmpCategoryValue;
99

1010
import java.io.Serializable;
11+
import java.util.ArrayList;
1112
import java.util.Date;
1213
import java.util.HashSet;
14+
import java.util.List;
1315
import java.util.Set;
1416

1517
@TranslatableClass (displayName = "Indicator")
@@ -83,7 +85,7 @@ public class AmpIndicator implements Serializable, Identifiable
8385
private Set<Long> logframeLinks;
8486
private String data;
8587
private String dataSource;
86-
private Set<AmpCategoryValue> disaggregation;
88+
private List<AmpCategoryValue> disaggregation = new ArrayList<>();
8789
private AmpCategoryValue unitOfMeasure;
8890
private String calculationMethod;
8991
private Set<AmpOrganisation> responsibleOrganizations;
@@ -274,10 +276,10 @@ public String getDataSource() {
274276
public void setDataSource(String dataSource) {
275277
this.dataSource = dataSource;
276278
}
277-
public Set<AmpCategoryValue> getDisaggregation() {
279+
public List<AmpCategoryValue> getDisaggregation() {
278280
return disaggregation;
279281
}
280-
public void setDisaggregation(Set<AmpCategoryValue> disaggregation) {
282+
public void setDisaggregation(List<AmpCategoryValue> disaggregation) {
281283
this.disaggregation = disaggregation;
282284
}
283285
public AmpCategoryValue getUnitOfMeasure() {

amp/src/main/resources/org/digijava/module/aim/dbentity/AmpIndicator.hbm.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@
5555
<many-to-one name="indicatorType" column="indicator_type_id" class="org.digijava.module.categorymanager.dbentity.AmpCategoryValue" cascade="none" />
5656
<property name="data" column="data" type="java.lang.String" />
5757
<property name="dataSource" column="data_source" type="java.lang.String" />
58-
<set name="disaggregation" table="AMP_INDICATOR_DISAGGREGATION" lazy="true" cascade="none">
58+
<list name="disaggregation" table="AMP_INDICATOR_DISAGGREGATION" lazy="true" cascade="none">
5959
<cache usage="read-write" />
6060
<key column="indicator_id" />
61+
<list-index column="order_index" />
6162
<many-to-many class="org.digijava.module.categorymanager.dbentity.AmpCategoryValue" column="category_value_id" />
62-
</set>
63+
</list>
6364
<many-to-one name="unitOfMeasure" column="unit_of_measure_id" class="org.digijava.module.categorymanager.dbentity.AmpCategoryValue" cascade="none" />
6465
<property name="calculationMethod" column="calculation_method" type="java.lang.String" />
6566
<set name="responsibleOrganizations" table="AMP_INDICATOR_ORGANIZATION" lazy="true" cascade="none">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<tns:patch closeOnSuccess="true" retryOnFail="true"
3+
xmlns:tns="http://docs.ampdev.net/schemas/xmlpatcher" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://docs.ampdev.net/schemas/xmlpatcher ../doc/xmlpatcher.xsd ">
5+
<jira>AMP-31091</jira>
6+
<author>bmokandu</author>
7+
<description>Add order_index column to AMP_INDICATOR_DISAGGREGATION table to preserve user-selected disaggregation order. Existing rows get order_index assigned based on category_value_id order.</description>
8+
<apply>
9+
<script>
10+
<lang delimiter=";" type="postgres"><![CDATA[
11+
12+
ALTER TABLE AMP_INDICATOR_DISAGGREGATION
13+
ADD COLUMN IF NOT EXISTS order_index INTEGER;
14+
15+
UPDATE AMP_INDICATOR_DISAGGREGATION aid
16+
SET order_index = sub.rn
17+
FROM (
18+
SELECT indicator_id, category_value_id,
19+
ROW_NUMBER() OVER (PARTITION BY indicator_id ORDER BY category_value_id) - 1 AS rn
20+
FROM AMP_INDICATOR_DISAGGREGATION
21+
) sub
22+
WHERE aid.indicator_id = sub.indicator_id
23+
AND aid.category_value_id = sub.category_value_id
24+
AND aid.order_index IS NULL
25+
26+
]]></lang>
27+
</script>
28+
</apply>
29+
</tns:patch>

0 commit comments

Comments
 (0)