One of my recent projects added a requirement to insert and or update records from a file rather than from the UI. Of course, all the business logic and validation that was being done for the UI had to be done on the records being updated or inserted from the file.
Good news was that we had kept all the business and validation logic out of the controller. So at least we were not faced with either refactoring the controller or duplicating the logic in another section of the program.
It was a good lesson for the junior programmers on the project -- as they had been chaffing at my insistence to keep business logic out of the control layer.
The file could contain thousands of records.
Mulling this over, I came up with the following design considerations.
Good news was that we had kept all the business and validation logic out of the controller. So at least we were not faced with either refactoring the controller or duplicating the logic in another section of the program.
It was a good lesson for the junior programmers on the project -- as they had been chaffing at my insistence to keep business logic out of the control layer.
The file could contain thousands of records.
Mulling this over, I came up with the following design considerations.
- Have the file be processed asynchronously.
- Have one transaction per record
- Re-use all the business logic encoded while developing the interactive screen.
- Not have any business logic specific to the file upload that was not directly relevant to the file-upload process itself. I.e. I did not want to introduce any business logic in the file-upload that was different than in the interactive screen.
- Have the process that reads and writes excel files be only loosely coupled with the upload process.
- Have the process be robust -- and stand up to server failures/restarts etc.
- Build in some support function to cancel/suspend the process.
- All uploads will from a file downloaded by the application.
- End User fills out a form to request a file download that he will update.
- End User will be directed to a status page for file being processed -- it will show the file in a process of 'Preparing'.
- The download will be processed asynchronously and on its completion and user will see a change of status on a page from preparing to 'Ready for download'.
- End User will download the file, update it and then upload it back into the system. The status of the file will be changed 'Validating'.
- System will validate the file asynchronously.
- End-user will see the results of the validation. If the validation failed, they can download the file with the validation errors in a new column in the spreadsheet. Correct them and re-upload.
- Once the file clears validation, they will be allowed to submit it for processing.
- The file changes/adds will be applied to the system. A final status of either successful, partially successful or failed will be returned.
No comments:
Post a Comment