11package de .symeda .sormas .backend .patch ;
22
33import java .util .Arrays ;
4+ import java .util .Optional ;
45import java .util .Set ;
56import java .util .stream .Collectors ;
67import java .util .stream .Stream ;
78
89import javax .annotation .Nullable ;
10+ import javax .ejb .EJB ;
911import javax .enterprise .context .ApplicationScoped ;
1012import javax .inject .Inject ;
1113import javax .validation .constraints .NotNull ;
1214
1315import org .slf4j .Logger ;
1416import org .slf4j .LoggerFactory ;
1517
18+ import de .symeda .sormas .api .systemconfiguration .SystemConfigurationValueFacade ;
1619import de .symeda .sormas .api .utils .Tuple ;
1720import de .symeda .sormas .backend .patch .alias .PathAliasHelper ;
1821
@@ -30,13 +33,17 @@ public class PatchFieldHelper {
3033 private static final String CLOSING_PARENTHESIS = ")" ;
3134 private static final String PIPE = "|" ;
3235
33- // might be more subtle: person.toto but also *.uuid (or uuid). includes approach ?
34- // TODO: must be twofold: enforced default fields : technical: uuid, user ... + custom config by admin
35- private Set <String > forbiddenFields = Set .of ("Person.birthdate" , "Person.birthdateDD" , "Person.birthdateMM" , "Person.birthdateYYYY" );
36+ public static final String PATCH_FORBIDDEN_FIELDS_CONFIG_KEY = "PATCH_FORBIDDEN_FIELDS" ;
37+
38+ private static final Set <String > DEFAULT_FORBIDDEN_FIELDS =
39+ Set .of ("Person.birthdate" , "Person.birthdateDD" , "Person.birthdateMM" , "Person.birthdateYYYY" );
3640
3741 @ Inject
3842 private PathAliasHelper pathAliasHelper ;
3943
44+ @ EJB
45+ private SystemConfigurationValueFacade systemConfigurationValueFacade ;
46+
4047 public PatchFieldHelper () {
4148 }
4249
@@ -78,7 +85,6 @@ public PathFailureCause checkIfPathIsInvalid(String path) {
7885 private PathFailureCause checkIfPathIsInvalidImpl (String path , Set <String > additionalSupportedPrefixes ) {
7986 PathFailureCause dataPatchFailureCause = null ;
8087
81- // TODO: check it would be required to distinguish read / write: per example Immunization can be read and write but write does not reach this code.
8288 if (!path .contains (PATH_SEPARATOR )) {
8389 dataPatchFailureCause = PathFailureCause .INVALID_PATH_FORMAT ;
8490 } else if (!(startsWithAllowedPrefix (path ) || pathStartsWithAllowedPrefix (path , additionalSupportedPrefixes ))) {
@@ -97,7 +103,18 @@ public Tuple<String, PathFailureCause> resolveAlias(String pathWithPotentialAlia
97103 }
98104
99105 private boolean fieldIsForbidden (String path ) {
100- return forbiddenFields .contains (path );
106+ Set <String > configured = resolveConfiguredForbiddenFields ();
107+ return configured .contains (path );
108+ }
109+
110+ private Set <String > resolveConfiguredForbiddenFields () {
111+ String configValue = systemConfigurationValueFacade != null
112+ ? systemConfigurationValueFacade .getValue (PATCH_FORBIDDEN_FIELDS_CONFIG_KEY )
113+ : null ;
114+ return Optional .ofNullable (configValue )
115+ .filter (v -> !v .isBlank ())
116+ .map (v -> Arrays .stream (v .split ("," )).map (String ::trim ).filter (s -> !s .isEmpty ()).collect (Collectors .toSet ()))
117+ .orElse (DEFAULT_FORBIDDEN_FIELDS );
101118 }
102119
103120 private boolean startsWithAllowedPrefix (String path ) {
0 commit comments