Using a routine in a map - 8.0

Talend Data Mapper User Guide

Version
8.0
Language
English
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
Design and Development > Designing Jobs
Last publication date
2024-03-28

Use a Java function to call a routine that generates a random string.

Before you begin

You have created a map with an input and output structure. You can use the sample provided below.

About this task

In this example, you have a file containing customer names and you want to generate an ID for each customer. You can use the following XML sample as input:
<customers>
   <customer>
      <firstName>Grover</firstName>
      <lastName>Truman</lastName>
   </customer>
   <customer>
      <firstName>Millard</firstName>
      <lastName>Roosevelt</lastName>
   </customer>
   <customer>
      <firstName>Theodore</firstName>
      <lastName>Garfield</lastName>
   </customer>
</customers>
The output structure should be the same as the input with an added id element.

Procedure

  1. Drag the input customer element to the corresponding output element to map the customer names.
  2. From the Functions tab, drag a Java function and drop it on the id element.
  3. Double-click the Java function and enter routines.DataMasking in the Class Name field and createRandomString in the Method Name field, then click OK.
  4. Drag and drop a Constant function on the Java function.
    The routine used in this example requires a parameter that indicates the number of characters in the string to generate.
  5. Double-click the Constant function and enter the length of the string you want to generate, 15 for example.
  6. In the Data Type drop-down list, select Integer (32) and click OK.
  7. Optional: Add another Constant function below the first one to add a list of characters allowed in the generated string.

Results

Your map in now configured. You can use the Test Run feature to see the result. In this example, the following output is returned:
<root>
  <customer>
    <firstName>Grover</firstName>
    <lastName>Truman</lastName>
    <id>tc2m9HQ9BQjbS7h</id>
  </customer>
  <customer>
    <firstName>Millard</firstName>
    <lastName>Roosevelt</lastName>
    <id>BcTd14JScXQQyjP</id>
  </customer>
  <customer>
    <firstName>Theodore</firstName>
    <lastName>Garfield</lastName>
    <id>BBCUINwgqXUh9ls</id>
  </customer>
</root>