- java.lang.Object
-
- services.CsvDataService
-
- All Implemented Interfaces:
IFileDataService
public class CsvDataService extends java.lang.Object implements IFileDataService
TheCsvDataService
class implements theIFileDataService
interface 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>
changeProjectTitleRequestCsvHeaders
The list of headers for the CSV file that stores change project title request data.private static java.util.List<java.lang.String>
fypCoordinatorCsvHeaders
The list of headers for the CSV file that stores FYP coordinator data.private static java.util.List<java.lang.String>
projectCsvHeaders
The list of headers for the CSV file that stores project data.private static java.util.List<java.lang.String>
requestCsvHeaders
The list of headers for the CSV file that stores request data.private static java.util.List<java.lang.String>
studentCsvHeaders
The list of headers for the CSV file that stores student data.private static java.util.List<java.lang.String>
supervisorCsvHeaders
The list of headers for the CSV file that stores supervisor data.private static java.util.List<java.lang.String>
transferStudentRequestCsvHeaders
The list of headers for the CSV file that stores transfer student request data.private static java.util.List<java.lang.String>
userCsvHeaders
The list of headers for the CSV file that stores user data.
-
Constructor Summary
Constructors Constructor Description CsvDataService()
Constructs an instance of theCsvDataService
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
exportFYPCoordinatorData(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.boolean
exportProjectData(java.lang.String projectsFilePath, java.util.Map<java.lang.Integer,Project> projectMap)
Exports project data to the specified file path.boolean
exportRequestData(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.boolean
exportStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath, java.util.Map<java.lang.String,Student> studentMap)
Exports student data to the specified file paths.boolean
exportSupervisorData(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.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.
-
-
-
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 theCsvDataService
class.
-
-
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:IFileDataService
Imports student data from the specified file paths.- Specified by:
importStudentData
in interfaceIFileDataService
- Parameters:
usersFilePath
- the file path of the users filestudentsFilePath
- the file path of the students file- Returns:
- a
Map
ofStudent
objects 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:IFileDataService
Exports student data to the specified file paths.- Specified by:
exportStudentData
in interfaceIFileDataService
- Parameters:
usersFilePath
- the file path of the users filestudentsFilePath
- the file path of the students filestudentMap
- aMap
ofStudent
objects 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:IFileDataService
Imports supervisor data from the specified file paths.- Specified by:
importSupervisorData
in interfaceIFileDataService
- Parameters:
usersFilePath
- the file path of the users filesupervisorsFilePath
- the file path of the supervisors file- Returns:
- a
Map
ofSupervisor
objects 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:IFileDataService
Exports supervisor data to the specified file paths.- Specified by:
exportSupervisorData
in interfaceIFileDataService
- Parameters:
usersFilePath
- the file path of the users filesupervisorsFilePath
- the file path of the supervisors filesupervisorMap
- aMap
ofSupervisor
objects 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:IFileDataService
Imports FYP Coordinator data from the specified file paths.- Specified by:
importFYPCoordinatorData
in 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
Map
ofFYPCoordinator
objects 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:IFileDataService
Exports FYP Coordinator data to the specified file paths.- Specified by:
exportFYPCoordinatorData
in 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
- aMap
ofFYPCoordinator
objects 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:IFileDataService
Imports project data from the specified file paths.- Specified by:
importProjectData
in 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
Map
ofProject
objects 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:IFileDataService
Exports project data to the specified file path.- Specified by:
exportProjectData
in interfaceIFileDataService
- Parameters:
projectsFilePath
- the file path of the projects fileprojectMap
- aMap
ofProject
objects 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:IFileDataService
Imports request data from the specified file paths.- Specified by:
importRequestData
in 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
Map
ofRequest
objects 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:IFileDataService
Exports request data to the specified file paths.- Specified by:
exportRequestData
in 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
- aMap
ofRequest
objects with their IDs as keys- Returns:
- true if the data was exported successfully, false otherwise
-
-