diff --git a/.gitignore b/.gitignore index 013be40..ec9e1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,17 @@ -/target/ -*.iml -.idea/ -classes/ -src/main/java/META-INF/ -dependency-reduced-pom.xml - -# Hides Eclipse Artifacts -.settings/ -.classpath -.project - -/BugReporter/src/META-INF/ -BugReporter/src/META-INF/ +/target/ +*.iml +.idea/ +classes/ +src/main/java/META-INF/ +dependency-reduced-pom.xml + +# Hides Eclipse Artifacts +.settings/ +.classpath +.project + +/BugReporter/src/META-INF/ +BugReporter/src/META-INF/ Everest/ -out/ \ No newline at end of file +out/ +BugReporter.jar \ No newline at end of file diff --git a/src/main/java/com/rohitawate/everest/Main.java b/src/main/java/com/rohitawate/everest/Main.java index cbf93db..8624ce2 100644 --- a/src/main/java/com/rohitawate/everest/Main.java +++ b/src/main/java/com/rohitawate/everest/Main.java @@ -15,7 +15,6 @@ */ package com.rohitawate.everest; -import com.rohitawate.everest.misc.EverestUtilities; import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.misc.ThemeManager; import com.rohitawate.everest.settings.SettingsLoader; @@ -51,8 +50,6 @@ public class Main extends Application { dashboardStage.setScene(new Scene(homeWindow)); dashboardStage.setTitle("Everest"); dashboardStage.show(); - - EverestUtilities.createBugReporter(); } public static void main(String args[]) { diff --git a/src/main/java/com/rohitawate/everest/controllers/AbstractSearchablePaneController.java b/src/main/java/com/rohitawate/everest/controllers/AbstractSearchablePaneController.java deleted file mode 100644 index b015970..0000000 --- a/src/main/java/com/rohitawate/everest/controllers/AbstractSearchablePaneController.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.rohitawate.everest.controllers; - -import java.io.IOException; -import java.net.URL; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; -import java.util.concurrent.ExecutionException; - -import com.jfoenix.controls.JFXButton; -import com.rohitawate.everest.misc.Services; - -import javafx.application.Platform; -import javafx.concurrent.Task; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.Parent; -import javafx.scene.control.SplitPane; -import javafx.scene.control.TextField; -import javafx.scene.layout.StackPane; -import javafx.scene.layout.VBox; - -public abstract class AbstractSearchablePaneController implements Initializable { - - @FXML - private StackPane searchPromptLayer, searchLayer, searchFailedLayer; - - @FXML - private JFXButton clearSearchFieldButton; - - @FXML - private TextField searchTextField; - - @FXML - private VBox searchTab, searchBox, searchPane; - - private List> searchableItems; - - - protected static class SearchEntry { - private final Parent fxmlItem; - private final Searchable searchable; - public SearchEntry(Parent fxmlItem, Searchable searchable) { - super(); - this.fxmlItem = fxmlItem; - this.searchable = searchable; - } - public Parent getFxmlItem() { - return fxmlItem; - } - public Searchable getSearchable() { - return searchable; - } - - } - - @Override - public void initialize(URL arg0, ResourceBundle arg1) { - searchableItems = new ArrayList<>(); - searchLayer.visibleProperty().bind(searchTextField.textProperty().isNotEmpty()); - - searchTextField.textProperty().addListener(((observable, oldValue, newValue) -> { - searchBox.getChildren().remove(0, searchBox.getChildren().size()); - searchFailedLayer.setVisible(false); - List> searchResults = getSearchResults(searchTextField.getText()); - - //TODO: this is calculating relativityIndex again - searchResults.sort((controller1, controller2) -> { - int relativity1 = controller1.getRelativityIndex(searchTextField.getText()); - int relativity2 = controller2.getRelativityIndex(searchTextField.getText()); - return relativity2 - relativity1; - }); - - if (searchResults.size() != 0) { - for (Searchable controller : searchResults) { - addSearchItem(controller.getState()); - } - } else { - searchFailedLayer.setVisible(true); - } - })); - - clearSearchFieldButton.setOnAction(e -> searchTextField.clear()); - - Platform.runLater(this::loadInitialItemsAsync); - } - - - private void loadInitialItemsAsync() { - Task> entryLoader = new Task>() { - @Override - protected List call() { - return loadInitialEntries(); - } - }; - - entryLoader.setOnSucceeded(e -> { - try { - List entries = entryLoader.get(); - if (entries.size() == 0) { - searchPromptLayer.setVisible(true); - return; - } - - for (T state : entries) - addHistoryItem(state); - } catch (InterruptedException | ExecutionException E) { - Services.loggingService.logSevere("Task thread interrupted while populating HistoryTab.", E, - LocalDateTime.now()); - } - }); - entryLoader.setOnFailed(e -> Services.loggingService.logWarning("Failed to load history.", - (Exception) entryLoader.getException(), LocalDateTime.now())); - new Thread(entryLoader).start(); - - } - - private void addSearchItem(T state) { - appendToList(state, searchBox, false); - } - - protected abstract List loadInitialEntries(); - - public void focusSearchField() { - searchTextField.requestFocus(); - } - - private Searchable appendToList(T state, VBox layer, boolean appendToStart) { - searchPromptLayer.setVisible(false); - try { - SearchEntry searchEntry = createEntryFromState(state); - - if (appendToStart) - layer.getChildren().add(0, searchEntry.getFxmlItem()); - else - layer.getChildren().add(searchEntry.getFxmlItem()); - - return searchEntry.getSearchable(); - } catch (IOException e) { - Services.loggingService.logSevere("Could not append HistoryItem to list.", e, LocalDateTime.now()); - } - - return null; - } - - - protected abstract SearchEntry createEntryFromState(T state) throws IOException; - - - public void addHistoryItem(T state) { - Searchable controller = appendToList(state, searchTab, true); - searchableItems.add(controller); - } - - private List> getSearchResults(String searchString) { - List> filteredList = new ArrayList<>(); - - for (Searchable controller : searchableItems) { - - int relativityIndex = controller.getRelativityIndex(searchString); - - // Split the string into words and get total relativity index as sum of - // individual indices. - String words[] = searchString.split("\\s"); - for (String word : words) - relativityIndex += controller.getRelativityIndex(word); - - if (relativityIndex != 0) - filteredList.add(controller); - } - - return filteredList; - } - - - public void toggleVisibilityIn(SplitPane splitPane) { - if (searchPane.isVisible()) { - searchPane = (VBox) splitPane.getItems().remove(0); - } else { - splitPane.getItems().add(0, searchPane); - } - - searchPane.setVisible(!searchPane.isVisible()); - } -} diff --git a/src/main/java/com/rohitawate/everest/controllers/HistoryItemController.java b/src/main/java/com/rohitawate/everest/controllers/HistoryItemController.java index 95eee8d..9c993cd 100644 --- a/src/main/java/com/rohitawate/everest/controllers/HistoryItemController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HistoryItemController.java @@ -23,6 +23,7 @@ import java.util.ResourceBundle; import javax.ws.rs.core.MediaType; +import com.rohitawate.everest.controllers.search.Searchable; import com.rohitawate.everest.controllers.state.DashboardState; import com.rohitawate.everest.controllers.state.FieldState; import com.rohitawate.everest.misc.Services; diff --git a/src/main/java/com/rohitawate/everest/controllers/SearchPaneController.java b/src/main/java/com/rohitawate/everest/controllers/HistoryPaneController.java similarity index 62% rename from src/main/java/com/rohitawate/everest/controllers/SearchPaneController.java rename to src/main/java/com/rohitawate/everest/controllers/HistoryPaneController.java index d106925..eb29470 100644 --- a/src/main/java/com/rohitawate/everest/controllers/SearchPaneController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HistoryPaneController.java @@ -1,53 +1,65 @@ -package com.rohitawate.everest.controllers; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.function.Consumer; - -import com.rohitawate.everest.controllers.state.DashboardState; -import com.rohitawate.everest.misc.Services; - -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.input.MouseButton; -import javafx.scene.layout.VBox; - -public class SearchPaneController extends AbstractSearchablePaneController { - - private List> stateClickHandler = new LinkedList<>(); - - @Override - protected List loadInitialEntries() { - return Services.historyManager.getHistory(); - } - - protected SearchEntry createEntryFromState(DashboardState state) throws IOException { - FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HistoryItem.fxml")); - Parent historyItem = loader.load(); - - HistoryItemController controller = loader.getController(); - - controller = loader.getController(); - controller.setState(state); - - // Clicking on HistoryItem opens it up in a new tab - historyItem.setOnMouseClicked(mouseEvent -> { - if (mouseEvent.getButton() == MouseButton.PRIMARY) - handleClick(state); - }); - return new SearchEntry(historyItem, controller); - } - - private void handleClick(DashboardState state) { - for (Consumer consumer : stateClickHandler) { - consumer.accept(state); - } - } - - public void addItemClickHandler(Consumer handler) { - stateClickHandler.add(handler); - } - - -} +/* + * 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; + +import com.rohitawate.everest.controllers.search.SearchablePaneController; +import com.rohitawate.everest.controllers.state.DashboardState; +import com.rohitawate.everest.misc.Services; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.input.MouseButton; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.function.Consumer; + +public class HistoryPaneController extends SearchablePaneController { + + private List> stateClickHandler = new LinkedList<>(); + + @Override + protected List loadInitialEntries() { + return Services.historyManager.getHistory(); + } + + protected SearchEntry createEntryFromState(DashboardState state) throws IOException { + FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HistoryItem.fxml")); + Parent historyItem = loader.load(); + + HistoryItemController controller = loader.getController(); + controller.setState(state); + + // Clicking on HistoryItem opens it up in a new tab + historyItem.setOnMouseClicked(mouseEvent -> { + if (mouseEvent.getButton() == MouseButton.PRIMARY) + handleClick(state); + }); + + return new SearchEntry<>(historyItem, controller); + } + + private void handleClick(DashboardState state) { + for (Consumer consumer : stateClickHandler) { + consumer.accept(state); + } + } + + public void addItemClickHandler(Consumer handler) { + stateClickHandler.add(handler); + } +} diff --git a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java index 8b394ad..ba51ed1 100644 --- a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java @@ -16,24 +16,12 @@ package com.rohitawate.everest.controllers; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.ResourceBundle; - import com.fasterxml.jackson.core.type.TypeReference; 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; import com.rohitawate.everest.misc.ThemeManager; - import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.property.StringProperty; @@ -45,11 +33,18 @@ import javafx.scene.Scene; import javafx.scene.control.SplitPane; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; -import javafx.scene.input.MouseButton; import javafx.scene.layout.StackPane; -import javafx.scene.layout.VBox; import javafx.stage.Stage; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.ResourceBundle; + public class HomeWindowController implements Initializable { @FXML private StackPane homeWindowSP; @@ -57,9 +52,8 @@ public class HomeWindowController implements Initializable { private SplitPane splitPane; @FXML private TabPane homeWindowTabPane; - @FXML - private SearchPaneController searchPaneController; + private HistoryPaneController historyPaneController; private HashMap tabControllerMap; @@ -69,7 +63,7 @@ public class HomeWindowController implements Initializable { tabControllerMap = new LinkedHashMap<>(); recoverState(); - searchPaneController.addItemClickHandler(this::addTab); + historyPaneController.addItemClickHandler(this::addTab); homeWindowSP.setFocusTraversable(true); Platform.runLater(() -> { @@ -79,9 +73,6 @@ public class HomeWindowController implements Initializable { // Saves the state of the application before closing Stage thisStage = (Stage) homeWindowSP.getScene().getWindow(); thisStage.setOnCloseRequest(e -> saveState()); - - - }); } @@ -109,7 +100,7 @@ public class HomeWindowController implements Initializable { homeWindowTabPane.getTabs().remove(activeTab); tabControllerMap.remove(activeTab); } else if (KeyMap.searchHistory.match(e)) { - searchPaneController.focusSearchField(); + historyPaneController.focusSearchField(); } else if (KeyMap.focusParams.match(e)) { Tab activeTab = getActiveTab(); DashboardController controller = tabControllerMap.get(activeTab); @@ -140,7 +131,7 @@ public class HomeWindowController implements Initializable { } private void toggleHistoryPane() { - searchPaneController.toggleVisibilityIn(splitPane); + historyPaneController.toggleVisibilityIn(splitPane); } private void addTab() { @@ -224,12 +215,9 @@ public class HomeWindowController implements Initializable { } finally { Services.loggingService.logInfo("Application loaded.", LocalDateTime.now()); } - } - public void addHistoryItem(DashboardState state) { - searchPaneController.addHistoryItem(state); - } - - + public void addHistoryItem(DashboardState state) { + historyPaneController.addHistoryItem(state); + } } diff --git a/src/main/java/com/rohitawate/everest/controllers/Searchable.java b/src/main/java/com/rohitawate/everest/controllers/Searchable.java deleted file mode 100644 index 2fa7186..0000000 --- a/src/main/java/com/rohitawate/everest/controllers/Searchable.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.rohitawate.everest.controllers; - -/** - * a searchable item that is used in a search-pane. - * @author pmucha - * - * @param - */ -public interface Searchable { - - int getRelativityIndex(String searchString); - - T getState(); - -} \ No newline at end of file diff --git a/src/main/java/com/rohitawate/everest/controllers/search/Searchable.java b/src/main/java/com/rohitawate/everest/controllers/search/Searchable.java new file mode 100644 index 0000000..892a647 --- /dev/null +++ b/src/main/java/com/rohitawate/everest/controllers/search/Searchable.java @@ -0,0 +1,28 @@ +/* + * 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.search; + +/** + * A searchable item that is used in a SearchPane. + * + * @param The search item that Searchable encapsulates. + * @author pmucha + */ +public interface Searchable { + int getRelativityIndex(String searchString); + T getState(); +} \ No newline at end of file diff --git a/src/main/java/com/rohitawate/everest/controllers/search/SearchablePaneController.java b/src/main/java/com/rohitawate/everest/controllers/search/SearchablePaneController.java new file mode 100644 index 0000000..4081999 --- /dev/null +++ b/src/main/java/com/rohitawate/everest/controllers/search/SearchablePaneController.java @@ -0,0 +1,194 @@ +/* + * 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.search; + +import com.jfoenix.controls.JFXButton; +import com.rohitawate.everest.misc.Services; +import javafx.application.Platform; +import javafx.concurrent.Task; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.control.SplitPane; +import javafx.scene.control.TextField; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; + +import java.io.IOException; +import java.net.URL; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; +import java.util.concurrent.ExecutionException; + +public abstract class SearchablePaneController implements Initializable { + @FXML + private StackPane searchPromptLayer, searchLayer, searchFailedLayer; + @FXML + private JFXButton clearSearchFieldButton; + @FXML + private TextField searchTextField; + @FXML + private VBox searchTab, searchBox, searchPane; + + private List> searchableItems; + + protected static class SearchEntry { + private final Parent fxmlItem; + private final Searchable searchable; + + public SearchEntry(Parent fxmlItem, Searchable searchable) { + super(); + this.fxmlItem = fxmlItem; + this.searchable = searchable; + } + + public Parent getFxmlItem() { + return fxmlItem; + } + + public Searchable getSearchable() { + return searchable; + } + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + searchableItems = new ArrayList<>(); + searchLayer.visibleProperty().bind(searchTextField.textProperty().isNotEmpty()); + + searchTextField.textProperty().addListener(((observable, oldValue, newValue) -> { + searchBox.getChildren().remove(0, searchBox.getChildren().size()); + searchFailedLayer.setVisible(false); + List> searchResults = getSearchResults(searchTextField.getText()); + + searchResults.sort((controller1, controller2) -> { + int relativity1 = controller1.getRelativityIndex(searchTextField.getText()); + int relativity2 = controller2.getRelativityIndex(searchTextField.getText()); + return relativity2 - relativity1; + }); + + if (searchResults.size() != 0) { + for (Searchable controller : searchResults) { + addSearchItem(controller.getState()); + } + } else { + searchFailedLayer.setVisible(true); + } + })); + + clearSearchFieldButton.setOnAction(e -> searchTextField.clear()); + + Platform.runLater(this::loadInitialItemsAsync); + } + + private void loadInitialItemsAsync() { + Task> entryLoader = new Task>() { + @Override + protected List call() { + return loadInitialEntries(); + } + }; + + entryLoader.setOnSucceeded(e -> { + try { + List entries = entryLoader.get(); + if (entries.size() == 0) { + searchPromptLayer.setVisible(true); + return; + } + + for (T state : entries) + addHistoryItem(state); + } catch (InterruptedException | ExecutionException E) { + Services.loggingService.logSevere("Task thread interrupted while populating HistoryTab.", E, + LocalDateTime.now()); + } + }); + + entryLoader.setOnFailed(e -> Services.loggingService.logWarning("Failed to load history.", + (Exception) entryLoader.getException(), LocalDateTime.now())); + + Services.singleExecutor.execute(entryLoader); + } + + private void addSearchItem(T state) { + appendToList(state, searchBox, false); + } + + protected abstract List loadInitialEntries(); + + public void focusSearchField() { + searchTextField.requestFocus(); + } + + private Searchable appendToList(T state, VBox layer, boolean appendToStart) { + searchPromptLayer.setVisible(false); + try { + SearchEntry searchEntry = createEntryFromState(state); + + if (appendToStart) + layer.getChildren().add(0, searchEntry.getFxmlItem()); + else + layer.getChildren().add(searchEntry.getFxmlItem()); + + return searchEntry.getSearchable(); + } catch (IOException e) { + Services.loggingService.logSevere("Could not append HistoryItem to list.", e, LocalDateTime.now()); + } + + return null; + } + + protected abstract SearchEntry createEntryFromState(T state) throws IOException; + + public void addHistoryItem(T state) { + Searchable controller = appendToList(state, searchTab, true); + searchableItems.add(controller); + } + + private List> getSearchResults(String searchString) { + List> filteredList = new ArrayList<>(); + + for (Searchable controller : searchableItems) { + + int relativityIndex = controller.getRelativityIndex(searchString); + + // Split the string into words and get total relativity index as sum of + // individual indices. + String words[] = searchString.split("\\s"); + for (String word : words) + relativityIndex += controller.getRelativityIndex(word); + + if (relativityIndex != 0) + filteredList.add(controller); + } + + return filteredList; + } + + public void toggleVisibilityIn(SplitPane splitPane) { + if (searchPane.isVisible()) { + searchPane = (VBox) splitPane.getItems().remove(0); + } else { + splitPane.getItems().add(0, searchPane); + } + + searchPane.setVisible(!searchPane.isVisible()); + } +} diff --git a/src/main/java/com/rohitawate/everest/history/HistoryManager.java b/src/main/java/com/rohitawate/everest/history/HistoryManager.java index eafe3ec..3025d7b 100644 --- a/src/main/java/com/rohitawate/everest/history/HistoryManager.java +++ b/src/main/java/com/rohitawate/everest/history/HistoryManager.java @@ -16,21 +16,6 @@ package com.rohitawate.everest.history; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.core.MediaType; - import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.rohitawate.everest.controllers.state.DashboardState; @@ -39,6 +24,16 @@ import com.rohitawate.everest.misc.EverestUtilities; import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.settings.Settings; +import javax.ws.rs.core.MediaType; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.sql.*; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + public class HistoryManager { private Connection conn; private JsonNode queries; @@ -387,19 +382,8 @@ public class HistoryManager { } } - if (state.params.size() > 0) { - // Saves request parameters - statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString())); - for (FieldState fieldState : state.params) { - statement.setInt(1, requestID); - statement.setString(2, "Param"); - statement.setString(3, fieldState.key); - statement.setString(4, fieldState.value); - statement.setInt(5, fieldState.checked ? 1 : 0); - - statement.executeUpdate(); - } - } + // Saves request parameters + saveTuple(state.params, "Param", requestID); if (!(state.httpMethod.equals("GET") || state.httpMethod.equals("DELETE"))) { // Maps the request to its ContentType for faster retrieval @@ -423,48 +407,11 @@ public class HistoryManager { statement.executeUpdate(); break; case MediaType.APPLICATION_FORM_URLENCODED: - if (state.urlStringTuples.size() > 0) { - 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, fieldState.key); - statement.setString(4, fieldState.value); - statement.setInt(5, fieldState.checked ? 1 : 0); - - statement.executeUpdate(); - } - } + saveTuple(state.urlStringTuples, "String", requestID); break; case MediaType.MULTIPART_FORM_DATA: - if (state.formStringTuples.size() > 0) { - 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, fieldState.key); - statement.setString(4, fieldState.value); - statement.setInt(5, fieldState.checked ? 1 : 0); - - statement.executeUpdate(); - } - } - - if (state.formFileTuples.size() > 0) { - 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, fieldState.key); - statement.setString(4, fieldState.value); - statement.setInt(5, fieldState.checked ? 1 : 0); - - statement.executeUpdate(); - } - } + saveTuple(state.formStringTuples, "String", requestID); + saveTuple(state.formFileTuples, "File", requestID); break; } } @@ -472,5 +419,25 @@ public class HistoryManager { Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); } } + + private void saveTuple(ArrayList 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); + + statement.executeUpdate(); + } catch (SQLException e) { + Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); + } + } + } + } } } \ No newline at end of file diff --git a/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java b/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java index 1a62d11..5d92450 100644 --- a/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java +++ b/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java @@ -19,14 +19,6 @@ package com.rohitawate.everest.misc; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.time.LocalDateTime; - public class EverestUtilities { public static ObjectMapper jsonMapper; @@ -44,21 +36,4 @@ public class EverestUtilities { public static String trimString(String input) { return input.replaceAll("\"", ""); } - - /** - * Copies the BugReporter from within the JAR to the installation directory. - */ - public static void createBugReporter() { - new Thread(() -> { - InputStream inputStream = EverestUtilities.class.getResourceAsStream("/BugReporter.jar"); - Path bugReporter = Paths.get("Everest/BugReporter.jar"); - try { - Files.copy(inputStream, bugReporter, StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - e.printStackTrace(); - } - Services.loggingService.logInfo("BugReporter was copied to installation directory.", LocalDateTime.now()); - - }).start(); - } } diff --git a/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java b/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java index a081c0e..e9d1204 100644 --- a/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java +++ b/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java @@ -16,79 +16,74 @@ package com.rohitawate.everest.requestmanager; -import java.util.LinkedList; +import java.util.ArrayList; +/** + * Provides the various RequestManagers employed by Everest. + *

