Skip to content

Commit

Permalink
Merge pull request #83 from CSC207-2023Y-UofT/76-finishing-database-l…
Browse files Browse the repository at this point in the history
…ayer-testing-documentation-and-implementation

76 intermediate update of documentation and testing
  • Loading branch information
igor-kan authored Aug 16, 2023
2 parents e8d43bd + 6433967 commit bf6acc8
Show file tree
Hide file tree
Showing 53 changed files with 1,506 additions and 1,626 deletions.
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ javafx {

dependencies {

testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
testImplementation 'org.junit.platform:junit-platform-launcher:1.10.0-M1'
// https://mvnrepository.com/artifact/com.opencsv/opencsv
implementation group: 'com.opencsv', name: 'opencsv', version: '3.7'
implementation group: 'com.opencsv', name: 'opencsv', version: '5.7.1'
implementation 'org.apache.commons:commons-csv:1.10.0'
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import c_interface_adapters.ProjectSelectionPresenter;
import d_frameworks_and_drivers.database_management.DatabaseInitializer.DBInitializer;
import d_frameworks_and_drivers.database_management.ProjectUUIDArray;

import javafx.application.Application;

import java.util.UUID;

public class Main {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,17 @@ public void addTaskModelToPosition(TaskModel newTaskModel, int position) {
* remove is not in the column model.
*/
public void removeTaskModel(TaskModel taskModelToRemove) throws NoSuchElementException {
// the java.util.List.remove method returns a bool,
// indicating whether the object was removed or not.
// If it wasn't removed, we want to throw an exception,
// saying that the task model isn't in the column model, thus, it can't be
// removed.
// If it was removed, we don't have to do anything extra.
if (!this.taskModels.remove(taskModelToRemove)) {
// the java.util.List.remove method returns a bool,
// indicating whether the object was removed or not.
// If it wasn't removed, we want to throw an exception,
// saying that the task model isn't in the column model, thus, it can't be
// removed.
// If it was removed, we don't have to do anything extra.
throw new NoSuchElementException(
"The task model " + taskModelToRemove.toString() + " is not in this column model");
}

}

/**
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/com/example/kanbangui/HelloApplication.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/com/example/kanbangui/HelloController.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public Map<String, String> getStringToStringMap(int keyColumn, int valueColumn){
/**
* Returns a Mapping from the string of key column field to the corresponding record
* @param keyColumn index of csv key column with string values only
* @param valueColumn index of csv value column
* @return Mapping from the string of key column field to the corresponding record
*/
public Map<String, CSVRecord> getStringToRecordMap(int keyColumn){
Expand All @@ -110,6 +109,32 @@ public Map<String, CSVRecord> getStringToRecordMap(int keyColumn){
}
return outputMap;
}


/**
* Returns a Mapping from the string of key column field to the corresponding record
* @param keyColumn index of csv key column with string values only
* @return Mapping from the string of key column field to the corresponding record
*/
public Map<String, CSVRecord> getStringToRecordMap(String keyColumn){
Map<String, CSVRecord> outputMap = new HashMap<>();
// Try with resource: create FileWriter, CSVParser object as resources - closes automatically
try (FileReader fileReader = new FileReader(csvFile);
CSVParser csvParser = new CSVParser(fileReader, CSVFormat.DEFAULT.withHeader().withNullString(""))){
// Iterate through each CSV record/row and append outputMap
for (CSVRecord csvRecord : csvParser) {
if (!(csvRecord.get(keyColumn) instanceof String)) {
throw new IllegalArgumentException("The key column contains non-string values. Cannot map.");
}
outputMap.put(csvRecord.get(keyColumn), csvRecord);

}

} catch (IOException e){
throw new RuntimeException("Error getting String-to-String map from CSV file: " + e.getMessage(), e);
}
return outputMap;
}
/**
* Close the CSVParser when the CSVSearcher is no longer needed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.util.*;

/**
Expand Down Expand Up @@ -119,6 +120,35 @@ public List<CSVRecord> getRecordsList(int fieldIndex, List<String> searchKeys){
}
}

/**
* Returns a list of csv records given field where to do the search and search keys list.
* @param field field where to do the search
* @param searchKeys search keys list
* @return list of csv records
*/
public List<CSVRecord> getRecordsList(String field, List<String> searchKeys){
List<CSVRecord> output = new ArrayList<>();
// Try with resource: create FileWriter, CSVParser object as resources - closes automatically
try (FileReader fileReader = new FileReader(csvFile);
DBMapper csvMapper = new DBMapper(csvFile.getPath());
CSVParser csvParser = new CSVParser(fileReader, CSVFormat.DEFAULT.withHeader().withNullString(""))) {
// first, generate map of from column with search keys to records
Map<String,CSVRecord> strRecordMap = csvMapper.getStringToRecordMap(field);
// Generate a list of values from the map using searched keys
for (String key : searchKeys) {
CSVRecord record = strRecordMap.get(key);
if (record != null) {
output.add(record);
}
}
return output;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
* Close the CSVParser when the CSVSearcher is no longer needed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DBManagerInsertController implements IDBInsert {
* Adds a project record with ProjectID, Name, Description and list of column IDs
* into the Database
*
* @param projectModel
* @param projectModel project model entity to be inserted
*/
public void DBInsert(ProjectModel projectModel) {

Expand Down Expand Up @@ -67,7 +67,7 @@ public void DBInsert(ProjectModel projectModel) {
* Adds a column record with fields "ColumnID","Name",
* and "Task ID's" into the Database
*
* @param columnModel
* @param columnModel column model entity to be inserted
*/
public void DBInsert(ColumnModel columnModel) {
// Try with resources: CSVWriter
Expand Down Expand Up @@ -148,7 +148,7 @@ public void DBInsert(TaskModel taskModel, UUID parentColumn) {

/**
* Adds a record of unique ID into the Database
* @param uuid
* @param uuid uuuid to be inserted
*/
public void DBInsert(UUID uuid) {
// Try with resources: CSVWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* A class responsible for managing the removal of data from the database.
*/
public class DBManagerRemoveController implements IDBRemove {
/**
* Removes a project entry from the database.
*
* This method takes the UUID of the project to be removed. It renames the Projects.csv file to ProjectsBin.csv to
* temporarily move the file aside. It initializes a ProjectDBInitializer to prepare for the CSV removal and update
* operation. Then, it calls CsvRemovalUpdate method to update the CSV file with the specified UUID removed. Finally,
* it renames ProjectsBin.csv back to Projects.csv after the update.
*
* @param uuid The UUID of the project to be removed from the database.
*/
public void DBRemoveProject(UUID uuid) {
File tempFile = new File("src/main/java/d_frameworks_and_drivers/" +
Expand All @@ -38,7 +47,13 @@ public void DBRemoveProject(UUID uuid) {
}

/**
* Removes a column entry from the database.
*
* Similar to DBRemoveProject, this method removes a column entry specified by the UUID. It performs similar steps
* such as temporarily renaming the Columns.csv file, initializing a ColumnDBInitializer, updating the CSV file,
* and renaming it back.
*
* @param uuid The UUID of the column to be removed from the database.
*/
public void DBRemoveColumn(UUID uuid) {
File tempFile = new File("src/main/java/d_frameworks_and_drivers/" +
Expand All @@ -56,7 +71,13 @@ public void DBRemoveColumn(UUID uuid) {
}

/**
* Removes a task entry from the database.
*
* Similar to the previous methods, this method removes a task entry specified by the UUID. It temporarily renames
* the Tasks.csv file, initializes a TaskDBInitializer, updates the CSV file, and renames it back.
* Additionally, it prints debug messages before and after the removal process.
*
* @param uuid The UUID of the task to be removed from the database.
*/
public void DBRemoveTask(UUID uuid) {
System.out.println("INSIDE DB REMOVE Task");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public ArrayList<String> DBColumnSearch(String id) {
}

/**
*
* @param id
* @return
* Searches project.csv for the entry with the UUID matching the id parameter
* then reads that line and converts it to an arraylist, with first element containing UUID,
* second element containing name and third - description, forth - containing list of column UUIDs
* * @param id project UUID ID as string
* @return arraylist of strings with project values from database
*/
public ArrayList<String> DBProjectSearch(String id) {
ArrayList<String> projectInfo = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public List<ProjectModel> IDstoProjectModelList() {
}

/**
*
* @param projectUUID
* @return
* Returns a project model given its UUID ID.
* @param projectUUID UUID ID
* @return a project model
*/
public ProjectModel IDsToProjectModel(UUID projectUUID) {
ArrayList<String> DbEntry = searchController.DBProjectSearch(projectUUID.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public class IDListsToModelList implements IDbIdToModelList {
//DBManagerInsertController dbManagerInsertController = new DBManagerInsertController();
DBManagerSearchController dbManagerSearchController = new DBManagerSearchController();
/**
* @param IDlist
* @return
* Returns a list of column entity models given a list of UUID IDs as strings for the columns.
* @param IDlist a list of UUID IDs as strings for the columns
* @return a list of column entity models
*/
public List<ColumnModel> IdToColumnModelList(List<String> IDlist) {
IDlist = List.of(IDlist.get(0).split(","));
Expand All @@ -44,6 +45,18 @@ public List<ColumnModel> IdToColumnModelList(List<String> IDlist) {
return resultColumnModels;
}

/**
* Creates and inserts a default column into the list of column models.
*
* This method generates a new default column with the name "Default Column" and an empty list of task models.
* The generated default column is added to the provided list of column models. Additionally, it inserts the default
* column into the database and updates the project's column list with the default column's ID. The method then
* removes the existing project entry from the database and replaces it with an updated entry containing the new
* default column ID and the provided list of column models.
*
* @param resultColumnModels The list of column models to which the default column will be added.
* @return The updated list of column models with the added default column.
*/
private List<ColumnModel> getDefaultColumn(List<ColumnModel> resultColumnModels) {
ColumnModel defaultColumn = new ColumnModel(
"Default Column",
Expand Down Expand Up @@ -71,8 +84,9 @@ private List<ColumnModel> getDefaultColumn(List<ColumnModel> resultColumnModels)
}

/**
* @param IDlist
* @return
* Returns a list of task entity models given a list of UUID IDs as strings for the tasks.
* @param IDlist a list of UUID IDs as strings for the tasks
* @return a list of task entity models
*/
public List<TaskModel> IdToTaskModelList(List<String> IDlist) {
//IDlist = List.of(IDlist.get(0).split(","));
Expand Down Expand Up @@ -108,8 +122,9 @@ public List<TaskModel> IdToTaskModelList(List<String> IDlist) {
}

/**
* @param IDlist
* @return
* Returns a list of project entity models given a list of UUID IDs as strings for the projects.
* @param IDlist a list of UUID IDs as strings for the projects
* @return a list of project entity models
*/
public List<ProjectModel> IdToProjectModelList(List<String> IDlist) {
IDlist = List.of(IDlist.get(0).split(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import java.io.File;
import java.io.FileWriter;


public class ColumnDBInitializer {
String[] ColumnHeaders = {"ColumnID", "Name", "Task ID's"};

/**
* Initializes column csv file for database with the above headers.
*/
public ColumnDBInitializer() {
// create CSVWriter object filewriter object as parameter
File file = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Columns/Columns.csv");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

public class DBInitializer {
String [] DBNames = {"Projects", "Columns", "Tasks"};

CSVWriter writer;
public DBInitializer(){
{
for (String s : DBNames) {
try {
writer = new CSVWriter(new FileWriter("./DatabaseFiles/" + s + "/" + s + ".csv"));
writer = new CSVWriter(new FileWriter("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/" + s + "/" + s + ".csv"));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
public class ProjectDBInitializer {
String [] ProjectHeaders = {"ProjectID", "Name", "Description", "Column ID's"};

/**
* Initializes project csv file for database with the above headers.
*/
public ProjectDBInitializer() {
// create CSVWriter object filewriter object as parameter
File file = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Projects/Projects.csv");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import java.io.FileWriter;

public class TaskDBInitializer {
String[] TaskHeaders = {"TaskID", "Name", "Description", "Completion Status", "Due Date"};
String[] TaskHeaders = {"TaskID", "Name", "Description", "Completion Status", "Due Date","ColumnID"};

/**
* Initializes tasks csv file for database with the above headers.
*/
public TaskDBInitializer() {
// create CSVWriter object filewriter object as parameter
File file = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/Tasks/Tasks.csv");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
public class UniqueIDsInitializer {
String [] IdsDbHeaders = {"UUID", "State"};

/**
* Initializes UUID csv file for database with the above headers.
*/
public UniqueIDsInitializer() {
// create CSVWriter object filewriter object as parameter
File file = new File("src/main/java/d_frameworks_and_drivers/database_management/DatabaseFiles/UniqueIDs/UniqueIDs.csv");
Expand Down
Loading

0 comments on commit bf6acc8

Please sign in to comment.