From bfb2c5627ad714ab537be01d560884c3d241a347 Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 2 Dec 2022 16:03:43 -0500 Subject: [PATCH] using an array for metadata extraction paths now instead of dictionaries w/ burnettk --- .../models/process_model.py | 11 +++-- .../routes/process_api_blueprint.py | 27 +++++++----- .../process_instance_report_service.py | 15 +++++-- .../integration/test_process_api.py | 8 +++- .../src/components/ProcessModelForm.tsx | 44 +++++++++---------- spiffworkflow-frontend/src/interfaces.ts | 7 +-- 6 files changed, 67 insertions(+), 45 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_model.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_model.py index 278b5ef6..e8d5eed1 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_model.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_model.py @@ -38,7 +38,7 @@ class ProcessModelInfo: fault_or_suspend_on_exception: str = NotificationType.fault.value exception_notification_addresses: list[str] = field(default_factory=list) parent_groups: list[dict] | None = None - metadata_extraction_paths: dict[str, str] | None = None + metadata_extraction_paths: list[dict[str, str]] | None = None def __post_init__(self) -> None: """__post_init__.""" @@ -77,8 +77,13 @@ class ProcessModelInfoSchema(Schema): exception_notification_addresses = marshmallow.fields.List( marshmallow.fields.String ) - metadata_extraction_paths = marshmallow.fields.Dict(keys=marshmallow.fields.Str(required=False), values=marshmallow.fields.Str(required=False), required=False) - + metadata_extraction_paths = marshmallow.fields.List( + marshmallow.fields.Dict( + keys=marshmallow.fields.Str(required=False), + values=marshmallow.fields.Str(required=False), + required=False, + ) + ) @post_load def make_spec( diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index 7e73a285..70653026 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -952,17 +952,26 @@ def process_instance_list( continue instance_metadata_alias = aliased(ProcessInstanceMetadataModel) - filter_for_column = next((f for f in process_instance_report.report_metadata['filter_by'] if f['field_name'] == column['accessor']), None) + filter_for_column = next( + ( + f + for f in process_instance_report.report_metadata["filter_by"] + if f["field_name"] == column["accessor"] + ), + None, + ) isouter = True - conditions = [ProcessInstanceModel.id == instance_metadata_alias.process_instance_id, - instance_metadata_alias.key == column["accessor"]] + conditions = [ + ProcessInstanceModel.id == instance_metadata_alias.process_instance_id, + instance_metadata_alias.key == column["accessor"], + ] if filter_for_column: isouter = False - conditions.append(instance_metadata_alias.value == filter_for_column["field_value"]) + conditions.append( + instance_metadata_alias.value == filter_for_column["field_value"] + ) process_instance_query = process_instance_query.join( - instance_metadata_alias, - and_(*conditions), - isouter=isouter + instance_metadata_alias, and_(*conditions), isouter=isouter ).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"])) process_instances = ( @@ -1154,9 +1163,7 @@ def process_instance_report_show( """Process_instance_report_show.""" process_instances = ProcessInstanceModel.query.order_by( ProcessInstanceModel.start_in_seconds.desc(), ProcessInstanceModel.id.desc() # type: ignore - ).paginate( - page=page, per_page=per_page, error_out=False - ) + ).paginate(page=page, per_page=per_page, error_out=False) process_instance_report = ProcessInstanceReportModel.query.filter_by( id=report_id, diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py index d9096d63..84d5d675 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py @@ -84,7 +84,11 @@ class ProcessInstanceReportService: # TODO replace with system reports that are loaded on launch (or similar) temp_system_metadata_map = { - "default": {"columns": cls.builtin_column_options(), "filter_by": [], 'order_by': ['-start_in_seconds', '-id']}, + "default": { + "columns": cls.builtin_column_options(), + "filter_by": [], + "order_by": ["-start_in_seconds", "-id"], + }, "system_report_instances_initiated_by_me": { "columns": [ {"Header": "id", "accessor": "id"}, @@ -96,13 +100,15 @@ class ProcessInstanceReportService: {"Header": "end_in_seconds", "accessor": "end_in_seconds"}, {"Header": "status", "accessor": "status"}, ], - "filter_by": [{"field_name": "initiated_by_me", "field_value": True}],'order_by': ['-start_in_seconds', '-id'] + "filter_by": [{"field_name": "initiated_by_me", "field_value": True}], + "order_by": ["-start_in_seconds", "-id"], }, "system_report_instances_with_tasks_completed_by_me": { "columns": cls.builtin_column_options(), "filter_by": [ {"field_name": "with_tasks_completed_by_me", "field_value": True} - ],'order_by': ['-start_in_seconds', '-id'] + ], + "order_by": ["-start_in_seconds", "-id"], }, "system_report_instances_with_tasks_completed_by_my_groups": { "columns": cls.builtin_column_options(), @@ -111,7 +117,8 @@ class ProcessInstanceReportService: "field_name": "with_tasks_completed_by_my_group", "field_value": True, } - ],'order_by': ['-start_in_seconds', '-id'] + ], + "order_by": ["-start_in_seconds", "-id"], }, } diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py index b30652a4..d49eb7c5 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -333,7 +333,9 @@ class TestProcessApi(BaseTest): process_model.display_name = "Updated Display Name" process_model.primary_file_name = "superduper.bpmn" process_model.primary_process_id = "superduper" - process_model.metadata_extraction_paths = {'extraction1': 'path1'} + process_model.metadata_extraction_paths = [ + {"key": "extraction1", "path": "path1"} + ] modified_process_model_identifier = process_model_identifier.replace("/", ":") response = client.put( @@ -347,7 +349,9 @@ class TestProcessApi(BaseTest): assert response.json["display_name"] == "Updated Display Name" assert response.json["primary_file_name"] == "superduper.bpmn" assert response.json["primary_process_id"] == "superduper" - assert response.json["metadata_extraction_paths"] == {'extraction1': 'path1'} + assert response.json["metadata_extraction_paths"] == [ + {"key": "extraction1", "path": "path1"} + ] def test_process_model_list_all( self, diff --git a/spiffworkflow-frontend/src/components/ProcessModelForm.tsx b/spiffworkflow-frontend/src/components/ProcessModelForm.tsx index 0866b60d..7e4e1169 100644 --- a/spiffworkflow-frontend/src/components/ProcessModelForm.tsx +++ b/spiffworkflow-frontend/src/components/ProcessModelForm.tsx @@ -6,7 +6,7 @@ import { Button, ButtonSet, Form, Stack, TextInput } from '@carbon/react'; import { AddAlt } from '@carbon/icons-react'; import { modifyProcessIdentifierForPathParam, slugifyString } from '../helpers'; import HttpService from '../services/HttpService'; -import { MetadataExtractionPaths, ProcessModel } from '../interfaces'; +import { MetadataExtractionPath, ProcessModel } from '../interfaces'; type OwnProps = { mode: string; @@ -92,31 +92,34 @@ export default function ProcessModelForm({ }; const metadataExtractionPathForm = ( - metadataKey: string, - metadataPath: string + index: number, + metadataExtractionPath: MetadataExtractionPath ) => { return ( <> { - const cep: MetadataExtractionPaths = - processModel.metadata_extraction_paths || {}; - delete cep[metadataKey]; - cep[event.target.value] = metadataPath; + const cep: MetadataExtractionPath[] = + processModel.metadata_extraction_paths || []; + const newMeta = { ...metadataExtractionPath }; + newMeta.key = event.target.value; + cep[index] = newMeta; updateProcessModel({ metadata_extraction_paths: cep }); }} /> { - const cep: MetadataExtractionPaths = - processModel.metadata_extraction_paths || {}; - cep[metadataKey] = event.target.value; + const cep: MetadataExtractionPath[] = + processModel.metadata_extraction_paths || []; + const newMeta = { ...metadataExtractionPath }; + newMeta.path = event.target.value; + cep[index] = newMeta; updateProcessModel({ metadata_extraction_paths: cep }); }} /> @@ -130,14 +133,9 @@ export default function ProcessModelForm({ 'processModel.metadata_extraction_paths', processModel.metadata_extraction_paths ); - return Object.keys(processModel.metadata_extraction_paths).map( - (metadataKey: string) => { - return metadataExtractionPathForm( - metadataKey, - processModel.metadata_extraction_paths - ? processModel.metadata_extraction_paths[metadataKey] - : '' - ); + return processModel.metadata_extraction_paths.map( + (metadataExtractionPath: MetadataExtractionPath, index: number) => { + return metadataExtractionPathForm(index, metadataExtractionPath); } ); } @@ -145,9 +143,9 @@ export default function ProcessModelForm({ }; const addBlankMetadataExtractionPath = () => { - const cep: MetadataExtractionPaths = - processModel.metadata_extraction_paths || {}; - Object.assign(cep, { '': '' }); + const cep: MetadataExtractionPath[] = + processModel.metadata_extraction_paths || []; + cep.push({ key: '', path: '' }); updateProcessModel({ metadata_extraction_paths: cep }); }; diff --git a/spiffworkflow-frontend/src/interfaces.ts b/spiffworkflow-frontend/src/interfaces.ts index 3b428b56..6c9ff905 100644 --- a/spiffworkflow-frontend/src/interfaces.ts +++ b/spiffworkflow-frontend/src/interfaces.ts @@ -98,8 +98,9 @@ export interface ProcessGroupLite { display_name: string; } -export interface MetadataExtractionPaths { - [key: string]: string; +export interface MetadataExtractionPath { + key: string; + path: string; } export interface ProcessModel { @@ -109,7 +110,7 @@ export interface ProcessModel { primary_file_name: string; files: ProcessFile[]; parent_groups?: ProcessGroupLite[]; - metadata_extraction_paths?: MetadataExtractionPaths; + metadata_extraction_paths?: MetadataExtractionPath[]; } export interface ProcessGroup {