ルートを作成して外部マップを使用 - 8.0

Talend Data Mapperファンクションリファレンスガイド

Version
8.0
Language
日本語
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
ジョブデザインと開発 > ジョブデザイン
Last publication date
2023-11-06

ルートを作成し、コンポーネントを設定して、外部マップ変数を作成および使用します。

手順

  1. Integrationパースペクティブで、[Route Designs] (ルートデザイン)ノードを右クリックして、[Create Route] (ルートを作成)をクリックします。
  2. ルートの名前、目的、説明を入力して[Finish] (完了)をクリックします。
  3. 次のコンポーネントをデザインワークスペースに追加し、[Row] (行) > [Route] (接続)接続にリンクさせます。
    • cTimer
    • cProcessor
    • cSetBody
    • cMap
    • cLog
    • 2つ目のcProcessor
    ルートは次のようになります。
  4. 1つ目のcProcessorコンポーネントをダブルクリックして、以下のように設定します:
    パラメーター
    Import
    import java.util.*;
    Code
    Map<String, Object> externalMap = new HashMap<>();
    externalMap.put("current.date",TalendDate.getCurrentDate());
    Map<String, Object> executionProperties = exchange.getIn().getHeaders();
    if (executionProperties==null){
      executionProperties = new HashMap<>();
      exchange.getIn().setHeaders(executionProperties);
    }
    executionProperties.put("org.talend.transform.externalmap", externalMap);

    このコードによって、後でマップで使えるcurrent.dateという名前の外部マップ変数を作成できます。

  5. cSetBodyコンポーネントをダブルクリックして、以下のように設定します:
    パラメーター
    Language Constant
    Expression "<orders><order><orderId>abc-6545165186</orderId><shippingDetails><lastName>Kennedy</lastName><firstName>John</firstName><street>Santa Rosa South</street><city>Columbus</city><state>New York</state></shippingDetails><items><item><id>4987601</id><price>649.99</price><quantity>1</quantity></item><item><id>8570817</id><price>99.99</price><quantity>3</quantity></item></items></order></orders>"
  6. 2つ目のcProcessorコンポーネントをダブルクリックして、以下のように設定します:
    パラメーター
    Code
    Map<String, Object> executionProperties = exchange.getIn().getHeaders();
    if (executionProperties==null){
      executionProperties = new HashMap<>();
      exchange.getIn().setHeaders(executionProperties);
    }
    Map<String, Object> externalMap = (Map<String, Object>)executionProperties.get("org.talend.transform.externalmap");
    System.out.println("Order ID: " + (String)externalMap.get("order.id"));
    System.out.println("Order due date: " + (String)externalMap.get("due.date"));

    このコードによって、マップで定義するorder.id外部マップ変数とdue.date外部マップ変数を出力できます。

タスクの結果

ルートが設定されており、マップを生成および設定できるようになります。