Hi all
I have been working on this issue for a while now and its getting frustrating. Due to my internships I can only work a few hours a day and spending days on one particular issue is getting me frustrated.
On import of MRRT templates they are validated against an xsd file to make sure they follow the MRRT standard. Recently we noticed that the xsd validation stops on the first violation and reports that error to the user as a sax parse exception so the user can handle. Which means if a file has 20 violations, they user might have to retry to import the template twenty times for the validator to report all 20 violations. To allow the validator to continue checking for violations until its found all before reporting, so that the user can fix all at once before reimporting the template, I wrote this code.
In that commit, the code checks for all violations, adds them to a list of violations then at the end throws an exception that reports all the violations, not just the first. Well, the requirement was to wrap the list of exceptions into a single exception but I wrapped just the error messages.
if (!exceptions.isEmpty()) {
throw new APIException(exceptions.toString());
}
I can’t figure out how to rap the list of exceptions into a single exception as I cannot pass List into the constructor of the Exception.
This validator is used the MrrtReportTemplateFileParser to validate the template files before creating MrrtReportTemplate object. You can see code here openmrs-module-radiology/DefaultMrrtReportTemplateFileParser.java at RAD-359 · ivange94/openmrs-module-radiology · GitHub
When a file does not meet the mrrt standard and hence validation fails, the error is reported using
catch (APIException exception) {
request.getSession()
.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
"Failed to import " + templateFile.getOriginalFilename() + " => " + exception.getMessage());
}
Here is a sample output of trying to import a file with two validation violations
Issues with current implementation
-
Output is not user friendly: All that output is just trying to say that the file does not have ‘title’ and ‘template_attribute’ tags which are mandatory.
-
I wrapped the exception messages inside the a new exception instead of wrapping all the exceptions objects inside the new exception. Well I have google and I have not figured out how to do this. Maybe I am not understand what @teleivo trying to say.
I would need some help in reporting that error on the UI so that it looks more user friendly and also how to wrap a list object inside one exception. I have tried googling but I don’t get anything useful.
Quote @wyclif “Why not use spring validator instead of implementing your own validator?”
Well I tried to use spring validator but I couldn’t figure out how to integrate the code with the spring validator. From what I know spring validator validates an object to make sure its valid. So every object that needs validation, say Report, will need a ReportValidator. But I don’t think that will work here because an MrrtReportTemplateValidator will be validating an MrrtReportTemplate to make sure it is valid. But am not sure this will work because my validator validates an html file against a schema and if its valid parse the contents of the file and then instantiate an MrrtReportTemplate. My point is my validator is called manually and is called even before an MrrtReportTemplate object is validated. Look at this line,