State maintenance logic now retains selection status of KeyValue fields
This commit is contained in:
parent
6e7606c99a
commit
51cbce3d7a
13 changed files with 299 additions and 149 deletions
|
@ -18,6 +18,8 @@ package com.rohitawate.everest.controllers;
|
|||
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea;
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea.HighlightMode;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import com.rohitawate.everest.misc.ThemeManager;
|
||||
import javafx.fxml.FXML;
|
||||
|
@ -36,7 +38,6 @@ import javax.ws.rs.core.MediaType;
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/*
|
||||
|
@ -123,9 +124,9 @@ public class BodyTabController implements Initializable {
|
|||
|
||||
state.rawBodyType = rawInputTypeBox.getValue();
|
||||
state.rawBody = rawInputArea.getText();
|
||||
state.urlStringTuples = urlTabController.getStringTuples(false);
|
||||
state.formStringTuples = formDataTabController.getStringTuples(false);
|
||||
state.formFileTuples = formDataTabController.getFileTuples(false);
|
||||
state.urlStringTuples = urlTabController.getFieldStates();
|
||||
state.formStringTuples = formDataTabController.getStringFieldStates();
|
||||
state.formFileTuples = formDataTabController.getFileFieldStates();
|
||||
state.binaryFilePath = filePathField.getText();
|
||||
|
||||
if (rawTab.isSelected()) {
|
||||
|
@ -156,18 +157,18 @@ public class BodyTabController implements Initializable {
|
|||
public void setState(DashboardState state) {
|
||||
// Adding URL tab's tuples
|
||||
if (state.urlStringTuples != null)
|
||||
for (Entry<String, String> entry : state.urlStringTuples.entrySet())
|
||||
urlTabController.addField(entry.getKey(), entry.getValue());
|
||||
for (FieldState fieldState : state.urlStringTuples)
|
||||
urlTabController.addField(fieldState);
|
||||
|
||||
// Adding Form tab's string tuples
|
||||
if (state.formStringTuples != null)
|
||||
for (Entry<String, String> entry : state.formStringTuples.entrySet())
|
||||
formDataTabController.addStringField(entry.getKey(), entry.getValue());
|
||||
for (FieldState fieldState : state.formStringTuples)
|
||||
formDataTabController.addStringField(fieldState);
|
||||
|
||||
// Adding Form tab's file tuples
|
||||
if (state.formFileTuples != null)
|
||||
for (Entry<String, String> entry : state.formFileTuples.entrySet())
|
||||
formDataTabController.addFileField(entry.getKey(), entry.getValue());
|
||||
for (FieldState fieldState : state.formFileTuples)
|
||||
formDataTabController.addFileField(fieldState);
|
||||
|
||||
setRawTab(state);
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ import com.jfoenix.controls.JFXProgressBar;
|
|||
import com.jfoenix.controls.JFXSnackbar;
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea;
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea.HighlightMode;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.exceptions.RedirectException;
|
||||
import com.rohitawate.everest.exceptions.UnreliableResponseException;
|
||||
import com.rohitawate.everest.misc.EverestUtilities;
|
||||
|
@ -58,7 +60,6 @@ import java.time.LocalDateTime;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class DashboardController implements Initializable {
|
||||
|
@ -483,21 +484,33 @@ public class DashboardController implements Initializable {
|
|||
return params;
|
||||
}
|
||||
|
||||
private void addParamField() {
|
||||
addParamField("", "", null);
|
||||
/**
|
||||
* Return an ArrayList of the state of all the fields in the Params tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getParamFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : paramsControllers)
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
private void addParamField(String key, String value) {
|
||||
addParamField(key, value, null);
|
||||
private void addParamField() {
|
||||
addParamField("", "", null, false);
|
||||
}
|
||||
|
||||
private void addParamField(FieldState state) {
|
||||
addParamField(state.key, state.value, null, state.checked);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addParamField(ActionEvent event) {
|
||||
addParamField("", "", event);
|
||||
addParamField("", "", event, false);
|
||||
}
|
||||
|
||||
// Adds a new URL-parameter field
|
||||
private void addParamField(String key, String value, ActionEvent event) {
|
||||
private void addParamField(String key, String value, ActionEvent event, boolean checked) {
|
||||
/*
|
||||
Re-uses previous field if it is empty,
|
||||
else loads a new one.
|
||||
|
@ -519,6 +532,7 @@ public class DashboardController implements Initializable {
|
|||
StringKeyValueFieldController controller = loader.getController();
|
||||
controller.setKeyField(key);
|
||||
controller.setValueField(value);
|
||||
controller.setChecked(checked);
|
||||
paramsControllers.add(controller);
|
||||
paramsCountProperty.set(paramsCountProperty.get() + 1);
|
||||
controller.deleteButton.visibleProperty().bind(Bindings.greaterThan(paramsCountProperty, 1));
|
||||
|
@ -553,8 +567,8 @@ public class DashboardController implements Initializable {
|
|||
|
||||
dashboardState.target = addressField.getText();
|
||||
dashboardState.httpMethod = httpMethodBox.getValue();
|
||||
dashboardState.headers = headerTabController.getHeaders(false);
|
||||
dashboardState.params = getParams(false);
|
||||
dashboardState.headers = headerTabController.getFieldStates();
|
||||
dashboardState.params = getParamFieldStates();
|
||||
|
||||
return dashboardState;
|
||||
}
|
||||
|
@ -582,12 +596,12 @@ public class DashboardController implements Initializable {
|
|||
addressField.setText(state.target);
|
||||
|
||||
if (state.headers != null)
|
||||
for (Entry entry : state.headers.entrySet())
|
||||
headerTabController.addHeader(entry.getKey().toString(), entry.getValue().toString());
|
||||
for (FieldState fieldState : state.headers)
|
||||
headerTabController.addHeader(fieldState);
|
||||
|
||||
if (state.params != null)
|
||||
for (Entry entry : state.params.entrySet())
|
||||
addParamField(entry.getKey().toString(), entry.getValue().toString());
|
||||
for (FieldState fieldState : state.params)
|
||||
addParamField(fieldState);
|
||||
|
||||
if (!(httpMethodBox.getValue().equals("GET") || httpMethodBox.getValue().equals("DELETE")))
|
||||
bodyTabController.setState(state);
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.rohitawate.everest.controllers;
|
|||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXCheckBox;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
@ -108,4 +109,12 @@ public class FileKeyValueFieldController implements Initializable {
|
|||
public boolean isFileValueFieldEmpty() {
|
||||
return fileValueField.getText().isEmpty();
|
||||
}
|
||||
|
||||
public FieldState getState() {
|
||||
return new FieldState(fileKeyField.getText(), fileValueField.getText(), checkBox.isSelected());
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
checkBox.setSelected(checked);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.rohitawate.everest.controllers;
|
||||
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import com.rohitawate.everest.misc.ThemeManager;
|
||||
import javafx.beans.binding.Bindings;
|
||||
|
@ -59,21 +60,20 @@ public class FormDataTabController implements Initializable {
|
|||
addStringField();
|
||||
}
|
||||
|
||||
public void addFileField(FieldState state) {
|
||||
addFileField(state.key, state.value, null, state.checked);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addFileField(ActionEvent event) {
|
||||
addFileField("", "", event);
|
||||
addFileField("", "", event, false);
|
||||
}
|
||||
|
||||
private void addFileField() {
|
||||
addFileField("", "", null);
|
||||
addFileField("", "", null, false);
|
||||
}
|
||||
|
||||
public void addFileField(String key, String value) {
|
||||
addFileField(key, value, null);
|
||||
}
|
||||
|
||||
private void addFileField(String key, String value, ActionEvent event) {
|
||||
private void addFileField(String key, String value, ActionEvent event, boolean checked) {
|
||||
//Re-uses previous field if it is empty else loads a new one.
|
||||
if (fileControllers.size() > 0 && event == null) {
|
||||
FileKeyValueFieldController previousController = fileControllers.get(fileControllers.size() - 1);
|
||||
|
@ -93,6 +93,7 @@ public class FormDataTabController implements Initializable {
|
|||
FileKeyValueFieldController controller = loader.getController();
|
||||
controller.setFileKeyField(key);
|
||||
controller.setFileValueField(value);
|
||||
controller.setChecked(checked);
|
||||
fileControllers.add(controller);
|
||||
fileControllersCount.set(fileControllersCount.get() + 1);
|
||||
controller.deleteButton.visibleProperty().bind(Bindings.greaterThan(fileControllersCount, 1));
|
||||
|
@ -107,20 +108,20 @@ public class FormDataTabController implements Initializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void addStringField(FieldState state) {
|
||||
addStringField(state.key, state.value, null, state.checked);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addStringField(ActionEvent event) {
|
||||
addStringField("", "", event);
|
||||
addStringField("", "", event, false);
|
||||
}
|
||||
|
||||
private void addStringField() {
|
||||
addStringField("", "", null);
|
||||
addStringField("", "", null, false);
|
||||
}
|
||||
|
||||
public void addStringField(String key, String value) {
|
||||
addStringField(key, value, null);
|
||||
}
|
||||
|
||||
private void addStringField(String key, String value, ActionEvent event) {
|
||||
private void addStringField(String key, String value, ActionEvent event, boolean checked) {
|
||||
/*
|
||||
Re-uses previous field if it is empty,
|
||||
else loads a new one.
|
||||
|
@ -142,6 +143,7 @@ public class FormDataTabController implements Initializable {
|
|||
StringKeyValueFieldController controller = loader.getController();
|
||||
controller.setKeyField(key);
|
||||
controller.setValueField(value);
|
||||
controller.setChecked(checked);
|
||||
stringControllers.add(controller);
|
||||
stringControllersCount.set(stringControllersCount.get() + 1);
|
||||
controller.deleteButton.visibleProperty().bind(Bindings.greaterThan(stringControllersCount, 1));
|
||||
|
@ -186,4 +188,30 @@ public class FormDataTabController implements Initializable {
|
|||
}
|
||||
return fileMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an ArrayList of the state of all the string fields in the Form data tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getStringFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : stringControllers)
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an ArrayList of the state of all the file fields in the Form data tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getFileFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (FileKeyValueFieldController controller : fileControllers)
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.rohitawate.everest.controllers;
|
||||
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import com.rohitawate.everest.misc.ThemeManager;
|
||||
import javafx.beans.binding.Bindings;
|
||||
|
@ -52,20 +53,20 @@ public class HeaderTabController implements Initializable {
|
|||
addHeader();
|
||||
}
|
||||
|
||||
public void addHeader(String key, String value) {
|
||||
addHeader(key, value, null);
|
||||
public void addHeader(FieldState state) {
|
||||
addHeader(state.key, state.value, null, state.checked);
|
||||
}
|
||||
|
||||
private void addHeader() {
|
||||
addHeader("", "", null);
|
||||
addHeader("", "", null, false);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addHeader(ActionEvent event) {
|
||||
addHeader("", "", event);
|
||||
addHeader("", "", event, false);
|
||||
}
|
||||
|
||||
private void addHeader(String key, String value, ActionEvent event) {
|
||||
private void addHeader(String key, String value, ActionEvent event, boolean checked) {
|
||||
/*
|
||||
Re-uses previous field if it is empty,
|
||||
else loads a new one.
|
||||
|
@ -88,6 +89,7 @@ public class HeaderTabController implements Initializable {
|
|||
StringKeyValueFieldController controller = loader.getController();
|
||||
controller.setKeyField(key);
|
||||
controller.setValueField(value);
|
||||
controller.setChecked(checked);
|
||||
controllers.add(controller);
|
||||
controllersCount.set(controllersCount.get() + 1);
|
||||
controller.deleteButton.visibleProperty().bind(Bindings.greaterThan(controllersCount, 1));
|
||||
|
@ -118,6 +120,19 @@ public class HeaderTabController implements Initializable {
|
|||
|
||||
headers.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an ArrayList of the state of all the fields in the Headers tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : controllers)
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.rohitawate.everest.controllers;
|
||||
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
@ -26,7 +28,6 @@ import javax.ws.rs.core.MediaType;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class HistoryItemController implements Initializable {
|
||||
|
@ -35,35 +36,21 @@ public class HistoryItemController implements Initializable {
|
|||
@FXML
|
||||
private Tooltip tooltip;
|
||||
|
||||
private DashboardState dashboardState;
|
||||
|
||||
public void setRequestType(String requestType) {
|
||||
this.requestType.setText(requestType);
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address.setText(address);
|
||||
}
|
||||
|
||||
public String getRequestType() {
|
||||
return requestType.getText();
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address.getText();
|
||||
}
|
||||
private DashboardState state;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
tooltip.textProperty().bind(address.textProperty());
|
||||
}
|
||||
|
||||
public DashboardState getDashboardState() {
|
||||
return dashboardState;
|
||||
public DashboardState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setDashboardState(DashboardState dashboardState) {
|
||||
this.dashboardState = dashboardState;
|
||||
public void setState(DashboardState state) {
|
||||
this.state = state;
|
||||
this.requestType.setText(state.httpMethod);
|
||||
this.address.setText(state.target);
|
||||
}
|
||||
|
||||
public int getRelativityIndex(String searchString) {
|
||||
|
@ -71,12 +58,12 @@ public class HistoryItemController implements Initializable {
|
|||
String comparisonString;
|
||||
|
||||
// Checks if matches with target
|
||||
comparisonString = dashboardState.target.toLowerCase();
|
||||
comparisonString = state.target.toLowerCase();
|
||||
if (comparisonString.contains(searchString))
|
||||
return 10;
|
||||
|
||||
try {
|
||||
URL url = new URL(dashboardState.target);
|
||||
URL url = new URL(state.target);
|
||||
|
||||
// Checks if matches with target's hostname
|
||||
comparisonString = url.getHost().toLowerCase();
|
||||
|
@ -92,55 +79,55 @@ public class HistoryItemController implements Initializable {
|
|||
}
|
||||
|
||||
// Checks if matches with HTTP method
|
||||
comparisonString = dashboardState.httpMethod.toLowerCase();
|
||||
comparisonString = state.httpMethod.toLowerCase();
|
||||
if (comparisonString.contains(searchString))
|
||||
return 7;
|
||||
|
||||
// Checks for a match in the params
|
||||
for (Map.Entry param : dashboardState.params.entrySet()) {
|
||||
if (param.getKey().toString().toLowerCase().contains(searchString) ||
|
||||
param.getKey().toString().toLowerCase().contains(searchString))
|
||||
for (FieldState state : state.params) {
|
||||
if (state.key.toLowerCase().contains(searchString) ||
|
||||
state.value.toLowerCase().contains(searchString))
|
||||
return 5;
|
||||
}
|
||||
|
||||
// Checks for a match in the headers
|
||||
for (Map.Entry header : dashboardState.headers.entrySet()) {
|
||||
if (header.getKey().toString().toLowerCase().contains(searchString) ||
|
||||
header.getValue().toString().toLowerCase().contains(searchString))
|
||||
for (FieldState state : state.headers) {
|
||||
if (state.key.toLowerCase().contains(searchString) ||
|
||||
state.value.toLowerCase().contains(searchString))
|
||||
return 6;
|
||||
}
|
||||
|
||||
if (dashboardState.httpMethod.equals("POST") || dashboardState.httpMethod.equals("PUT")) {
|
||||
switch (dashboardState.contentType) {
|
||||
if (state.httpMethod.equals("POST") || state.httpMethod.equals("PUT")) {
|
||||
switch (state.contentType) {
|
||||
case MediaType.TEXT_PLAIN:
|
||||
case MediaType.APPLICATION_JSON:
|
||||
case MediaType.APPLICATION_XML:
|
||||
case MediaType.TEXT_HTML:
|
||||
case MediaType.APPLICATION_OCTET_STREAM:
|
||||
// Checks for match in rawBody of the request
|
||||
comparisonString = dashboardState.rawBody.toLowerCase();
|
||||
comparisonString = state.rawBody.toLowerCase();
|
||||
if (comparisonString.contains(searchString))
|
||||
return 8;
|
||||
break;
|
||||
case MediaType.APPLICATION_FORM_URLENCODED:
|
||||
// Checks for match in string tuples
|
||||
for (Map.Entry tuple : dashboardState.urlStringTuples.entrySet()) {
|
||||
if (tuple.getKey().toString().toLowerCase().contains(searchString) ||
|
||||
tuple.getValue().toString().toLowerCase().contains(searchString))
|
||||
for (FieldState state : state.urlStringTuples) {
|
||||
if (state.key.toLowerCase().contains(searchString) ||
|
||||
state.value.toLowerCase().contains(searchString))
|
||||
return 8;
|
||||
}
|
||||
break;
|
||||
case MediaType.MULTIPART_FORM_DATA:
|
||||
// Checks for match in string and file tuples
|
||||
for (Map.Entry tuple : dashboardState.formStringTuples.entrySet()) {
|
||||
if (tuple.getKey().toString().toLowerCase().contains(searchString) ||
|
||||
tuple.getValue().toString().toLowerCase().contains(searchString))
|
||||
for (FieldState state : state.formStringTuples) {
|
||||
if (state.key.toLowerCase().contains(searchString) ||
|
||||
state.value.toLowerCase().contains(searchString))
|
||||
return 8;
|
||||
}
|
||||
|
||||
for (Map.Entry tuple : dashboardState.formFileTuples.entrySet()) {
|
||||
if (tuple.getKey().toString().toLowerCase().contains(searchString) ||
|
||||
tuple.getValue().toString().toLowerCase().contains(searchString))
|
||||
for (FieldState state : state.formFileTuples) {
|
||||
if (state.key.toLowerCase().contains(searchString) ||
|
||||
state.value.toLowerCase().contains(searchString))
|
||||
return 8;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.rohitawate.everest.controllers;
|
|||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.misc.EverestUtilities;
|
||||
import com.rohitawate.everest.misc.KeyMap;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
|
@ -94,7 +95,7 @@ public class HomeWindowController implements Initializable {
|
|||
|
||||
if (searchResults.size() != 0) {
|
||||
for (HistoryItemController controller : searchResults) {
|
||||
addSearchItem(controller.getDashboardState());
|
||||
addSearchItem(controller.getState());
|
||||
}
|
||||
} else {
|
||||
searchFailedLayer.setVisible(true);
|
||||
|
@ -307,11 +308,7 @@ public class HomeWindowController implements Initializable {
|
|||
Parent historyItem = loader.load();
|
||||
|
||||
controller = loader.getController();
|
||||
|
||||
controller.setRequestType(state.httpMethod);
|
||||
|
||||
controller.setAddress(state.target);
|
||||
controller.setDashboardState(state);
|
||||
controller.setState(state);
|
||||
|
||||
if (appendToStart)
|
||||
layer.getChildren().add(0, historyItem);
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.rohitawate.everest.controllers;
|
|||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXCheckBox;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
@ -91,4 +92,12 @@ public class StringKeyValueFieldController implements Initializable {
|
|||
public boolean isValueFieldEmpty() {
|
||||
return valueField.getText().isEmpty();
|
||||
}
|
||||
|
||||
public FieldState getState() {
|
||||
return new FieldState(keyField.getText(), valueField.getText(), checkBox.isSelected());
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
checkBox.setSelected(checked);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.rohitawate.everest.controllers;
|
||||
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import com.rohitawate.everest.misc.ThemeManager;
|
||||
import javafx.beans.binding.Bindings;
|
||||
|
@ -51,20 +52,25 @@ public class URLTabController implements Initializable {
|
|||
addField();
|
||||
}
|
||||
|
||||
|
||||
public void addField(FieldState state) {
|
||||
addField(state.key, state.value, null, state.checked);
|
||||
}
|
||||
|
||||
private void addField() {
|
||||
addField("", "", null);
|
||||
addField("", "", null, false);
|
||||
}
|
||||
|
||||
public void addField(String key, String value) {
|
||||
addField(key, value, null);
|
||||
addField(key, value, null, false);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addField(ActionEvent event) {
|
||||
addField("", "", event);
|
||||
addField("", "", event, false);
|
||||
}
|
||||
|
||||
private void addField(String key, String value, ActionEvent event) {
|
||||
private void addField(String key, String value, ActionEvent event, boolean checked) {
|
||||
/*
|
||||
Re-uses previous field if it is empty,
|
||||
else loads a new one.
|
||||
|
@ -115,4 +121,17 @@ public class URLTabController implements Initializable {
|
|||
}
|
||||
return tuples;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an ArrayList of the state of all the fields in the URL-encoded tab.
|
||||
*/
|
||||
public ArrayList<FieldState> getFieldStates() {
|
||||
ArrayList<FieldState> states = new ArrayList<>();
|
||||
|
||||
for (StringKeyValueFieldController controller : controllers)
|
||||
states.add(controller.getState());
|
||||
|
||||
return states;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.rohitawate.everest.controllers;
|
||||
package com.rohitawate.everest.controllers.state;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Convenience class to abstract the state of the application.
|
||||
|
@ -24,13 +24,23 @@ import java.util.HashMap;
|
|||
public class DashboardState {
|
||||
public String target;
|
||||
public String httpMethod;
|
||||
public HashMap<String, String> params;
|
||||
public HashMap<String, String> headers;
|
||||
public ArrayList<FieldState> params;
|
||||
public ArrayList<FieldState> headers;
|
||||
|
||||
// Determined from the active tab within the Body tab
|
||||
public String contentType;
|
||||
|
||||
// Body and content-type of requests with raw bodies
|
||||
public String rawBody;
|
||||
public String rawBodyType;
|
||||
public HashMap<String, String> urlStringTuples;
|
||||
public HashMap<String, String> formStringTuples;
|
||||
public HashMap<String, String> formFileTuples;
|
||||
|
||||
// Tuples of URL-encoded requests
|
||||
public ArrayList<FieldState> urlStringTuples;
|
||||
|
||||
// String and file tuples of multipart-form requests
|
||||
public ArrayList<FieldState> formStringTuples;
|
||||
public ArrayList<FieldState> formFileTuples;
|
||||
|
||||
// File path of application/octet-stream requests
|
||||
public String binaryFilePath;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright 2018 Rohit Awate.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.rohitawate.everest.controllers.state;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Convenience class to represent the state of StringKeyValueFieldController and FileKeyValueField for
|
||||
* application state maintenance logic.
|
||||
*/
|
||||
public class FieldState {
|
||||
public String key;
|
||||
public String value;
|
||||
public boolean checked;
|
||||
|
||||
public FieldState() {
|
||||
this.key = null;
|
||||
this.value = null;
|
||||
this.checked = false;
|
||||
}
|
||||
|
||||
public FieldState(String key, String value, boolean checked) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldState that = (FieldState) o;
|
||||
return checked == that.checked &&
|
||||
Objects.equals(key, that.key) &&
|
||||
Objects.equals(value, that.value);
|
||||
}
|
||||
}
|
|
@ -18,7 +18,8 @@ package com.rohitawate.everest.history;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rohitawate.everest.controllers.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.EverestUtilities;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import com.rohitawate.everest.settings.Settings;
|
||||
|
@ -31,9 +32,7 @@ import java.sql.*;
|
|||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class HistoryManager {
|
||||
private Connection conn;
|
||||
|
@ -178,8 +177,8 @@ public class HistoryManager {
|
|||
return history;
|
||||
}
|
||||
|
||||
private HashMap<String, String> getRequestHeaders(int requestID) {
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
private ArrayList<FieldState> getRequestHeaders(int requestID) {
|
||||
ArrayList<FieldState> headers = new ArrayList<>();
|
||||
|
||||
try {
|
||||
PreparedStatement statement =
|
||||
|
@ -189,10 +188,12 @@ public class HistoryManager {
|
|||
ResultSet RS = statement.executeQuery();
|
||||
|
||||
String key, value;
|
||||
boolean checked;
|
||||
while (RS.next()) {
|
||||
key = RS.getString("Key");
|
||||
value = RS.getString("Value");
|
||||
headers.put(key, value);
|
||||
checked = RS.getBoolean("Checked");
|
||||
headers.add(new FieldState(key, value, checked));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now());
|
||||
|
@ -205,11 +206,11 @@ public class HistoryManager {
|
|||
* @param type Type of tuples needed ('String', 'File' or 'Param')
|
||||
* @return tuples - Map of tuples of corresponding type
|
||||
*/
|
||||
private HashMap<String, String> getTuples(int requestID, String type) {
|
||||
private ArrayList<FieldState> getTuples(int requestID, String type) {
|
||||
if (!(type.equals("String") || type.equals("File") || type.equals("Param")))
|
||||
return null;
|
||||
|
||||
HashMap<String, String> tuples = new HashMap<>();
|
||||
ArrayList<FieldState> tuples = new ArrayList<>();
|
||||
|
||||
try {
|
||||
PreparedStatement statement =
|
||||
|
@ -220,14 +221,17 @@ public class HistoryManager {
|
|||
ResultSet RS = statement.executeQuery();
|
||||
|
||||
String key, value;
|
||||
boolean checked;
|
||||
while (RS.next()) {
|
||||
key = RS.getString("Key");
|
||||
value = RS.getString("Value");
|
||||
tuples.put(key, value);
|
||||
checked = RS.getBoolean("Checked");
|
||||
tuples.add(new FieldState(key, value, checked));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now());
|
||||
}
|
||||
|
||||
return tuples;
|
||||
}
|
||||
|
||||
|
@ -256,16 +260,16 @@ public class HistoryManager {
|
|||
if (lastRequestID == -1)
|
||||
return false;
|
||||
|
||||
HashMap<String, String> map;
|
||||
ArrayList<FieldState> states;
|
||||
|
||||
// Checks for new or modified headers
|
||||
map = getRequestHeaders(lastRequestID);
|
||||
if (!areMapsIdentical(map, newState.headers))
|
||||
states = getRequestHeaders(lastRequestID);
|
||||
if (!areListsEqual(states, newState.headers))
|
||||
return false;
|
||||
|
||||
// Checks for new or modified params
|
||||
map = getTuples(lastRequestID, "Param");
|
||||
if (!areMapsIdentical(map, newState.params))
|
||||
states = getTuples(lastRequestID, "Param");
|
||||
if (!areListsEqual(states, newState.params))
|
||||
return false;
|
||||
|
||||
if (!(newState.httpMethod.equals("GET") || newState.httpMethod.equals("DELETE"))) {
|
||||
|
@ -287,16 +291,16 @@ public class HistoryManager {
|
|||
break;
|
||||
case MediaType.APPLICATION_FORM_URLENCODED:
|
||||
// Checks for new or modified string tuples
|
||||
map = getTuples(lastRequestID, "String");
|
||||
return areMapsIdentical(map, newState.urlStringTuples);
|
||||
states = getTuples(lastRequestID, "String");
|
||||
return areListsEqual(states, newState.urlStringTuples);
|
||||
case MediaType.MULTIPART_FORM_DATA:
|
||||
// Checks for new or modified string tuples
|
||||
map = getTuples(lastRequestID, "String");
|
||||
boolean stringComparison = areMapsIdentical(map, newState.formStringTuples);
|
||||
states = getTuples(lastRequestID, "String");
|
||||
boolean stringComparison = areListsEqual(states, newState.formStringTuples);
|
||||
|
||||
// Checks for new or modified file tuples
|
||||
map = getTuples(lastRequestID, "File");
|
||||
boolean fileComparison = areMapsIdentical(map, newState.formFileTuples);
|
||||
states = getTuples(lastRequestID, "File");
|
||||
boolean fileComparison = areListsEqual(states, newState.formFileTuples);
|
||||
|
||||
return stringComparison && fileComparison;
|
||||
}
|
||||
|
@ -313,19 +317,19 @@ public class HistoryManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean areMapsIdentical(HashMap<String, String> firstMap, HashMap<String, String> secondMap) {
|
||||
if (firstMap == null && secondMap == null)
|
||||
private boolean areListsEqual(ArrayList<FieldState> firstList, ArrayList<FieldState> secondList) {
|
||||
if (firstList == null && secondList == null)
|
||||
return true;
|
||||
|
||||
if ((firstMap == null && secondMap != null) ||
|
||||
(firstMap != null && secondMap == null))
|
||||
if ((firstList == null && secondList != null) ||
|
||||
(firstList != null && secondList == null))
|
||||
return false;
|
||||
|
||||
for (Entry entry : secondMap.entrySet()) {
|
||||
if (!firstMap.containsKey(entry.getKey().toString()) ||
|
||||
!firstMap.get(entry.getKey().toString()).equals(entry.getValue().toString()))
|
||||
for (FieldState state : secondList) {
|
||||
if (!firstList.contains(state))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -355,10 +359,12 @@ public class HistoryManager {
|
|||
if (state.headers.size() > 0) {
|
||||
// Saves request headers
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveHeader").toString()));
|
||||
for (Entry entry : state.headers.entrySet()) {
|
||||
|
||||
for (FieldState fieldState : state.headers) {
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, entry.getKey().toString());
|
||||
statement.setString(3, entry.getValue().toString());
|
||||
statement.setString(2, fieldState.key);
|
||||
statement.setString(3, fieldState.value);
|
||||
statement.setInt(4, fieldState.checked ? 1 : 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
@ -367,11 +373,12 @@ public class HistoryManager {
|
|||
if (state.params.size() > 0) {
|
||||
// Saves request parameters
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
|
||||
for (Entry entry : state.params.entrySet()) {
|
||||
for (FieldState fieldState : state.params) {
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, "Param");
|
||||
statement.setString(3, entry.getKey().toString());
|
||||
statement.setString(4, entry.getValue().toString());
|
||||
statement.setString(3, fieldState.key);
|
||||
statement.setString(4, fieldState.value);
|
||||
statement.setInt(5, fieldState.checked ? 1 : 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
@ -400,13 +407,14 @@ public class HistoryManager {
|
|||
break;
|
||||
case MediaType.APPLICATION_FORM_URLENCODED:
|
||||
if (state.urlStringTuples.size() > 0) {
|
||||
for (Entry<String, String> entry : state.urlStringTuples.entrySet()) {
|
||||
for (FieldState fieldState : state.urlStringTuples) {
|
||||
// Saves the string tuples
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, "String");
|
||||
statement.setString(3, entry.getKey());
|
||||
statement.setString(4, entry.getValue());
|
||||
statement.setString(3, fieldState.key);
|
||||
statement.setString(4, fieldState.value);
|
||||
statement.setInt(5, fieldState.checked ? 1 : 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
@ -414,26 +422,28 @@ public class HistoryManager {
|
|||
break;
|
||||
case MediaType.MULTIPART_FORM_DATA:
|
||||
if (state.formStringTuples.size() > 0) {
|
||||
for (Entry<String, String> entry : state.formStringTuples.entrySet()) {
|
||||
for (FieldState fieldState : state.formStringTuples) {
|
||||
// Saves the string tuples
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, "String");
|
||||
statement.setString(3, entry.getKey());
|
||||
statement.setString(4, entry.getValue());
|
||||
statement.setString(3, fieldState.key);
|
||||
statement.setString(4, fieldState.value);
|
||||
statement.setInt(5, fieldState.checked ? 1 : 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
if (state.formFileTuples.size() > 0) {
|
||||
for (Entry<String, String> entry : state.formFileTuples.entrySet()) {
|
||||
// Saves the file tuples
|
||||
for (FieldState fieldState : state.formFileTuples) {
|
||||
// Saves the string tuples
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
|
||||
statement.setInt(1, requestID);
|
||||
statement.setString(2, "File");
|
||||
statement.setString(3, entry.getKey());
|
||||
statement.setString(4, entry.getValue());
|
||||
statement.setString(3, fieldState.key);
|
||||
statement.setString(4, fieldState.value);
|
||||
statement.setInt(5, fieldState.checked ? 1 : 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"createRequestsTable": "CREATE TABLE IF NOT EXISTS Requests(ID INTEGER PRIMARY KEY, Type TEXT NOT NULL, Target TEXT NOT NULL, Date TEXT NOT NULL)",
|
||||
"createHeadersTable": "CREATE TABLE IF NOT EXISTS Headers(RequestID INTEGER, Key TEXT NOT NULL, Value TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
|
||||
"createHeadersTable": "CREATE TABLE IF NOT EXISTS Headers(RequestID INTEGER, Key TEXT NOT NULL, Value TEXT NOT NULL, Checked INTEGER CHECK (Checked IN (0, 1)), FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
|
||||
"createRequestContentMapTable": "CREATE TABLE IF NOT EXISTS RequestContentMap(RequestID INTEGER, ContentType TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
|
||||
"createBodiesTable": "CREATE TABLE IF NOT EXISTS Bodies(RequestID INTEGER, Body TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
|
||||
"createTuplesTable": "CREATE TABLE IF NOT EXISTS Tuples(RequestID INTEGER, TupleType TEXT NOT NULL, Key TEXT NOT NULL, Value TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
|
||||
"createTuplesTable": "CREATE TABLE IF NOT EXISTS Tuples(RequestID INTEGER, TupleType TEXT NOT NULL, Key TEXT NOT NULL, Value TEXT NOT NULL, Checked INTEGER CHECK (Checked IN (0, 1)), FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
|
||||
"saveRequest": "INSERT INTO Requests(Type, Target, Date) VALUES(?, ?, ?)",
|
||||
"saveHeader": "INSERT INTO Headers(RequestID, Key, Value) VALUES(?, ?, ?)",
|
||||
"saveHeader": "INSERT INTO Headers(RequestID, Key, Value, Checked) VALUES(?, ?, ?, ?)",
|
||||
"saveRequestContentPair": "INSERT INTO RequestContentMap(RequestID, ContentType) VALUES(?, ?)",
|
||||
"saveBody": "INSERT INTO Bodies(RequestID, Body) VALUES(?, ?)",
|
||||
"saveTuple": "INSERT INTO Tuples(RequestID, TupleType, Key, Value) VALUES(?, ?, ?, ?)",
|
||||
"saveTuple": "INSERT INTO Tuples(RequestID, TupleType, Key, Value, Checked) VALUES(?, ?, ?, ?, ?)",
|
||||
"selectRecentRequests": "SELECT * FROM Requests WHERE Requests.Date > ?",
|
||||
"selectRequestHeaders": "SELECT * FROM Headers WHERE RequestID == ?",
|
||||
"selectRequestContentType": "SELECT ContentType FROM RequestContentMap WHERE RequestID == ?",
|
||||
|
|
Loading…
Reference in a new issue