2020-05-25 19:30:06 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from crc import db
|
|
|
|
from crc.api.common import ApiError
|
|
|
|
from crc.models.study import StudyModel
|
|
|
|
from crc.scripts.script import Script
|
|
|
|
|
|
|
|
|
2020-05-27 00:06:50 +00:00
|
|
|
class mock_study:
|
|
|
|
def __init__(self):
|
|
|
|
self.title = ""
|
|
|
|
self.principle_investigator_id = ""
|
|
|
|
|
|
|
|
|
2020-05-25 19:30:06 +00:00
|
|
|
class UpdateStudy(Script):
|
|
|
|
|
|
|
|
argument_error_message = "You must supply at least one argument to the " \
|
2021-03-02 15:03:53 +00:00
|
|
|
"update_study task, in the form [study_field]=[value]",
|
2020-05-25 19:30:06 +00:00
|
|
|
|
|
|
|
def get_description(self):
|
|
|
|
return """
|
|
|
|
Allows you to set specific attributes on the Study model by mapping them to
|
2021-03-02 15:03:53 +00:00
|
|
|
values in the task data. Should be called with the value to set (either title, short_title, or pi)
|
2020-05-25 19:30:06 +00:00
|
|
|
|
|
|
|
Example:
|
2021-03-02 15:03:53 +00:00
|
|
|
update_study(title=PIComputingID.label, short_title="Really Short Name")
|
2020-05-25 19:30:06 +00:00
|
|
|
"""
|
|
|
|
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
2020-05-27 00:06:50 +00:00
|
|
|
study = mock_study
|
2021-03-02 15:03:53 +00:00
|
|
|
self.__update_study(task, study, *args, **kwargs)
|
2020-05-25 19:30:06 +00:00
|
|
|
|
|
|
|
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
|
|
|
study = db.session.query(StudyModel).filter(StudyModel.id == study_id).first()
|
2021-03-02 15:03:53 +00:00
|
|
|
self.__update_study(task, study, *args, **kwargs)
|
2020-05-27 00:06:50 +00:00
|
|
|
db.session.add(study)
|
2020-05-25 19:30:06 +00:00
|
|
|
|
2021-03-02 15:03:53 +00:00
|
|
|
def __update_study(self, task, study, *args, **kwargs):
|
|
|
|
if len(kwargs.keys()) < 1:
|
2020-05-25 19:30:06 +00:00
|
|
|
raise ApiError.from_task("missing_argument", self.argument_error_message,
|
|
|
|
task=task)
|
|
|
|
|
2021-03-02 15:03:53 +00:00
|
|
|
for arg in kwargs.keys():
|
|
|
|
if arg.lower() == "title":
|
|
|
|
study.title = kwargs[arg]
|
|
|
|
elif arg.lower() == "short_title":
|
|
|
|
study.short_title = kwargs[arg]
|
|
|
|
elif arg.lower() == "pi":
|
|
|
|
study.primary_investigator_id = kwargs[arg]
|
2020-05-25 19:30:06 +00:00
|
|
|
else:
|
|
|
|
raise ApiError.from_task("invalid_argument", self.argument_error_message,
|
|
|
|
task=task)
|