- 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>
campCsvHeaders
List of headers for the CSV file that stores camp data.private static java.util.List<java.lang.String>
committeeCsvHeaders
List of headers for the CSV file that stores camp committee member data.private static java.util.List<java.lang.String>
enquiryCsvHeaders
List of headers for the CSV file that stores enquiry data.private static java.util.List<java.lang.String>
staffCsvHeaders
List of headers for the CSV file that stores staff data.private static java.util.List<java.lang.String>
studentCsvHeaders
List of headers for the CSV file that stores student data.private static java.util.List<java.lang.String>
suggestionCsvHeaders
List of headers for the CSV file that stores suggestion data.private static java.util.List<java.lang.String>
userCsvHeaders
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
exportCampData(java.lang.String campsFilePath, java.util.Map<java.lang.Integer,Camp> campMap)
Exports camp data to the specified file.boolean
exportCommitteeData(java.lang.String usersFilePath, java.lang.String committeesFilePath, java.util.Map<java.lang.String,Committee> committeeMap)
Exports committee data to specified files.boolean
exportEnquiryData(java.lang.String enquiryFilePath, java.util.Map<java.lang.Integer,Enquiry> enquiryMap)
Exports enquiry data to the specified file.boolean
exportStaffData(java.lang.String usersFilePath, java.lang.String staffsFilePath, java.util.Map<java.lang.String,Staff> staffMap)
Exports staff data to specified files.boolean
exportStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath, java.util.Map<java.lang.String,Student> studentMap)
Exports student data to specified files.boolean
exportSuggestionData(java.lang.String suggestionFilePath, java.util.Map<java.lang.Integer,Suggestion> suggestionMap)
Exports suggestion data to the specified file.java.util.Map<java.lang.Integer,Camp>
importCampData(java.lang.String campsFilePath)
Imports camp data from the specified file.java.util.Map<java.lang.String,Committee>
importCommitteeData(java.lang.String usersFilePath, java.lang.String committeesFilePath)
Imports committee data from specified files.java.util.Map<java.lang.Integer,Enquiry>
importEnquiryData(java.lang.String enquiryFilePath)
Imports enquiry data from the specified file.java.util.Map<java.lang.String,Staff>
importStaffData(java.lang.String usersFilePath, java.lang.String staffsFilePath)
Imports staff data from specified files.java.util.Map<java.lang.String,Student>
importStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath)
Imports student data from specified files.java.util.Map<java.lang.Integer,Suggestion>
importSuggestionData(java.lang.String suggestionFilePath)
Imports suggestion data from the specified file.private java.util.Map<java.lang.String,java.lang.String>
parseUserRow(java.lang.String[] userRow)
parse string into a map for codejava.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
List of headers for the CSV file that stores user data.
-
studentCsvHeaders
private static java.util.List<java.lang.String> studentCsvHeaders
List of headers for the CSV file that stores student data.
-
staffCsvHeaders
private static java.util.List<java.lang.String> staffCsvHeaders
List of headers for the CSV file that stores staff data.
-
committeeCsvHeaders
private static java.util.List<java.lang.String> committeeCsvHeaders
List of headers for the CSV file that stores camp committee member data.
-
campCsvHeaders
private static java.util.List<java.lang.String> campCsvHeaders
List of headers for the CSV file that stores camp data.
-
enquiryCsvHeaders
private static java.util.List<java.lang.String> enquiryCsvHeaders
List of headers for the CSV file that stores enquiry data.
-
suggestionCsvHeaders
private static java.util.List<java.lang.String> suggestionCsvHeaders
List of headers for the CSV file that stores suggestion 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)
parse string into a map for code- Parameters:
userRow
- string from csv file- Returns:
- map for code
-
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 specified files.- Specified by:
importStudentData
in interfaceIFileDataService
- Parameters:
usersFilePath
- The file path for user data.studentsFilePath
- The file path for student data.- Returns:
- A
Map
containingStudent
data with user 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 specified files.- Specified by:
exportStudentData
in interfaceIFileDataService
- Parameters:
usersFilePath
- The file path for user data.studentsFilePath
- The file path for student data.studentMap
- AMap
containingStudent
data with user IDs as keys.- Returns:
true
if the export is successful,false
otherwise.
-
importStaffData
public java.util.Map<java.lang.String,Staff> importStaffData(java.lang.String usersFilePath, java.lang.String staffsFilePath)
Description copied from interface:IFileDataService
Imports staff data from specified files.- Specified by:
importStaffData
in interfaceIFileDataService
- Parameters:
usersFilePath
- The file path for user data.staffsFilePath
- The file path for staff data.- Returns:
- A
Map
containingStaff
data with user IDs as keys.
-
exportStaffData
public boolean exportStaffData(java.lang.String usersFilePath, java.lang.String staffsFilePath, java.util.Map<java.lang.String,Staff> staffMap)
Description copied from interface:IFileDataService
Exports staff data to specified files.- Specified by:
exportStaffData
in interfaceIFileDataService
- Parameters:
usersFilePath
- The file path for user data.staffsFilePath
- The file path for staff data.staffMap
- AMap
containingStaff
data with user IDs as keys.- Returns:
true
if the export is successful,false
otherwise.
-
importCommitteeData
public java.util.Map<java.lang.String,Committee> importCommitteeData(java.lang.String usersFilePath, java.lang.String committeesFilePath)
Description copied from interface:IFileDataService
Imports committee data from specified files.- Specified by:
importCommitteeData
in interfaceIFileDataService
- Parameters:
usersFilePath
- The file path for user data.committeesFilePath
- The file path for committee data.- Returns:
- A
Map
containingCommittee
data with user IDs as keys.
-
exportCommitteeData
public boolean exportCommitteeData(java.lang.String usersFilePath, java.lang.String committeesFilePath, java.util.Map<java.lang.String,Committee> committeeMap)
Description copied from interface:IFileDataService
Exports committee data to specified files.- Specified by:
exportCommitteeData
in interfaceIFileDataService
- Parameters:
usersFilePath
- The file path for user data.committeesFilePath
- The file path for committee data.committeeMap
- AMap
containingCommittee
data with user IDs as keys.- Returns:
true
if the export is successful,false
otherwise.
-
importCampData
public java.util.Map<java.lang.Integer,Camp> importCampData(java.lang.String campsFilePath)
Description copied from interface:IFileDataService
Imports camp data from the specified file.- Specified by:
importCampData
in interfaceIFileDataService
- Parameters:
campsFilePath
- The file path for camp data.- Returns:
- A
Map
containingCamp
data with camp IDs as keys.
-
exportCampData
public boolean exportCampData(java.lang.String campsFilePath, java.util.Map<java.lang.Integer,Camp> campMap)
Description copied from interface:IFileDataService
Exports camp data to the specified file.- Specified by:
exportCampData
in interfaceIFileDataService
- Parameters:
campsFilePath
- The file path for camp data.campMap
- AMap
containingCamp
data with camp IDs as keys.- Returns:
true
if the export is successful,false
otherwise.
-
importEnquiryData
public java.util.Map<java.lang.Integer,Enquiry> importEnquiryData(java.lang.String enquiryFilePath)
Description copied from interface:IFileDataService
Imports enquiry data from the specified file.- Specified by:
importEnquiryData
in interfaceIFileDataService
- Parameters:
enquiryFilePath
- The file path for enquiry data.- Returns:
- A
Map
containingEnquiry
data with enquiry IDs as keys.
-
exportEnquiryData
public boolean exportEnquiryData(java.lang.String enquiryFilePath, java.util.Map<java.lang.Integer,Enquiry> enquiryMap)
Description copied from interface:IFileDataService
Exports enquiry data to the specified file.- Specified by:
exportEnquiryData
in interfaceIFileDataService
- Parameters:
enquiryFilePath
- The file path for enquiry data.enquiryMap
- AMap
containingEnquiry
data with enquiry IDs as keys.- Returns:
true
if the export is successful,false
otherwise.
-
importSuggestionData
public java.util.Map<java.lang.Integer,Suggestion> importSuggestionData(java.lang.String suggestionFilePath)
Description copied from interface:IFileDataService
Imports suggestion data from the specified file.- Specified by:
importSuggestionData
in interfaceIFileDataService
- Parameters:
suggestionFilePath
- The file path for suggestion data.- Returns:
- A
Map
containingSuggestion
data with suggestion IDs as keys.
-
exportSuggestionData
public boolean exportSuggestionData(java.lang.String suggestionFilePath, java.util.Map<java.lang.Integer,Suggestion> suggestionMap)
Description copied from interface:IFileDataService
Exports suggestion data to the specified file.- Specified by:
exportSuggestionData
in interfaceIFileDataService
- Parameters:
suggestionFilePath
- The file path for suggestion data.suggestionMap
- AMap
containingSuggestion
data with suggestion IDs as keys.- Returns:
true
if the export is successful,false
otherwise.
-
-