Add state maintenance for inner auth tabs

This commit is contained in:
Rohit Awate 2018-09-01 10:13:48 +05:30
parent d348218541
commit 4701fc18ff
4 changed files with 36 additions and 12 deletions

View file

@ -5,6 +5,7 @@ import com.rohitawate.everest.auth.BasicAuthProvider;
import com.rohitawate.everest.auth.DigestAuthProvider; import com.rohitawate.everest.auth.DigestAuthProvider;
import com.rohitawate.everest.controllers.DashboardController; import com.rohitawate.everest.controllers.DashboardController;
import com.rohitawate.everest.state.ComposerState; import com.rohitawate.everest.state.ComposerState;
import com.rohitawate.everest.sync.DataManager;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -69,6 +70,15 @@ public class AuthTabController implements Initializable {
} }
public void getState(ComposerState state) { public void getState(ComposerState state) {
switch (authTabPane.getSelectionModel().getSelectedIndex()) {
case 0:
state.authMethod = DataManager.BASIC;
break;
case 1:
state.authMethod = DataManager.DIGEST;
break;
}
state.basicUsername = basicController.getUsername(); state.basicUsername = basicController.getUsername();
state.basicPassword = basicController.getPassword(); state.basicPassword = basicController.getPassword();
state.basicEnabled = basicController.isSelected(); state.basicEnabled = basicController.isSelected();
@ -81,6 +91,14 @@ public class AuthTabController implements Initializable {
public void setState(ComposerState state) { public void setState(ComposerState state) {
basicController.setState(state.basicUsername, state.basicPassword, state.basicEnabled); basicController.setState(state.basicUsername, state.basicPassword, state.basicEnabled);
digestController.setState(state.digestUsername, state.digestPassword, state.digestEnabled); digestController.setState(state.digestUsername, state.digestPassword, state.digestEnabled);
switch (state.authMethod) {
case DataManager.BASIC:
authTabPane.getSelectionModel().select(0);
break;
case DataManager.DIGEST:
authTabPane.getSelectionModel().select(1);
}
} }
public void setDashboard(DashboardController dashboard) { public void setDashboard(DashboardController dashboard) {

View file

@ -26,6 +26,7 @@ import java.util.List;
public class ComposerState { public class ComposerState {
public String target; public String target;
public String httpMethod; public String httpMethod;
public String authMethod;
public List<FieldState> params; public List<FieldState> params;
public List<FieldState> headers; public List<FieldState> headers;
@ -65,6 +66,7 @@ public class ComposerState {
ComposerState state = (ComposerState) o; ComposerState state = (ComposerState) o;
if (!target.equals(state.target)) return false; if (!target.equals(state.target)) return false;
if (!httpMethod.equals(state.httpMethod)) return false; if (!httpMethod.equals(state.httpMethod)) return false;
if (!authMethod.equals(state.authMethod)) return false;
if (!params.equals(state.params)) return false; if (!params.equals(state.params)) return false;
if (!headers.equals(state.headers)) return false; if (!headers.equals(state.headers)) return false;
if (!basicUsername.equals(state.basicUsername)) return false; if (!basicUsername.equals(state.basicUsername)) return false;

View file

@ -8,6 +8,16 @@ import java.util.List;
* Manages the history and (in the future) the projects of Everest. * Manages the history and (in the future) the projects of Everest.
*/ */
public interface DataManager { public interface DataManager {
String HEADER = "Header";
String PARAM = "Param";
String URL_STRING = "URLString";
String FORM_STRING = "FormString";
String AUTH_METHOD = "AuthMethod";
String FILE = "File";
String BASIC = "Basic";
String DIGEST = "Digest";
String ID = "ID";
/** /**
* Saves the state of the Composer when the request was made. * Saves the state of the Composer when the request was made.
*/ */

View file

@ -36,7 +36,7 @@ class SQLiteManager implements DataManager {
private static class Queries { private static class Queries {
private static final String[] CREATE_QUERIES = { private static final String[] CREATE_QUERIES = {
"CREATE TABLE IF NOT EXISTS Requests(ID INTEGER PRIMARY KEY, Type TEXT NOT NULL, Target TEXT NOT NULL, Date TEXT NOT NULL)", "CREATE TABLE IF NOT EXISTS Requests(ID INTEGER PRIMARY KEY, Type TEXT NOT NULL, Target TEXT NOT NULL, AuthMethod TEXT, Date TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS RequestContentMap(RequestID INTEGER, ContentType TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))", "CREATE TABLE IF NOT EXISTS RequestContentMap(RequestID INTEGER, ContentType TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
"CREATE TABLE IF NOT EXISTS Bodies(RequestID INTEGER, Type TEXT NOT NULL CHECK(Type IN ('application/json', 'application/xml', 'text/html', 'text/plain')), Body TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))", "CREATE TABLE IF NOT EXISTS Bodies(RequestID INTEGER, Type TEXT NOT NULL CHECK(Type IN ('application/json', 'application/xml', 'text/html', 'text/plain')), Body TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
"CREATE TABLE IF NOT EXISTS FilePaths(RequestID INTEGER, Path TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))", "CREATE TABLE IF NOT EXISTS FilePaths(RequestID INTEGER, Path TEXT NOT NULL, FOREIGN KEY(RequestID) REFERENCES Requests(ID))",
@ -44,7 +44,7 @@ class SQLiteManager implements DataManager {
"CREATE TABLE IF NOT EXISTS SimpleAuthCredentials(RequestID INTEGER, Type TEXT NOT NULL, Username TEXT NOT NULL, Password TEXT NOT NULL, Enabled INTEGER CHECK (Enabled IN (1, 0)), FOREIGN KEY(RequestID) REFERENCES Requests(ID))" "CREATE TABLE IF NOT EXISTS SimpleAuthCredentials(RequestID INTEGER, Type TEXT NOT NULL, Username TEXT NOT NULL, Password TEXT NOT NULL, Enabled INTEGER CHECK (Enabled IN (1, 0)), FOREIGN KEY(RequestID) REFERENCES Requests(ID))"
}; };
private static final String SAVE_REQUEST = "INSERT INTO Requests(Type, Target, Date) VALUES(?, ?, ?)"; private static final String SAVE_REQUEST = "INSERT INTO Requests(Type, Target, AuthMethod, Date) VALUES(?, ?, ?, ?)";
private static final String SAVE_REQUEST_CONTENT_PAIR = "INSERT INTO RequestContentMap(RequestID, ContentType) VALUES(?, ?)"; private static final String SAVE_REQUEST_CONTENT_PAIR = "INSERT INTO RequestContentMap(RequestID, ContentType) VALUES(?, ?)";
private static final String SAVE_BODY = "INSERT INTO Bodies(RequestID, Body, Type) VALUES(?, ?, ?)"; private static final String SAVE_BODY = "INSERT INTO Bodies(RequestID, Body, Type) VALUES(?, ?, ?)";
private static final String SAVE_FILE_PATH = "INSERT INTO FilePaths(RequestID, Path) VALUES(?, ?)"; private static final String SAVE_FILE_PATH = "INSERT INTO FilePaths(RequestID, Path) VALUES(?, ?)";
@ -59,15 +59,6 @@ class SQLiteManager implements DataManager {
private static final String SELECT_MOST_RECENT_REQUEST = "SELECT * FROM Requests ORDER BY ID DESC LIMIT 1"; private static final String SELECT_MOST_RECENT_REQUEST = "SELECT * FROM Requests ORDER BY ID DESC LIMIT 1";
} }
private static final String ID = "ID";
private static final String HEADER = "Header";
private static final String PARAM = "Param";
private static final String URL_STRING = "URLString";
private static final String FORM_STRING = "FormString";
private static final String FILE = "File";
private static final String BASIC = "Basic";
private static final String DIGEST = "Digest";
public SQLiteManager() { public SQLiteManager() {
try { try {
String configPath = "Everest/config/"; String configPath = "Everest/config/";
@ -107,7 +98,8 @@ class SQLiteManager implements DataManager {
statement.setString(1, newState.httpMethod); statement.setString(1, newState.httpMethod);
statement.setString(2, newState.target); statement.setString(2, newState.target);
statement.setString(3, LocalDate.now().toString()); statement.setString(3, newState.authMethod);
statement.setString(4, LocalDate.now().toString());
statement.executeUpdate(); statement.executeUpdate();
// Get latest RequestID to insert into Headers table // Get latest RequestID to insert into Headers table
@ -184,6 +176,7 @@ class SQLiteManager implements DataManager {
state = new ComposerState(); state = new ComposerState();
state.target = resultSet.getString("Target"); state.target = resultSet.getString("Target");
state.authMethod = resultSet.getString(AUTH_METHOD);
int requestID = resultSet.getInt(ID); int requestID = resultSet.getInt(ID);
state.headers = getTuples(requestID, HEADER); state.headers = getTuples(requestID, HEADER);
@ -304,6 +297,7 @@ class SQLiteManager implements DataManager {
requestID = RS.getInt(ID); requestID = RS.getInt(ID);
lastRequest.target = RS.getString("Target"); lastRequest.target = RS.getString("Target");
lastRequest.httpMethod = RS.getString("Type"); lastRequest.httpMethod = RS.getString("Type");
lastRequest.authMethod = RS.getString(AUTH_METHOD);
} }
getSimpleAuthCredentials(lastRequest, requestID, BASIC); getSimpleAuthCredentials(lastRequest, requestID, BASIC);