Cleanup validation for get_locatime.

Make sure we send the same type of values back for validation.
This commit is contained in:
mike cullerton 2021-10-26 14:29:38 -04:00
parent c566fa1c8f
commit f88aba1db0
4 changed files with 38 additions and 21 deletions

View File

@ -1,5 +1,6 @@
import sys import sys
import traceback import traceback
import datetime
from crc import app, session from crc import app, session
from crc.api.common import ApiError from crc.api.common import ApiError
@ -43,7 +44,9 @@ email(subject="My Subject", recipients="user@example.com", attachments=['Study_A
subject = self.get_subject(kwargs['subject']) subject = self.get_subject(kwargs['subject'])
recipients = self.get_email_addresses(kwargs['recipients'], study_id) recipients = self.get_email_addresses(kwargs['recipients'], study_id)
content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data) content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data)
return EmailModel(subject=subject, recipients=recipients, content=content, content_html=content_html)
email_model = EmailModel(subject=subject, recipients=recipients, content=content, content_html=content_html, timestamp=datetime.datetime.utcnow())
return EmailModelSchema().dump(email_model)
def do_task(self, task, study_id, workflow_id, *args, **kwargs): def do_task(self, task, study_id, workflow_id, *args, **kwargs):

View File

@ -2,7 +2,9 @@ from crc.scripts.script import Script
from crc.api.common import ApiError from crc.api.common import ApiError
from crc import session from crc import session
from crc.models.email import EmailModel, EmailModelSchema from crc.models.email import EmailModel, EmailModelSchema
import json from crc.services.email_service import EmailService
import datetime
class EmailData(Script): class EmailData(Script):
@ -12,11 +14,22 @@ class EmailData(Script):
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
if 'email_id' in kwargs or 'workflow_spec_id' in kwargs: if 'email_id' in kwargs or 'workflow_spec_id' in kwargs:
return True subject = 'My Test Email'
else: recipients = 'user@example.com'
return False content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data)
email_model = EmailModel(subject=subject,
recipients=recipients,
content=content,
content_html=content_html,
timestamp=datetime.datetime.utcnow())
return EmailModelSchema(many=True).dump([email_model])
def do_task(self, task, study_id, workflow_id, **kwargs): else:
raise ApiError.from_task(code='missing_email_id',
message='You must include an email_id or workflow_spec_id with the get_email_data script.',
task=task)
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
email_models = None email_models = None
email_data = None email_data = None
if 'email_id' in kwargs: if 'email_id' in kwargs:

View File

@ -1,5 +1,3 @@
import datetime
from crc.api.common import ApiError from crc.api.common import ApiError
from crc.scripts.script import Script from crc.scripts.script import Script
@ -15,7 +13,7 @@ class GetLocaltime(Script):
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
if 'timestamp' in kwargs: if 'timestamp' in kwargs:
return datetime.datetime.now() return self.do_task(task, study_id, workflow_id, *args, **kwargs)
raise ApiError(code='missing_timestamp', raise ApiError(code='missing_timestamp',
message='You must include a timestamp to convert.') message='You must include a timestamp to convert.')

View File

@ -15,7 +15,9 @@
<bpmn:documentation>This is my email</bpmn:documentation> <bpmn:documentation>This is my email</bpmn:documentation>
<bpmn:incoming>Flow_0lnc9x0</bpmn:incoming> <bpmn:incoming>Flow_0lnc9x0</bpmn:incoming>
<bpmn:outgoing>Flow_0gtgzcf</bpmn:outgoing> <bpmn:outgoing>Flow_0gtgzcf</bpmn:outgoing>
<bpmn:script>email_model = email(subject='My Email Subject', recipients='user@example.com')</bpmn:script> <bpmn:script>email_model = email(subject='My Email Subject', recipients='user@example.com')
email_data = get_email_data(email_id=email_model['id'])
</bpmn:script>
</bpmn:scriptTask> </bpmn:scriptTask>
<bpmn:scriptTask id="Activity_1by2ose" name="Get Localtime"> <bpmn:scriptTask id="Activity_1by2ose" name="Get Localtime">
<bpmn:documentation>timestamp = email_model.timestamp <bpmn:documentation>timestamp = email_model.timestamp
@ -23,7 +25,8 @@ localtime = get_localtime(str(timestamp))</bpmn:documentation>
<bpmn:incoming>Flow_0gtgzcf</bpmn:incoming> <bpmn:incoming>Flow_0gtgzcf</bpmn:incoming>
<bpmn:outgoing>Flow_0k1hbif</bpmn:outgoing> <bpmn:outgoing>Flow_0k1hbif</bpmn:outgoing>
<bpmn:script>timestamp=email_model.timestamp <bpmn:script>timestamp=email_model.timestamp
localtime = get_localtime(timestamp=timestamp)</bpmn:script> localtime = get_localtime(timestamp=timestamp)
</bpmn:script>
</bpmn:scriptTask> </bpmn:scriptTask>
<bpmn:manualTask id="Activity_0d5fjpa" name="Display Times"> <bpmn:manualTask id="Activity_0d5fjpa" name="Display Times">
<bpmn:documentation># Timestamp <bpmn:documentation># Timestamp
@ -38,21 +41,21 @@ localtime = get_localtime(timestamp=timestamp)</bpmn:script>
</bpmn:process> </bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1dxw783"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1dxw783">
<bpmndi:BPMNEdge id="Flow_0lnc9x0_di" bpmnElement="Flow_0lnc9x0"> <bpmndi:BPMNEdge id="Flow_0kgtoh1_di" bpmnElement="Flow_0kgtoh1">
<di:waypoint x="215" y="117" /> <di:waypoint x="690" y="117" />
<di:waypoint x="270" y="117" /> <di:waypoint x="752" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0gtgzcf_di" bpmnElement="Flow_0gtgzcf">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge> </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0k1hbif_di" bpmnElement="Flow_0k1hbif"> <bpmndi:BPMNEdge id="Flow_0k1hbif_di" bpmnElement="Flow_0k1hbif">
<di:waypoint x="530" y="117" /> <di:waypoint x="530" y="117" />
<di:waypoint x="590" y="117" /> <di:waypoint x="590" y="117" />
</bpmndi:BPMNEdge> </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0kgtoh1_di" bpmnElement="Flow_0kgtoh1"> <bpmndi:BPMNEdge id="Flow_0gtgzcf_di" bpmnElement="Flow_0gtgzcf">
<di:waypoint x="690" y="117" /> <di:waypoint x="370" y="117" />
<di:waypoint x="752" y="117" /> <di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0lnc9x0_di" bpmnElement="Flow_0lnc9x0">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge> </bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" /> <dc:Bounds x="179" y="99" width="36" height="36" />