エンティティーの取得
Insight Server に GET 操作要求を送信することで、ソリューション・エンティティーに関する情報を取得できます。 GET 要求に対する応答には、エンティティー ID によって識別される単一のエンティティー表現が含まれます。
このタスクについて
デフォルトでは、取得された情報は XML 形式で返されます。値を JSON に設定することで、返される形式を変更できます。出力形式の選択は、データの受信に使用しているツールに基づきます。JSON 出力を読み取って解釈する方法について詳しくは、『JSON マッピング (JSON mapping)』を参照してください。
手順
- ブラウザーのアドレス・フィールドに汎用 REST URL を入力することで、Insight Server にアクセス可能であることを確認します。REST URL の例については、エンティティーの管理を参照してください。
- ご使用のブラウザーかスクリプトを使用して GET 要求を送信し、エンティティーに関する情報を取得します。 例:
この場合、カスタマー・エンティティーの ID は 200 です。https://localhost:9443/ibm/ia/rest/solutions/BankingSolution/entity-types/CustomerID/entities/200返される内容は以下のとおりです。<object xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ibm.com/ia/Entity" type="com.example.model.ComplexEntity"> <attribute name="$CreationTime"> <null/> </attribute> <attribute name="$IdAttrib"> <string>id</string> </attribute> <attribute name="complexEvent"> <object type="com.example.model.ComplexEvent"> <attribute name="$Id"> <string>25AAE2D8845270CAB511E5A3BE8C0B69</string> </attribute> <attribute name="$TimeAttrib"> <string>datetime</string> </attribute> <attribute name="completed"> <boolean>false</boolean> </attribute> <attribute name="complexEntities"> <collection> <object type="com.ibm.ia.model.Relationship"> <attribute name="key"> <string>E0025</string> </attribute> <attribute name="type"> <string>com.example.model.ComplexEntity</string> </attribute> </object> <object type="com.ibm.ia.model.Relationship"> <attribute name="key"> <string>E0014</string> </attribute> <attribute name="type"> <string>com.example.model.ComplexEntity</string> </attribute> </object> </collection> </attribute> <attribute name="datetime"> <null/> </attribute> <attribute name="value"> <string>test</string> </attribute> </object> </attribute> <attribute name="enumType"> <object type="com.example.model.EnumType" staticReference="gamma"/> </attribute> <attribute name="id"> <string>E0025</string> </attribute> <attribute name="testConcepts"> <collection> <object type="com.example.model.TestConcept"> <attribute name="value"> <int>3643</int> </attribute> </object> <object type="com.example.model.TestConcept"> <attribute name="value"> <int>-771</int> </attribute> </object> </collection> </attribute> </object>GET 要求には、オプションの regex パラメーターを含めることができます。GET 要求に正規表現 (regex) 照会ストリングを追加すると、その表現と一致する 1 つまたは 1 組のエンティティーを取得できます。この照会に 1 つエンティティー ID、またはエンティティー ID の範囲が含まれている場合は、一致する ID のエンティティーのみがサーバー応答で返されます。例:
この場合は、ID が 200、201、202、203、204、または 205 のエンティティーが GET 要求に対する応答で返されます。https://localhost:9443/ibm/ia/rest/solutions/BankingSolution/entity-types/CustomerID?regex=20[0-5] - オプション: Accept 要求ヘッダーで、エンティティーに関する情報を JSON 形式で取得するように値を application/json に設定します。 例:
この場合、カスタマー・エンティティーの ID は 200 です。https://localhost:9443/ibm/ia/rest/solutions/BankingSolution/entity-types/CustomerID/entities/200返される内容は以下のとおりです。{ "$class": "com.example.model.ComplexEntity", "$CreationTime": null, "$IdAttrib": "id", "complexEvent": { "$Id": "25AAE2D8845270CAB511E5A3BE8C0B69", "$TimeAttrib": "datetime", "completed": false, "complexEntities": [ { "$class": "com.ibm.ia.model.Relationship", "key": "E0025", "type": "com.example.model.ComplexEntity" }, { "$class": "com.ibm.ia.model.Relationship", "key": "E0014", "type": "com.example.model.ComplexEntity" } ], "datetime": null, "value": "test" }, "enumType": "gamma", "id": "E0025", "testConcepts": [ { "value": 3643 }, { "value": -771 } ] } - オプション: 前回の要求以降に変更されたエンティティーのみを返すよう、要求に If-None-Match 要求ヘッダーと ETag ヘッダーを含めます。 ヒント: GET 要求を頻繁に行ったり、GET 要求によって多数のエンティティーが返されたりすると、要求の量によってイベントの処理パフォーマンスに影響がでることがあります。その場合は、ETag ヘッダーを使用して、エンティティーの取得を最適化し、処理速度を向上させます。