Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-issues#1298: Decision Services & multiple DRDs: make it possible o add external Decisions to a Decision Service #2508

Merged
merged 39 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b690ebb
kie-issues#1298: Decision Services & multiple DRDs: make it possible …
danielzhe Jul 31, 2024
33de8ea
Tests e2e
danielzhe Aug 2, 2024
2db60f6
webkit
danielzhe Aug 2, 2024
b55113d
Code review. More tests. Fixed an issue about moving nodes from DS to…
danielzhe Aug 5, 2024
24f1b15
Tests screenshots 1
danielzhe Aug 5, 2024
f916099
Tests screenshots 2
danielzhe Aug 5, 2024
99924ea
Tests screenshots 3
danielzhe Aug 6, 2024
d64a04e
Better screenshots for test.
danielzhe Aug 6, 2024
a078041
Mutations now does not count with "correct parameters".
danielzhe Aug 6, 2024
c9f88bf
Href.
danielzhe Aug 7, 2024
411e61d
Merge branch 'main' into included-ds
danielzhe Aug 7, 2024
6cd536f
Update packages/dmn-editor/src/mutations/addDecisionToDecisionService.ts
danielzhe Aug 7, 2024
a44b7da
Update packages/dmn-editor/src/diagram/Diagram.tsx
danielzhe Aug 7, 2024
fad6167
Update packages/dmn-editor/src/mutations/deleteDecisionFromDecisionSe…
danielzhe Aug 7, 2024
3ee4271
Fix build error (??????)
danielzhe Aug 7, 2024
a84bea2
Merge branch 'main' into included-ds
danielzhe Aug 9, 2024
90c03ff
Fixed the invocation string
danielzhe Aug 14, 2024
c3c23dd
Merge branch 'main' into included-ds
danielzhe Aug 14, 2024
54b419c
Fixed hooks
danielzhe Aug 19, 2024
40a0fdf
Merge branch 'main' into included-ds
danielzhe Aug 22, 2024
227ee5a
Merge branch 'main' into included-ds
danielzhe Sep 2, 2024
3d8abb5
Handles 3rd level of included models
danielzhe Sep 2, 2024
9d7a04e
Fix
danielzhe Sep 3, 2024
a5f3e71
Update packages/dmn-editor/src/propertiesPanel/DecisionServicePropert…
danielzhe Sep 5, 2024
8bbb1cf
Fixing hooks and renaming variable
danielzhe Sep 5, 2024
81d260f
Reduce nesting. Remove unused parameters.
danielzhe Sep 9, 2024
1bdc614
.
tiagobento Sep 11, 2024
ffa1867
Merge pull request #8 from tiagobento/included-ds-pair-programming-da…
danielzhe Sep 11, 2024
2921171
Merge branch 'main' into included-ds
danielzhe Sep 11, 2024
e22fcd1
Refactor DmnEditorRoot
danielzhe Sep 12, 2024
3cb35a5
Refactor DmnEditorRoot
danielzhe Sep 12, 2024
334cf35
Clean
danielzhe Sep 12, 2024
bd5786c
clean
danielzhe Sep 12, 2024
0e90a76
Update packages/dmn-editor/src/mutations/deleteImport.ts
danielzhe Sep 19, 2024
a03e182
Fixes issues 3 and 4
danielzhe Sep 25, 2024
d9408e7
decisionHref
danielzhe Sep 25, 2024
4759ae3
hook
danielzhe Sep 25, 2024
91a815f
Revert
danielzhe Sep 26, 2024
702f44f
Fix 3 and 4 issues
danielzhe Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/dmn-editor/src/DmnEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ export const DmnEditorInternal = ({
</Tab>

<Tab eventKey={DmnEditorTab.INCLUDED_MODELS} title={tabTitle.includedModels}>
{navigationTab === DmnEditorTab.INCLUDED_MODELS && <IncludedModels />}
<div data-testid={"kie-tools--dmn-editor--included-models-container"}>
{navigationTab === DmnEditorTab.INCLUDED_MODELS && <IncludedModels />}
</div>
</Tab>
</Tabs>
</div>
Expand Down
6 changes: 4 additions & 2 deletions packages/dmn-editor/src/diagram/Diagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
} from "../externalNodes/ExternalNodesPanel";
import { nodeNatures } from "../mutations/NodeNature";
import { addConnectedNode } from "../mutations/addConnectedNode";
import { addDecisionToDecisionService } from "../mutations/addDecisionToDecisionService";
import { addDecisionToDecisionService, DrgElement } from "../mutations/addDecisionToDecisionService";
import { addEdge } from "../mutations/addEdge";
import { addShape } from "../mutations/addShape";
import { addStandaloneNode } from "../mutations/addStandaloneNode";
Expand Down Expand Up @@ -1009,12 +1009,14 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
addDecisionToDecisionService({
definitions: state.dmn.model.definitions,
drdIndex: state.computed(state).getDrdIndex(),
decisionId: selectedNodes[i].data.dmnObject!["@_id"]!, // We can assume that all selected nodes are Decisions because the contaiment was validated above.
drgElement: selectedNodes[i].data.dmnObject as DrgElement,
decisionServiceId: state
.computed(state)
.getDiagramData(externalModelsByNamespace)
.nodesById.get(dropTargetNode.id)!.data.dmnObject!["@_id"]!,
snapGrid: state.diagram.snapGrid,
decisionShape: selectedNodes[i].data.shape,
elementId: selectedNodes[i].id, // The "real" id is here, which can be the local id or an imported node id (uri + external element id).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comment about the mutation itself...

});
}
} else {
Expand Down
6 changes: 5 additions & 1 deletion packages/dmn-editor/src/diagram/Palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ export function Palette({ pulse }: { pulse: boolean }) {
<br />
<aside className={"kie-dmn-editor--external-nodes-panel-toggle"}>
{diagram.openLhsPanel === DiagramLhsPanel.EXTERNAL_NODES && (
<div className={"kie-dmn-editor--palette-nodes-popover"} style={{ maxHeight }}>
<div
className={"kie-dmn-editor--palette-nodes-popover"}
style={{ maxHeight }}
data-testid={"kie-tools--dmn-editor--external-nodes-container"}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "DRG nodes" panel doesn't have a data-testid, why don't we use the same strategy we're using for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests for "DRG Nodes" panel? I only found for drag nodes from the palette not from the "DRG Nodes" panel. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiagobento actually we are about to add data-testid also for the DRG Nodes panel, see the PR #2462

One thing we could unify is the data-testid suffix. @danielzhe is using -container while me is using -popover, what do you prefer? I chose -popover due to related className.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good then! Thanks for the insights. I have no preference for the suffix, just please coordinate that it is consistent. @jomarko @danielzhe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it to -popover since it is related to the className and makes more sense! Thank you, @jomarko

<ExternalNodesPanel />
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export function ExternalNodesPanel() {
externalDrgElementId: drgElement["@_id"]!,
})
}
data-testid={`kie-tools--dmn-editor--external-node-${_import["@_name"]}-${drgElement["@_name"]}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ${_import["@_name"]} always non empty? I mean containing some non white characters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can be an empty string. Great catch.

>
<Flex
alignItems={{ default: "alignItemsCenter" }}
Expand Down
6 changes: 5 additions & 1 deletion packages/dmn-editor/src/includedModels/IncludedModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export function IncludedModels() {
return (
<>
<Modal
data-testid={"kie-tools--dmn-editor--included-models-modal"}
isOpen={isModalOpen}
onClose={() => cancel()}
title={"Include model"}
Expand Down Expand Up @@ -553,7 +554,10 @@ function IncludedModelCard({
ev.preventDefault();
}}
variant={"link"}
style={{ color: "var(--pf-global--danger-color--200)", fontWeight: "bold" }}
style={{
color: "var(--pf-global--danger-color--200)",
fontWeight: "bold",
}}
>
{`Yes, remove included ${extension.toUpperCase()}`}
</AlertActionLink>
Expand Down
36 changes: 25 additions & 11 deletions packages/dmn-editor/src/mutations/addDecisionToDecisionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,42 @@ import { SnapGrid } from "../store/Store";
import { MIN_NODE_SIZES } from "../diagram/nodes/DefaultSizes";
import { NODE_TYPES } from "../diagram/nodes/NodeTypes";
import { Normalized } from "../normalization/normalize";
import {
DMN15__tBusinessKnowledgeModel,
DMN15__tDecision,
DMN15__tDecisionService,
DMN15__tInputData,
DMN15__tKnowledgeSource,
} from "@kie-tools/dmn-marshaller/src/schemas/dmn-1_5/ts-gen/types";

export type DrgElement =
| Normalized<{ __$$element: "decision" } & DMN15__tDecision>
| Normalized<{ __$$element: "businessKnowledgeModel" } & DMN15__tBusinessKnowledgeModel>
| Normalized<{ __$$element: "decisionService" } & DMN15__tDecisionService>
| Normalized<{ __$$element: "inputData" } & DMN15__tInputData>
| Normalized<{ __$$element: "knowledgeSource" } & DMN15__tKnowledgeSource>;

export function addDecisionToDecisionService({
definitions,
decisionId,
drgElement,
decisionServiceId,
drdIndex,
snapGrid,
decisionShape,
elementId,
}: {
definitions: Normalized<DMN15__tDefinitions>;
decisionId: string;
drgElement: DrgElement;
decisionServiceId: string;
drdIndex: number;
snapGrid: SnapGrid;
decisionShape: Normalized<DMNDI15__DMNShape>;
elementId: string;
}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elementId --> decisionId

I understand drgElement doesn't necessarily is inside definitions, so please make this action dependent on external models too. There's no way to know whether or not drgElement and elementId are aligned...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous code we was getting the ID, in Diagram.tsx using the following code:

decisionId: selectedNodes[i].data.dmnObject!["@_id"]!, // We can assume that all selected nodes are Decisions because the contaiment was validated above.

So I think it is safe to assume that selectedNodes[i].data.dmnObject is always a Decision which is the DrgElement that we looking for. Maybe I should change the type of DrgElement I defined here
to:

export type DecisionDrgElement = Normalized<{ __$$element: "decision" } & DMN15__tDecision>

About the ID, I can't see any case where the ID of the selected node will be different than the DRG, except for the imported nodes the ID in the DRG is not full, it is only the local ID (the Guid), but from selectedNodes[I].["@_id"] is the real ID used in the current diagram (namespace + id).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, we don't have DRG element always in the definitions: the external nodes do not have DRG element, only DMNDI. The DRG we have in selectedNodes[i].data.dmnObject is a loaded DRG from the external model, that's why its ID is different to the internal one, the one in href.
See below:

  <decisionService name="New Decision Service" id="_A0908B2B-DBE7-41C7-B055-0C0DAD17CE54">
    <variable name="New Decision Service" id="_145CD7A7-B14D-4D63-B9D3-85601FC915B1" />
    <outputDecision href="https://kie.apache.org/dmn/_D19B0015-2CBD-4BA8-84A9-5F554D84A9E1#_05621ED4-9236-47F1-B93A-164A4527B136" />
    <encapsulatedDecision href="https://kie.apache.org/dmn/_D19B0015-2CBD-4BA8-84A9-5F554D84A9E1#_1991FB34-1253-4A54-AD3D-89697938DDFA" />
    <encapsulatedDecision href="#_8E89DDF6-7ABC-4FBF-A1B6-B68BC32A52AE" />
  </decisionService>
  <decision name="New Decision" id="_8E89DDF6-7ABC-4FBF-A1B6-B68BC32A52AE">
    <variable name="New Decision" id="_BFB8A43B-5ADA-47D8-815E-8A0505814AA1" />
  </decision>

Notice only the 8E89DDF6-7ABC-4FBF-A1B6-B68BC32A52AE is present in the file.
The other nodes are not, only as a dmndi.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need the ID, but we need to know that this ID represents a Decision. The only way to know that is having the externalModelsByNamespace passed as parameter to the "addDecisionToDecisionService" mutation, so we can make that validation. You're mentioning the arguments you're passing when calling this mutation, but the mutation itself, after your changes, can be called with

{ 
  elementId: "bar"
  drgElement: { 
    "@_id": "foo" 
    ...
  }
}

which has the potential of being wrong. What I'm saying is that we rollback to the way it was before, and we include the externalModelsByNamespace parameters so we can look if that href (nmspc#id) represents a Decision on the model with namespace nmspc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think got your point! I guarantee in the Diagram.tsx that the ID represents a decision, but I am not doing the same inside the mutation, in other words, the mutation is not "safe" anymore, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can guarantee that you're calling it correctly now, but you can't guarantee that this will be true forever :P

console.debug(`DMN MUTATION: Adding Decision '${decisionId}' to Decision Service '${decisionServiceId}'`);
console.debug(`DMN MUTATION: Adding Decision '${elementId}' to Decision Service '${decisionServiceId}'`);

const decision = definitions.drgElement?.find((s) => s["@_id"] === decisionId);
if (decision?.__$$element !== "decision") {
throw new Error(`DMN MUTATION: DRG Element with id '${decisionId}' is either not a Decision or doesn't exist.`);
if (drgElement?.__$$element !== "decision") {
throw new Error(`DMN MUTATION: DRG Element with id '${elementId}' is either not a Decision or doesn't exist.`);
}

const decisionService = definitions.drgElement?.find((s) => s["@_id"] === decisionServiceId);
Expand All @@ -54,9 +71,6 @@ export function addDecisionToDecisionService({
}

const diagram = addOrGetDrd({ definitions, drdIndex });
const decisionShape = diagram.diagramElements.find(
(s) => s["@_dmnElementRef"] === decisionId && s.__$$element === "dmndi:DMNShape"
) as Normalized<DMNDI15__DMNShape>;

const decisionServiceShape = diagram.diagramElements.find(
(s) => s["@_dmnElementRef"] === decisionServiceId && s.__$$element === "dmndi:DMNShape"
Expand All @@ -65,10 +79,10 @@ export function addDecisionToDecisionService({
const section = getSectionForDecisionInsideDecisionService({ decisionShape, decisionServiceShape, snapGrid });
if (section === "encapsulated") {
decisionService.encapsulatedDecision ??= [];
decisionService.encapsulatedDecision.push({ "@_href": `#${decisionId}` });
decisionService.encapsulatedDecision.push({ "@_href": `${elementId}` });
} else if (section === "output") {
decisionService.outputDecision ??= [];
decisionService.outputDecision.push({ "@_href": `#${decisionId}` });
decisionService.outputDecision.push({ "@_href": `${elementId}` });
} else {
throw new Error(`DMN MUTATION: Invalid section to add decision to: '${section}' `);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/dmn-editor/stories/dev/DevWebApp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
*/

import * as React from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { useCallback, useMemo, useRef, useState } from "react";
import type { Meta, StoryObj } from "@storybook/react";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those changes are made automatically by the Prettier

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Prettier doesn't change the imports... Maybe it's your VS Code "Organize imports"?

import "@patternfly/react-core/dist/styles/base.css";
import { Flex, FlexItem } from "@patternfly/react-core/dist/js/layouts/Flex";
import { Page, PageSection } from "@patternfly/react-core/dist/js/components/Page";
import { DmnLatestModel, getMarshaller, DmnMarshaller } from "@kie-tools/dmn-marshaller";
import { Normalized, normalize } from "@kie-tools/dmn-editor/dist/normalization/normalize";
import { DmnLatestModel, DmnMarshaller, getMarshaller } from "@kie-tools/dmn-marshaller";
import { normalize, Normalized } from "@kie-tools/dmn-editor/dist/normalization/normalize";
import { availableModelsByPath, modelsByNamespace } from "./availableModelsToInclude";
import { generateEmptyDmn15 } from "../misc/empty/Empty.stories";
import { loanPreQualificationDmn } from "../useCases/loanPreQualification/LoanPreQualification.stories";
import { DmnEditorWrapper } from "../dmnEditorStoriesWrapper";
import {
DmnEditorProps,
DmnEditorRef,
ExternalModelsIndex,
OnDmnModelChange,
OnRequestExternalModelByPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import EmptyWithAvailableExternalModelsStories from "./EmptyWithAvailableExternalModels.stories";
import { Meta } from "@storybook/blocks";

<Meta title="MDX/Misc/EmptyWithAvailableExternalModelsStories" of={EmptyWithAvailableExternalModelsStories} />

## Empty With Available External Models

When user starts with an empty diagram, a wizard for quick content initialization is displayed.
The wizard enables to create simple diagram with one input and one output or a diagram with one decision table expression.
This model also have some external models available to be included.
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import * as React from "react";
import { useCallback, useMemo, useState } from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { DmnLatestModel, DmnMarshaller, getMarshaller } from "@kie-tools/dmn-marshaller";
import { ns as dmn15ns } from "@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/meta";
import { generateUuid } from "@kie-tools/boxed-expression-component/dist/api";
import { DMN15_SPEC } from "@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/Dmn15Spec";
import {
DmnEditor,
DmnEditorProps,
ExternalModelsIndex,
OnRequestExternalModelByPath,
OnRequestExternalModelsAvailableToInclude,
OnDmnModelChange,
} from "@kie-tools/dmn-editor/dist/DmnEditor";
import { normalize, Normalized } from "@kie-tools/dmn-editor/dist/normalization/normalize";

import { DmnEditorWrapper, StorybookDmnEditorProps } from "../../dmnEditorStoriesWrapper";

import { availableModelsByPath, modelsByNamespace } from "./availableModelsToInclude";

export const generateEmptyDmn15 = () => `<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="${dmn15ns.get("")}"
expressionLanguage="${DMN15_SPEC.expressionLanguage.default}"
namespace="https://kie.apache.org/dmn/${generateUuid()}"
id="${generateUuid()}"
name="DMN${generateUuid()}">
</definitions>`;

const initialModel = generateEmptyDmn15();

function EmptyStoryWithIncludedModels(args: DmnEditorProps) {
const [state, setState] = useState<{
marshaller: DmnMarshaller;
stack: Normalized<DmnLatestModel>[];
pointer: number;
}>(() => {
const initialDmnMarshaller = getMarshaller(initialModel, { upgradeTo: "latest" });
return {
marshaller: initialDmnMarshaller,
stack: [normalize(initialDmnMarshaller.parser.parse())],
pointer: 0,
};
});

const currentModel = state.stack[state.pointer];

const externalModelsByNamespace = useMemo<ExternalModelsIndex>(() => {
return (currentModel.definitions.import ?? []).reduce((acc, i) => {
acc[i["@_namespace"]] = modelsByNamespace[i["@_namespace"]];
return acc;
}, {} as ExternalModelsIndex);
}, [currentModel.definitions.import]);

const onRequestExternalModelByPath = useCallback<OnRequestExternalModelByPath>(async (path) => {
return availableModelsByPath[path] ?? null;
}, []);

const onRequestExternalModelsAvailableToInclude = useCallback<OnRequestExternalModelsAvailableToInclude>(async () => {
return Object.keys(availableModelsByPath);
}, []);

const onModelChange = useCallback<OnDmnModelChange>((model) => {
setState((prev) => {
const newStack = prev.stack.slice(0, prev.pointer + 1);
return {
...prev,
stack: [...newStack, model],
pointer: newStack.length,
};
});
}, []);

return (
<>
{DmnEditorWrapper({
model: currentModel,
originalVersion: args.originalVersion,
onModelChange,
onRequestExternalModelByPath,
onRequestExternalModelsAvailableToInclude,
externalModelsByNamespace: externalModelsByNamespace,
externalContextName: args.externalContextName,
externalContextDescription: args.externalContextDescription,
validationMessages: args.validationMessages,
evaluationResults: args.evaluationResults,
issueTrackerHref: args.issueTrackerHref,
})}
</>
);
}

const meta: Meta<DmnEditorProps> = {
title: "Misc/EmptyWithAvailableExternalModels",
component: DmnEditor,
includeStories: /^[A-Z]/,
};

export default meta;
type Story = StoryObj<typeof EmptyStoryWithIncludedModels>;

export const EmptyWithAvailableExternalModels: Story = {
render: (args) => EmptyStoryWithIncludedModels(args),
args: {
model: getMarshaller(initialModel, { upgradeTo: "latest" }).parser.parse(),
originalVersion: "1.5",
evaluationResults: {},
externalContextDescription: "External context description",
externalContextName: "Storybook - DMN Editor",
externalModelsByNamespace: {},
issueTrackerHref: "",
validationMessages: {},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { getMarshaller } from "@kie-tools/dmn-marshaller";
import { normalize } from "@kie-tools/dmn-editor/dist/normalization/normalize";
import { XML2PMML } from "@kie-tools/pmml-editor-marshaller";
import * as DmnEditor from "@kie-tools/dmn-editor/dist/DmnEditor";
import { getPmmlNamespace } from "@kie-tools/dmn-editor/dist/pmml/pmml";
import { sumBkm, sumDiffDs, testTreePmml } from "./externalModels";

export const sumBkmModel = normalize(getMarshaller(sumBkm, { upgradeTo: "latest" }).parser.parse());
export const sumDiffDsModel = normalize(getMarshaller(sumDiffDs, { upgradeTo: "latest" }).parser.parse());
export const testTreePmmlModel = XML2PMML(testTreePmml);

export const availableModels: DmnEditor.ExternalModel[] = [
{
type: "dmn",
model: sumBkmModel,
svg: "",
normalizedPosixPathRelativeToTheOpenFile: "dev-webapp/available-models-to-include/sumBkm.dmn",
},
{
type: "dmn",
model: sumDiffDsModel,
svg: "",
normalizedPosixPathRelativeToTheOpenFile: "dev-webapp/available-models-to-include/sumDiffDs.dmn",
},
{
type: "dmn",
model: normalize(
getMarshaller(`<definitions xmlns="https://www.omg.org/spec/DMN/20230324/MODEL/" />`, {
upgradeTo: "latest",
}).parser.parse()
),
svg: "",
normalizedPosixPathRelativeToTheOpenFile: "dev-webapp/available-models-to-include/empty.dmn",
},
{
type: "pmml",
model: testTreePmmlModel,
normalizedPosixPathRelativeToTheOpenFile: "dev-webapp/available-models-to-include/testTree.pmml",
},
];

export const availableModelsByPath: Record<string, DmnEditor.ExternalModel> = Object.values(availableModels).reduce(
(acc, v) => {
acc[v.normalizedPosixPathRelativeToTheOpenFile] = v;
return acc;
},
{} as Record<string, DmnEditor.ExternalModel>
);

export const modelsByNamespace = Object.values(availableModels).reduce((acc, v) => {
if (v.type === "dmn") {
acc[v.model.definitions["@_namespace"]] = v;
} else if (v.type === "pmml") {
acc[getPmmlNamespace({ normalizedPosixPathRelativeToTheOpenFile: v.normalizedPosixPathRelativeToTheOpenFile })] = v;
}
return acc;
}, {} as DmnEditor.ExternalModelsIndex);
Loading
Loading