mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 13:18:35 +00:00
Also: All script tasks should raise WorkflowTaskExecExceptions - NOT APIExceptions - this is because our scripts are executed by Spiff (not the other way around) so the errors need to pass fluidly through spiff, and come back to use THEN we can convert them to APIErrors. Otherwise we lose all kinds of good information about the error.
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from SpiffWorkflow.exceptions import WorkflowTaskExecException
|
|
|
|
from crc.scripts.script import Script
|
|
from crc.api.common import ApiError
|
|
from crc.services.protocol_builder import ProtocolBuilderService
|
|
from crc.services.study_service import StudyService
|
|
from crc.services.workflow_spec_service import WorkflowSpecService
|
|
|
|
|
|
class CheckStudy(Script):
|
|
|
|
pb = ProtocolBuilderService()
|
|
|
|
def get_description(self):
|
|
return """Returns the Check Study data for a Study"""
|
|
|
|
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
|
spec_service = WorkflowSpecService()
|
|
categories = spec_service.get_categories()
|
|
study = StudyService.get_study(study_id, categories)
|
|
if study:
|
|
return {"DETAIL": "Passed validation.", "STATUS": "No Error"}
|
|
else:
|
|
raise WorkflowTaskExecException(task, 'Function check_study failed. There is no study for study_id {study_id}.')
|
|
|
|
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
|
check_study = self.pb.check_study(study_id)
|
|
if check_study:
|
|
return check_study
|
|
else:
|
|
raise WorkflowTaskExecException(task, 'There was a problem checking information for this study.')
|