Add file_data_get and file_data_set functions that can be accessed in a bpmn script function

Fixes #299
This commit is contained in:
Kelly McDonald 2021-04-26 09:55:28 -04:00
parent d3d7eeb309
commit 40ee20ecca
5 changed files with 36 additions and 9 deletions

View File

@ -16,6 +16,7 @@ class DataStoreModel(db.Model):
task_id = db.Column(db.String)
spec_id = db.Column(db.String)
user_id = db.Column(db.String, nullable=True)
file_id = db.Column(db.Integer, db.ForeignKey('file.id'), nullable=True)
value = db.Column(db.String)

View File

@ -6,7 +6,8 @@ from marshmallow_enum import EnumField
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
from sqlalchemy import func, Index
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import deferred
from sqlalchemy.orm import deferred, relationship
from crc.models.data_store import DataStoreModel # this is needed by the relationship
from crc import db, ma
@ -87,6 +88,7 @@ class FileModel(db.Model):
# it instead, hide it in the interface.
is_review = db.Column(db.Boolean, default=False, nullable=True)
archived = db.Column(db.Boolean, default=False, nullable=False)
tags = relationship("DataStoreModel", cascade="all,delete", backref="file")
class File(object):
@classmethod

View File

@ -38,14 +38,29 @@ class DataStoreBase(object):
message=f"The {script_name} script takes two arguments, starting with the key and a "
"value for the key")
def get_prev_value(self, study_id, user_id, key):
study = session.query(DataStoreModel).filter_by(study_id=study_id, user_id=user_id, key=key).first()
def get_prev_value(self, study_id, user_id, key, file_id):
study = session.query(DataStoreModel).filter_by(study_id=study_id,
user_id=user_id,
file_id=file_id,
key=key).first()
return study
def set_data_common(self, task_id, study_id, user_id, workflow_id, workflow_spec_id, script_name, *args, **kwargs):
def set_data_common(self,
task_id,
study_id,
user_id,
workflow_id,
workflow_spec_id,
script_name,
file_id,
*args,
**kwargs):
self.check_args_2(args, script_name=script_name)
study = self.get_prev_value(study_id=study_id, user_id=user_id, key=args[0])
study = self.get_prev_value(study_id=study_id,
user_id=user_id,
file_id=file_id,
key=args[0])
if workflow_spec_id is None and workflow_id is not None:
workflow = session.query(WorkflowModel).filter(WorkflowModel.id == workflow_id).first()
workflow_spec_id = workflow.workflow_spec_id
@ -57,6 +72,7 @@ class DataStoreBase(object):
study_id=study_id,
task_id=task_id,
user_id=user_id, # Make this available to any User
file_id=file_id,
workflow_id=workflow_id,
spec_id=workflow_spec_id)
study.value = args[1]
@ -68,14 +84,20 @@ class DataStoreBase(object):
'old_value': prev_value,
'overwritten': overwritten}
def get_data_common(self, study_id, user_id, script_name, *args):
def get_data_common(self, study_id, user_id, script_name, file_id=None, *args):
self.check_args(args, 2, script_name)
study = session.query(DataStoreModel).filter_by(study_id=study_id, user_id=user_id, key=args[0]).first()
study = session.query(DataStoreModel).filter_by(study_id=study_id,
user_id=user_id,
file_id=file_id,
key=args[
0]).first()
if study:
return study.value
else:
return args[1]
def get_multi_common(self, study_id, user_id):
study = session.query(DataStoreModel).filter_by(study_id=study_id, user_id=user_id)
def get_multi_common(self, study_id, user_id, file_id=None):
study = session.query(DataStoreModel).filter_by(study_id=study_id,
user_id=user_id,
file_id=file_id)
return study

View File

@ -13,5 +13,6 @@ class StudyDataGet(Script,DataStoreBase):
return self.get_data_common(study_id,
None,
'study_data_get',
None,
*args)

View File

@ -15,4 +15,5 @@ class UserDataGet(Script, DataStoreBase):
return self.get_data_common(None,
g.user.uid,
'user_data_get',
None,
*args)