Skip to content

Commit d198be3

Browse files
committed
♻️ Alias using references to avoid 'magic-strings'
1 parent ebbacae commit d198be3

1 file changed

Lines changed: 45 additions & 17 deletions

File tree

sormas-backend/src/main/java/de/symeda/sormas/backend/patch/alias/PathAliasHelper.java

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,29 @@
1212
import javax.enterprise.context.ApplicationScoped;
1313
import javax.validation.constraints.NotNull;
1414

15+
import de.symeda.sormas.api.epidata.EpiDataDto;
1516
import org.apache.commons.collections4.CollectionUtils;
1617
import org.slf4j.Logger;
1718
import org.slf4j.LoggerFactory;
1819

1920
import de.symeda.sormas.api.caze.CaseDataDto;
21+
import de.symeda.sormas.api.clinicalcourse.HealthConditionsDto;
22+
import de.symeda.sormas.api.exposure.ExposureDto;
23+
import de.symeda.sormas.api.hospitalization.HospitalizationDto;
24+
import de.symeda.sormas.api.hospitalization.PreviousHospitalizationDto;
25+
import de.symeda.sormas.api.infrastructure.community.CommunityDto;
26+
import de.symeda.sormas.api.infrastructure.continent.ContinentDto;
27+
import de.symeda.sormas.api.infrastructure.country.CountryDto;
28+
import de.symeda.sormas.api.infrastructure.district.DistrictDto;
29+
import de.symeda.sormas.api.infrastructure.facility.FacilityDto;
30+
import de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto;
31+
import de.symeda.sormas.api.infrastructure.region.RegionDto;
32+
import de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentDto;
33+
import de.symeda.sormas.api.location.LocationDto;
34+
import de.symeda.sormas.api.person.PersonContactDetailDto;
2035
import de.symeda.sormas.api.person.PersonDto;
36+
import de.symeda.sormas.api.symptoms.SymptomsDto;
37+
import de.symeda.sormas.api.user.UserDto;
2138
import de.symeda.sormas.api.utils.Tuple;
2239
import de.symeda.sormas.backend.patch.PathFailureCause;
2340

@@ -37,32 +54,43 @@ public class PathAliasHelper {
3754
/**
3855
* Can be used as OUT: for displaying purposes but not for in.
3956
*/
40-
public static final Map<String, Set<String>> DEFAULT_FORBIDDEN_ALIASES_DICTIONARY =
41-
Map.of("Location", Set.of("Person.address", "Exposure.location"));
57+
public static final Map<String, Set<String>> DEFAULT_FORBIDDEN_ALIASES_DICTIONARY = Map.of(
58+
"Location",
59+
Set.of(toFieldName(PersonDto.I18N_PREFIX, PersonDto.ADDRESS), toFieldName(ExposureDto.I18N_PREFIX, ExposureDto.LOCATION)));
4260

43-
public static final Map<String, String> REFERENCE_TO_ROOT_DICTIONARY = Map.of("CaseData.person", PersonDto.I18N_PREFIX);
61+
public static final Map<String, String> REFERENCE_TO_ROOT_DICTIONARY = Map.of(
62+
toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.PERSON),
63+
PersonDto.I18N_PREFIX,
64+
toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.EPI_DATA),
65+
EpiDataDto.I18N_PREFIX);
4466

4567
private static @NotNull HashMap<String, String> buildDefaultAliasDictionary() {
4668
HashMap<String, String> dictionary = new HashMap<>();
4769

48-
dictionary.put("Symptoms", "CaseData.symptoms");
49-
dictionary.put("HealthConditions", "CaseData.healthConditions");
50-
dictionary.put("Hospitalization", "CaseData.hospitalization");
51-
dictionary.put("PreviousHospitalization", "CaseData.hospitalization.previousHospitalizations");
52-
dictionary.put("PersonContactDetail", "Person.personContactDetails");
53-
dictionary.put("Facility", "CaseData.healthFacility");
54-
dictionary.put("PointOfEntry", "CaseData.pointOfEntry");
55-
dictionary.put("Region", "CaseData.responsibleRegion");
56-
dictionary.put("District", "CaseData.responsibleDistrict");
57-
dictionary.put("Community", "CaseData.responsibleCommunity");
58-
dictionary.put("Country", "Person.birthCountry");
59-
dictionary.put("Subcontinent", "Person.address.subcontinent");
60-
dictionary.put("Continent", "Person.address.continent");
61-
dictionary.put("User", "CaseData.followUpStatusChangeUser");
70+
dictionary.put(SymptomsDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.SYMPTOMS));
71+
dictionary.put(HealthConditionsDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.HEALTH_CONDITIONS));
72+
dictionary.put(HospitalizationDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.HOSPITALIZATION));
73+
dictionary.put(
74+
PreviousHospitalizationDto.I18N_PREFIX,
75+
toFieldName(toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.HOSPITALIZATION), HospitalizationDto.PREVIOUS_HOSPITALIZATIONS));
76+
dictionary.put(PersonContactDetailDto.I18N_PREFIX, toFieldName(PersonDto.I18N_PREFIX, PersonDto.PERSON_CONTACT_DETAILS));
77+
dictionary.put(FacilityDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.HEALTH_FACILITY));
78+
dictionary.put(PointOfEntryDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.POINT_OF_ENTRY));
79+
dictionary.put(RegionDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.RESPONSIBLE_REGION));
80+
dictionary.put(DistrictDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.RESPONSIBLE_DISTRICT));
81+
dictionary.put(CommunityDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.RESPONSIBLE_COMMUNITY));
82+
dictionary.put(CountryDto.I18N_PREFIX, toFieldName(PersonDto.I18N_PREFIX, PersonDto.BIRTH_COUNTRY));
83+
dictionary.put(SubcontinentDto.I18N_PREFIX, toFieldName(toFieldName(PersonDto.I18N_PREFIX, PersonDto.ADDRESS), LocationDto.SUB_CONTINENT));
84+
dictionary.put(ContinentDto.I18N_PREFIX, toFieldName(toFieldName(PersonDto.I18N_PREFIX, PersonDto.ADDRESS), LocationDto.CONTINENT));
85+
dictionary.put(UserDto.I18N_PREFIX, toFieldName(CaseDataDto.I18N_PREFIX, CaseDataDto.FOLLOW_UP_STATUS_CHANGE_USER));
6286

6387
return dictionary;
6488
}
6589

90+
private static String toFieldName(String prefix, String fieldName) {
91+
return prefix + '.' + fieldName;
92+
}
93+
6694
@NotNull
6795
public Tuple<String, PathFailureCause> resolveAlias(String pathWithPotentialAlias) {
6896
int firstPathSeparatorIndex = pathWithPotentialAlias.indexOf(PATH_SEPARATOR);

0 commit comments

Comments
 (0)