Skip to content

Commit

Permalink
♻️ refactor: Enhance the error message for mapping jobs' validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukan10 committed Aug 13, 2024
1 parent f227619 commit e05eb7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ case class FhirMappingJob(id: String = UUID.randomUUID().toString,
/**
* Validates the mapping job
*
* @throws BadRequestException if a streaming job is attempted to be scheduled.
* @throws BadRequestException if a streaming job is attempted to be scheduled or if a data source referenced
* by a mapping task is missing from the source settings.
*/
def validate(): Unit = {
if(sourceSettings.exists(_._2.asStream) && schedulingSettings.nonEmpty){
throw new BadRequestException("Streaming jobs cannot be scheduled.")
}

// Check mapping tasks of the job, if a data source of a mapping task is missing throw an error
mappings.foreach((mappingTask) => {
mappingTask.sourceContext.foreach((sourceContext) => {
// Check mapping tasks of the job, if a data source of a mapping task is missing, throw an error
mappings.foreach(mappingTask => {
mappingTask.sourceContext.foreach(sourceContext => {
if(sourceContext._2.sourceRef.nonEmpty && !sourceSettings.contains(sourceContext._2.sourceRef.get)) {
throw new BadRequestException(s"The data source with the source name ${sourceContext._2.sourceRef.get} is referenced by mapping tasks of this job.")
throw new BadRequestException(s"The data source referenced by source name '${sourceContext._2.sourceRef.get}' in the mapping task '${mappingTask.mappingRef}' is not found in the source settings of the job.")
}
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class JobEndpointTest extends BaseEndpointTest {
status shouldEqual StatusCodes.BadRequest
// validate error message
val response = responseAs[String]
response should include("Detail: The data source with the source name source2 is referenced by mapping tasks of this job.")
response should include("Detail: The data source referenced by source name 'source2' in the mapping task 'mappingRef1' is not found in the source settings of the job.")
// validate that job metadata file is still the same
val projects: JArray = TestUtil.getProjectJsonFile(toFhirEngineConfig)
(projects.arr.find(p => (p \ "id").extract[String] == projectId).get \ "mappingJobs").asInstanceOf[JArray].arr.length shouldEqual 1
Expand Down

0 comments on commit e05eb7b

Please sign in to comment.