Skip to content

Commit

Permalink
Corrected DB errors and implement full scale functionality as well as…
Browse files Browse the repository at this point in the history
… a singleton design current ID class
  • Loading branch information
alexolowo committed Aug 12, 2023
1 parent 03e5153 commit 23fa27a
Show file tree
Hide file tree
Showing 22 changed files with 255 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void deleteProject(UUID ID) {

// List<String> 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 :|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public void deleteTask() {
// initialize controller
IDBRemove removeTask = new DBManagerRemoveController();
// remove task from database
removeTask.DBRemove(taskModel, taskID);
removeTask.DBRemoveTask(taskID);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -51,6 +53,7 @@ public ProjectViewingAndModificationInteractor(ProjectViewingAndModificationOutp
@Override
public void removeCurrentProject() {
currentProjectRepository.removeCurrentProject();
currentProjectID.removeCurrentProjectID();
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/c_interface_adapters/ProjectSelectionPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +48,7 @@ public class ProjectSelectionPresenter extends Application implements ProjectSel
private ProjectSelectionViewModel projectSelectionViewModel;
private ProjectSelectionController controller;
List<ProjectModel> AllProjectsList = new ArrayList<>();
EntityIDstoModelController entityIDstoModelController = new EntityIDstoModelController();



Expand Down Expand Up @@ -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<Pair<String, String>> dialog = new Dialog<>();
dialog.setTitle("Create Project");
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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<String[]> 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();
Expand All @@ -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) {

Expand Down Expand Up @@ -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]));

Expand Down Expand Up @@ -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<String> columnRoot = dbManagerSearchController.DBColumnSearch(parentColumn.toString());
List<TaskModel> 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();
Expand Down
Loading

0 comments on commit 23fa27a

Please sign in to comment.