diff --git a/bin/save_all_bpmn.py b/bin/save_all_bpmn.py index aae63c92..55a0de90 100644 --- a/bin/save_all_bpmn.py +++ b/bin/save_all_bpmn.py @@ -1,12 +1,12 @@ """Grabs tickets from csv and makes process instances.""" import os +from lxml.etree import Element as EtreeElement + from spiffworkflow_backend import create_app from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.spec_file_service import SpecFileService -from lxml.etree import Element as EtreeElement - def main(): """Main.""" @@ -14,42 +14,56 @@ def main(): flask_env_key = "FLASK_SESSION_SECRET_KEY" os.environ[flask_env_key] = "whatevs" home = os.environ["HOME"] - os.environ["BPMN_SPEC_ABSOLUTE_DIR"] = f"{home}/projects/github/sartography/sample-process-models" + os.environ[ + "BPMN_SPEC_ABSOLUTE_DIR" + ] = f"{home}/projects/github/sartography/sample-process-models" app = create_app() with app.app_context(): no_primary = [] process_models = ProcessModelService().get_process_models() for process_model in process_models: if process_model.primary_file_name: - files = SpecFileService.get_files(process_model, extension_filter="bpmn") + files = SpecFileService.get_files( + process_model, extension_filter="bpmn" + ) if len(files) == 1: # print(f"primary_file_name: {process_model.primary_file_name}") bpmn_xml_file_contents = SpecFileService.get_data( process_model, process_model.primary_file_name ) - # bpmn_etree_element: EtreeElement = ( - # SpecFileService.get_etree_element_from_binary_data( - # bpmn_xml_file_contents, process_model.primary_file_name - # ) - # ) - # try: - # attributes_to_update = { - # "primary_process_id": ( - # SpecFileService.get_bpmn_process_identifier( - # bpmn_etree_element - # ) - # ), - # } - # ProcessModelService().update_spec( - # process_model, attributes_to_update - # ) - SpecFileService.update_file(process_model, process_model.primary_file_name, bpmn_xml_file_contents) - # except Exception: - # print(process_model.id) + bpmn_etree_element: EtreeElement = ( + SpecFileService.get_etree_element_from_binary_data( + bpmn_xml_file_contents, process_model.primary_file_name + ) + ) + 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 + # ) + # SpecFileService.update_file(process_model, process_model.primary_file_name, bpmn_xml_file_contents) + # except Exception as exception: + except Exception: + print(f"BAD ONE: {process_model.id}") + # raise exception else: no_primary.append(process_model) - for bpmn in no_primary: - print(bpmn) + # for bpmn in no_primary: + # print(bpmn) if __name__ == "__main__": diff --git a/migrations/versions/097f52a3ec5d_.py b/migrations/versions/6d3ffcc6849e_.py similarity index 98% rename from migrations/versions/097f52a3ec5d_.py rename to migrations/versions/6d3ffcc6849e_.py index bcb34549..fac466a1 100644 --- a/migrations/versions/097f52a3ec5d_.py +++ b/migrations/versions/6d3ffcc6849e_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 097f52a3ec5d +Revision ID: 6d3ffcc6849e Revises: -Create Date: 2022-09-16 10:44:23.258357 +Create Date: 2022-09-16 18:20:43.082949 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '097f52a3ec5d' +revision = '6d3ffcc6849e' down_revision = None branch_labels = None depends_on = None @@ -208,11 +208,11 @@ def upgrade(): op.create_table('spiff_logging', sa.Column('id', sa.Integer(), nullable=False), sa.Column('process_instance_id', sa.Integer(), nullable=False), - sa.Column('bpmn_process_identifier', sa.String(length=50), nullable=False), - sa.Column('bpmn_task_identifier', sa.String(length=50), nullable=False), + sa.Column('bpmn_process_identifier', sa.String(length=255), nullable=False), + sa.Column('bpmn_task_identifier', sa.String(length=255), nullable=False), sa.Column('spiff_task_guid', sa.String(length=50), nullable=False), sa.Column('timestamp', sa.DECIMAL(precision=17, scale=6), nullable=False), - sa.Column('message', sa.String(length=50), nullable=True), + sa.Column('message', sa.String(length=255), nullable=True), sa.Column('current_user_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['current_user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['process_instance_id'], ['process_instance.id'], ), diff --git a/src/spiffworkflow_backend/models/spiff_logging.py b/src/spiffworkflow_backend/models/spiff_logging.py index 3ff250b5..83b71790 100644 --- a/src/spiffworkflow_backend/models/spiff_logging.py +++ b/src/spiffworkflow_backend/models/spiff_logging.py @@ -17,9 +17,9 @@ class SpiffLoggingModel(SpiffworkflowBaseDBModel): __tablename__ = "spiff_logging" id: int = db.Column(db.Integer, primary_key=True) process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False) # type: ignore - bpmn_process_identifier: str = db.Column(db.String(50), nullable=False) - bpmn_task_identifier: str = db.Column(db.String(50), nullable=False) + bpmn_process_identifier: str = db.Column(db.String(255), nullable=False) + bpmn_task_identifier: str = db.Column(db.String(255), nullable=False) spiff_task_guid: str = db.Column(db.String(50), nullable=False) timestamp: float = db.Column(db.DECIMAL(17, 6), nullable=False) - message: Optional[str] = db.Column(db.String(50), nullable=True) + message: Optional[str] = db.Column(db.String(255), nullable=True) current_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True) diff --git a/src/spiffworkflow_backend/routes/process_api_blueprint.py b/src/spiffworkflow_backend/routes/process_api_blueprint.py index 0ed24f73..befa9fff 100644 --- a/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -654,7 +654,7 @@ def process_instance_report_delete( def service_tasks_show() -> flask.wrappers.Response: - """service_tasks_show.""" + """Service_tasks_show.""" available_connectors = ServiceTaskService.available_connectors() print(available_connectors) diff --git a/src/spiffworkflow_backend/services/service_task_service.py b/src/spiffworkflow_backend/services/service_task_service.py index 45a2eb81..b37154e0 100644 --- a/src/spiffworkflow_backend/services/service_task_service.py +++ b/src/spiffworkflow_backend/services/service_task_service.py @@ -22,6 +22,7 @@ class ServiceTaskDelegate: """Calls a connector via the configured proxy.""" def normalize_value(v: Any) -> Any: + """Normalize_value.""" value = v["value"] secret_prefix = "secret:" # noqa: S105 if value.startswith(secret_prefix):