tiagobento commented on code in PR #2508:
URL:
https://github.com/apache/incubator-kie-tools/pull/2508#discussion_r1707834878
##########
packages/dmn-editor/src/mutations/addDecisionToDecisionService.ts:
##########
@@ -25,25 +25,48 @@ 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 { ExternalModelsIndex } from "../DmnEditor";
+import { buildXmlHref, parseXmlHref } from "../xml/xmlHrefs";
+import { DmnLatestModel } from "@kie-tools/dmn-marshaller/dist";
+import { xmlHrefToQName } from "../xml/xmlHrefToQName";
export function addDecisionToDecisionService({
definitions,
- decisionId,
+ decisionHref,
decisionServiceId,
drdIndex,
snapGrid,
+ externalModelsByNamespace,
}: {
definitions: Normalized<DMN15__tDefinitions>;
- decisionId: string;
+ decisionHref: string;
decisionServiceId: string;
drdIndex: number;
snapGrid: SnapGrid;
+ externalModelsByNamespace: ExternalModelsIndex | undefined;
}) {
- console.debug(`DMN MUTATION: Adding Decision '${decisionId}' to Decision
Service '${decisionServiceId}'`);
+ console.debug(`DMN MUTATION: Adding Decision '${decisionHref}' 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.`);
+ const href = parseXmlHref(decisionHref);
+
+ const externalModel = externalModelsByNamespace?.[href.namespace ?? ""];
+ if (href.namespace && !externalModel) {
+ throw new Error(`DMN MUTATION: Namespace '${href.namespace}' not found.`);
+ }
+
+ if (externalModel && (externalModel.model as
Normalized<DmnLatestModel>).definitions) {
Review Comment:
(Not that your code is wrong, it's just longer)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]