Merge pull request #342 from sartography/enum-file-data-375

Enum file data #375
This commit is contained in:
Dan Funk 2021-07-23 13:47:57 -04:00 committed by GitHub
commit 25e00823a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 10 deletions

View File

@ -30,6 +30,8 @@ from crc.models.study import StudyModel
from crc.models.task_event import TaskEventModel
from crc.models.user import UserModel, UserModelSchema
from crc.models.workflow import WorkflowModel, WorkflowStatus, WorkflowSpecModel
from crc.services.data_store_service import DataStoreBase
from crc.services.document_service import DocumentService
from crc.services.file_service import FileService
from crc.services.lookup_service import LookupService
@ -312,8 +314,11 @@ class WorkflowService(object):
field.get_property(Task.FIELD_PROP_FILE_DATA) in data and \
field.id in data:
file_id = data[field.get_property(Task.FIELD_PROP_FILE_DATA)]["id"]
data_store = DataStoreModel(file_id=file_id, key=field.id, value=data[field.id])
db.session.add(data_store)
if field.type == 'enum':
data_args = (field.id, data[field.id]['label'])
else:
data_args = (field.id, data[field.id])
DataStoreBase().set_data_common(task.id, None, None, None, None, None, file_id, *data_args)
@staticmethod
def evaluate_property(property_name, field, task):

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0b469f0" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
<bpmn:process id="Process_4b7fa29" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1kvuzs1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1kvuzs1" sourceRef="StartEvent_1" targetRef="Activity_0gtrm5e" />
<bpmn:userTask id="Activity_0gtrm5e" name="Select Enum" camunda:formKey="Upload Application">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="IRB_HSR_Application_Type" label="IRB-HSR Application Type" type="enum">
<camunda:properties>
<camunda:property id="file_data" value="Study_App_Doc" />
<camunda:property id="spreadsheet.name" value="IRB_HSR_Application_Type.xlsx" />
<camunda:property id="spreadsheet.label.column" value="Label" />
<camunda:property id="spreadsheet.value.column" value="Value" />
<camunda:property id="group" value="Application" />
</camunda:properties>
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
<camunda:formField id="Study_App_Doc" label="IRB-HSR Application" type="file" />
<camunda:formField id="my_test_field" label="Nickname" type="string">
<camunda:properties>
<camunda:property id="file_data" value="Study_App_Doc" />
</camunda:properties>
</camunda:formField>
<camunda:formField id="some_date" label="Date" type="date">
<camunda:properties>
<camunda:property id="file_data" value="Study_App_Doc" />
</camunda:properties>
</camunda:formField>
<camunda:formField id="a_boolean" label="A Boolean" type="boolean">
<camunda:properties>
<camunda:property id="file_data" value="Study_App_Doc" />
</camunda:properties>
</camunda:formField>
<camunda:formField id="the_number" label="The Number" type="long">
<camunda:properties>
<camunda:property id="file_data" value="Study_App_Doc" />
</camunda:properties>
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1kvuzs1</bpmn:incoming>
<bpmn:outgoing>Flow_0han7ki</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="Flow_0han7ki" sourceRef="Activity_0gtrm5e" targetRef="Activity_0gpetln" />
<bpmn:manualTask id="Activity_0gpetln" name="Print Enum">
<bpmn:documentation># Enum</bpmn:documentation>
<bpmn:incoming>Flow_0han7ki</bpmn:incoming>
<bpmn:outgoing>Flow_0h5cdg9</bpmn:outgoing>
</bpmn:manualTask>
<bpmn:endEvent id="Event_124aupd">
<bpmn:incoming>Flow_0h5cdg9</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0h5cdg9" sourceRef="Activity_0gpetln" targetRef="Event_124aupd" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_4b7fa29">
<bpmndi:BPMNEdge id="Flow_0h5cdg9_di" bpmnElement="Flow_0h5cdg9">
<di:waypoint x="530" y="117" />
<di:waypoint x="592" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0han7ki_di" bpmnElement="Flow_0han7ki">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1kvuzs1_di" bpmnElement="Flow_1kvuzs1">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_11t0hqf_di" bpmnElement="Activity_0gtrm5e">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0fax1lv_di" bpmnElement="Activity_0gpetln">
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_124aupd_di" bpmnElement="Event_124aupd">
<dc:Bounds x="592" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -1,18 +1,17 @@
import json
from tests.base_test import BaseTest
from crc import db
from crc.models.data_store import DataStoreModel
from crc.services.file_service import FileService
from crc.services.workflow_processor import WorkflowProcessor
from tests.base_test import BaseTest
from crc.models.workflow import WorkflowStatus
from crc import db
from crc.api.common import ApiError
from crc.models.task_event import TaskEventModel, TaskEventSchema
from crc.services.workflow_service import WorkflowService
from io import BytesIO
import json
class TestFileDatastore(BaseTest):
def test_file_datastore_workflow(self):
self.load_example_data()
self.create_reference_document()
@ -32,3 +31,41 @@ class TestFileDatastore(BaseTest):
self.assertEqual(task_data['output'], 'me')
self.assertEqual(task_data['output2'], 'nope')
def test_file_data_store_file_data_property(self):
self.load_example_data()
workflow = self.create_workflow('enum_file_data')
workflow_api = self.get_workflow_api(workflow)
task = workflow_api.next_task
# upload the file
correct_name = task.form['fields'][1]['id']
data = {'file': (BytesIO(b"abcdef"), 'test_file.txt')}
rv = self.app.post('/v1.0/file?study_id=%i&workflow_id=%s&task_id=%s&form_field_key=%s' %
(workflow.study_id, workflow.id, task.id, correct_name), data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assert_success(rv)
file_id = json.loads(rv.get_data())['id']
# process the form that sets the datastore values
self.complete_form(workflow, task, {'Study_App_Doc': {'id': file_id},
'IRB_HSR_Application_Type': {'label': 'Expedited Application'},
'my_test_field': 'some string',
'the_number': 8,
'a_boolean': True,
'some_date': '2021-07-23'})
# assert the data_store was set correctly
data_store_keys = ['IRB_HSR_Application_Type', 'my_test_field', 'the_number', 'a_boolean', 'some_date']
data_store = db.session.query(DataStoreModel).filter(DataStoreModel.file_id==file_id).all()
for item in data_store:
self.assertIn(item.key, data_store_keys)
if item.key == 'IRB_HSR_Application_Type':
self.assertEqual('Expedited Application', item.value)
if item.key == 'my_test_field':
self.assertEqual('some string', item.value)
if item.key == 'the_number':
self.assertEqual('8', item.value)
if item.key == 'a_boolean':
self.assertEqual('true', item.value)
if item.key == 'some_date':
self.assertEqual('2021-07-23', item.value)