From f1ca82d61cd9a6378629e55b7639bddc86a5f266 Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Wed, 4 Jul 2018 19:23:31 +0530 Subject: [PATCH] Project-wide cleanup and optimizations --- .gitignore | 31 +- .../java/com/rohitawate/everest/Main.java | 3 - .../AbstractSearchablePaneController.java | 186 ----------- .../controllers/HistoryItemController.java | 1 + ...roller.java => HistoryPaneController.java} | 118 +++---- .../controllers/HomeWindowController.java | 44 +-- .../everest/controllers/Searchable.java | 15 - .../controllers/search/Searchable.java | 28 ++ .../search/SearchablePaneController.java | 194 +++++++++++ .../everest/history/HistoryManager.java | 103 ++---- .../everest/misc/EverestUtilities.java | 25 -- .../requestmanager/RequestManagersPool.java | 105 +++--- src/main/resources/BugReporter.jar | Bin 3373 -> 0 bytes .../{SearchPane.fxml => HistoryPane.fxml} | 300 +++++++++--------- .../resources/fxml/homewindow/HomeWindow.fxml | 43 +-- 15 files changed, 579 insertions(+), 617 deletions(-) delete mode 100644 src/main/java/com/rohitawate/everest/controllers/AbstractSearchablePaneController.java rename src/main/java/com/rohitawate/everest/controllers/{SearchPaneController.java => HistoryPaneController.java} (62%) delete mode 100644 src/main/java/com/rohitawate/everest/controllers/Searchable.java create mode 100644 src/main/java/com/rohitawate/everest/controllers/search/Searchable.java create mode 100644 src/main/java/com/rohitawate/everest/controllers/search/SearchablePaneController.java delete mode 100644 src/main/resources/BugReporter.jar rename src/main/resources/fxml/homewindow/{SearchPane.fxml => HistoryPane.fxml} (95%) 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 bdde1bf14f8b525d773536f70360c26936fdd8b4..0000000000000000000000000000000000000000 GI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pAj5!tyG)8 zChS3(N+@xl8AEOwF1yr|LS^8FdGDqI*+pCurh;ZDORY1ya9*(Wqa`zR&Zaw3# z(siXBk+tq=Ln_T}u8#@lrvNA&1J1FBU#^ zPwPK1JgHY{(JSt4Nfsq4skE9fsSXW$IvdGpX6159?YLpX9Ka``@Ala|qSr+gxXnD6;2A;=hvnI@zgZAPoR;%<|vlP7MH10{({?sD38* zKbgS*LPE*{_zN!n9{zv9#Xsv$+rLob?_GX@!rvG91qy#vz|ZghV8bsvHQ@hm` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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"> - +