added message correlations to message instance list api call w/ burnettk

This commit is contained in:
jasquat 2022-11-14 10:14:00 -05:00
parent 30ab6a8ac3
commit 79537645ee
5 changed files with 69 additions and 47 deletions

View File

@ -44,6 +44,9 @@ class MessageCorrelationModel(SpiffworkflowBaseDBModel):
updated_at_in_seconds: int = db.Column(db.Integer)
created_at_in_seconds: int = db.Column(db.Integer)
message_correlation_property = relationship(
"MessageCorrelationPropertyModel"
)
message_correlations_message_instances = relationship(
"MessageCorrelationMessageInstanceModel", cascade="delete"
)

View File

@ -59,6 +59,8 @@ class MessageInstanceModel(SpiffworkflowBaseDBModel):
updated_at_in_seconds: int = db.Column(db.Integer)
created_at_in_seconds: int = db.Column(db.Integer)
message_correlations: dict | None = None
@validates("message_type")
def validate_message_type(self, key: str, value: Any) -> Any:
"""Validate_message_type."""

View File

@ -1,4 +1,5 @@
"""APIs for dealing with process groups, process models, and process instances."""
import dataclasses
import json
import os
import random
@ -13,6 +14,10 @@ from typing import Union
import connexion # type: ignore
import flask.wrappers
import jinja2
from spiffworkflow_backend.models import message_correlation_message_instance
from spiffworkflow_backend.models.message_correlation import MessageCorrelationModel
from spiffworkflow_backend.models.message_correlation_message_instance import MessageCorrelationMessageInstanceModel
from spiffworkflow_backend.models.message_correlation_property import MessageCorrelationPropertyModel
import werkzeug
from flask import Blueprint
from flask import current_app
@ -581,16 +586,25 @@ def message_instance_list(
MessageInstanceModel.created_at_in_seconds.desc(), # type: ignore
MessageInstanceModel.id.desc(), # type: ignore
)
.join(MessageModel)
.join(MessageModel, MessageModel.id == MessageInstanceModel.message_model_id)
.join(ProcessInstanceModel)
.add_columns(
MessageModel.identifier.label("message_identifier"),
ProcessInstanceModel.process_model_identifier,
ProcessInstanceModel.process_group_identifier,
)
.paginate(page=page, per_page=per_page, error_out=False)
)
for message_instance in message_instances:
message_correlations: dict = {}
for mcmi in message_instance.MessageInstanceModel.message_correlations_message_instances:
mc = MessageCorrelationModel.query.filter_by(id=mcmi.message_correlation_id).all()
for m in mc:
if m.name not in message_correlations:
message_correlations[m.name] = {}
message_correlations[m.name][m.message_correlation_property.identifier] = m.value
message_instance.MessageInstanceModel.message_correlations = message_correlations
response_json = {
"results": message_instances.items,
"pagination": {

View File

@ -65,7 +65,7 @@ export default function MessageInstanceList() {
</td>
<td>{rowToUse.message_identifier}</td>
<td>{rowToUse.message_type}</td>
<td>{rowToUse.failure_cause}</td>
<td>{rowToUse.failure_cause || '-'}</td>
<td>{rowToUse.status}</td>
<td>
{convertSecondsToFormattedDate(rowToUse.created_at_in_seconds)}

View File

@ -276,26 +276,6 @@ export default function ProcessInstanceList() {
</DatePicker>
);
};
const getSearchParamsAsQueryString = () => {
let queryParamString = '';
Object.keys(parametersToAlwaysFilterBy).forEach((paramName) => {
const searchParamValue = searchParams.get(paramName);
if (searchParamValue) {
queryParamString += `&${paramName}=${searchParamValue}`;
}
});
Object.keys(parametersToGetFromSearchParams).forEach(
(paramName: string) => {
if (searchParams.get(paramName)) {
queryParamString += `&${paramName}=${searchParams.get(paramName)}`;
}
}
);
return queryParamString;
};
const processStatusSearch = () => {
return (
<MultiSelect
@ -315,7 +295,6 @@ export default function ProcessInstanceList() {
/>
);
};
const clearFilters = () => {
setProcessModelSelection(null);
setProcessStatusSelection([]);
@ -324,7 +303,6 @@ export default function ProcessInstanceList() {
setEndFrom('');
setEndTo('');
};
const filterOptions = () => {
if (!showFilterOptions) {
return null;
@ -385,6 +363,33 @@ export default function ProcessInstanceList() {
</>
);
};
const toggleShowFilterOptions = () => {
setShowFilterOptions(!showFilterOptions);
};
const filterComponent = () => {
return (
<>
<Grid fullWidth>
<Column
sm={{ span: 1, offset: 3 }}
md={{ span: 1, offset: 7 }}
lg={{ span: 1, offset: 15 }}
>
<Button
data-qa="filter-section-expand-toggle"
kind="ghost"
renderIcon={Filter}
iconDescription="Filter Options"
hasIconOnly
size="lg"
onClick={toggleShowFilterOptions}
/>
</Column>
</Grid>
{filterOptions()}
</>
);
};
const buildTable = () => {
const headerLabels: Record<string, string> = {
@ -493,12 +498,27 @@ export default function ProcessInstanceList() {
);
};
const processInstanceTitleElement = () => {
return <h1>Process Instances</h1>;
const getSearchParamsAsQueryString = () => {
let queryParamString = '';
Object.keys(parametersToAlwaysFilterBy).forEach((paramName) => {
const searchParamValue = searchParams.get(paramName);
if (searchParamValue) {
queryParamString += `&${paramName}=${searchParamValue}`;
}
});
Object.keys(parametersToGetFromSearchParams).forEach(
(paramName: string) => {
if (searchParams.get(paramName)) {
queryParamString += `&${paramName}=${searchParams.get(paramName)}`;
}
}
);
return queryParamString;
};
const toggleShowFilterOptions = () => {
setShowFilterOptions(!showFilterOptions);
const processInstanceTitleElement = () => {
return <h1>Process Instances</h1>;
};
if (pagination) {
@ -507,24 +527,7 @@ export default function ProcessInstanceList() {
<>
{processInstanceBreadcrumbElement()}
{processInstanceTitleElement()}
<Grid fullWidth>
<Column
sm={{ span: 1, offset: 3 }}
md={{ span: 1, offset: 7 }}
lg={{ span: 1, offset: 15 }}
>
<Button
data-qa="filter-section-expand-toggle"
kind="ghost"
renderIcon={Filter}
iconDescription="Filter Options"
hasIconOnly
size="lg"
onClick={toggleShowFilterOptions}
/>
</Column>
</Grid>
{filterOptions()}
{filterComponent()}
<br />
<PaginationForTable
page={page}