2022-09-16 21:04:45 +00:00
|
|
|
"""Grabs tickets from csv and makes process instances."""
|
|
|
|
import os
|
|
|
|
|
|
|
|
from spiffworkflow_backend import create_app
|
|
|
|
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
|
|
|
from spiffworkflow_backend.services.spec_file_service import SpecFileService
|
|
|
|
|
2022-09-16 22:41:39 +00:00
|
|
|
# from lxml.etree import Element as EtreeElement
|
|
|
|
|
2022-09-16 21:04:45 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Main."""
|
2022-10-10 18:27:20 +00:00
|
|
|
os.environ["SPIFFWORKFLOW_BACKEND_ENV"] = "development"
|
2022-09-16 21:04:45 +00:00
|
|
|
flask_env_key = "FLASK_SESSION_SECRET_KEY"
|
|
|
|
os.environ[flask_env_key] = "whatevs"
|
2022-09-19 17:02:30 +00:00
|
|
|
if "BPMN_SPEC_ABSOLUTE_DIR" not in os.environ:
|
2022-09-19 16:15:16 +00:00
|
|
|
home = os.environ["HOME"]
|
2022-09-19 16:16:10 +00:00
|
|
|
full_process_model_path = (
|
|
|
|
f"{home}/projects/github/sartography/sample-process-models"
|
|
|
|
)
|
2022-09-19 16:15:16 +00:00
|
|
|
if os.path.isdir(full_process_model_path):
|
2022-09-19 16:16:10 +00:00
|
|
|
os.environ["BPMN_SPEC_ABSOLUTE_DIR"] = full_process_model_path
|
2022-09-19 16:15:16 +00:00
|
|
|
else:
|
|
|
|
raise Exception(f"Could not find {full_process_model_path}")
|
2022-09-16 21:04:45 +00:00
|
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
|
|
no_primary = []
|
2022-09-28 19:33:12 +00:00
|
|
|
failing_process_models = []
|
2022-09-16 21:04:45 +00:00
|
|
|
process_models = ProcessModelService().get_process_models()
|
|
|
|
for process_model in process_models:
|
|
|
|
if process_model.primary_file_name:
|
2022-09-19 13:03:13 +00:00
|
|
|
|
2022-09-16 22:39:00 +00:00
|
|
|
bpmn_xml_file_contents = SpecFileService.get_data(
|
|
|
|
process_model, process_model.primary_file_name
|
|
|
|
)
|
2022-09-16 22:41:39 +00:00
|
|
|
bad_files = [
|
|
|
|
"B.1.0.bpmn",
|
|
|
|
"C.1.0.bpmn",
|
|
|
|
"C.2.0.bpmn",
|
|
|
|
"C.6.0.bpmn",
|
|
|
|
"TC-5.1.bpmn",
|
|
|
|
]
|
2022-09-16 22:39:00 +00:00
|
|
|
if process_model.primary_file_name in bad_files:
|
|
|
|
continue
|
|
|
|
print(f"primary_file_name: {process_model.primary_file_name}")
|
2022-09-28 19:33:12 +00:00
|
|
|
try:
|
|
|
|
SpecFileService.update_file(
|
|
|
|
process_model,
|
|
|
|
process_model.primary_file_name,
|
|
|
|
bpmn_xml_file_contents,
|
|
|
|
)
|
|
|
|
except Exception as ex:
|
2022-09-28 20:01:49 +00:00
|
|
|
failing_process_models.append(
|
|
|
|
(process_model.primary_file_name, str(ex))
|
|
|
|
)
|
2022-09-16 22:41:39 +00:00
|
|
|
# files = SpecFileService.get_files(
|
|
|
|
# process_model, extension_filter="bpmn"
|
|
|
|
# )
|
|
|
|
# bpmn_etree_element: EtreeElement = (
|
|
|
|
# SpecFileService.get_etree_element_from_binary_data(
|
|
|
|
# bpmn_xml_file_contents, process_model.primary_file_name
|
|
|
|
# )
|
|
|
|
# )
|
2022-09-16 22:39:00 +00:00
|
|
|
# if len(files) == 1:
|
2022-09-16 22:41:39 +00:00
|
|
|
# try:
|
|
|
|
# new_bpmn_process_identifier = (
|
|
|
|
# SpecFileService.get_bpmn_process_identifier(
|
|
|
|
# bpmn_etree_element
|
|
|
|
# )
|
|
|
|
# )
|
|
|
|
# if (
|
|
|
|
# process_model.primary_process_id
|
|
|
|
# != new_bpmn_process_identifier
|
|
|
|
# ):
|
|
|
|
# print(
|
|
|
|
# "primary_process_id: ", process_model.primary_process_id
|
|
|
|
# )
|
|
|
|
# # attributes_to_update = {
|
|
|
|
# # "primary_process_id": new_bpmn_process_identifier
|
|
|
|
# # }
|
|
|
|
# # ProcessModelService().update_spec(
|
|
|
|
# # process_model, attributes_to_update
|
|
|
|
# # )
|
|
|
|
# # except Exception as exception:
|
|
|
|
# except Exception:
|
|
|
|
# print(f"BAD ONE: {process_model.id}")
|
|
|
|
# # raise exception
|
2022-09-16 21:04:45 +00:00
|
|
|
else:
|
|
|
|
no_primary.append(process_model)
|
2022-09-16 22:22:10 +00:00
|
|
|
# for bpmn in no_primary:
|
|
|
|
# print(bpmn)
|
2022-09-28 19:33:12 +00:00
|
|
|
for bpmn_errors in failing_process_models:
|
|
|
|
print(bpmn_errors)
|
|
|
|
if len(failing_process_models) > 0:
|
|
|
|
exit(1)
|
2022-09-16 21:04:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|