diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVMapper.java b/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVMapper.java index 28c7372..9ff3e10 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVMapper.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVMapper.java @@ -88,7 +88,6 @@ public Map 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 getStringToRecordMap(int keyColumn){ diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVSearcher.java b/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVSearcher.java index e675b02..7f7fc44 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVSearcher.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBAdapters/CSVSearcher.java @@ -38,10 +38,11 @@ private void openResources() throws IOException { } /** - * Searches for and returns csv record corresponding to field value given field/column index + * Searches for and returns csv record corresponding to field value given column header string * - * @param fieldIndex - * @param fieldValue + * @param fieldIndex field where to do the search + * @param fieldValue search keys list + * @return csv record */ public CSVRecord getRecord(int fieldIndex, String fieldValue) throws IOException { // Try with resource: create FileWriter, CSVParser object as resources - closes automatically @@ -66,8 +67,9 @@ public CSVRecord getRecord(int fieldIndex, String fieldValue) throws IOException /** * Searches for and returns csv record corresponding to field value given column header string * - * @param fieldIndex - * @param fieldValue + * @param keyHeader field where to do the search + * @param fieldValue search keys list + * @return csv record */ public CSVRecord getRecord(String keyHeader, String fieldValue) throws IOException { // Try with resource: create FileWriter, CSVParser object as resources - closes automatically @@ -89,10 +91,10 @@ public CSVRecord getRecord(String keyHeader, String fieldValue) throws IOExcepti } /** - * - * @param fieldIndex - * @param searchKeys - * @return + * Returns a list of csv records given field where to do the search and search keys list. + * @param fieldIndex field where to do the search + * @param searchKeys search keys list + * @return list of csv records */ public List getRecordsList(int fieldIndex, List searchKeys){ List output = new ArrayList<>(); @@ -117,13 +119,34 @@ public List getRecordsList(int fieldIndex, List 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 getRecordsList(String field, List searchKeys){ + List output = new ArrayList<>(); + // Try with resource: create FileWriter, CSVParser object as resources - closes automatically + try (FileReader fileReader = new FileReader(csvFile); + CSVMapper csvMapper = new CSVMapper(csvFile.getPath()); + CSVParser csvParser = new CSVParser(fileReader, CSVFormat.DEFAULT.withHeader().withNullString(""))) { + // first, generate map of from column with search keys to records + Map 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. 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..f87b7cc 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 @@ -25,7 +25,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) { @@ -65,7 +65,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 @@ -141,7 +141,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 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..6730470 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 @@ -23,6 +23,7 @@ public class DBManagerRemoveController implements IDBRemove { /** + * * @param projectModel */ public void DBRemove(ProjectModel projectModel, UUID uuid) { 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..9d481c0 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 @@ -62,8 +62,11 @@ public ArrayList 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 DBProjectSearch(String id) { ArrayList projectInfo = new ArrayList<>(); 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..5a9d842 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 @@ -105,8 +105,9 @@ public List 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 DbEntry = searchController.DBProjectSearch(projectUUID.toString()); 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..11c3460 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 @@ -14,8 +14,9 @@ public class IDListsToModelList implements IDbIdToModelList { 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 IdToColumnModelList(List IDlist) { IDlist = List.of(IDlist.get(0).split(",")); @@ -38,8 +39,9 @@ public List IdToColumnModelList(List IDlist) { } /** - * @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 IdToTaskModelList(List IDlist) { IDlist = List.of(IDlist.get(0).split(",")); @@ -58,8 +60,9 @@ public List IdToTaskModelList(List 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 IdToProjectModelList(List IDlist) { IDlist = List.of(IDlist.get(0).split(",")); diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ColumnDBInitializer.java b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ColumnDBInitializer.java index 115c6b4..a2935a0 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ColumnDBInitializer.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ColumnDBInitializer.java @@ -5,9 +5,13 @@ import java.io.File; import java.io.FileWriter; + public class ColumnDBInitializer { String[] ColumnHeaders = {"ColumnID", "Name", "Task ID's", "ProjectID"}; + /** + * 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"); diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/DBInitializer.java b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/DBInitializer.java index 96a746b..e28a716 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/DBInitializer.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/DBInitializer.java @@ -10,6 +10,7 @@ public class DBInitializer { String [] DBNames = {"Projects", "Columns", "Tasks"}; + CSVWriter writer; public DBInitializer(){ { diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ProjectDBInitializer.java b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ProjectDBInitializer.java index 038bfdd..c33a789 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ProjectDBInitializer.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/ProjectDBInitializer.java @@ -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"); diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/TaskDBInitializer.java b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/TaskDBInitializer.java index cc51151..5ad7c3a 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/TaskDBInitializer.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/TaskDBInitializer.java @@ -8,6 +8,9 @@ public class TaskDBInitializer { 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"); diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/UniqueIDsInitializer.java b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/UniqueIDsInitializer.java index 93b075a..8ea15ce 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/UniqueIDsInitializer.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DatabaseInitializer/UniqueIDsInitializer.java @@ -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");