+ * Pools are created as needed i.e. the first DELETE request + * will create the pool of DELETERequestManagers. If a DELETE + * request is never made, the pool won't be created. Same applies + * for all other types of requests. + *

+ * When demanding a RequestManager, the pool is checked linearly. + * The first RequestManager which is not currently running will be + * returned to the caller. If all the managers in the pool are running, + * a new one is created, added to the pool, and returned. + */ public class RequestManagersPool { - private LinkedList getManagers; - private LinkedList dataManagers; - private LinkedList deleteManagers; + private ArrayList getManagers; + private ArrayList dataManagers; + private ArrayList deleteManagers; public GETRequestManager get() { - if (getManagers == null) { - GETRequestManager newManager = new GETRequestManager(); + if (getManagers == null) + getManagers = new ArrayList<>(); - new Thread(() -> { - getManagers = new LinkedList<>(); - getManagers.add(newManager); - }).start(); - - return newManager; - } else { - for (GETRequestManager getManager : getManagers) { - if (!getManager.isRunning()) - return getManager; + for (GETRequestManager getManager : getManagers) { + if (!getManager.isRunning()) { + getManager.reset(); + return getManager; } - - GETRequestManager newManager = new GETRequestManager(); - getManagers.add(newManager); - - return newManager; } + + GETRequestManager newManager = new GETRequestManager(); + getManagers.add(newManager); + + return newManager; } public DataDispatchRequestManager data() { - if (dataManagers == null) { - DataDispatchRequestManager newManager = new DataDispatchRequestManager(); + if (dataManagers == null) + dataManagers = new ArrayList<>(); - new Thread(() -> { - dataManagers = new LinkedList<>(); - dataManagers.add(newManager); - }).start(); - - return newManager; - } else { - for (DataDispatchRequestManager dataManager : dataManagers) { - if (!dataManager.isRunning()) - return dataManager; + for (DataDispatchRequestManager dataManager : dataManagers) { + if (!dataManager.isRunning()) { + dataManager.reset(); + return dataManager; } - - DataDispatchRequestManager newManager = new DataDispatchRequestManager(); - dataManagers.add(newManager); - - return newManager; } + + DataDispatchRequestManager newManager = new DataDispatchRequestManager(); + dataManagers.add(newManager); + + return newManager; } public DELETERequestManager delete() { - if (deleteManagers == null) { - DELETERequestManager newManager = new DELETERequestManager(); + if (deleteManagers == null) + deleteManagers = new ArrayList<>(); - new Thread(() -> { - deleteManagers = new LinkedList<>(); - deleteManagers.add(newManager); - }).start(); - - return newManager; - } else { - for (DELETERequestManager deleteManager : deleteManagers) { - if (!deleteManager.isRunning()) - return deleteManager; + for (DELETERequestManager deleteManager : deleteManagers) { + if (!deleteManager.isRunning()) { + deleteManager.reset(); + return deleteManager; } - - DELETERequestManager newManager = new DELETERequestManager(); - deleteManagers.add(newManager); - - return newManager; } + + DELETERequestManager newManager = new DELETERequestManager(); + deleteManagers.add(newManager); + + return newManager; } } diff --git a/src/main/resources/BugReporter.jar b/src/main/resources/BugReporter.jar deleted file mode 100644 index bdde1bf..0000000 Binary files a/src/main/resources/BugReporter.jar and /dev/null differ diff --git a/src/main/resources/fxml/homewindow/SearchPane.fxml b/src/main/resources/fxml/homewindow/HistoryPane.fxml similarity index 95% rename from src/main/resources/fxml/homewindow/SearchPane.fxml rename to src/main/resources/fxml/homewindow/HistoryPane.fxml index 0589e01..ee34dc7 100644 --- a/src/main/resources/fxml/homewindow/SearchPane.fxml +++ b/src/main/resources/fxml/homewindow/HistoryPane.fxml @@ -1,151 +1,151 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/fxml/homewindow/HomeWindow.fxml b/src/main/resources/fxml/homewindow/HomeWindow.fxml index 2812b97..7e373b3 100644 --- a/src/main/resources/fxml/homewindow/HomeWindow.fxml +++ b/src/main/resources/fxml/homewindow/HomeWindow.fxml @@ -1,29 +1,34 @@ - + + + + + - - - - - - + stylesheets="@../../css/Adreana.css" + xmlns="http://javafx.com/javafx/8.0.141" + xmlns:fx="http://javafx.com/fxml/1" + fx:controller="com.rohitawate.everest.controllers.HomeWindowController"> - +