Skip to content

Commit 9906f0c

Browse files
authored
Merge pull request #13849 from utafrali/fix/issue-13848-invalid-disease-list-in-sormas-data-dict
Fix disease list generation to respect hide flag in @diseases
2 parents bde5f20 + 33b9906 commit 9906f0c

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

sormas-backend/src/main/java/de/symeda/sormas/backend/info/EntityColumns.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,15 @@ private String getDiseases(FieldData fieldData) {
215215
if (diseases == null) {
216216
return "All";
217217
} else {
218+
List<Disease> diseaseList;
219+
if (diseases.hide()) {
220+
List<Disease> hiddenDiseases = Arrays.asList(diseases.value());
221+
diseaseList = Arrays.stream(Disease.values()).filter(d -> !hiddenDiseases.contains(d)).collect(Collectors.toList());
222+
} else {
223+
diseaseList = Arrays.asList(diseases.value());
224+
}
218225
StringBuilder diseasesString = new StringBuilder();
219-
for (Disease disease : diseases.value()) {
226+
for (Disease disease : diseaseList) {
220227
if (diseasesString.length() > 0)
221228
diseasesString.append(", ");
222229
diseasesString.append(disease.toShortString());
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
3+
* Copyright © 2016-2022 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
*/
15+
16+
package de.symeda.sormas.backend.info;
17+
18+
import static org.hamcrest.MatcherAssert.assertThat;
19+
import static org.hamcrest.Matchers.containsString;
20+
import static org.hamcrest.Matchers.is;
21+
import static org.hamcrest.Matchers.not;
22+
23+
import java.lang.reflect.Field;
24+
import java.lang.reflect.Method;
25+
26+
import org.junit.jupiter.api.Test;
27+
28+
import de.symeda.sormas.api.Disease;
29+
import de.symeda.sormas.api.utils.Diseases;
30+
31+
public class EntityColumnsTest {
32+
33+
private static class TestDto {
34+
35+
@Diseases(value = {
36+
Disease.GIARDIASIS,
37+
Disease.CRYPTOSPORIDIOSIS }, hide = true)
38+
private String fieldWithHide;
39+
40+
@Diseases({
41+
Disease.EVD,
42+
Disease.DENGUE })
43+
private String fieldWithoutHide;
44+
45+
private String fieldWithoutAnnotation;
46+
}
47+
48+
private String invokeGetDiseases(String fieldName) throws Exception {
49+
EntityColumns entityColumns = new EntityColumns(null, false);
50+
Field field = TestDto.class.getDeclaredField(fieldName);
51+
FieldData fieldData = new FieldData(field, TestDto.class, "Test");
52+
Method getDiseases = EntityColumns.class.getDeclaredMethod("getDiseases", FieldData.class);
53+
getDiseases.setAccessible(true);
54+
return (String) getDiseases.invoke(entityColumns, fieldData);
55+
}
56+
57+
@Test
58+
public void testGetDiseases_noAnnotation_returnsAll() throws Exception {
59+
assertThat(invokeGetDiseases("fieldWithoutAnnotation"), is("All"));
60+
}
61+
62+
@Test
63+
public void testGetDiseases_withHideFalse_returnsListedDiseases() throws Exception {
64+
String result = invokeGetDiseases("fieldWithoutHide");
65+
assertThat(result, containsString(Disease.EVD.toShortString()));
66+
assertThat(result, containsString(Disease.DENGUE.toShortString()));
67+
assertThat(result, not(containsString(Disease.GIARDIASIS.toShortString())));
68+
}
69+
70+
@Test
71+
public void testGetDiseases_withHideTrue_returnsAllDiseasesExceptListed() throws Exception {
72+
String result = invokeGetDiseases("fieldWithHide");
73+
assertThat(result, not(containsString(Disease.GIARDIASIS.toShortString())));
74+
assertThat(result, not(containsString(Disease.CRYPTOSPORIDIOSIS.toShortString())));
75+
assertThat(result, containsString(Disease.EVD.toShortString()));
76+
assertThat(result, containsString(Disease.DENGUE.toShortString()));
77+
}
78+
}

0 commit comments

Comments
 (0)