Fix issue where partially-filled KeyValue fields weren't saved during a tab switch
This commit is contained in:
parent
2e6e1c147c
commit
9515782650
6 changed files with 35 additions and 30 deletions
|
@ -539,8 +539,7 @@ public class DashboardController implements Initializable {
|
|||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : paramsControllers)
|
||||
if (!controller.isKeyFieldEmpty() && !controller.isValueFieldEmpty())
|
||||
states.add(controller.getState());
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
|
|
|
@ -198,28 +198,26 @@ public class FormDataTabController implements Initializable {
|
|||
|
||||
|
||||
/**
|
||||
* @return List of the states of all the non-empty string fields in the Form data tab.
|
||||
* @return List of the states of all the string fields in the Form data tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getStringFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : stringControllers)
|
||||
if (!controller.isKeyFieldEmpty() && !controller.isValueFieldEmpty())
|
||||
states.add(controller.getState());
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return List of the states of all the non-empty file fields in the Form data tab.
|
||||
* @return List of the states of all the file fields in the Form data tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getFileFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (FileKeyValueFieldController controller : fileControllers)
|
||||
if (!controller.isFileKeyFieldEmpty() && !controller.isFileValueFieldEmpty())
|
||||
states.add(controller.getState());
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
|
|
|
@ -123,14 +123,13 @@ public class HeaderTabController implements Initializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a list of the state of all the non-empty fields in the Headers tab.
|
||||
* Return a list of the state of all the fields in the Headers tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : controllers)
|
||||
if (!controller.isKeyFieldEmpty() && !controller.isValueFieldEmpty())
|
||||
states.add(controller.getState());
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
|
|
|
@ -130,8 +130,7 @@ public class URLTabController implements Initializable {
|
|||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : controllers)
|
||||
if (!controller.isKeyFieldEmpty() && !controller.isValueFieldEmpty())
|
||||
states.add(controller.getState());
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.rohitawate.everest.controllers.state;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -48,4 +50,9 @@ public class FieldState {
|
|||
Objects.equals(key, that.key) &&
|
||||
Objects.equals(value, that.value);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isEmpty() {
|
||||
return key.isEmpty() && value.isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -338,7 +338,7 @@ public class HistoryManager {
|
|||
return false;
|
||||
|
||||
for (FieldState state : secondList) {
|
||||
if (!firstList.contains(state))
|
||||
if (!state.isEmpty() && state.checked && !firstList.contains(state))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -373,12 +373,14 @@ public class HistoryManager {
|
|||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveHeader").toString()));
|
||||
|
||||
for (FieldState fieldState : state.headers) {
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, fieldState.key);
|
||||
statement.setString(3, fieldState.value);
|
||||
statement.setInt(4, fieldState.checked ? 1 : 0);
|
||||
if (!fieldState.isEmpty() && fieldState.checked) {
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, fieldState.key);
|
||||
statement.setString(3, fieldState.value);
|
||||
statement.setInt(4, fieldState.checked ? 1 : 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -423,18 +425,19 @@ public class HistoryManager {
|
|||
private void saveTuple(ArrayList<FieldState> tuples, String tupleType, int requestID) {
|
||||
if (tuples.size() > 0) {
|
||||
for (FieldState fieldState : tuples) {
|
||||
// Saves the string tuples
|
||||
try {
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, tupleType);
|
||||
statement.setString(3, fieldState.key);
|
||||
statement.setString(4, fieldState.value);
|
||||
statement.setInt(5, fieldState.checked ? 1 : 0);
|
||||
if (!fieldState.isEmpty() && fieldState.checked) {
|
||||
try {
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, tupleType);
|
||||
statement.setString(3, fieldState.key);
|
||||
statement.setString(4, fieldState.value);
|
||||
statement.setInt(5, fieldState.checked ? 1 : 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue