This commit is contained in:
burnettk 2022-11-24 12:00:26 -05:00
parent bfae6ac63d
commit 2eb3ef6aa3
22 changed files with 71 additions and 68 deletions

View File

@ -74,7 +74,7 @@ def main():
print(f"ticket_identifier: {ticket_identifier}")
print(f"priority: {priority}")
process_instance = ProcessInstanceService.create_process_instance(
process_instance = ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_identifier_ticket,
user,
process_group_identifier="sartography-admin",

View File

@ -68,7 +68,7 @@ def main():
print(f"priority: {priority}")
# if there is no month, who cares about it.
if month:
process_instance = ProcessInstanceService.create_process_instance(
process_instance = ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_identifier=process_model_identifier_ticket,
user=user,
process_group_identifier="sartography-admin",

View File

@ -96,7 +96,7 @@ def setup_process_instances_for_reports(
# )
process_instances = []
for data in [kay(), ray(), jay()]:
process_instance = ProcessInstanceService.create_process_instance(
process_instance = ProcessInstanceService.create_process_instance_from_process_model_identifier(
# process_group_identifier=process_group_id,
process_model_identifier=process_model_identifier,
user=user,

View File

@ -1,5 +1,3 @@
from __future__ import with_statement
import logging
from logging.config import fileConfig

View File

@ -1,7 +1,6 @@
"""Process_instance."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
from typing import cast
@ -18,7 +17,6 @@ from sqlalchemy.orm import relationship
from sqlalchemy.orm import validates
from spiffworkflow_backend.helpers.spiff_enum import SpiffEnum
from spiffworkflow_backend.models.process_model import ProcessModelInfo
from spiffworkflow_backend.models.task import Task
from spiffworkflow_backend.models.task import TaskSchema
from spiffworkflow_backend.models.user import UserModel

View File

@ -75,7 +75,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
def add_fixtures(cls) -> None:
"""Add_fixtures."""
try:
# process_model = ProcessModelService().get_process_model(
# process_model = ProcessModelService.get_process_model(
# process_model_id="sartography-admin/ticket"
# )
user = UserModel.query.first()
@ -205,7 +205,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
) -> ProcessInstanceReportModel:
"""Create_with_attributes."""
# <<<<<<< HEAD
# process_model = ProcessModelService().get_process_model(
# process_model = ProcessModelService.get_process_model(
# process_model_id=f"{process_model_identifier}"
# )
# process_instance_report = cls(

View File

@ -43,7 +43,7 @@ def process_group_show(process_group_id: str) -> str:
@admin_blueprint.route("/process-models/<process_model_id>", methods=["GET"])
def process_model_show(process_model_id: str) -> Union[str, Response]:
"""Show_process_model."""
process_model = ProcessModelService().get_process_model(process_model_id)
process_model = ProcessModelService.get_process_model(process_model_id)
files = SpecFileService.get_files(process_model, extension_filter="bpmn")
current_file_name = process_model.primary_file_name
if current_file_name is None:
@ -64,7 +64,7 @@ def process_model_show(process_model_id: str) -> Union[str, Response]:
)
def process_model_show_file(process_model_id: str, file_name: str) -> str:
"""Process_model_show_file."""
process_model = ProcessModelService().get_process_model(process_model_id)
process_model = ProcessModelService.get_process_model(process_model_id)
bpmn_xml = SpecFileService.get_data(process_model, file_name)
files = SpecFileService.get_files(process_model, extension_filter="bpmn")
return render_template(
@ -109,7 +109,7 @@ def process_model_upload_file(process_model_id: str) -> Response:
)
def process_model_edit(process_model_id: str, file_name: str) -> str:
"""Edit_bpmn."""
process_model = ProcessModelService().get_process_model(process_model_id)
process_model = ProcessModelService.get_process_model(process_model_id)
bpmn_xml = SpecFileService.get_data(process_model, file_name)
return render_template(
@ -125,7 +125,7 @@ def process_model_edit(process_model_id: str, file_name: str) -> str:
)
def process_model_save(process_model_id: str, file_name: str) -> Union[str, Response]:
"""Process_model_save."""
process_model = ProcessModelService().get_process_model(process_model_id)
process_model = ProcessModelService.get_process_model(process_model_id)
SpecFileService.update_file(process_model, file_name, request.get_data())
if process_model.primary_file_name is None:
flash("No primary_file_name", "error")
@ -143,14 +143,16 @@ def process_model_save(process_model_id: str, file_name: str) -> Union[str, Resp
def process_model_run(process_model_id: str) -> Union[str, Response]:
"""Process_model_run."""
user = UserService.create_user("internal", "Mr. Test", username="Mr. Test")
process_instance = ProcessInstanceService.create_process_instance(
process_model_id, user
process_instance = (
ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_id, user
)
)
processor = ProcessInstanceProcessor(process_instance)
processor.do_engine_steps()
result = processor.get_data()
process_model = ProcessModelService().get_process_model(process_model_id)
process_model = ProcessModelService.get_process_model(process_model_id)
files = SpecFileService.get_files(process_model, extension_filter="bpmn")
current_file_name = process_model.primary_file_name
if current_file_name is None:

View File

@ -363,7 +363,7 @@ def process_model_list(
per_page: int = 100,
) -> flask.wrappers.Response:
"""Process model list!"""
process_models = ProcessModelService().get_process_models(
process_models = ProcessModelService.get_process_models(
process_group_id=process_group_identifier,
recursive=recursive,
filter_runnable_by_user=filter_runnable_by_user,
@ -495,8 +495,10 @@ def process_instance_create(modified_process_model_id: str) -> flask.wrappers.Re
process_model_identifier = un_modify_modified_process_model_id(
modified_process_model_id
)
process_instance = ProcessInstanceService.create_process_instance(
process_model_identifier, g.user
process_instance = (
ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_identifier, g.user
)
)
return Response(
json.dumps(ProcessInstanceModelSchema().dump(process_instance)),
@ -1595,7 +1597,7 @@ def get_process_model(process_model_id: str) -> ProcessModelInfo:
"""Get_process_model."""
process_model = None
try:
process_model = ProcessModelService().get_process_model(process_model_id)
process_model = ProcessModelService.get_process_model(process_model_id)
except ProcessEntityNotFoundError as exception:
raise (
ApiError(

View File

@ -30,7 +30,7 @@ def load_acceptance_test_fixtures() -> list[ProcessInstanceModel]:
process_instances = []
for i in range(len(statuses)):
process_instance = ProcessInstanceService.create_process_instance(
process_instance = ProcessInstanceService.create_process_instance_from_process_model_identifier(
test_process_model_id, user
)
process_instance.status = statuses[i]

View File

@ -26,7 +26,7 @@ class DataSetupService:
current_app.logger.debug("DataSetupService.save_all_process_models() start")
failing_process_models = []
process_models = ProcessModelService().get_process_models(recursive=True)
process_models = ProcessModelService.get_process_models(recursive=True)
SpecFileService.clear_caches()
for process_model in process_models:
current_app.logger.debug(f"Process Model: {process_model.display_name}")

View File

@ -34,7 +34,7 @@ class ErrorHandlingService:
self, _processor: ProcessInstanceProcessor, _error: Union[ApiError, Exception]
) -> None:
"""On unhandled exceptions, set instance.status based on model.fault_or_suspend_on_exception."""
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
_processor.process_model_identifier
)
if process_model.fault_or_suspend_on_exception == "suspend":

View File

@ -117,7 +117,7 @@ class MessageService:
user: UserModel,
) -> ProcessInstanceModel:
"""Process_message_triggerable_process_model."""
process_instance_receive = ProcessInstanceService.create_process_instance(
process_instance_receive = ProcessInstanceService.create_process_instance_from_process_model_identifier(
message_triggerable_process_model.process_model_identifier,
user,
)

View File

@ -349,7 +349,9 @@ class ProcessInstanceProcessor:
check_sub_specs(test_spec, 5)
self.process_model_identifier = process_instance_model.process_model_identifier
self.process_model_display_name = process_instance_model.process_model_display_name
self.process_model_display_name = (
process_instance_model.process_model_display_name
)
try:
self.bpmn_process_instance = self.__get_bpmn_process_instance(
@ -374,7 +376,7 @@ class ProcessInstanceProcessor:
cls, process_model_identifier: str
) -> Tuple[BpmnProcessSpec, IdToBpmnProcessSpecMapping]:
"""Get_process_model_and_subprocesses."""
process_model_info = ProcessModelService().get_process_model(
process_model_info = ProcessModelService.get_process_model(
process_model_identifier
)
if process_model_info is None:
@ -662,7 +664,7 @@ class ProcessInstanceProcessor:
bpmn_process_identifier: str,
) -> Optional[str]:
"""Backfill_missing_spec_reference_records."""
process_models = ProcessModelService().get_process_models(recursive=True)
process_models = ProcessModelService.get_process_models(recursive=True)
for process_model in process_models:
try:
refs = SpecFileService.reference_map(

View File

@ -29,8 +29,9 @@ class ProcessInstanceService:
TASK_STATE_LOCKED = "locked"
@staticmethod
@classmethod
def create_process_instance(
cls,
process_model: ProcessModelInfo,
user: UserModel,
) -> ProcessInstanceModel:
@ -49,6 +50,16 @@ class ProcessInstanceService:
db.session.commit()
return process_instance_model
@classmethod
def create_process_instance_from_process_model_identifier(
cls,
process_model_identifier: str,
user: UserModel,
) -> ProcessInstanceModel:
"""Create_process_instance_from_process_model_identifier."""
process_model = ProcessModelService.get_process_model(process_model_identifier)
return cls.create_process_instance(process_model, user)
@staticmethod
def do_waiting() -> None:
"""Do_waiting."""
@ -89,7 +100,7 @@ class ProcessInstanceService:
process_model = process_model_service.get_process_model(
processor.process_model_identifier
)
title_value = process_model.display_name if process_model else ""
process_model.display_name if process_model else ""
process_instance_api = ProcessInstanceApi(
id=processor.get_process_instance_id(),
status=processor.get_status(),

View File

@ -44,9 +44,10 @@ class ProcessModelService(FileSystemService):
return True
return False
def is_model(self, path: str) -> bool:
@classmethod
def is_model(cls, path: str) -> bool:
"""Is_model."""
model_json_path = os.path.join(path, self.PROCESS_MODEL_JSON_FILE)
model_json_path = os.path.join(path, cls.PROCESS_MODEL_JSON_FILE)
if os.path.exists(model_json_path):
return True
return False
@ -144,7 +145,8 @@ class ProcessModelService(FileSystemService):
path = os.path.join(FileSystemService.root_path(), relative_path)
return cls().__scan_process_model(path, process_group=process_group)
def get_process_model(self, process_model_id: str) -> ProcessModelInfo:
@classmethod
def get_process_model(cls, process_model_id: str) -> ProcessModelInfo:
"""Get a process model from a model and group id.
process_model_id is the full path to the model--including groups.
@ -155,7 +157,7 @@ class ProcessModelService(FileSystemService):
model_path = os.path.abspath(
os.path.join(FileSystemService.root_path(), process_model_id)
)
if self.is_model(model_path):
if cls.is_model(model_path):
process_model = self.get_process_model_from_relative_path(process_model_id)
return process_model
raise ProcessEntityNotFoundError("process_model_not_found")
@ -285,7 +287,7 @@ class ProcessModelService(FileSystemService):
for _root, dirs, _files in os.walk(group_path):
for dir in dirs:
model_dir = os.path.join(group_path, dir)
if ProcessModelService().is_model(model_dir):
if ProcessModelService.is_model(model_dir):
process_model = self.get_process_model(model_dir)
all_nested_models.append(process_model)
return all_nested_models
@ -382,7 +384,7 @@ class ProcessModelService(FileSystemService):
process_group.process_groups.append(
self.find_or_create_process_group(nested_item.path)
)
elif self.is_model(nested_item.path):
elif ProcessModelService.is_model(nested_item.path):
process_group.process_models.append(
self.__scan_process_model(
nested_item.path,

View File

@ -133,7 +133,7 @@ class TestProcessApi(BaseTest):
process_model_description=model_description,
user=with_super_admin_user,
)
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
process_model_identifier,
)
assert model_display_name == process_model.display_name
@ -155,9 +155,7 @@ class TestProcessApi(BaseTest):
user=with_super_admin_user,
)
# get the model, assert that primary is set
process_model = ProcessModelService().get_process_model(
process_model_identifier
)
process_model = ProcessModelService.get_process_model(process_model_identifier)
assert process_model.primary_file_name == bpmn_file_name
assert process_model.primary_process_id == "sample"
@ -208,9 +206,7 @@ class TestProcessApi(BaseTest):
headers=self.logged_in_headers(with_super_admin_user),
)
assert response.status_code == 200
process_model = ProcessModelService().get_process_model(
process_model_identifier
)
process_model = ProcessModelService.get_process_model(process_model_identifier)
assert process_model.primary_file_name == bpmn_file_name
assert process_model.primary_process_id == terminal_primary_process_id
@ -236,9 +232,7 @@ class TestProcessApi(BaseTest):
)
# assert we have a model
process_model = ProcessModelService().get_process_model(
process_model_identifier
)
process_model = ProcessModelService.get_process_model(process_model_identifier)
assert process_model is not None
assert process_model.id == process_model_identifier
@ -254,7 +248,7 @@ class TestProcessApi(BaseTest):
# assert we no longer have a model
with pytest.raises(ProcessEntityNotFoundError):
ProcessModelService().get_process_model(process_model_identifier)
ProcessModelService.get_process_model(process_model_identifier)
def test_process_model_delete_with_instances(
self,
@ -327,9 +321,7 @@ class TestProcessApi(BaseTest):
process_model_id=process_model_identifier,
user=with_super_admin_user,
)
process_model = ProcessModelService().get_process_model(
process_model_identifier
)
process_model = ProcessModelService.get_process_model(process_model_identifier)
assert process_model.id == process_model_identifier
assert process_model.display_name == "Cooooookies"
assert process_model.primary_file_name is None
@ -1902,9 +1894,7 @@ class TestProcessApi(BaseTest):
process_instance_id = self.setup_testing_instance(
client, process_model_identifier, with_super_admin_user
)
process_model = ProcessModelService().get_process_model(
process_model_identifier
)
process_model = ProcessModelService.get_process_model(process_model_identifier)
ProcessModelService().update_process_model(
process_model,
{"fault_or_suspend_on_exception": NotificationType.suspend.value},
@ -1957,9 +1947,7 @@ class TestProcessApi(BaseTest):
client, process_model_identifier, with_super_admin_user
)
process_model = ProcessModelService().get_process_model(
process_model_identifier
)
process_model = ProcessModelService.get_process_model(process_model_identifier)
ProcessModelService().update_process_model(
process_model,
{"exception_notification_addresses": ["with_super_admin_user@example.com"]},
@ -2483,7 +2471,7 @@ class TestProcessApi(BaseTest):
process_model_display_name=process_model_id,
process_model_description=process_model_id,
)
persisted = ProcessModelService().get_process_model(original_process_model_path)
persisted = ProcessModelService.get_process_model(original_process_model_path)
assert persisted is not None
assert persisted.id == original_process_model_path
@ -2503,11 +2491,11 @@ class TestProcessApi(BaseTest):
# make sure the original model does not exist
with pytest.raises(ProcessEntityNotFoundError) as e:
ProcessModelService().get_process_model(original_process_model_path)
ProcessModelService.get_process_model(original_process_model_path)
assert e.value.args[0] == "process_model_not_found"
# make sure the new model does exist
new_process_model = ProcessModelService().get_process_model(
new_process_model = ProcessModelService.get_process_model(
new_process_model_path
)
assert new_process_model is not None

View File

@ -52,7 +52,7 @@ class SecretServiceTestHelpers(BaseTest):
process_model_description=self.test_process_model_description,
user=user,
)
process_model_info = ProcessModelService().get_process_model(
process_model_info = ProcessModelService.get_process_model(
process_model_identifier
)
return process_model_info

View File

@ -113,7 +113,7 @@ class TestAuthorizationService(BaseTest):
bpmn_file_location="model_with_lanes",
)
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
process_model_id=process_model_identifier
)
process_instance = self.create_process_instance_from_process_model(

View File

@ -44,7 +44,7 @@ class TestMessageInstance(BaseTest):
client, with_super_admin_user
)
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
process_model_id=process_model_identifier
)
process_instance = self.create_process_instance_from_process_model(
@ -81,7 +81,7 @@ class TestMessageInstance(BaseTest):
client, with_super_admin_user
)
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
process_model_id=process_model_identifier
)
process_instance = self.create_process_instance_from_process_model(
@ -127,7 +127,7 @@ class TestMessageInstance(BaseTest):
client, with_super_admin_user
)
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
process_model_id=process_model_identifier
)
process_instance = self.create_process_instance_from_process_model(
@ -174,7 +174,7 @@ class TestMessageInstance(BaseTest):
client, with_super_admin_user
)
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
process_model_id=process_model_identifier
)
process_instance = self.create_process_instance_from_process_model(

View File

@ -47,7 +47,7 @@ class TestMessageService(BaseTest):
bpmn_file_name="message_sender.bpmn",
)
process_instance_sender = ProcessInstanceService.create_process_instance(
process_instance_sender = ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_sender.id,
with_super_admin_user,
)
@ -154,7 +154,7 @@ class TestMessageService(BaseTest):
user = self.find_or_create_user()
process_instance_sender = ProcessInstanceService.create_process_instance(
process_instance_sender = ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_sender.id,
user,
# process_group_identifier=process_model_sender.process_group_id,

View File

@ -188,7 +188,7 @@ class TestSpecFileService(BaseTest):
# ,
# process_model_source_directory="call_activity_nested",
# )
process_model_info = ProcessModelService().get_process_model(
process_model_info = ProcessModelService.get_process_model(
process_model_identifier
)
files = SpecFileService.get_files(process_model_info)

View File

@ -28,7 +28,7 @@ class TestVariousBpmnConstructs(BaseTest):
"timer_intermediate_catch_event",
)
process_model = ProcessModelService().get_process_model(
process_model = ProcessModelService.get_process_model(
process_model_id=process_model_identifier
)