pyl w/ burnettk
This commit is contained in:
parent
15784c0ea3
commit
d35c2a9f2d
|
@ -1915,7 +1915,7 @@ class ProcessInstanceProcessor:
|
||||||
if json_data_dict is not None:
|
if json_data_dict is not None:
|
||||||
json_data = (
|
json_data = (
|
||||||
db.session.query(JsonDataModel.id)
|
db.session.query(JsonDataModel.id)
|
||||||
.filter_by(hash=json_data_dict['hash'])
|
.filter_by(hash=json_data_dict["hash"])
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
if json_data is None:
|
if json_data is None:
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
import json
|
import json
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from flask import current_app
|
|
||||||
from typing import TypedDict
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
|
from flask import current_app
|
||||||
from SpiffWorkflow.bpmn.serializer.workflow import BpmnWorkflow # type: ignore
|
from SpiffWorkflow.bpmn.serializer.workflow import BpmnWorkflow # type: ignore
|
||||||
from SpiffWorkflow.bpmn.serializer.workflow import BpmnWorkflowSerializer
|
from SpiffWorkflow.bpmn.serializer.workflow import BpmnWorkflowSerializer
|
||||||
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
|
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
|
||||||
from SpiffWorkflow.task import TaskStateNames
|
from SpiffWorkflow.task import TaskStateNames
|
||||||
|
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
||||||
|
from sqlalchemy.dialects.postgresql import insert as postgres_insert
|
||||||
|
|
||||||
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel
|
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel
|
||||||
from spiffworkflow_backend.models.db import db
|
from spiffworkflow_backend.models.db import db
|
||||||
|
@ -16,9 +18,6 @@ from spiffworkflow_backend.models.json_data import JsonDataModel # noqa: F401
|
||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||||
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
|
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
|
||||||
|
|
||||||
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
|
||||||
from sqlalchemy.dialects.postgresql import insert as postgres_insert
|
|
||||||
|
|
||||||
|
|
||||||
class JsonDataDict(TypedDict):
|
class JsonDataDict(TypedDict):
|
||||||
hash: str
|
hash: str
|
||||||
|
@ -27,7 +26,9 @@ class JsonDataDict(TypedDict):
|
||||||
|
|
||||||
class TaskService:
|
class TaskService:
|
||||||
@classmethod
|
@classmethod
|
||||||
def insert_or_update_json_data_records(cls, json_data_hash_to_json_data_dict_mapping: dict[str, JsonDataDict]) -> None:
|
def insert_or_update_json_data_records(
|
||||||
|
cls, json_data_hash_to_json_data_dict_mapping: dict[str, JsonDataDict]
|
||||||
|
) -> None:
|
||||||
list_of_dicts = [*json_data_hash_to_json_data_dict_mapping.values()]
|
list_of_dicts = [*json_data_hash_to_json_data_dict_mapping.values()]
|
||||||
if len(list_of_dicts) > 0:
|
if len(list_of_dicts) > 0:
|
||||||
# >>> from sqlalchemy.dialects.postgresql import insert
|
# >>> from sqlalchemy.dialects.postgresql import insert
|
||||||
|
@ -45,16 +46,15 @@ class TaskService:
|
||||||
# ... set_=dict(data='updated value')
|
# ... set_=dict(data='updated value')
|
||||||
# ... )
|
# ... )
|
||||||
on_duplicate_key_stmt = None
|
on_duplicate_key_stmt = None
|
||||||
if current_app.config['SPIFFWORKFLOW_BACKEND_DATABASE_TYPE'] == "mysql":
|
if current_app.config["SPIFFWORKFLOW_BACKEND_DATABASE_TYPE"] == "mysql":
|
||||||
insert_stmt = mysql_insert(JsonDataModel).values(list_of_dicts)
|
insert_stmt = mysql_insert(JsonDataModel).values(list_of_dicts)
|
||||||
on_duplicate_key_stmt = insert_stmt.on_duplicate_key_update(
|
on_duplicate_key_stmt = insert_stmt.on_duplicate_key_update(
|
||||||
data=insert_stmt.inserted.data,
|
data=insert_stmt.inserted.data, status="U"
|
||||||
status='U'
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
insert_stmt = postgres_insert(JsonDataModel).values(list_of_dicts)
|
insert_stmt = postgres_insert(JsonDataModel).values(list_of_dicts)
|
||||||
on_duplicate_key_stmt = insert_stmt.on_conflict_do_nothing(
|
on_duplicate_key_stmt = insert_stmt.on_conflict_do_nothing(
|
||||||
index_elements=['hash']
|
index_elements=["hash"]
|
||||||
)
|
)
|
||||||
db.session.execute(on_duplicate_key_stmt)
|
db.session.execute(on_duplicate_key_stmt)
|
||||||
|
|
||||||
|
@ -86,7 +86,9 @@ class TaskService:
|
||||||
spiff_task_data = new_properties_json.pop("data")
|
spiff_task_data = new_properties_json.pop("data")
|
||||||
task_model.properties_json = new_properties_json
|
task_model.properties_json = new_properties_json
|
||||||
task_model.state = TaskStateNames[new_properties_json["state"]]
|
task_model.state = TaskStateNames[new_properties_json["state"]]
|
||||||
json_data_dict = cls._update_task_data_on_task_model(task_model, spiff_task_data)
|
json_data_dict = cls._update_task_data_on_task_model(
|
||||||
|
task_model, spiff_task_data
|
||||||
|
)
|
||||||
return json_data_dict
|
return json_data_dict
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -214,7 +216,10 @@ class TaskService:
|
||||||
bpmn_process_data_json.encode("utf8")
|
bpmn_process_data_json.encode("utf8")
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
if bpmn_process.json_data_hash != bpmn_process_data_hash:
|
if bpmn_process.json_data_hash != bpmn_process_data_hash:
|
||||||
new_json_data_dicts[bpmn_process_data_hash] = {"hash": bpmn_process_data_hash, "data": bpmn_process_data_dict}
|
new_json_data_dicts[bpmn_process_data_hash] = {
|
||||||
|
"hash": bpmn_process_data_hash,
|
||||||
|
"data": bpmn_process_data_dict,
|
||||||
|
}
|
||||||
bpmn_process.json_data_hash = bpmn_process_data_hash
|
bpmn_process.json_data_hash = bpmn_process_data_hash
|
||||||
|
|
||||||
if bpmn_process_parent is None:
|
if bpmn_process_parent is None:
|
||||||
|
@ -251,6 +256,6 @@ class TaskService:
|
||||||
)
|
)
|
||||||
new_task_models[task_model.guid] = task_model
|
new_task_models[task_model.guid] = task_model
|
||||||
if json_data_dict is not None:
|
if json_data_dict is not None:
|
||||||
new_json_data_dicts[json_data_dict['hash']] = json_data_dict
|
new_json_data_dicts[json_data_dict["hash"]] = json_data_dict
|
||||||
|
|
||||||
return (bpmn_process, new_task_models, new_json_data_dicts)
|
return (bpmn_process, new_task_models, new_json_data_dicts)
|
||||||
|
|
|
@ -19,7 +19,8 @@ from spiffworkflow_backend.models.message_instance_correlation import (
|
||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||||
from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel
|
from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel
|
||||||
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
|
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
|
||||||
from spiffworkflow_backend.services.task_service import JsonDataDict, TaskService
|
from spiffworkflow_backend.services.task_service import JsonDataDict
|
||||||
|
from spiffworkflow_backend.services.task_service import TaskService
|
||||||
|
|
||||||
|
|
||||||
class EngineStepDelegate:
|
class EngineStepDelegate:
|
||||||
|
@ -90,7 +91,7 @@ class TaskModelSavingDelegate(EngineStepDelegate):
|
||||||
self.current_task_model, spiff_task, self.serializer
|
self.current_task_model, spiff_task, self.serializer
|
||||||
)
|
)
|
||||||
if json_data_dict is not None:
|
if json_data_dict is not None:
|
||||||
self.json_data_dicts[json_data_dict['hash']] = json_data_dict
|
self.json_data_dicts[json_data_dict["hash"]] = json_data_dict
|
||||||
self.task_models[self.current_task_model.guid] = self.current_task_model
|
self.task_models[self.current_task_model.guid] = self.current_task_model
|
||||||
if self.secondary_engine_step_delegate:
|
if self.secondary_engine_step_delegate:
|
||||||
self.secondary_engine_step_delegate.did_complete_task(spiff_task)
|
self.secondary_engine_step_delegate.did_complete_task(spiff_task)
|
||||||
|
@ -126,7 +127,7 @@ class TaskModelSavingDelegate(EngineStepDelegate):
|
||||||
)
|
)
|
||||||
self.task_models[task_model.guid] = task_model
|
self.task_models[task_model.guid] = task_model
|
||||||
if json_data_dict is not None:
|
if json_data_dict is not None:
|
||||||
self.json_data_dicts[json_data_dict['hash']] = json_data_dict
|
self.json_data_dicts[json_data_dict["hash"]] = json_data_dict
|
||||||
|
|
||||||
|
|
||||||
class StepDetailLoggingDelegate(EngineStepDelegate):
|
class StepDetailLoggingDelegate(EngineStepDelegate):
|
||||||
|
|
Loading…
Reference in New Issue