From cb2bab33b018f224d65d0c3020eb99d683e14785 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 11 May 2022 16:57:39 -0400 Subject: [PATCH] Restore admin warnings --- crc/services/study_service.py | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crc/services/study_service.py b/crc/services/study_service.py index 965c0e79..d17f36b5 100755 --- a/crc/services/study_service.py +++ b/crc/services/study_service.py @@ -69,6 +69,44 @@ class StudyService(object): studies.append(study) return studies + @staticmethod + def get_study_warnings(workflow_metas, status): + + # Grab warnings generated from the master workflow for debugging + warnings = [] + unused_statuses = status.copy() # A list of all the statuses that are not used. + for wfm in workflow_metas: + unused_statuses.pop(wfm.workflow_spec_id, None) + wfm.state_message = '' + # do we have a status for you + if wfm.workflow_spec_id not in status.keys(): + warnings.append(ApiError("missing_status", + "No status information provided about workflow %s" % wfm.workflow_spec_id)) + continue + if not isinstance(status[wfm.workflow_spec_id], dict): + warnings.append(ApiError(code='invalid_status', + message=f'Status must be a dictionary with "status" and "message" keys. ' + f'Name is {wfm.workflow_spec_id}. Status is {status[wfm.workflow_spec_id]}')) + continue + if 'status' not in status[wfm.workflow_spec_id].keys(): + warnings.append(ApiError("missing_status_key", + "Workflow '%s' is present in master workflow, but doesn't have a status" % wfm.workflow_spec_id)) + continue + if not WorkflowState.has_value(status[wfm.workflow_spec_id]['status']): + warnings.append(ApiError("invalid_state", + "Workflow '%s' can not be set to '%s', should be one of %s" % ( + wfm.workflow_spec_id, status[wfm.workflow_spec_id]['status'], + ",".join(WorkflowState.list()) + ))) + continue + + for status in unused_statuses: + if isinstance(unused_statuses[status], dict) and 'status' in unused_statuses[status]: + warnings.append(ApiError("unmatched_status", "The master workflow provided a status for '%s' a " + "workflow that doesn't seem to exist." % + status)) + + return warnings @staticmethod @timeit @@ -104,6 +142,7 @@ class StudyService(object): workflow_metas = StudyService._get_workflow_metas(study_id, category) category_meta = [] if master_workflow_results: + study.warnings = StudyService.get_study_warnings(workflow_metas, master_workflow_results) category_meta = StudyService._update_status_of_category_meta(master_workflow_results, category) category.workflows = workflow_metas category.meta = category_meta