- java.lang.Object
-
- services.CsvDataService
-
- All Implemented Interfaces:
IFileDataService
public class CsvDataService extends java.lang.Object implements IFileDataService
TheCsvDataServiceclass implements theIFileDataServiceinterface and provides methods for reading and writing data from/to CSV files.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<java.lang.String>changeProjectTitleRequestCsvHeadersThe list of headers for the CSV file that stores change project title request data.private static java.util.List<java.lang.String>fypCoordinatorCsvHeadersThe list of headers for the CSV file that stores FYP coordinator data.private static java.util.List<java.lang.String>projectCsvHeadersThe list of headers for the CSV file that stores project data.private static java.util.List<java.lang.String>requestCsvHeadersThe list of headers for the CSV file that stores request data.private static java.util.List<java.lang.String>studentCsvHeadersThe list of headers for the CSV file that stores student data.private static java.util.List<java.lang.String>supervisorCsvHeadersThe list of headers for the CSV file that stores supervisor data.private static java.util.List<java.lang.String>transferStudentRequestCsvHeadersThe list of headers for the CSV file that stores transfer student request data.private static java.util.List<java.lang.String>userCsvHeadersThe list of headers for the CSV file that stores user data.
-
Constructor Summary
Constructors Constructor Description CsvDataService()Constructs an instance of theCsvDataServiceclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexportFYPCoordinatorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath, java.lang.String fypCoordinatorsFilePath, java.util.Map<java.lang.String,FYPCoordinator> fypCoordinatorMap)Exports FYP Coordinator data to the specified file paths.booleanexportProjectData(java.lang.String projectsFilePath, java.util.Map<java.lang.Integer,Project> projectMap)Exports project data to the specified file path.booleanexportRequestData(java.lang.String requestsFilePath, java.lang.String transferStudentRequestsFilePath, java.lang.String changeProjectTitleRequestsFilePath, java.util.Map<java.lang.Integer,Request> requestMap)Exports request data to the specified file paths.booleanexportStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath, java.util.Map<java.lang.String,Student> studentMap)Exports student data to the specified file paths.booleanexportSupervisorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath, java.util.Map<java.lang.String,Supervisor> supervisorMap)Exports supervisor data to the specified file paths.java.util.Map<java.lang.String,FYPCoordinator>importFYPCoordinatorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath, java.lang.String fypCoordinatorsFilePath)Imports FYP Coordinator data from the specified file paths.java.util.Map<java.lang.Integer,Project>importProjectData(java.lang.String projectsFilePath, java.lang.String usersFilePath, java.lang.String studentsFilePath, java.lang.String supervisorsFilePath, java.lang.String fypCoordinatorsFilePath)Imports project data from the specified file paths.java.util.Map<java.lang.Integer,Request>importRequestData(java.lang.String requestsFilePath, java.lang.String transferStudentRequestsFilePath, java.lang.String changeProjectTitleRequestsFilePath)Imports request data from the specified file paths.java.util.Map<java.lang.String,Student>importStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath)Imports student data from the specified file paths.java.util.Map<java.lang.String,Supervisor>importSupervisorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath)Imports supervisor data from the specified file paths.private java.util.Map<java.lang.String,java.lang.String>parseUserRow(java.lang.String[] userRow)Parses a string array containing user data and returns a map of user information.java.util.List<java.lang.String[]>readCsvFile(java.lang.String filePath, java.util.List<java.lang.String> headers)Reads data from the CSV file located at the given file path and returns it as a list of string arrays.booleanwriteCsvFile(java.lang.String filePath, java.util.List<java.lang.String> headers, java.util.List<java.lang.String> lines)Writes the given data to a CSV file located at the given file path.
-
-
-
Field Detail
-
userCsvHeaders
private static java.util.List<java.lang.String> userCsvHeaders
The list of headers for the CSV file that stores user data.
-
studentCsvHeaders
private static java.util.List<java.lang.String> studentCsvHeaders
The list of headers for the CSV file that stores student data.
-
supervisorCsvHeaders
private static java.util.List<java.lang.String> supervisorCsvHeaders
The list of headers for the CSV file that stores supervisor data.
-
fypCoordinatorCsvHeaders
private static java.util.List<java.lang.String> fypCoordinatorCsvHeaders
The list of headers for the CSV file that stores FYP coordinator data.
-
projectCsvHeaders
private static java.util.List<java.lang.String> projectCsvHeaders
The list of headers for the CSV file that stores project data.
-
requestCsvHeaders
private static java.util.List<java.lang.String> requestCsvHeaders
The list of headers for the CSV file that stores request data.
-
transferStudentRequestCsvHeaders
private static java.util.List<java.lang.String> transferStudentRequestCsvHeaders
The list of headers for the CSV file that stores transfer student request data.
-
changeProjectTitleRequestCsvHeaders
private static java.util.List<java.lang.String> changeProjectTitleRequestCsvHeaders
The list of headers for the CSV file that stores change project title request data.
-
-
Constructor Detail
-
CsvDataService
public CsvDataService()
Constructs an instance of theCsvDataServiceclass.
-
-
Method Detail
-
readCsvFile
public java.util.List<java.lang.String[]> readCsvFile(java.lang.String filePath, java.util.List<java.lang.String> headers)Reads data from the CSV file located at the given file path and returns it as a list of string arrays.- Parameters:
filePath- the file path of the CSV file to readheaders- the list of headers for the CSV file- Returns:
- a list of string arrays containing the CSV data
-
writeCsvFile
public boolean writeCsvFile(java.lang.String filePath, java.util.List<java.lang.String> headers, java.util.List<java.lang.String> lines)Writes the given data to a CSV file located at the given file path.- Parameters:
filePath- the file path of the CSV file to writeheaders- the list of headers for the CSV filelines- the list of lines to write to the CSV file- Returns:
- true if the data is written successfully, false otherwise
-
parseUserRow
private java.util.Map<java.lang.String,java.lang.String> parseUserRow(java.lang.String[] userRow)
Parses a string array containing user data and returns a map of user information.- Parameters:
userRow- the string array containing the user data- Returns:
- a map of user information, where the keys are "userID", "password", "email", "role", and "name" and the values are the corresponding values in the userRow array
-
importStudentData
public java.util.Map<java.lang.String,Student> importStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath)
Description copied from interface:IFileDataServiceImports student data from the specified file paths.- Specified by:
importStudentDatain interfaceIFileDataService- Parameters:
usersFilePath- the file path of the users filestudentsFilePath- the file path of the students file- Returns:
- a
MapofStudentobjects with their IDs as keys
-
exportStudentData
public boolean exportStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath, java.util.Map<java.lang.String,Student> studentMap)Description copied from interface:IFileDataServiceExports student data to the specified file paths.- Specified by:
exportStudentDatain interfaceIFileDataService- Parameters:
usersFilePath- the file path of the users filestudentsFilePath- the file path of the students filestudentMap- aMapofStudentobjects with their IDs as keys- Returns:
- true if the data was exported successfully, false otherwise
-
importSupervisorData
public java.util.Map<java.lang.String,Supervisor> importSupervisorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath)
Description copied from interface:IFileDataServiceImports supervisor data from the specified file paths.- Specified by:
importSupervisorDatain interfaceIFileDataService- Parameters:
usersFilePath- the file path of the users filesupervisorsFilePath- the file path of the supervisors file- Returns:
- a
MapofSupervisorobjects with their IDs as keys
-
exportSupervisorData
public boolean exportSupervisorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath, java.util.Map<java.lang.String,Supervisor> supervisorMap)Description copied from interface:IFileDataServiceExports supervisor data to the specified file paths.- Specified by:
exportSupervisorDatain interfaceIFileDataService- Parameters:
usersFilePath- the file path of the users filesupervisorsFilePath- the file path of the supervisors filesupervisorMap- aMapofSupervisorobjects with their IDs as keys- Returns:
- true if the data was exported successfully, false otherwise
-
importFYPCoordinatorData
public java.util.Map<java.lang.String,FYPCoordinator> importFYPCoordinatorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath, java.lang.String fypCoordinatorsFilePath)
Description copied from interface:IFileDataServiceImports FYP Coordinator data from the specified file paths.- Specified by:
importFYPCoordinatorDatain interfaceIFileDataService- Parameters:
usersFilePath- the file path of the users filesupervisorsFilePath- the file path of the supervisors filefypCoordinatorsFilePath- the file path of the FYP Coordinators file- Returns:
- a
MapofFYPCoordinatorobjects with their IDs as keys
-
exportFYPCoordinatorData
public boolean exportFYPCoordinatorData(java.lang.String usersFilePath, java.lang.String supervisorsFilePath, java.lang.String fypCoordinatorsFilePath, java.util.Map<java.lang.String,FYPCoordinator> fypCoordinatorMap)Description copied from interface:IFileDataServiceExports FYP Coordinator data to the specified file paths.- Specified by:
exportFYPCoordinatorDatain interfaceIFileDataService- Parameters:
usersFilePath- the file path of the users filesupervisorsFilePath- the file path of the supervisors filefypCoordinatorsFilePath- the file path of the FYP Coordinators filefypCoordinatorMap- aMapofFYPCoordinatorobjects with their IDs as keys- Returns:
- true if the data was exported successfully, false otherwise
-
importProjectData
public java.util.Map<java.lang.Integer,Project> importProjectData(java.lang.String projectsFilePath, java.lang.String usersFilePath, java.lang.String studentsFilePath, java.lang.String supervisorsFilePath, java.lang.String fypCoordinatorsFilePath)
Description copied from interface:IFileDataServiceImports project data from the specified file paths.- Specified by:
importProjectDatain interfaceIFileDataService- Parameters:
projectsFilePath- the file path of the projects fileusersFilePath- the file path of the users filestudentsFilePath- the file path of the students filesupervisorsFilePath- the file path of the supervisors filefypCoordinatorsFilePath- the file path of the FYP Coordinators file- Returns:
- a
MapofProjectobjects with their IDs as keys
-
exportProjectData
public boolean exportProjectData(java.lang.String projectsFilePath, java.util.Map<java.lang.Integer,Project> projectMap)Description copied from interface:IFileDataServiceExports project data to the specified file path.- Specified by:
exportProjectDatain interfaceIFileDataService- Parameters:
projectsFilePath- the file path of the projects fileprojectMap- aMapofProjectobjects with their IDs as keys- Returns:
- true if the data was exported successfully, false otherwise
-
importRequestData
public java.util.Map<java.lang.Integer,Request> importRequestData(java.lang.String requestsFilePath, java.lang.String transferStudentRequestsFilePath, java.lang.String changeProjectTitleRequestsFilePath)
Description copied from interface:IFileDataServiceImports request data from the specified file paths.- Specified by:
importRequestDatain interfaceIFileDataService- Parameters:
requestsFilePath- the file path of the requests filetransferStudentRequestsFilePath- the file path of the transfer student requests filechangeProjectTitleRequestsFilePath- the file path of the change project title requests file- Returns:
- a
MapofRequestobjects with their IDs as keys
-
exportRequestData
public boolean exportRequestData(java.lang.String requestsFilePath, java.lang.String transferStudentRequestsFilePath, java.lang.String changeProjectTitleRequestsFilePath, java.util.Map<java.lang.Integer,Request> requestMap)Description copied from interface:IFileDataServiceExports request data to the specified file paths.- Specified by:
exportRequestDatain interfaceIFileDataService- Parameters:
requestsFilePath- the file path of the requests filetransferStudentRequestsFilePath- the file path of the transfer student requests filechangeProjectTitleRequestsFilePath- the file path of the change project title requests filerequestMap- aMapofRequestobjects with their IDs as keys- Returns:
- true if the data was exported successfully, false otherwise
-
-