Skip to main content Skip to complementary content

Using a routine in a map

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>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!