I have a requirement as follows:
- Read data from CSV file.
- Find duplicate rows based on key passed. (Say example, CSV file has 10 columns, we need to find duplicates based on a particular row key)
- A boolean to reject/accept duplicate rows.
- Cell Processors to validate each row in the file.
This is for a bulk upload data where I read the file row by row, find if the row has valid data and the row is not duplicate based on key passed and finally return a list of valid rows.
abstract class BulkUploadService{ List<BulkDTO> process(File file){ // Read a file and the value from below methods overridden by their child classes } abstract CellProcessors[] cellProcessors(); abstract boolean isDuplicatesAllowed(); abstract String[] headers(); abstract String rowKey(); }
The method process() needs - File, Row key, CellProcessors, boolean to accept/reject duplicates, and few more to process and return a list of valid rows in the form of DTOs. The child classes will implement BulkUploadService
and override all the methods except process() to supply data for the process() method to return a valid list.
The reason I want to abstract out is this BulkUploadService should handle all the business logic and return a valid list for the concrete classes and the concrete classes should focus just on supplying information. Is there a better way to design for this scenario?
Aucun commentaire:
Enregistrer un commentaire