- 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>campCsvHeadersList of headers for the CSV file that stores camp data.private static java.util.List<java.lang.String>committeeCsvHeadersList of headers for the CSV file that stores camp committee member data.private static java.util.List<java.lang.String>enquiryCsvHeadersList of headers for the CSV file that stores enquiry data.private static java.util.List<java.lang.String>staffCsvHeadersList of headers for the CSV file that stores staff data.private static java.util.List<java.lang.String>studentCsvHeadersList of headers for the CSV file that stores student data.private static java.util.List<java.lang.String>suggestionCsvHeadersList of headers for the CSV file that stores suggestion data.private static java.util.List<java.lang.String>userCsvHeadersList 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 booleanexportCampData(java.lang.String campsFilePath, java.util.Map<java.lang.Integer,Camp> campMap)Exports camp data to the specified file.booleanexportCommitteeData(java.lang.String usersFilePath, java.lang.String committeesFilePath, java.util.Map<java.lang.String,Committee> committeeMap)Exports committee data to specified files.booleanexportEnquiryData(java.lang.String enquiryFilePath, java.util.Map<java.lang.Integer,Enquiry> enquiryMap)Exports enquiry data to the specified file.booleanexportStaffData(java.lang.String usersFilePath, java.lang.String staffsFilePath, java.util.Map<java.lang.String,Staff> staffMap)Exports staff data to specified files.booleanexportStudentData(java.lang.String usersFilePath, java.lang.String studentsFilePath, java.util.Map<java.lang.String,Student> studentMap)Exports student data to specified files.booleanexportSuggestionData(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.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
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 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)
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:IFileDataServiceImports student data from specified files.- Specified by:
importStudentDatain interfaceIFileDataService- Parameters:
usersFilePath- The file path for user data.studentsFilePath- The file path for student data.- Returns:
- A
MapcontainingStudentdata 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:IFileDataServiceExports student data to specified files.- Specified by:
exportStudentDatain interfaceIFileDataService- Parameters:
usersFilePath- The file path for user data.studentsFilePath- The file path for student data.studentMap- AMapcontainingStudentdata with user IDs as keys.- Returns:
trueif the export is successful,falseotherwise.
-
importStaffData
public java.util.Map<java.lang.String,Staff> importStaffData(java.lang.String usersFilePath, java.lang.String staffsFilePath)
Description copied from interface:IFileDataServiceImports staff data from specified files.- Specified by:
importStaffDatain interfaceIFileDataService- Parameters:
usersFilePath- The file path for user data.staffsFilePath- The file path for staff data.- Returns:
- A
MapcontainingStaffdata 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:IFileDataServiceExports staff data to specified files.- Specified by:
exportStaffDatain interfaceIFileDataService- Parameters:
usersFilePath- The file path for user data.staffsFilePath- The file path for staff data.staffMap- AMapcontainingStaffdata with user IDs as keys.- Returns:
trueif the export is successful,falseotherwise.
-
importCommitteeData
public java.util.Map<java.lang.String,Committee> importCommitteeData(java.lang.String usersFilePath, java.lang.String committeesFilePath)
Description copied from interface:IFileDataServiceImports committee data from specified files.- Specified by:
importCommitteeDatain interfaceIFileDataService- Parameters:
usersFilePath- The file path for user data.committeesFilePath- The file path for committee data.- Returns:
- A
MapcontainingCommitteedata 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:IFileDataServiceExports committee data to specified files.- Specified by:
exportCommitteeDatain interfaceIFileDataService- Parameters:
usersFilePath- The file path for user data.committeesFilePath- The file path for committee data.committeeMap- AMapcontainingCommitteedata with user IDs as keys.- Returns:
trueif the export is successful,falseotherwise.
-
importCampData
public java.util.Map<java.lang.Integer,Camp> importCampData(java.lang.String campsFilePath)
Description copied from interface:IFileDataServiceImports camp data from the specified file.- Specified by:
importCampDatain interfaceIFileDataService- Parameters:
campsFilePath- The file path for camp data.- Returns:
- A
MapcontainingCampdata 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:IFileDataServiceExports camp data to the specified file.- Specified by:
exportCampDatain interfaceIFileDataService- Parameters:
campsFilePath- The file path for camp data.campMap- AMapcontainingCampdata with camp IDs as keys.- Returns:
trueif the export is successful,falseotherwise.
-
importEnquiryData
public java.util.Map<java.lang.Integer,Enquiry> importEnquiryData(java.lang.String enquiryFilePath)
Description copied from interface:IFileDataServiceImports enquiry data from the specified file.- Specified by:
importEnquiryDatain interfaceIFileDataService- Parameters:
enquiryFilePath- The file path for enquiry data.- Returns:
- A
MapcontainingEnquirydata 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:IFileDataServiceExports enquiry data to the specified file.- Specified by:
exportEnquiryDatain interfaceIFileDataService- Parameters:
enquiryFilePath- The file path for enquiry data.enquiryMap- AMapcontainingEnquirydata with enquiry IDs as keys.- Returns:
trueif the export is successful,falseotherwise.
-
importSuggestionData
public java.util.Map<java.lang.Integer,Suggestion> importSuggestionData(java.lang.String suggestionFilePath)
Description copied from interface:IFileDataServiceImports suggestion data from the specified file.- Specified by:
importSuggestionDatain interfaceIFileDataService- Parameters:
suggestionFilePath- The file path for suggestion data.- Returns:
- A
MapcontainingSuggestiondata 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:IFileDataServiceExports suggestion data to the specified file.- Specified by:
exportSuggestionDatain interfaceIFileDataService- Parameters:
suggestionFilePath- The file path for suggestion data.suggestionMap- AMapcontainingSuggestiondata with suggestion IDs as keys.- Returns:
trueif the export is successful,falseotherwise.
-
-