demo-process-models/playground/dan/dans-first-progress-model/cereals_data_store.bpmn

202 lines
7.7 KiB
XML

<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:spiffworkflow="http://spiffworkflow.org/bpmn/schema/1.0/core" id="Definitions_96f6665" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.10.0">
<bpmn:dataStore id="typeahead" name="TypeaheadDataStore" />
<bpmn:process id="cereals_data_store" name="Cites States and Countries Typeahead List" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0tn4ed3</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0tn4ed3" sourceRef="StartEvent_1" targetRef="Activity_09mu4sd" />
<bpmn:endEvent id="Event_0jxoz7s">
<bpmn:incoming>Flow_0lz96a1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0lz96a1" sourceRef="Activity_0o51srq" targetRef="Event_0jxoz7s" />
<bpmn:scriptTask id="Activity_0o51srq" name="Parse response">
<bpmn:extensionElements>
<spiffworkflow:unitTests>
<spiffworkflow:unitTest id="test_top3">
<spiffworkflow:inputJson>{
"typeahead": {},
"cities_result": [
{
"id": 52,
"name": "Ashkāsham",
"state_id": 3901,
"state_code": "BDS",
"state_name": "Badakhshan",
"country_id": 1,
"country_code": "AF",
"country_name": "Afghanistan",
"latitude": "36.68333000",
"longitude": "71.53333000",
"wikiDataId": "Q4805192"
},
{
"id": 68,
"name": "Fayzabad",
"state_id": 3901,
"state_code": "BDS",
"state_name": "Badakhshan",
"country_id": 1,
"country_code": "AF",
"country_name": "Afghanistan",
"latitude": "37.11664000",
"longitude": "70.58002000",
"wikiDataId": "Q156558"
},
{
"id": 78,
"name": "Jurm",
"state_id": 3901,
"state_code": "BDS",
"state_name": "Badakhshan",
"country_id": 1,
"country_code": "AF",
"country_name": "Afghanistan",
"latitude": "36.86477000",
"longitude": "70.83421000",
"wikiDataId": "Q10308323"
}
]
}</spiffworkflow:inputJson>
<spiffworkflow:expectedOutputJson>{
"typeahead": {
"cities": [
{
"search_term": "Ashkāsham",
"result": {
"name": "Ashkāsham",
"country": "Afghanistan",
"state": "Badakhshan"
}
},
{
"search_term": "Fayzabad",
"result": {
"name": "Fayzabad",
"country": "Afghanistan",
"state": "Badakhshan"
}
},
{
"search_term": "Jurm",
"result": {
"name": "Jurm",
"country": "Afghanistan",
"state": "Badakhshan"
}
}
],
"countries": [
{
"result": {
"name": "Afghanistan"
},
"search_term": "Afghanistan"
}
],
"states": [
{
"result": {
"country": "Afghanistan",
"name": "Badakhshan"
},
"search_term": "Badakhshan"
}
]
}
}</spiffworkflow:expectedOutputJson>
</spiffworkflow:unitTest>
</spiffworkflow:unitTests>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0w7oyed</bpmn:incoming>
<bpmn:outgoing>Flow_0lz96a1</bpmn:outgoing>
<bpmn:dataOutputAssociation id="DataOutputAssociation_0tjuw5b">
<bpmn:targetRef>DataStoreReference_1oronwq</bpmn:targetRef>
</bpmn:dataOutputAssociation>
<bpmn:script>def parse_cities_result():
cities = []
countries = []
states = []
states_by_country = {}
for result in cities_result:
name = result["name"]
state = result["state_name"]
country = result["country_name"]
cities.append({"search_term": name, "result": {"name": name, "state": state, "country": country}})
if country not in states_by_country:
states_by_country[country] = set()
states_by_country[country].add(state)
for country in states_by_country.keys():
countries.append({"search_term": country, "result":{"name": country}})
for state in states_by_country[country]:
states.append({"search_term": state, "result": {"name": state, "country": country}})
return { "cities": cities, "countries": countries, "states": states }
typeahead = parse_cities_result()
del(cities_result)</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_0w7oyed" sourceRef="Activity_09mu4sd" targetRef="Activity_0o51srq" />
<bpmn:serviceTask id="Activity_09mu4sd" name="Fetch json">
<bpmn:extensionElements>
<spiffworkflow:serviceTaskOperator id="http/GetRequest" resultVariable="cities_result">
<spiffworkflow:parameters>
<spiffworkflow:parameter id="basic_auth_password" type="str" />
<spiffworkflow:parameter id="basic_auth_username" type="str" />
<spiffworkflow:parameter id="headers" type="any" />
<spiffworkflow:parameter id="params" type="any" />
<spiffworkflow:parameter id="url" type="str" value="&#34;https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/master/cities.json&#34;" />
</spiffworkflow:parameters>
</spiffworkflow:serviceTaskOperator>
<spiffworkflow:instructionsForEndUser>Fetching data from Countries-States-Cities DB (GitHub)</spiffworkflow:instructionsForEndUser>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0tn4ed3</bpmn:incoming>
<bpmn:outgoing>Flow_0w7oyed</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:dataStoreReference id="DataStoreReference_1oronwq" name="Update &#10;Typeahead Data Store" dataStoreRef="typeahead" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Cites_States_Countries_Typeahead_List">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0jxoz7s_di" bpmnElement="Event_0jxoz7s">
<dc:Bounds x="542" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1fwfxsn_di" bpmnElement="Activity_0o51srq">
<dc:Bounds x="390" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1hntoll_di" bpmnElement="Activity_09mu4sd">
<dc:Bounds x="250" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="DataStoreReference_1oronwq_di" bpmnElement="DataStoreReference_1oronwq">
<dc:Bounds x="415" y="245" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="400" y="302" width="81" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0tn4ed3_di" bpmnElement="Flow_0tn4ed3">
<di:waypoint x="215" y="117" />
<di:waypoint x="250" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0lz96a1_di" bpmnElement="Flow_0lz96a1">
<di:waypoint x="490" y="117" />
<di:waypoint x="542" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="DataOutputAssociation_0tjuw5b_di" bpmnElement="DataOutputAssociation_0tjuw5b">
<di:waypoint x="441" y="157" />
<di:waypoint x="444" y="245" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0w7oyed_di" bpmnElement="Flow_0w7oyed">
<di:waypoint x="350" y="117" />
<di:waypoint x="390" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>