7.4. 特定の DMN モデルの REST エンドポイント
Red Hat Process Automation Manager には、Business Central ユーザーインターフェイスを使用せずに、特定の DMN モデルとの対話すに使用できるモデル固有の DMN KIE Server エンドポイントが含まれます。
Red Hat Process Automation Manager のコンテナーの DMN モデルごとに、以下の KIE Server REST エンドポイントは、DMN モデルのコンテンツに基づいて自動的に生成されます。
-
POST /server/containers/{containerId}/dmn/models/{modelname}: コンテナーで指定された DMN モデルを評価するための business-domain エンドポイント -
POST /server/containers/{containerId}/dmn/models/{decisionServiceName}: コンテナーで利用可能な特定の DMN モデルで指定のデシジョンサービスコンポーネントを評価するためのビジネスドメインエンドポイント -
POST /server/containers/{containerId}/dmn/models/{modelname}/dmnresult: 指定した DMN モデルの評価および business-domain コンテキスト、ヘルパーメッセージ、ヘルパーデシジョンポインターなど、DMNResult応答を返すエンドポイント -
POST /server/containers/{containerId}/dmn/models/{modelname}/{decisionServiceName}/dmnresult:特定の DMN モデルで指定のデシジョンサービスコンポーネントを評価して、ビジネスドメインのコンテキスト、ヘルパーメッセージ、およびヘルプデシジョンポインターなど、DMNResult応答を返すエンドポイント -
GET /server/containers/{containerId}/dmn/models/{modelname}: デシジョンロジックなしの標準の DMN XML を返し、指定の DMN モデルの入力とデシジョンを含むエンドポイント -
GET /server/containers/{containerId}/dmn/openapi.json(|.yaml): 指定のコンテナーで DMN モデルの Swagger または OAS を取得するエンドポイント
これらのエンドポイントを使用して、モデル内の DMN モデルまたは特定のデシジョンサービスと対話できます。これらの REST エンドポイントの business-domain と dmnresult を使用する場合は、以下の考慮事項を確認してください。
-
REST ビジネスドメインエンドポイント: クライアントアプリケーションが正の評価結果だけを対象としていて、
InfoまたはWarnメッセージの解析を行わず、エラーに HTTP 5xx 応答だけが必要な場合にはこのエンドポイントタイプを使用します。また、このタイプのエンドポイントは、デシジョンサービスの結果のシングルトン強制が DMN のモデル動作に似ているので、単一ページアプリケーションのようなクライアントにも役立ちます。 -
REST
dmnresultエンドポイント: クライアントがInfo、Warn、またはErrorメッセージの解析が必要な場合は、このエンドポイントタイプを使用します。
エンドポイントごとに、REST クライアントまたは curl ユーティリティーを使用して、以下のコンポーネントで要求を送信します。
-
ベース URL:
http://HOST:PORT/kie-server/services/rest/ パスパラメーター:
-
{containerId}:mykjar-projectなどのコンテナーの文字列識別子 -
{modelName}:Traffic Violationなどの DMN モデルの文字列識別子 -
{decisionServiceName}:TrafficViolationDecisionServiceなどの DMN DRG のデシジョンサービスコンポーネントの文字列識別子 -
dmnresult: エンドポイントが、詳細にわたるInfo、WarnおよびErrorメッセージを含む、完全なDMNResult応答を返すことができるようにする文字列識別子
-
HTTP ヘッダー:
POST要求のみ:-
accept:application/json -
content-type:application/json
-
-
HTTP メソッド:
GETまたはPOST
以下のエンドポイントの例は、TrafficViolationDecisionService デシジョンサービスコンポーネントが含まれる Traffic Violation DMN モデルを格納する mykjar-project コンテナーをもとにしています。
これらの全エンドポイントに対して、DMN 評価の Error メッセージが発生すると、DMNResult 応答が HTTP 5xx エラーと共に返されます。DMN の Info または Warn メッセージが表示されると、クライアント側のビジネスロジックに使用される X-Kogito-decision-messages 拡張 HTTP ヘッダーで、business- domain REST ボディーと共に関連する応答が返されます。クライアント側に詳細にわたるビジネスロジックの要件がある場合には、クライアントはエンドポイントの dmnresult バリアントを使用できます。
- 指定のコンテナー内の DMN モデルの Swagger または OAS 取得
GET /server/containers/{containerId}/dmn/openapi.json (|.yaml)REST エンドポイントの例
http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/openapi.json (|.yaml)- デシジョンロジックのない DMN XML を返します。
GET /server/containers/{containerId}/dmn/models/{modelname}REST エンドポイントの例
http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violationcurl 要求例
curl -u wbadmin:wbadmin -X GET "http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic%20Violation" -H "accept: application/xml"応答例 (XML)
<?xml version='1.0' encoding='UTF-8'?> <dmn:definitions xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/" xmlns="https://kiegroup.org/dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" xmlns:kie="http://www.drools.org/kie/dmn/1.2" xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/" xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="_1C792953-80DB-4B32-99EB-25FBE32BAF9E" name="Traffic Violation" expressionLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" namespace="https://kiegroup.org/dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF"> <dmn:extensionElements/> <dmn:itemDefinition id="_63824D3F-9173-446D-A940-6A7F0FA056BB" name="tDriver" isCollection="false"> <dmn:itemComponent id="_9DAB5DAA-3B44-4F6D-87F2-95125FB2FEE4" name="Name" isCollection="false"> <dmn:typeRef>string</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_856BA8FA-EF7B-4DF9-A1EE-E28263CE9955" name="Age" isCollection="false"> <dmn:typeRef>number</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_FDC2CE03-D465-47C2-A311-98944E8CC23F" name="State" isCollection="false"> <dmn:typeRef>string</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_D6FD34C4-00DC-4C79-B1BF-BBCF6FC9B6D7" name="City" isCollection="false"> <dmn:typeRef>string</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_7110FE7E-1A38-4C39-B0EB-AEEF06BA37F4" name="Points" isCollection="false"> <dmn:typeRef>number</dmn:typeRef> </dmn:itemComponent> </dmn:itemDefinition> <dmn:itemDefinition id="_40731093-0642-4588-9183-1660FC55053B" name="tViolation" isCollection="false"> <dmn:itemComponent id="_39E88D9F-AE53-47AD-B3DE-8AB38D4F50B3" name="Code" isCollection="false"> <dmn:typeRef>string</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_1648EA0A-2463-4B54-A12A-D743A3E3EE7B" name="Date" isCollection="false"> <dmn:typeRef>date</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_9F129EAA-4E71-4D99-B6D0-84EEC3AC43CC" name="Type" isCollection="false"> <dmn:typeRef>string</dmn:typeRef> <dmn:allowedValues kie:constraintType="enumeration" id="_626A8F9C-9DD1-44E0-9568-0F6F8F8BA228"> <dmn:text>"speed", "parking", "driving under the influence"</dmn:text> </dmn:allowedValues> </dmn:itemComponent> <dmn:itemComponent id="_DDD10D6E-BD38-4C79-9E2F-8155E3A4B438" name="Speed Limit" isCollection="false"> <dmn:typeRef>number</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_229F80E4-2892-494C-B70D-683ABF2345F6" name="Actual Speed" isCollection="false"> <dmn:typeRef>number</dmn:typeRef> </dmn:itemComponent> </dmn:itemDefinition> <dmn:itemDefinition id="_2D4F30EE-21A6-4A78-A524-A5C238D433AE" name="tFine" isCollection="false"> <dmn:itemComponent id="_B9F70BC7-1995-4F51-B949-1AB65538B405" name="Amount" isCollection="false"> <dmn:typeRef>number</dmn:typeRef> </dmn:itemComponent> <dmn:itemComponent id="_F49085D6-8F08-4463-9A1A-EF6B57635DBD" name="Points" isCollection="false"> <dmn:typeRef>number</dmn:typeRef> </dmn:itemComponent> </dmn:itemDefinition> <dmn:inputData id="_1929CBD5-40E0-442D-B909-49CEDE0101DC" name="Violation"> <dmn:variable id="_C16CF9B1-5FAB-48A0-95E0-5FCD661E0406" name="Violation" typeRef="tViolation"/> </dmn:inputData> <dmn:decision id="_4055D956-1C47-479C-B3F4-BAEB61F1C929" name="Fine"> <dmn:variable id="_8C1EAC83-F251-4D94-8A9E-B03ACF6849CD" name="Fine" typeRef="tFine"/> <dmn:informationRequirement id="_800A3BBB-90A3-4D9D-BA5E-A311DED0134F"> <dmn:requiredInput href="#_1929CBD5-40E0-442D-B909-49CEDE0101DC"/> </dmn:informationRequirement> </dmn:decision> <dmn:inputData id="_1F9350D7-146D-46F1-85D8-15B5B68AF22A" name="Driver"> <dmn:variable id="_A80F16DF-0DB4-43A2-B041-32900B1A3F3D" name="Driver" typeRef="tDriver"/> </dmn:inputData> <dmn:decision id="_8A408366-D8E9-4626-ABF3-5F69AA01F880" name="Should the driver be suspended?"> <dmn:question>Should the driver be suspended due to points on his license?</dmn:question> <dmn:allowedAnswers>"Yes", "No"</dmn:allowedAnswers> <dmn:variable id="_40387B66-5D00-48C8-BB90-E83EE3332C72" name="Should the driver be suspended?" typeRef="string"/> <dmn:informationRequirement id="_982211B1-5246-49CD-BE85-3211F71253CF"> <dmn:requiredInput href="#_1F9350D7-146D-46F1-85D8-15B5B68AF22A"/> </dmn:informationRequirement> <dmn:informationRequirement id="_AEC4AA5F-50C3-4FED-A0C2-261F90290731"> <dmn:requiredDecision href="#_4055D956-1C47-479C-B3F4-BAEB61F1C929"/> </dmn:informationRequirement> </dmn:decision> <dmndi:DMNDI> <dmndi:DMNDiagram> <di:extension/> <dmndi:DMNShape id="dmnshape-_1929CBD5-40E0-442D-B909-49CEDE0101DC" dmnElementRef="_1929CBD5-40E0-442D-B909-49CEDE0101DC" isCollapsed="false"> <dmndi:DMNStyle> <dmndi:FillColor red="255" green="255" blue="255"/> <dmndi:StrokeColor red="0" green="0" blue="0"/> <dmndi:FontColor red="0" green="0" blue="0"/> </dmndi:DMNStyle> <dc:Bounds x="708" y="350" width="100" height="50"/> <dmndi:DMNLabel/> </dmndi:DMNShape> <dmndi:DMNShape id="dmnshape-_4055D956-1C47-479C-B3F4-BAEB61F1C929" dmnElementRef="_4055D956-1C47-479C-B3F4-BAEB61F1C929" isCollapsed="false"> <dmndi:DMNStyle> <dmndi:FillColor red="255" green="255" blue="255"/> <dmndi:StrokeColor red="0" green="0" blue="0"/> <dmndi:FontColor red="0" green="0" blue="0"/> </dmndi:DMNStyle> <dc:Bounds x="709" y="210" width="100" height="50"/> <dmndi:DMNLabel/> </dmndi:DMNShape> <dmndi:DMNShape id="dmnshape-_1F9350D7-146D-46F1-85D8-15B5B68AF22A" dmnElementRef="_1F9350D7-146D-46F1-85D8-15B5B68AF22A" isCollapsed="false"> <dmndi:DMNStyle> <dmndi:FillColor red="255" green="255" blue="255"/> <dmndi:StrokeColor red="0" green="0" blue="0"/> <dmndi:FontColor red="0" green="0" blue="0"/> </dmndi:DMNStyle> <dc:Bounds x="369" y="344" width="100" height="50"/> <dmndi:DMNLabel/> </dmndi:DMNShape> <dmndi:DMNShape id="dmnshape-_8A408366-D8E9-4626-ABF3-5F69AA01F880" dmnElementRef="_8A408366-D8E9-4626-ABF3-5F69AA01F880" isCollapsed="false"> <dmndi:DMNStyle> <dmndi:FillColor red="255" green="255" blue="255"/> <dmndi:StrokeColor red="0" green="0" blue="0"/> <dmndi:FontColor red="0" green="0" blue="0"/> </dmndi:DMNStyle> <dc:Bounds x="534" y="83" width="133" height="63"/> <dmndi:DMNLabel/> </dmndi:DMNShape> <dmndi:DMNEdge id="dmnedge-_800A3BBB-90A3-4D9D-BA5E-A311DED0134F" dmnElementRef="_800A3BBB-90A3-4D9D-BA5E-A311DED0134F"> <di:waypoint x="758" y="375"/> <di:waypoint x="759" y="235"/> </dmndi:DMNEdge> <dmndi:DMNEdge id="dmnedge-_982211B1-5246-49CD-BE85-3211F71253CF" dmnElementRef="_982211B1-5246-49CD-BE85-3211F71253CF"> <di:waypoint x="419" y="369"/> <di:waypoint x="600.5" y="114.5"/> </dmndi:DMNEdge> <dmndi:DMNEdge id="dmnedge-_AEC4AA5F-50C3-4FED-A0C2-261F90290731" dmnElementRef="_AEC4AA5F-50C3-4FED-A0C2-261F90290731"> <di:waypoint x="759" y="235"/> <di:waypoint x="600.5" y="114.5"/> </dmndi:DMNEdge> </dmndi:DMNDiagram> </dmndi:DMNDI>- 指定されたコンテナーで指定の DMN モデルを評価します
POST /server/containers/{containerId}/dmn/models/{modelname}REST エンドポイントの例
http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violationcurl 要求例
curl -u wbadmin:wbadmin-X POST "http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violation" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"Driver\":{\"Points\":15},\"Violation\":{\"Date\":\"2021-04-08\",\"Type\":\"speed\",\"Actual Speed\":135,\"Speed Limit\":100}}"入力データでの POST 要求ボディーの例
{ "Driver": { "Points": 15 }, "Violation": { "Date": "2021-04-08", "Type": "speed", "Actual Speed": 135, "Speed Limit": 100 } }応答例 (JSON)
{ "Violation": { "Type": "speed", "Speed Limit": 100, "Actual Speed": 135, "Code": null, "Date": "2021-04-08" }, "Driver": { "Points": 15, "State": null, "City": null, "Age": null, "Name": null }, "Fine": { "Points": 7, "Amount": 1000 }, "Should the driver be suspended?": "Yes" }- コンテナーで指定された DMN モデル内の指定のデシジョンサービスを評価します
POST /server/containers/{containerId}/dmn/models/{modelname}/{decisionServiceName}このエンドポイントでは、要求ボディーにデシジョンサービスのすべての要件を含める必要があります。応答は、デシジョン値、元の入力値、およびシリアル化形式の他の parametric DRG コンポーネントすべてなど、デシジョンサービスの結果として返される DMN コンテキストです。たとえば、ビジネスナレッジモデルは、署名の文字列のシリアル化形式で利用できます。
デシジョンサービスが単一の出力デシジョンで構成される場合には、応答はその特定のデシジョンから返される値になります。この動作は、モデル自体でデシジョンサービスを呼び出す時に、仕様機能の API レベルで同等の値を指定します。これにより、たとえば単一ページの Web アプリケーションから DMN デシジョンサービスと対話ができます。
図7.1 単一の出力デシジョンを含む
TrafficViolationDecisionServiceデシジョンサービスの例
図7.2 複数の出力デシジョンを含む
TrafficViolationDecisionServiceデシジョンサービスの例
REST エンドポイントの例
http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violation/TrafficViolationDecisionService入力データでの POST 要求ボディーの例
{ "Driver": { "Points": 2 }, "Violation": { "Type": "speed", "Actual Speed": 120, "Speed Limit": 100 } }curl 要求例
curl -X POST http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violation/TrafficViolationDecisionService -H 'content-type: application/json' -H 'accept: application/json' -d '{"Driver": {"Points": 2}, "Violation": {"Type": "speed", "Actual Speed": 120, "Speed Limit": 100}}'シングル出力デシジョンの応答例 (JSON)
"No"複数出力デシジョンの応答例 (JSON)
{ "Violation": { "Type": "speed", "Speed Limit": 100, "Actual Speed": 120 }, "Driver": { "Points": 2 }, "Fine": { "Points": 3, "Amount": 500 }, "Should the driver be suspended?": "No" }- 指定したコンテナーで指定の DMN モデルを評価し、
DMNResult応答を返します。 POST /server/containers/{containerId}/dmn/models/{modelname}/dmnresultREST エンドポイントの例
http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violation/dmnresult入力データでの POST 要求ボディーの例
{ "Driver": { "Points": 2 }, "Violation": { "Type": "speed", "Actual Speed": 120, "Speed Limit": 100 } }curl 要求例
curl -X POST http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violation/dmnresult -H 'content-type: application/json' -H 'accept: application/json' -d '{"Driver": {"Points": 2}, "Violation": {"Type": "speed", "Actual Speed": 120, "Speed Limit": 100}}'応答例 (JSON)
{ "namespace": "https://kiegroup.org/dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "modelName": "Traffic Violation", "dmnContext": { "Violation": { "Type": "speed", "Speed Limit": 100, "Actual Speed": 120, "Code": null, "Date": null }, "Driver": { "Points": 2, "State": null, "City": null, "Age": null, "Name": null }, "Fine": { "Points": 3, "Amount": 500 }, "Should the driver be suspended?": "No" }, "messages": [], "decisionResults": [ { "decisionId": "_4055D956-1C47-479C-B3F4-BAEB61F1C929", "decisionName": "Fine", "result": { "Points": 3, "Amount": 500 }, "messages": [], "evaluationStatus": "SUCCEEDED" }, { "decisionId": "_8A408366-D8E9-4626-ABF3-5F69AA01F880", "decisionName": "Should the driver be suspended?", "result": "No", "messages": [], "evaluationStatus": "SUCCEEDED" } ] }- 指定したコンテナーの DMN モデル内で指定のデシジョンサービスを評価し、
DMNResult応答を返します。 POST /server/containers/{containerId}/dmn/models/{modelname}/{decisionServiceName}/dmnresultREST エンドポイントの例
http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violation/TrafficViolationDecisionService/dmnresult入力データでの POST 要求ボディーの例
{ "Driver": { "Points": 2 }, "Violation": { "Type": "speed", "Actual Speed": 120, "Speed Limit": 100 } }curl 要求例
curl -X POST http://localhost:8080/kie-server/services/rest/server/containers/mykjar-project/dmn/models/Traffic Violation/TrafficViolationDecisionService/dmnresult -H 'content-type: application/json' -H 'accept: application/json' -d '{"Driver": {"Points": 2}, "Violation": {"Type": "speed", "Actual Speed": 120, "Speed Limit": 100}}'応答例 (JSON)
{ "namespace": "https://kiegroup.org/dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "modelName": "Traffic Violation", "dmnContext": { "Violation": { "Type": "speed", "Speed Limit": 100, "Actual Speed": 120, "Code": null, "Date": null }, "Driver": { "Points": 2, "State": null, "City": null, "Age": null, "Name": null }, "Should the driver be suspended?": "No" }, "messages": [], "decisionResults": [ { "decisionId": "_8A408366-D8E9-4626-ABF3-5F69AA01F880", "decisionName": "Should the driver be suspended?", "result": "No", "messages": [], "evaluationStatus": "SUCCEEDED" } ] }