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:
parent
d3d7eeb309
commit
40ee20ecca
|
@ -16,6 +16,7 @@ class DataStoreModel(db.Model):
|
||||||
task_id = db.Column(db.String)
|
task_id = db.Column(db.String)
|
||||||
spec_id = db.Column(db.String)
|
spec_id = db.Column(db.String)
|
||||||
user_id = db.Column(db.String, nullable=True)
|
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)
|
value = db.Column(db.String)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ from marshmallow_enum import EnumField
|
||||||
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
|
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
|
||||||
from sqlalchemy import func, Index
|
from sqlalchemy import func, Index
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
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
|
from crc import db, ma
|
||||||
|
|
||||||
|
@ -87,6 +88,7 @@ class FileModel(db.Model):
|
||||||
# it instead, hide it in the interface.
|
# it instead, hide it in the interface.
|
||||||
is_review = db.Column(db.Boolean, default=False, nullable=True)
|
is_review = db.Column(db.Boolean, default=False, nullable=True)
|
||||||
archived = db.Column(db.Boolean, default=False, nullable=False)
|
archived = db.Column(db.Boolean, default=False, nullable=False)
|
||||||
|
tags = relationship("DataStoreModel", cascade="all,delete", backref="file")
|
||||||
|
|
||||||
class File(object):
|
class File(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -38,14 +38,29 @@ class DataStoreBase(object):
|
||||||
message=f"The {script_name} script takes two arguments, starting with the key and a "
|
message=f"The {script_name} script takes two arguments, starting with the key and a "
|
||||||
"value for the key")
|
"value for the key")
|
||||||
|
|
||||||
def get_prev_value(self, study_id, user_id, key):
|
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, key=key).first()
|
study = session.query(DataStoreModel).filter_by(study_id=study_id,
|
||||||
|
user_id=user_id,
|
||||||
|
file_id=file_id,
|
||||||
|
key=key).first()
|
||||||
return study
|
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)
|
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:
|
if workflow_spec_id is None and workflow_id is not None:
|
||||||
workflow = session.query(WorkflowModel).filter(WorkflowModel.id == workflow_id).first()
|
workflow = session.query(WorkflowModel).filter(WorkflowModel.id == workflow_id).first()
|
||||||
workflow_spec_id = workflow.workflow_spec_id
|
workflow_spec_id = workflow.workflow_spec_id
|
||||||
|
@ -57,6 +72,7 @@ class DataStoreBase(object):
|
||||||
study_id=study_id,
|
study_id=study_id,
|
||||||
task_id=task_id,
|
task_id=task_id,
|
||||||
user_id=user_id, # Make this available to any User
|
user_id=user_id, # Make this available to any User
|
||||||
|
file_id=file_id,
|
||||||
workflow_id=workflow_id,
|
workflow_id=workflow_id,
|
||||||
spec_id=workflow_spec_id)
|
spec_id=workflow_spec_id)
|
||||||
study.value = args[1]
|
study.value = args[1]
|
||||||
|
@ -68,14 +84,20 @@ class DataStoreBase(object):
|
||||||
'old_value': prev_value,
|
'old_value': prev_value,
|
||||||
'overwritten': overwritten}
|
'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)
|
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:
|
if study:
|
||||||
return study.value
|
return study.value
|
||||||
else:
|
else:
|
||||||
return args[1]
|
return args[1]
|
||||||
|
|
||||||
def get_multi_common(self, study_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)
|
study = session.query(DataStoreModel).filter_by(study_id=study_id,
|
||||||
|
user_id=user_id,
|
||||||
|
file_id=file_id)
|
||||||
return study
|
return study
|
||||||
|
|
|
@ -13,5 +13,6 @@ class StudyDataGet(Script,DataStoreBase):
|
||||||
return self.get_data_common(study_id,
|
return self.get_data_common(study_id,
|
||||||
None,
|
None,
|
||||||
'study_data_get',
|
'study_data_get',
|
||||||
|
None,
|
||||||
*args)
|
*args)
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,5 @@ class UserDataGet(Script, DataStoreBase):
|
||||||
return self.get_data_common(None,
|
return self.get_data_common(None,
|
||||||
g.user.uid,
|
g.user.uid,
|
||||||
'user_data_get',
|
'user_data_get',
|
||||||
|
None,
|
||||||
*args)
|
*args)
|
||||||
|
|
Loading…
Reference in New Issue