spiff-arena/bin/import_tickets_for_script_t...

111 lines
3.8 KiB
Python
Raw Normal View History

"""Import tickets, for use in script task."""
def main():
"""Use main to avoid global namespace."""
import csv
from flask_bpmn.models.db import db
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.services.process_instance_processor import (
ProcessInstanceProcessor,
)
from spiffworkflow_backend.services.process_instance_service import (
ProcessInstanceService,
)
from spiffworkflow_backend.models.process_instance_report import (
ProcessInstanceReportModel,
)
process_model_identifier_ticket = "ticket"
db.session.query(ProcessInstanceModel).filter(
ProcessInstanceModel.process_model_identifier == process_model_identifier_ticket
).delete()
db.session.commit()
"""Print process instance count."""
process_instances = ProcessInstanceModel.query.filter_by(
process_model_identifier=process_model_identifier_ticket
).all()
process_instance_count = len(process_instances)
print(f"process_instance_count: {process_instance_count}")
columns_to_data_key_mappings = {
"Month": "month",
"MS": "milestone",
"Done?": "done",
"#": "notion_id",
"ID": "req_id",
"Dev Days": "dev_days",
"Feature": "feature",
"Feature description": "feature_description",
"Priority": "priority",
}
columns_to_header_index_mappings = {}
user = UserModel.query.first()
with open("tests/files/tickets.csv") as infile:
reader = csv.reader(infile, delimiter=",")
# first row is garbage
next(reader)
header = next(reader)
for column_name in columns_to_data_key_mappings:
columns_to_header_index_mappings[column_name] = header.index(column_name)
id_index = header.index("ID")
priority_index = header.index("Priority")
month_index = header.index("Month")
print(f"header: {header}")
for row in reader:
ticket_identifier = row[id_index]
priority = row[priority_index]
month = row[month_index]
print(f"ticket_identifier: {ticket_identifier}")
print(f"priority: {priority}")
# if there is no month, who cares about it.
if month:
process_instance = ProcessInstanceService.create_process_instance(
process_model_identifier=process_model_identifier_ticket,
user=user,
process_group_identifier="sartography-admin",
)
processor = ProcessInstanceProcessor(process_instance)
processor.do_engine_steps()
# processor.save()
for (
column_name,
desired_data_key,
) in columns_to_data_key_mappings.items():
appropriate_index = columns_to_header_index_mappings[column_name]
print(f"appropriate_index: {appropriate_index}")
processor.bpmn_process_instance.data[desired_data_key] = row[
appropriate_index
]
# you at least need a month, or else this row in the csv is considered garbage
month_value = processor.bpmn_process_instance.data["month"]
if month_value == "" or month_value is None:
Squashed 'spiffworkflow-backend/' changes from 5225a8b4..1e831706 1e831706 Merge pull request #146 from sartography/test_arena_push df95dccf fixed conflicts and updated usage of active task status w/ burnettk 33b81894 Merge pull request #145 from sartography/feature/remove-task-data-from-active-task 7e1ce35c remove task_data column b9cd1c06 Merge pull request #144 from sartography/feature/lib-updates-and-mypy 5e09e28d fix mypy 68485ab4 use fork of sqlalchemy-stubs 872480db Merge remote-tracking branch 'origin/main' into feature/lib-updates-and-mypy 18a892f6 work in progress 84344d53 Pause/resume process instances (#2) 53652cff Merge commit '4a48d9cccd1ca8619b3dbef3c10bcce667c9d9e0' 9ea3def2 lint c05b5181 Merge remote-tracking branch 'origin/main' into feature/lib-updates-and-mypy b2a75f60 Merge commit 'c661100e03eef762cb51b02be1b309ec47be7002' 3ddaa5d0 lib updates and mypy 30d04282 Merge commit '4fdb0f3ec4b3b6a68cc2e56ed84ffb6dc2743068' a961b2a1 Merge commit '81746ee508f6ab0ffe757856d9a3d5d855db2560' 10651984 Merge commit '8f8b4717990eb86c6bfd2f309ef064152c51b452' 59b90fba Merge branch 'main' of github.com:sartography/spiff-arena 577e0fe3 Merge commit 'a166df83031cb88d223e5c75ae8db8c896622821' 11d40241 Merge commit '106e2ca7214aec4dba965ccb3f94b0658acaa2b2' 1fcc935e Merge commit '9781908243408ed221f2b0131a00b8a9612f81f3' e9734bff Merge commit '64e7049c9a0a4360101a155a41ce64ae692acd3c' 28239aa4 Merge commit 'aa22f4b397a899fa06d06c2e9127ca98d9eb909a' 8b184a5c Merge commit '4f0f5b1ece069ec56f8eb4154d61334a321749a1' bd1effc6 Merge commit 'b4975660431c275ce736e0431b98c39548200af1' eafa4f61 Merge commit 'c9bd62250452403550ae1bf1d27547d4796dd316' 50d9a0c3 Merge commit '9be0517531543655a35023af17b76dbb41eab93e' 34e98b77 Merge commit 'a1a01ad25a1ef60b879dede6f037f0fff3381ae4' c8d0cb8a Merge commit 'bee232a55a82054e629f48f0333495b61a7da7d1' 00478271 Merge commit '71e189afbc127b574cca8d02fc31b2e65aff0d52' 657fbad9 Merge commit 'f21d0ef3a98458deb347fb2a51fab0b5b41f7fe2' c91c279e Merge commit '93dbce681ec89bc45479748aaae06ddd92b64da4' b95a1af9 Merge commit '48918b00428e777ea29d351662467c0ac4e34a36' afea9254 pre-commit updates e3bc3b76 Merge main, resolve conflicts 2e317da8 Updaging the jinja processing so it doesn't leave a bunch of blank lines in the markdown that has strong feelings about white space. Updating the front end to render markdown formatted instructions. And adding a little css love to tables that are generated in Markdown. git-subtree-dir: spiffworkflow-backend git-subtree-split: 1e831706a1f7ed841e343537cfe1dc05d5eedaca
2022-10-21 14:36:41 +00:00
db.session.delete(process_instance)
db.session.commit()
continue
processor.save()
process_instance_data = processor.get_data()
print(f"process_instance_data: {process_instance_data}")
ProcessInstanceReportModel.add_fixtures()
print("added report fixtures")
main()
# to avoid serialization issues
del main