From 23fa27aa704e7db19e340fb5befa4b83dfbca13e Mon Sep 17 00:00:00 2001 From: Oluwasina Olowookere Date: Fri, 11 Aug 2023 22:39:16 -0400 Subject: [PATCH] Corrected DB errors and implement full scale functionality as well as a singleton design current ID class --- .../use_cases/CurrentProjectID.java | 28 +++++++++ .../project_selection_gateways/IDBRemove.java | 10 +--- .../DeleteProject.java | 2 +- .../EditProjectDetails.java | 4 +- .../ProjectSelectionInteractor.java | 7 +++ .../AddColumn.java | 10 +++- .../DeleteColumn.java | 2 +- .../DeleteTask.java | 2 +- .../EditColumnDetails.java | 4 +- .../EditTaskDetails.java | 3 +- .../MoveTask.java | 2 +- ...ojectViewingAndModificationInteractor.java | 3 + .../ProjectSelectionPresenter.java | 11 ++++ ...rojectViewingAndModificationPresenter.java | 21 +++++++ .../DBManagerInsertController.java | 41 ++++++++++--- .../DBManagerRemoveController.java | 59 +++++++++---------- .../DBManagerSearchController.java | 16 +++-- .../EntityIDstoModelController.java | 48 ++++++++------- .../DBControllers/IDListsToModelList.java | 50 +++++++++++++++- .../DatabaseFiles/Columns/Columns.csv | 7 ++- .../DatabaseFiles/Projects/Projects.csv | 14 ++--- .../DatabaseFiles/Tasks/Tasks.csv | 6 +- 22 files changed, 255 insertions(+), 95 deletions(-) create mode 100644 src/main/java/b_application_business_rules/use_cases/CurrentProjectID.java diff --git a/src/main/java/b_application_business_rules/use_cases/CurrentProjectID.java b/src/main/java/b_application_business_rules/use_cases/CurrentProjectID.java new file mode 100644 index 0000000..374581f --- /dev/null +++ b/src/main/java/b_application_business_rules/use_cases/CurrentProjectID.java @@ -0,0 +1,28 @@ +package b_application_business_rules.use_cases; + +import java.util.UUID; + +public class CurrentProjectID { + + private static final CurrentProjectID currentProjectID = new CurrentProjectID(null); + + private UUID[] selectedProjectID = new UUID[1]; + public CurrentProjectID(UUID uuid){ + this.selectedProjectID[0] = uuid; + } + public static CurrentProjectID getCurrentProjectID(){ + return currentProjectID; + } + + public UUID getSelectedProjectID() { + return selectedProjectID[0]; + } + + public void setSelectedProjectID(UUID selectedProjectID) { + this.selectedProjectID[0] = selectedProjectID; + } + + public void removeCurrentProjectID(){ + this.setSelectedProjectID(null); + } +} diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java index 4e63d0e..2d12a40 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java @@ -1,13 +1,9 @@ package b_application_business_rules.use_cases.project_selection_gateways; -import b_application_business_rules.entity_models.ColumnModel; -import b_application_business_rules.entity_models.ProjectModel; -import b_application_business_rules.entity_models.TaskModel; - import java.util.UUID; public interface IDBRemove { - void DBRemove(ProjectModel projectModel, UUID uuid); - void DBRemove(TaskModel taskModel, UUID uuid); - void DBRemove(ColumnModel columnModel, UUID uuid); + void DBRemoveProject(UUID uuid); + void DBRemoveTask(UUID uuid); + void DBRemoveColumn(UUID uuid); } diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java index 57a0a48..8336f7a 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java @@ -29,7 +29,7 @@ public void deleteProject(UUID ID) { // List projectUUIDs = databaseSearcher.DBColumnSearch(ID.toString()); ProjectModel tempProjectModel = new ProjectModel("tempname", ID, "", null); - databaseRemover.DBRemove(tempProjectModel, ID); + databaseRemover.DBRemoveProject(ID); // TOOD -- So, like, the DBRemove needs a ProjectModel, in addition to the UUID, // but like, it never actually uses it :| diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/EditProjectDetails.java b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/EditProjectDetails.java index e1c952f..38f67e1 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/EditProjectDetails.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/EditProjectDetails.java @@ -39,7 +39,7 @@ public void setName(String newName) { // currentProject model...? IDBRemove databaseRemover = new DBManagerRemoveController(); - databaseRemover.DBRemove(this.currentProjectModel, this.currentProjectModel.getID()); + databaseRemover.DBRemoveProject(this.currentProjectModel.getID()); this.currentProjectModel.setName(newName); @@ -62,7 +62,7 @@ public void setDescription(String newDescription) { // currentProject model...? IDBRemove databaseRemover = new DBManagerRemoveController(); - databaseRemover.DBRemove(this.currentProjectModel, this.currentProjectModel.getID()); + databaseRemover.DBRemoveProject(this.currentProjectModel.getID()); this.currentProjectModel.setName(newDescription); diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java index 27b5072..f21bbce 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java @@ -8,6 +8,7 @@ import b_application_business_rules.boundaries.ProjectSelectionInputBoundary; import b_application_business_rules.boundaries.ProjectSelectionOutputBoundary; +import b_application_business_rules.use_cases.CurrentProjectID; import b_application_business_rules.use_cases.CurrentProjectRepository; import b_application_business_rules.use_cases.project_selection_gateways.IDbIdToModel; import d_frameworks_and_drivers.database_management.DBControllers.DbIDToModel; @@ -33,6 +34,8 @@ public class ProjectSelectionInteractor implements ProjectSelectionInputBoundary private final CurrentProjectRepository currentProjectRepository = CurrentProjectRepository .getCurrentprojectrepository(); + private final CurrentProjectID currentProjectID = CurrentProjectID.getCurrentProjectID(); + // The presenter holds the reference to the ProjectSelectionOutputBoundary // instance, // which is responsible for displaying the results of the use cases. @@ -72,6 +75,9 @@ public void setCurrentProject(Project project) { public void setCurrentProject(ProjectModel project) { currentProjectRepository.setCurrentProject(project); } + public void setCurrentProjectID(UUID uuid) { + currentProjectID.setSelectedProjectID(uuid); + } /** * Creates a new project. This method is called when the user creates a new @@ -122,6 +128,7 @@ public void openProject(UUID currentProjectID) { new ColumnModel("COLUMN 2", new ArrayList<>(), UUID.randomUUID())); ProjectModel projectModel = new ProjectModel( "Project P1", UUID.randomUUID(), "", ColumnsList); + setCurrentProjectID(currentProjectID); ProjectModel ProjectFromDB = iDbIdToModel.IdToProjectModel(currentProjectID.toString()); setCurrentProject(ProjectFromDB); presenter.displayCurrentProject(ProjectFromDB); diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java index 0272e97..a563009 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java @@ -7,8 +7,10 @@ import b_application_business_rules.entity_models.ProjectModel; import b_application_business_rules.use_cases.CurrentProjectRepository; import b_application_business_rules.use_cases.project_selection_gateways.IDBInsert; +import b_application_business_rules.use_cases.project_selection_gateways.IDBRemove; import b_application_business_rules.use_cases.project_selection_gateways.IDbIdToModel; import b_application_business_rules.use_cases.project_selection_use_cases.DeleteProject; +import d_frameworks_and_drivers.database_management.DBControllers.DBManagerRemoveController; import d_frameworks_and_drivers.database_management.DBControllers.DbIDToModel; import d_frameworks_and_drivers.database_management.DBControllers.DBManagerInsertController; @@ -54,11 +56,15 @@ public void addColumn() { // Update database to add the column. IDBInsert dbInsertManager = new DBManagerInsertController(); + IDBRemove idbRemove = new DBManagerRemoveController(); + dbInsertManager.DBInsert(columnModel); ProjectModel updatedProject = iDbIdToModel.IdToProjectModel(currentProject.getID().toString()); updatedProject.getColumnModels().add(columnModel); - DeleteProject deleteProject = new DeleteProject(); - deleteProject.deleteProject(iDbIdToModel.IdToProjectModel(currentProject.getID().toString())); + idbRemove.DBRemoveProject(currentProject.getID()); + + //DeleteProject deleteProject = new DeleteProject(); + //deleteProject.deleteProject(iDbIdToModel.IdToProjectModel(currentProject.getID().toString())); dbInsertManager.DBInsert(updatedProject); } diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java index ca83630..37f2fec 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java @@ -62,6 +62,6 @@ public void deleteColumn() { // Update the database to remove the column. IDBRemove dbRemoveManager = new DBManagerRemoveController(); - dbRemoveManager.DBRemove(new ColumnModel(column), idOfColumn); + dbRemoveManager.DBRemoveColumn(idOfColumn); } } diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteTask.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteTask.java index d2099ce..2bdbe7a 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteTask.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteTask.java @@ -47,6 +47,6 @@ public void deleteTask() { // initialize controller IDBRemove removeTask = new DBManagerRemoveController(); // remove task from database - removeTask.DBRemove(taskModel, taskID); + removeTask.DBRemoveTask(taskID); } } \ No newline at end of file diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditColumnDetails.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditColumnDetails.java index 0f016af..201aefc 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditColumnDetails.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditColumnDetails.java @@ -1,8 +1,6 @@ package b_application_business_rules.use_cases.project_viewing_and_modification_use_cases; -import a_enterprise_business_rules.entities.Project; import b_application_business_rules.entity_models.ColumnModel; -import b_application_business_rules.use_cases.CurrentProjectRepository; import b_application_business_rules.use_cases.project_selection_gateways.IDBInsert; import b_application_business_rules.use_cases.project_selection_gateways.IDBRemove; import d_frameworks_and_drivers.database_management.DBControllers.DBManagerInsertController; @@ -40,7 +38,7 @@ public void setColumnName(String newName) { this.columnModel.setName(newName); IDBRemove dbRemoveManager = new DBManagerRemoveController(); - dbRemoveManager.DBRemove(this.columnModel, this.columnModel.getID()); + dbRemoveManager.DBRemoveColumn(this.columnModel.getID()); // Update database to add the column. IDBInsert dbInsertManager = new DBManagerInsertController(); diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditTaskDetails.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditTaskDetails.java index f593080..0771d86 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditTaskDetails.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/EditTaskDetails.java @@ -2,7 +2,6 @@ import b_application_business_rules.DataAccessInterface; -import b_application_business_rules.entity_models.ColumnModel; import b_application_business_rules.entity_models.TaskModel; import b_application_business_rules.factories.TaskModelFactory; import b_application_business_rules.use_cases.project_selection_gateways.IDBInsert; @@ -69,7 +68,7 @@ public void updateTaskDetail(UUID taskID, TaskModel updatedTask, UUID parentColu oldTaskDescription, oldTaskStatus, oldTaskDate); // Removing the old task - removeTask.DBRemove(oldTask, taskID); + removeTask.DBRemoveTask(taskID); // Inserting the new task insertTask.DBInsert(updatedTask, parentColumn); diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/MoveTask.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/MoveTask.java index 5fe1220..4b7af74 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/MoveTask.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/MoveTask.java @@ -43,7 +43,7 @@ public void moveTask(TaskModel task) { this.column2.addTaskModel(task); IDBRemove databaseRemover = new DBManagerRemoveController(); - databaseRemover.DBRemove(this.project, this.project.getID()); + databaseRemover.DBRemoveProject(this.project.getID()); IDBInsert databaseInserter = new DBManagerInsertController(); databaseInserter.DBInsert(this.project); diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java index 5a22f4c..b4080ea 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java @@ -6,6 +6,7 @@ import b_application_business_rules.entity_models.ProjectModel; import b_application_business_rules.entity_models.TaskModel; import b_application_business_rules.factories.TaskModelFactory; +import b_application_business_rules.use_cases.CurrentProjectID; import b_application_business_rules.use_cases.CurrentProjectRepository; import c_interface_adapters.view_models.TaskViewModel; @@ -26,6 +27,7 @@ public class ProjectViewingAndModificationInteractor implements ProjectViewingAn // The currentProjectRepository holds the reference to the // CurrentProjectRepository instance. CurrentProjectRepository currentProjectRepository = CurrentProjectRepository.getCurrentprojectrepository(); + CurrentProjectID currentProjectID = CurrentProjectID.getCurrentProjectID(); // The presenter holds the reference to the // ProjectViewingAndModificationOutputBoundary instance, @@ -51,6 +53,7 @@ public ProjectViewingAndModificationInteractor(ProjectViewingAndModificationOutp @Override public void removeCurrentProject() { currentProjectRepository.removeCurrentProject(); + currentProjectID.removeCurrentProjectID(); } @Override diff --git a/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java b/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java index c38e466..3dc0aea 100644 --- a/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java +++ b/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java @@ -4,11 +4,14 @@ import b_application_business_rules.entity_models.ColumnModel; import b_application_business_rules.entity_models.ProjectModel; import b_application_business_rules.entity_models.TaskModel; +import b_application_business_rules.use_cases.CurrentProjectRepository; +import b_application_business_rules.use_cases.project_selection_gateways.IDBInsert; import b_application_business_rules.use_cases.project_selection_use_cases.DeleteProjectUseCase; import c_interface_adapters.view_models.ColumnViewModel; import c_interface_adapters.view_models.ProjectSelectionViewModel; import c_interface_adapters.view_models.ProjectViewModel; import c_interface_adapters.view_models.TaskViewModel; +import d_frameworks_and_drivers.database_management.DBControllers.DBManagerInsertController; import d_frameworks_and_drivers.database_management.DBControllers.EntityIDstoModelController; import javafx.application.Application; import javafx.event.ActionEvent; @@ -45,6 +48,7 @@ public class ProjectSelectionPresenter extends Application implements ProjectSel private ProjectSelectionViewModel projectSelectionViewModel; private ProjectSelectionController controller; List AllProjectsList = new ArrayList<>(); + EntityIDstoModelController entityIDstoModelController = new EntityIDstoModelController(); @@ -506,6 +510,7 @@ void addCreateProjectButton(int col, int row) { * Handles the "Create Project" Popup for the user to input the necessary information. */ private void handleCreateProjectPopup(ActionEvent actionEvent) { + IDBInsert idbInsert = new DBManagerInsertController(); // Create a new Dialog Dialog> dialog = new Dialog<>(); dialog.setTitle("Create Project"); @@ -534,6 +539,12 @@ private void handleCreateProjectPopup(ActionEvent actionEvent) { if (dialogButton == ButtonType.OK) { String projectName = nameTextField.getText(); String projectDescription = descTextField.getText(); + idbInsert.DBInsert(new ProjectModel( + projectName, + UUID.randomUUID(), + projectDescription, + new ArrayList<>() + )); return new Pair<>(projectName, projectDescription); } return null; diff --git a/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java b/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java index bb7d49b..e9f13aa 100644 --- a/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java +++ b/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java @@ -7,6 +7,7 @@ import c_interface_adapters.view_models.ProjectViewModel; import c_interface_adapters.view_models.TaskViewModel; import d_frameworks_and_drivers.database_management.DBControllers.DBManagerSearchController; +import d_frameworks_and_drivers.database_management.DBControllers.IDListsToModelList; import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.fxml.FXMLLoader; @@ -116,7 +117,27 @@ public void displayAllProjects() { @Override public void displayNewTask(UUID columnBoxID, TaskViewModel newTask) { + VBox columnNeeded = new VBox(); + for (VBox vbox : VBoxContainer) { + System.out.println("DISPLAY NEW TASKKKKKK"); + System.out.println(vbox.getId()); + System.out.println(columnBoxID.toString()); + if(vbox.getId().equals(columnBoxID.toString())){ + columnNeeded = vbox; + } + } + IDListsToModelList idListsToModelList = new IDListsToModelList(); + DBManagerSearchController dbManagerSearchController = new DBManagerSearchController(); + populateTasksForEachColumn( + columnNeeded, + idListsToModelList + .IdToTaskModelList(List.of(dbManagerSearchController + .DBColumnSearch(columnBoxID + .toString()).get(2).split(","))), + controller + ); System.out.println("hi"); + System.out.println(columnNeeded); } // public void dispayProjectDescription(ProjectModel project) { diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerInsertController.java b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerInsertController.java index a1fc432..4f4dfe2 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerInsertController.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerInsertController.java @@ -4,6 +4,7 @@ import b_application_business_rules.entity_models.ColumnModel; import b_application_business_rules.entity_models.ProjectModel; import b_application_business_rules.entity_models.TaskModel; +import b_application_business_rules.use_cases.CurrentProjectID; import b_application_business_rules.use_cases.CurrentProjectRepository; import b_application_business_rules.use_cases.project_selection_gateways.IDBInsert; @@ -19,8 +20,9 @@ public class DBManagerInsertController implements IDBInsert { - - + IDListsToModelList idListsToModelList = new IDListsToModelList(); + DBManagerSearchController dbManagerSearchController = new DBManagerSearchController(); + DBManagerRemoveController dbManagerRemoveController = new DBManagerRemoveController(); /** * Adds a project record with ProjectID, Name, Description and list of column IDs * into the Database @@ -30,11 +32,11 @@ public class DBManagerInsertController implements IDBInsert { public void DBInsert(ProjectModel projectModel) { EntityIDsToListController entityIDsToListController = new EntityIDsToListController(); - File file = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv"); + File projectFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv"); List content = new ArrayList<>(); - + System.out.println(projectFile.exists()); // Read the existing content of the CSV file into memory - try (CSVReader reader = new CSVReader(new FileReader(file))) { + try (CSVReader reader = new CSVReader(new FileReader(projectFile))) { content.addAll(reader.readAll()); } catch (Exception e) { e.printStackTrace(); @@ -53,7 +55,7 @@ public void DBInsert(ProjectModel projectModel) { content.add(data.toArray(new String[0])); // Write the updated content back to the CSV file - try (CSVWriter writer = new CSVWriter(new FileWriter(file))) { + try (CSVWriter writer = new CSVWriter(new FileWriter(projectFile))) { writer.writeAll(content); } catch (Exception e) { @@ -88,7 +90,7 @@ public void DBInsert(ColumnModel columnModel) { data.add(columnModel.getID().toString()); data.add(columnModel.getName()); data.add(entityIDsToListController.EntityIDsToList(columnModel)); - data.add(CurrentProjectRepository.getCurrentprojectrepository().getCurrentProject().getID().toString()); + data.add(CurrentProjectID.getCurrentProjectID().getSelectedProjectID().toString()); content.add(data.toArray(new String[0])); @@ -133,6 +135,31 @@ public void DBInsert(TaskModel taskModel, UUID parentColumn) { // Write the updated content back to the CSV file try (CSVWriter writer = new CSVWriter(new FileWriter(file))) { writer.writeAll(content); + + List columnRoot = dbManagerSearchController.DBColumnSearch(parentColumn.toString()); + List taskModelList = idListsToModelList.IdToTaskModelList(List.of(columnRoot.get(2))); + taskModelList.add(taskModel); + StringBuilder temp = new StringBuilder(columnRoot.get(2)); + + if(!(columnRoot.get(2).isEmpty() || columnRoot.get(2).equals("") || columnRoot.get(2)==null)){ + temp.append(","); + } + temp.append(taskModel.getID().toString()); + System.out.println("COLUMN UPDATING"); + System.out.println(temp); + + dbManagerRemoveController.DBRemoveColumn(parentColumn); + columnRoot.set(2, temp.toString()); + System.out.println("COLUMN UPDATING"); + System.out.println(List.of(columnRoot.get(2))); + DBInsert(new ColumnModel( + columnRoot.get(1), + taskModelList, + UUID.fromString(columnRoot.get(0)) + ) + ); + + } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerRemoveController.java b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerRemoveController.java index 8a8d0f8..93ef923 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerRemoveController.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerRemoveController.java @@ -6,10 +6,6 @@ import b_application_business_rules.use_cases.project_selection_gateways.IDBRemove; -import b_application_business_rules.entity_models.ColumnModel; -import b_application_business_rules.entity_models.ProjectModel; -import b_application_business_rules.entity_models.TaskModel; - import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVPrinter; @@ -18,72 +14,75 @@ import java.io.File; import java.io.FileReader; import java.io.FileWriter; +import java.util.ArrayList; import java.util.List; import java.util.UUID; public class DBManagerRemoveController implements IDBRemove { /** - * @param projectModel + * */ - public void DBRemove(ProjectModel projectModel, UUID uuid) { + public void DBRemoveProject(UUID uuid) { File tempFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv"); - tempFile.renameTo(new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/ProjectsBin.csv")); + tempFile.renameTo(new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/ProjectsBin.csv")); ProjectDBInitializer projectDBInitializer = new ProjectDBInitializer(); File newFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv"); - CsvRemovalUpdate(uuid, tempFile, newFile); + File binFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/ProjectsBin.csv"); + CsvRemovalUpdate(uuid, binFile, newFile); + binFile.renameTo(newFile); } /** - * @param taskModel + * */ - public void DBRemove(TaskModel taskModel, UUID uuid) { + public void DBRemoveColumn(UUID uuid) { File tempFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/Columns.csv"); tempFile.renameTo(new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/ColumnsBin.csv")); - ColumnDBInitializer columnDBInitializer = new ColumnDBInitializer(); + TaskDBInitializer taskDBInitializer = new TaskDBInitializer(); File newFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/Columns.csv"); - CsvRemovalUpdate(uuid, tempFile, newFile); - + File binFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/ColumnsBin.csv"); + CsvRemovalUpdate(uuid, binFile, newFile); + binFile.renameTo(newFile); } /** - * @param columnModel + * */ - public void DBRemove(ColumnModel columnModel, UUID uuid) { + public void DBRemoveTask(UUID uuid) { File tempFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv"); tempFile.renameTo(new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/TasksBin.csv")); - TaskDBInitializer taskDBInitializer = new TaskDBInitializer(); - File newFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv"); + ColumnDBInitializer columnDBInitializer = new ColumnDBInitializer(); + File newFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/TasksBin.csv"); - CsvRemovalUpdate(uuid, tempFile, newFile); + File binFile = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/TasksBin.csv"); + CsvRemovalUpdate(uuid, binFile, newFile); + binFile.renameTo(newFile); } /** * Updates the tempFile to newFile by removing one record with a given ID. * - * @param uuid - * @param tempFile - * @param newFile + * @param uuid the uuid of the record we want to exclude + * @param tempFile which in this case is the old csv file that needs to be swapped out + * @param newFile the new file we want to write changes to */ private void CsvRemovalUpdate(UUID uuid, File tempFile, File newFile) { try (FileReader fileReader = new FileReader(tempFile); - CSVParser csvParser = new CSVParser(fileReader, CSVFormat.DEFAULT.withHeader()); + CSVParser csvParser = new CSVParser(fileReader, CSVFormat.DEFAULT); FileWriter fileWriter = new FileWriter(newFile); - CSVPrinter csvPrinter = new CSVPrinter(fileWriter, CSVFormat.DEFAULT.withHeader())) { + CSVPrinter csvPrinter = new CSVPrinter(fileWriter, CSVFormat.DEFAULT)) { - // Iterate through each row in the CSV file for (CSVRecord csvRecord : csvParser) { - // Check if the current row's column value matches the value to delete - String columnValue = csvRecord.get(0); // 0 instead of String since method used for various files - if (!columnValue.equals(uuid.toString())) { - // If it does not match, write the row to the new CSV file - csvPrinter.printRecord(csvRecord); + List record = csvRecord.toList(); + if (!record.get(0).equals(uuid.toString())){ + csvPrinter.printRecord(record); } } - // Flush the CSVPrinter csvPrinter.flush(); + csvPrinter.close(); tempFile.delete(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerSearchController.java b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerSearchController.java index 8b7f9d2..641cc4b 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerSearchController.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/DBManagerSearchController.java @@ -24,6 +24,7 @@ public class DBManagerSearchController implements IDBSearch { * @return columnInfo */ public ArrayList DBColumnSearch(String id) { + System.out.println("Search id"); System.out.println(id); EntityIDsToListController entityIDsToListController = new EntityIDsToListController(); ArrayList columnInfo = new ArrayList<>(); @@ -36,16 +37,16 @@ public ArrayList DBColumnSearch(String id) { // Iterate through each CSV record until the matching ID is found for (CSVRecord csvRecord : csvParser) { - ArrayList result = new ArrayList<>(List.of(csvRecord.values())); + ArrayList result = new ArrayList<>(csvRecord.toList()); String firstHeaderValue = result.get(0).toString(); System.out.println("-----------"); System.out.println(result); - System.out.println(id); - System.out.println(firstHeaderValue.equals(id)); + System.out.println(id.trim()); + System.out.println(firstHeaderValue.equals(id.trim())); System.out.println("-----------"); // Once matching ID is found, column attributes are saved and exit loop - if (firstHeaderValue.equals(id)) { + if (firstHeaderValue.equals(id.trim())) { System.out.println("INSIDE IF FOR COLUMN SEARCH"); columnInfo.add(result.get(0).toString()); @@ -105,16 +106,21 @@ public ArrayList DBProjectSearch(String id) { public ArrayList DBTaskSearch(String id) { ArrayList taskInfo = new ArrayList<>(); String csvFilePath = "src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv"; + System.out.println("DBTaskSearch"); + System.out.println(id); // Opening and reading through the Column.csv file try (FileReader fileReader = new FileReader(csvFilePath); CSVParser csvParser = new CSVParser(fileReader, CSVFormat.DEFAULT.withHeader())) { + System.out.println("INSIDE TRY FOR DBTASK SEARCH"); // Iterate through each CSV record until the matching ID is found for (CSVRecord csvRecord : csvParser) { ArrayList result = new ArrayList<>(List.of(csvRecord.values())); String firstHeaderValue = result.get(0).toString(); + System.out.println("resultresultresultresultresult"); + System.out.println(result); // Once matching ID is found, column attributes are saved and exit loop if (firstHeaderValue.equals(id)) { taskInfo.add(csvRecord.get(0)); @@ -128,7 +134,7 @@ public ArrayList DBTaskSearch(String id) { } catch (Exception e) { e.printStackTrace(); } - + System.out.println(taskInfo); return taskInfo; } diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDstoModelController.java b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDstoModelController.java index d75d37a..fbfdff0 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDstoModelController.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDstoModelController.java @@ -54,38 +54,46 @@ public List IDstoProjectModelList() { if (!(Arrays.stream(tempColumnID).toList().get(0) == null || Arrays.stream(tempColumnID).toList().get(0).trim().isEmpty())) { for (String tempCol : tempColumnID) { //Find the correct column given the string UUID in Column.csv + System.out.println("------------IDs To Project Models"); + System.out.println(Arrays.stream(tempColumnID).toList()); + System.out.println(tempCol); ArrayList columnInfo = searchController.DBColumnSearch(tempCol); //Saving the column ID and name + System.out.println("------------ColumnInfo"); + System.out.println(columnInfo); + System.out.println(columnInfo.get(0)); UUID columnID = UUID.fromString(columnInfo.get(0)); String columnName = columnInfo.get(1); //Temporary Array of string to hold the task IDs - List tempTaskID = Arrays.stream(columnInfo.get(2).split(",")).toList(); + String[] tempTaskID = columnInfo.get(2).split(","); System.out.println("Task ID ARRAY"); System.out.println(tempTaskID); List taskModelList = new ArrayList<>(); - for (String tempTask : tempTaskID) { - System.out.println("Task ID"); - System.out.println(tempTask); - ArrayList taskInfo = searchController.DBTaskSearch(tempTask); - - System.out.println("TaskInfo"); - System.out.println(taskInfo); - UUID taskID = UUID.fromString(taskInfo.get(0)); - String taskName = taskInfo.get(1); - String taskDescription = taskInfo.get(2); - boolean isCompleted = Boolean.parseBoolean(taskInfo.get(3)); - LocalDateTime dueDate = LocalDateTime.parse(taskInfo.get(4), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); - - //Creating a TaskModel object - TaskModel newTModel = TaskModelFactory.create(taskName, taskID, taskDescription, - isCompleted, dueDate); - //Appending it to list of TaskModels - taskModelList.add(newTModel); - + if (!(Arrays.stream(tempTaskID).toList().get(0) == null || Arrays.stream(tempTaskID).toList().get(0).trim().isEmpty())) { + for (String tempTask : tempTaskID) { + System.out.println("Task ID"); + System.out.println(tempTask); + ArrayList taskInfo = searchController.DBTaskSearch(tempTask); + + System.out.println("TaskInfo"); + System.out.println(taskInfo); + UUID taskID = UUID.fromString(taskInfo.get(0)); + String taskName = taskInfo.get(1); + String taskDescription = taskInfo.get(2); + boolean isCompleted = Boolean.parseBoolean(taskInfo.get(3)); + LocalDateTime dueDate = LocalDateTime.parse(taskInfo.get(4), DateTimeFormatter.ISO_LOCAL_DATE_TIME); + + //Creating a TaskModel object + TaskModel newTModel = TaskModelFactory.create(taskName, taskID, taskDescription, + isCompleted, dueDate); + //Appending it to list of TaskModels + taskModelList.add(newTModel); + + } } //Creating a ColumnModel object ColumnModel newCModel = ColumnModelFactory.create(columnName, taskModelList, columnID); diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/IDListsToModelList.java b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/IDListsToModelList.java index 6a60f12..a9bb8dd 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/IDListsToModelList.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/IDListsToModelList.java @@ -3,6 +3,7 @@ import b_application_business_rules.entity_models.ColumnModel; import b_application_business_rules.entity_models.ProjectModel; import b_application_business_rules.entity_models.TaskModel; +import b_application_business_rules.use_cases.CurrentProjectID; import b_application_business_rules.use_cases.project_selection_gateways.IDbIdToModelList; import java.time.LocalDateTime; @@ -12,6 +13,7 @@ import java.util.UUID; public class IDListsToModelList implements IDbIdToModelList { + //DBManagerInsertController dbManagerInsertController = new DBManagerInsertController(); DBManagerSearchController dbManagerSearchController = new DBManagerSearchController(); /** * @param IDlist @@ -21,7 +23,12 @@ public List IdToColumnModelList(List IDlist) { IDlist = List.of(IDlist.get(0).split(",")); List resultColumnModels = new ArrayList<>(); System.out.println("---------IDlist"); - System.out.println(IDlist.get(0)); + System.out.println(IDlist); + + if(IDlist.get(0).equals("")){ + return getDefaultColumn(resultColumnModels); + } + for (String col : IDlist) { List temp = dbManagerSearchController.DBColumnSearch(col); System.out.println("IDs Lists To Model List"); @@ -37,21 +44,58 @@ public List IdToColumnModelList(List IDlist) { return resultColumnModels; } + private List getDefaultColumn(List resultColumnModels) { + ColumnModel defaultColumn = new ColumnModel( + "Default Column", + new ArrayList<>(), + UUID.randomUUID() + ); + resultColumnModels.add(defaultColumn); + DBManagerInsertController dbManagerInsertController = new DBManagerInsertController(); + dbManagerInsertController.DBInsert(defaultColumn); + + ArrayList oldProject = dbManagerSearchController.DBProjectSearch(CurrentProjectID + .getCurrentProjectID().getSelectedProjectID().toString()); + oldProject.set(3, defaultColumn.getID().toString()); + + DBManagerRemoveController dbManagerRemoveController = new DBManagerRemoveController(); + dbManagerRemoveController.DBRemoveProject(CurrentProjectID + .getCurrentProjectID().getSelectedProjectID()); + dbManagerInsertController.DBInsert(new ProjectModel( + oldProject.get(1), + UUID.fromString(oldProject.get(0)), + oldProject.get(2), + resultColumnModels + )); + return resultColumnModels; + } + /** * @param IDlist * @return */ public List IdToTaskModelList(List IDlist) { - IDlist = List.of(IDlist.get(0).split(",")); + //IDlist = List.of(IDlist.get(0).split(",")); List resultTaskModels = new ArrayList<>(); + + //check if list is empty first + if(IDlist.get(0)==null || IDlist.get(0).isEmpty() || IDlist.get(0).equals("")){ + return resultTaskModels; + } + System.out.println("temptemptemptemptemp"); + System.out.println(IDlist); + for (String task : IDlist) { List temp = dbManagerSearchController.DBTaskSearch(task); + System.out.println("temptemptemptemptemp"); + System.out.println(temp); + System.out.println(task); TaskModel TaskModelTemp = new TaskModel( temp.get(1), UUID.fromString(temp.get(0)), temp.get(2), !temp.get(3).isEmpty(), - LocalDateTime.parse(temp.get(4), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))); + LocalDateTime.parse(temp.get(4), DateTimeFormatter.ISO_LOCAL_DATE_TIME)); resultTaskModels.add(TaskModelTemp); } return resultTaskModels; diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/Columns.csv b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/Columns.csv index 01c2ef3..052901f 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/Columns.csv +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/Columns.csv @@ -1,4 +1,9 @@ "ColumnID","Name","Task ID's","ProjectID" "c38bd87b-9c60-4aac-85dd-10567c30af94","ahsak","7132fc12-6207-4c80-8090-4aaae619f517","d3f49ff2-0ff9-4632-ac6c-f21cefffb501" "dbd3ef27-b36b-4e50-aaf2-a53672a5d204","kkdw","","1fc2f4b1-379f-45c6-93bc-c4b88b8d0af5" -"52b90186-8db8-42c7-b714-efc2f5baaeb8","DBInsert1 Test col UI","550e8400-e29b-41d4-a716-446655440000","d3f49ff2-0ff9-4632-ac6c-f21cefffb501" \ No newline at end of file +"52b90186-8db8-42c7-b714-efc2f5baaeb8","DBInsert1 Test col UI","550e8400-e29b-41d4-a716-446655440000","d3f49ff2-0ff9-4632-ac6c-f21cefffb501" +"2ae4e0b9-331b-4b80-ae60-7fb7bf7d9cb2","t","","d3f49ff2-0ff9-4632-ac6c-f21cefffb501" +"05b8f154-162f-4e7b-ba89-6ce2c09400be","Default Column","","eaa3bc8e-02e9-468b-892e-981df97043d0" +"559423ef-1954-44aa-8976-8f42d4346f2d","NewColumn","","eaa3bc8e-02e9-468b-892e-981df97043d0" +"b443372c-9e99-432c-adf6-8b24cf8fa8d8","Default Column","e1430bda-93ef-4942-ab7b-d45f2b1bb9f6","eabfa91c-8ea9-4d20-b6ff-41dbe132a2ef" +"913fbf9d-24ce-4736-a793-91771c4a8f49","Default Column","67065e7a-3757-4aa8-a426-3885c833d43f","9a74bb2d-14e0-4abe-8a58-a404959b0af0" diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv index 711f07e..b773654 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv @@ -1,8 +1,8 @@ "ProjectID","Name","Description","Column ID's" -"d3f49ff2-0ff9-4632-ac6c-f21cefffb501","DBInsert 1","checking if the Database registers input into UI","c38bd87b-9c60-4aac-85dd-10567c30af94,52b90186-8db8-42c7-b714-efc2f5baaeb8" -"eaa3bc8e-02e9-468b-892e-981df97043d0","DBInsert 2","checking if the Database registers input into UI", -"eabfa91c-8ea9-4d20-b6ff-41dbe132a2ef","DBINSERT 3","checking if the Database registers input into UI", -"9a74bb2d-14e0-4abe-8a58-a404959b0af0","DBINSERT 4","checking if the Database registers input into UI", -"ccef01c4-a0d9-4da5-b9c4-a3a637946869","DBINSERT 5","checking if the Database registers input into UI", -"ce542f01-a7de-467d-90d0-1c1d380e0722","DBINSERT 6","checking if the Database registers input into UI", -"635e2ea8-7c2b-43db-b031-839ce82f29f1","DBINSERT 7","checking if the Database registers input into UI", \ No newline at end of file +"ccef01c4-a0d9-4da5-b9c4-a3a637946869","DBINSERT 5","checking if the Database registers input into UI","" +"ce542f01-a7de-467d-90d0-1c1d380e0722","DBINSERT 6","checking if the Database registers input into UI","" +"635e2ea8-7c2b-43db-b031-839ce82f29f1","DBINSERT 7","checking if the Database registers input into UI","" +"d3f49ff2-0ff9-4632-ac6c-f21cefffb501","DBInsert 1","checking if the Database registers input into UI","c38bd87b-9c60-4aac-85dd-10567c30af94, 52b90186-8db8-42c7-b714-efc2f5baaeb8, 2ae4e0b9-331b-4b80-ae60-7fb7bf7d9cb2" +"eaa3bc8e-02e9-468b-892e-981df97043d0","DBInsert 2","checking if the Database registers input into UI","05b8f154-162f-4e7b-ba89-6ce2c09400be, 559423ef-1954-44aa-8976-8f42d4346f2d" +"eabfa91c-8ea9-4d20-b6ff-41dbe132a2ef","DBINSERT 3","checking if the Database registers input into UI","b443372c-9e99-432c-adf6-8b24cf8fa8d8" +"9a74bb2d-14e0-4abe-8a58-a404959b0af0","DBINSERT 4","checking if the Database registers input into UI","913fbf9d-24ce-4736-a793-91771c4a8f49" diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv index fd19d0d..fb95aa8 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv @@ -1,3 +1,5 @@ "TaskID","Name","Description","Completion Status","Due Date","ColumnID" -7132fc12-6207-4c80-8090-4aaae619f517,DB Task 1,Testing,false,2022-02-16 10:22,c38bd87b-9c60-4aac-85dd-10567c30af94 -550e8400-e29b-41d4-a716-446655440000,DB Task 2,Testing,false,2022-02-16 10:22,52b90186-8db8-42c7-b714-efc2f5baaeb8 \ No newline at end of file +"7132fc12-6207-4c80-8090-4aaae619f517","DB Task 1","Testing","false",2022-02-16T10:22,"c38bd87b-9c60-4aac-85dd-10567c30af94" +"550e8400-e29b-41d4-a716-446655440000","DB Task 2","Testing","false",2022-02-16T10:22,"52b90186-8db8-42c7-b714-efc2f5baaeb8" +"e1430bda-93ef-4942-ab7b-d45f2b1bb9f6","haska","asa","false",2023-08-11T00:00,"b443372c-9e99-432c-adf6-8b24cf8fa8d8" +"67065e7a-3757-4aa8-a426-3885c833d43f","TestTask4","cscs","false","2023-08-18T00:00","913fbf9d-24ce-4736-a793-91771c4a8f49"