using an array for metadata extraction paths now instead of dictionaries w/ burnettk

This commit is contained in:
jasquat 2022-12-02 16:03:43 -05:00
parent 6b75fc32a3
commit bfb2c5627a
6 changed files with 67 additions and 45 deletions

View File

@ -38,7 +38,7 @@ class ProcessModelInfo:
fault_or_suspend_on_exception: str = NotificationType.fault.value fault_or_suspend_on_exception: str = NotificationType.fault.value
exception_notification_addresses: list[str] = field(default_factory=list) exception_notification_addresses: list[str] = field(default_factory=list)
parent_groups: list[dict] | None = None 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: def __post_init__(self) -> None:
"""__post_init__.""" """__post_init__."""
@ -77,8 +77,13 @@ class ProcessModelInfoSchema(Schema):
exception_notification_addresses = marshmallow.fields.List( exception_notification_addresses = marshmallow.fields.List(
marshmallow.fields.String 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 @post_load
def make_spec( def make_spec(

View File

@ -952,17 +952,26 @@ def process_instance_list(
continue continue
instance_metadata_alias = aliased(ProcessInstanceMetadataModel) 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 isouter = True
conditions = [ProcessInstanceModel.id == instance_metadata_alias.process_instance_id, conditions = [
instance_metadata_alias.key == column["accessor"]] ProcessInstanceModel.id == instance_metadata_alias.process_instance_id,
instance_metadata_alias.key == column["accessor"],
]
if filter_for_column: if filter_for_column:
isouter = False 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( process_instance_query = process_instance_query.join(
instance_metadata_alias, instance_metadata_alias, and_(*conditions), isouter=isouter
and_(*conditions),
isouter=isouter
).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"])) ).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"]))
process_instances = ( process_instances = (
@ -1154,9 +1163,7 @@ def process_instance_report_show(
"""Process_instance_report_show.""" """Process_instance_report_show."""
process_instances = ProcessInstanceModel.query.order_by( process_instances = ProcessInstanceModel.query.order_by(
ProcessInstanceModel.start_in_seconds.desc(), ProcessInstanceModel.id.desc() # type: ignore ProcessInstanceModel.start_in_seconds.desc(), ProcessInstanceModel.id.desc() # type: ignore
).paginate( ).paginate(page=page, per_page=per_page, error_out=False)
page=page, per_page=per_page, error_out=False
)
process_instance_report = ProcessInstanceReportModel.query.filter_by( process_instance_report = ProcessInstanceReportModel.query.filter_by(
id=report_id, id=report_id,

View File

@ -84,7 +84,11 @@ class ProcessInstanceReportService:
# TODO replace with system reports that are loaded on launch (or similar) # TODO replace with system reports that are loaded on launch (or similar)
temp_system_metadata_map = { 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": { "system_report_instances_initiated_by_me": {
"columns": [ "columns": [
{"Header": "id", "accessor": "id"}, {"Header": "id", "accessor": "id"},
@ -96,13 +100,15 @@ class ProcessInstanceReportService:
{"Header": "end_in_seconds", "accessor": "end_in_seconds"}, {"Header": "end_in_seconds", "accessor": "end_in_seconds"},
{"Header": "status", "accessor": "status"}, {"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": { "system_report_instances_with_tasks_completed_by_me": {
"columns": cls.builtin_column_options(), "columns": cls.builtin_column_options(),
"filter_by": [ "filter_by": [
{"field_name": "with_tasks_completed_by_me", "field_value": True} {"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": { "system_report_instances_with_tasks_completed_by_my_groups": {
"columns": cls.builtin_column_options(), "columns": cls.builtin_column_options(),
@ -111,7 +117,8 @@ class ProcessInstanceReportService:
"field_name": "with_tasks_completed_by_my_group", "field_name": "with_tasks_completed_by_my_group",
"field_value": True, "field_value": True,
} }
],'order_by': ['-start_in_seconds', '-id'] ],
"order_by": ["-start_in_seconds", "-id"],
}, },
} }

View File

@ -333,7 +333,9 @@ class TestProcessApi(BaseTest):
process_model.display_name = "Updated Display Name" process_model.display_name = "Updated Display Name"
process_model.primary_file_name = "superduper.bpmn" process_model.primary_file_name = "superduper.bpmn"
process_model.primary_process_id = "superduper" 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("/", ":") modified_process_model_identifier = process_model_identifier.replace("/", ":")
response = client.put( response = client.put(
@ -347,7 +349,9 @@ class TestProcessApi(BaseTest):
assert response.json["display_name"] == "Updated Display Name" assert response.json["display_name"] == "Updated Display Name"
assert response.json["primary_file_name"] == "superduper.bpmn" assert response.json["primary_file_name"] == "superduper.bpmn"
assert response.json["primary_process_id"] == "superduper" 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( def test_process_model_list_all(
self, self,

View File

@ -6,7 +6,7 @@ import { Button, ButtonSet, Form, Stack, TextInput } from '@carbon/react';
import { AddAlt } from '@carbon/icons-react'; import { AddAlt } from '@carbon/icons-react';
import { modifyProcessIdentifierForPathParam, slugifyString } from '../helpers'; import { modifyProcessIdentifierForPathParam, slugifyString } from '../helpers';
import HttpService from '../services/HttpService'; import HttpService from '../services/HttpService';
import { MetadataExtractionPaths, ProcessModel } from '../interfaces'; import { MetadataExtractionPath, ProcessModel } from '../interfaces';
type OwnProps = { type OwnProps = {
mode: string; mode: string;
@ -92,31 +92,34 @@ export default function ProcessModelForm({
}; };
const metadataExtractionPathForm = ( const metadataExtractionPathForm = (
metadataKey: string, index: number,
metadataPath: string metadataExtractionPath: MetadataExtractionPath
) => { ) => {
return ( return (
<> <>
<TextInput <TextInput
id="process-model-metadata-extraction-path-key" id="process-model-metadata-extraction-path-key"
labelText="Extraction Key" labelText="Extraction Key"
value={metadataKey} value={metadataExtractionPath.key}
onChange={(event: any) => { onChange={(event: any) => {
const cep: MetadataExtractionPaths = const cep: MetadataExtractionPath[] =
processModel.metadata_extraction_paths || {}; processModel.metadata_extraction_paths || [];
delete cep[metadataKey]; const newMeta = { ...metadataExtractionPath };
cep[event.target.value] = metadataPath; newMeta.key = event.target.value;
cep[index] = newMeta;
updateProcessModel({ metadata_extraction_paths: cep }); updateProcessModel({ metadata_extraction_paths: cep });
}} }}
/> />
<TextInput <TextInput
id="process-model-metadata-extraction-path" id="process-model-metadata-extraction-path"
labelText="Extraction Path" labelText="Extraction Path"
value={metadataPath} value={metadataExtractionPath.path}
onChange={(event: any) => { onChange={(event: any) => {
const cep: MetadataExtractionPaths = const cep: MetadataExtractionPath[] =
processModel.metadata_extraction_paths || {}; processModel.metadata_extraction_paths || [];
cep[metadataKey] = event.target.value; const newMeta = { ...metadataExtractionPath };
newMeta.path = event.target.value;
cep[index] = newMeta;
updateProcessModel({ metadata_extraction_paths: cep }); updateProcessModel({ metadata_extraction_paths: cep });
}} }}
/> />
@ -130,14 +133,9 @@ export default function ProcessModelForm({
'processModel.metadata_extraction_paths', 'processModel.metadata_extraction_paths',
processModel.metadata_extraction_paths processModel.metadata_extraction_paths
); );
return Object.keys(processModel.metadata_extraction_paths).map( return processModel.metadata_extraction_paths.map(
(metadataKey: string) => { (metadataExtractionPath: MetadataExtractionPath, index: number) => {
return metadataExtractionPathForm( return metadataExtractionPathForm(index, metadataExtractionPath);
metadataKey,
processModel.metadata_extraction_paths
? processModel.metadata_extraction_paths[metadataKey]
: ''
);
} }
); );
} }
@ -145,9 +143,9 @@ export default function ProcessModelForm({
}; };
const addBlankMetadataExtractionPath = () => { const addBlankMetadataExtractionPath = () => {
const cep: MetadataExtractionPaths = const cep: MetadataExtractionPath[] =
processModel.metadata_extraction_paths || {}; processModel.metadata_extraction_paths || [];
Object.assign(cep, { '': '' }); cep.push({ key: '', path: '' });
updateProcessModel({ metadata_extraction_paths: cep }); updateProcessModel({ metadata_extraction_paths: cep });
}; };

View File

@ -98,8 +98,9 @@ export interface ProcessGroupLite {
display_name: string; display_name: string;
} }
export interface MetadataExtractionPaths { export interface MetadataExtractionPath {
[key: string]: string; key: string;
path: string;
} }
export interface ProcessModel { export interface ProcessModel {
@ -109,7 +110,7 @@ export interface ProcessModel {
primary_file_name: string; primary_file_name: string;
files: ProcessFile[]; files: ProcessFile[];
parent_groups?: ProcessGroupLite[]; parent_groups?: ProcessGroupLite[];
metadata_extraction_paths?: MetadataExtractionPaths; metadata_extraction_paths?: MetadataExtractionPath[];
} }
export interface ProcessGroup { export interface ProcessGroup {