1818import java .util .Map ;
1919
2020import com .vaadin .ui .Button ;
21+ import com .vaadin .ui .CheckBox ;
2122import com .vaadin .ui .FormLayout ;
2223import com .vaadin .ui .HorizontalLayout ;
2324import com .vaadin .ui .Label ;
4041import de .symeda .sormas .api .patch .partial_retrieval .DisplayablePartialRetrievalResponse ;
4142import de .symeda .sormas .ui .utils .ButtonHelper ;
4243import de .symeda .sormas .ui .utils .CssStyles ;
44+ import de .symeda .sormas .ui .utils .VaadinUiUtil ;
4345
4446/**
4547 * Modal editor window allowing users to correct failed survey response fields and reprocess.
48+ * Each failed field can be ignored (excluded from reprocessing) or have its key renamed.
4649 */
4750public class SurveyResponseFailureEditor extends Window {
4851
@@ -76,7 +79,9 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
7679 FormLayout failuresForm = new FormLayout ();
7780 failuresForm .setMargin (false );
7881
79- Map <String , TextField > fieldEditors = new HashMap <>();
82+ Map <String , CheckBox > ignoreCheckboxes = new HashMap <>();
83+ Map <String , TextField > keyEditors = new HashMap <>();
84+ Map <String , TextField > valueEditors = new HashMap <>();
8085
8186 for (Map .Entry <String , DataPatchFailure > entry : failures .entrySet ()) {
8287 String fieldPath = entry .getKey ();
@@ -91,6 +96,11 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
9196 fieldContainer .setMargin (false );
9297 fieldContainer .setSpacing (false );
9398
99+ // Ignore checkbox
100+ CheckBox ignoreCheckbox = new CheckBox (I18nProperties .getCaption (Captions .surveyResponseIgnoreField ));
101+ ignoreCheckboxes .put (fieldPath , ignoreCheckbox );
102+ fieldContainer .addComponent (ignoreCheckbox );
103+
94104 Label causeLabel = new Label (I18nProperties .getCaption (Captions .surveyResponseFailureCause ) + ": " + causeName );
95105 CssStyles .style (causeLabel , CssStyles .LABEL_SMALL , CssStyles .LABEL_SECONDARY );
96106 fieldContainer .addComponent (causeLabel );
@@ -100,14 +110,28 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
100110 CssStyles .style (currentValueLabel , CssStyles .LABEL_SMALL , CssStyles .LABEL_SECONDARY );
101111 fieldContainer .addComponent (currentValueLabel );
102112
103- TextField valueField = new TextField ();
104- valueField .setCaption (fieldLabel );
113+ // Key rename field
114+ TextField keyField = new TextField (I18nProperties .getCaption (Captions .surveyResponseKeyName ));
115+ keyField .setValue (fieldPath );
116+ keyField .setWidth (100 , Unit .PERCENTAGE );
117+ keyEditors .put (fieldPath , keyField );
118+ fieldContainer .addComponent (keyField );
119+
120+ // Value field
121+ TextField valueField = new TextField (fieldLabel );
105122 valueField .setWidth (100 , Unit .PERCENTAGE );
106123 if (failure .getProvidedFieldValue () != null ) {
107124 valueField .setValue (failure .getProvidedFieldValue ().toString ());
108125 }
126+ valueEditors .put (fieldPath , valueField );
109127 fieldContainer .addComponent (valueField );
110- fieldEditors .put (fieldPath , valueField );
128+
129+ // Wire ignore checkbox to disable key/value fields
130+ ignoreCheckbox .addValueChangeListener (event -> {
131+ boolean ignored = Boolean .TRUE .equals (event .getValue ());
132+ keyField .setEnabled (!ignored );
133+ valueField .setEnabled (!ignored );
134+ });
111135
112136 failuresForm .addComponent (fieldContainer );
113137 }
@@ -124,10 +148,12 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
124148 FormLayout validForm = new FormLayout ();
125149 validForm .setMargin (true );
126150
127- for (Map .Entry <String , Object > entry : validValues .entrySet ()) {
128- String fieldPath = entry .getKey ();
151+ VaadinUiUtil .showWarningPopup (String .format ("validValues: [%s]" , validValues ));
152+
153+ for (Map .Entry <String , Object > validEntry : validValues .entrySet ()) {
154+ String fieldPath = validEntry .getKey ();
129155 String fieldLabel = resolveFieldName (fieldPath , displayData );
130- Label label = new Label (entry .getValue () != null ? entry .getValue ().toString () : "" );
156+ Label label = new Label (validEntry .getValue () != null ? validEntry .getValue ().toString () : "" );
131157 label .setCaption (fieldLabel );
132158 validForm .addComponent (label );
133159 }
@@ -144,9 +170,16 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
144170 Button saveAndReprocessButton =
145171 ButtonHelper .createButton (Captions .actionSaveAndReprocess , I18nProperties .getCaption (Captions .actionSaveAndReprocess ), e -> {
146172 Map <String , Object > correctedDictionary = new HashMap <>(validValues );
147- for (Map .Entry <String , TextField > editorEntry : fieldEditors .entrySet ()) {
148- String value = editorEntry .getValue ().getValue ();
149- correctedDictionary .put (editorEntry .getKey (), value );
173+ for (String fieldPath : valueEditors .keySet ()) {
174+ CheckBox ignoreCheckbox = ignoreCheckboxes .get (fieldPath );
175+ if (ignoreCheckbox != null && Boolean .TRUE .equals (ignoreCheckbox .getValue ())) {
176+ continue ;
177+ }
178+ String key = keyEditors .get (fieldPath ).getValue ();
179+ if (key == null || key .trim ().isEmpty ()) {
180+ key = fieldPath ;
181+ }
182+ correctedDictionary .put (key , valueEditors .get (fieldPath ).getValue ());
150183 }
151184
152185 FacadeProvider .getExternalMessageFacade ().reprocessSurveyResponse (externalMessage .getUuid (), correctedDictionary );
0 commit comments