Import the New Order events

See how to adapt your solution so you can bring in all the orders classified as New Order.

Attributes and Event Types

1.Create a new mapping for the sample data

You can see the relationship between events in Kabels order workflow and the attributes in your application in the table above. Only one change is needed for the New Order event: Step name.  

Map that information into the Order entity while preserving the ability to replay previous steps in the future.

Backup the mapNewOrder mapping

Step

Action

1

On the left menu, click Mappings.

2

Select the mapNewOrder mapping and click the Copy icon.

3

Keep the current space – Initializers – selected and click Copy.

4 Name the new route xmapNewOrder, and Save. This creates a backup copy of the mapNewOrder mapping.


Modify the mapNewOrder mapping for the New Order event

Try and modify the mapping as needed. If you get stuck or need help, look at the Helpful hints section below the table. 

Step

Action

1

In the context of the mapNewOrder mapping, add the information missing to fully map the New Order event.

Reminder: You are missing a parameter for the name of the step.

2 Add the missing parameter for the step Name attribute.
3 Add an operation for the new attribute.
4 When everything looks correct, click Save.
5

Click the Copy snippet for routing context icon.

Helpful Hints

Order Mapping Parameters

 

Order Mapping Operations

 

2. Expand the order route for the New Order events

The only change needed is for the route to pass the parameter for Step.

Backup the rouOrder route

Step

Action

1

On the left menu, click Routes.

2

Select the rouOrder route and click the Copy icon.

3

Keep the current space – Initializers – selected and click Copy.

4 Name the new route xrouOrder, and Save. This creates a backup copy of the rouOrder route.

Modify the rouOrder route so you can inject a file

The xrouOrder route was set up to import data based on a resource. Now, you're going to import data using the direct:file method. 

Modify the rouOrder route:

Step

Action

1

Modify the from uri statement so it uses the direct:file method:

 <from uri="direct:file"/>
2

In the <unmarshal> statement:

  • Replace the symbol used as the CSV delimiter from "|" to ","
  • Delete the useMaps="true" statement.
  • Add the following: skipHeaderRecord="true".

Your statement should look like this:

<unmarshal>
<csv delimiter="," skipHeaderRecord="true"/>
</unmarshal>

3

In the <split> statement, delete the two lines after <simple> ${body}</simple>.

4

Paste the contents from your mapping.

The contents you've added should look like this:

 <u:map-create>
        <u:map-entry key="CustomerName">
            <!-- Add expression for CustomerName -->
        </u:map-entry>
        <u:map-entry key="CustomerReference">
            <!-- Add expression for CustomerReference -->
        </u:map-entry>
        <u:map-entry key="CycleNumber">
            <!-- Add expression for CycleNumber -->
        </u:map-entry>
        <u:map-entry key="Timestamp">
            <!-- Add expression for Timestamp -->
        </u:map-entry>
        <u:map-entry key="step">
            <!-- Add expression for step -->
        </u:map-entry>
    </u:map-create>


Map the mapping parameters to the columns in your import file

As you can see from the content, you just pasted into the route, you are expected to fill in missing information, namely, you must specify for each parameter in the mapping the location (here is the column number) where the information will be found in your import file.

For example, if you take a look at the CycleNumber attribute, the corresponding column of information in the export file is  the third column, 3 Order No.

In your route, on the u:map line for Cycle Number, this is exactly what you need to specify: that the information for Cycle number will be found in the third column of the file, that is to say in ${body[3]}:

<u:map-entry key="CycleNumber">
<simple>${body[3]}</simple>
Step Action
1 In the rouOrder route, indicate the correct $body expression for each u:map parameter. See example above for help.


Modify the rouOrder route for the New Order event

You want the rouOrder route to call the Order mapping for every New Order event and only for New Order events.

The sample data has three different event types: New OrderOrder Valid, and Payment Received. As it is written right now, your route will send data from all three types of events to your Order mapping. You need to filter and direct the events that you send to the mappings.

Understand conditional route processing

Camel being an open-source format, you can usually find useful  information about Camel route syntax by simply googling it. For example, google "camel csv example" and you will find useful information within the first three or four results.

However, you might find it harder to find documentation around conditional processing. Here is what you need to know. The structure of a conditional operation follows this outline:

<choice>
	<when>
	[simple evaluation expression]
	[simple statements]
	</when>

	<otherwise>
	[simple statements]
	</otherwise>
</choice>

The simple evaluation expression checks the event type and would look something like this:

<simple>${body[x]} == "Type" </simple>

Can you see how and where to build the statements to handle this conditional situation?

Step

Action

1

There is one more thing to add: conditional processing. You want to place the conditional statements after the closing <setBody> statement.

As with other commands, Decision Insight will automatically close statement pairs as you enter the statements. Start by entering those two statements and hitting enter to separate them.

<choice>
<when>
</when>
</choice>

2

Place your cursor between the <when> statements and enter the following:

<simple>${body[step]} == "New Order"</simple>
<log message="Sent to new mapping ${body}"/>
<to uri="tnd-absorption:mapNewOrder"/>
3

Before running your route for the first time, turn the <to uri> statement into a comment. This way you can validate your logic without changing any of the data in Decision Insight's memory.

4

Save the route.

Test run the route

Step Action
1

Start the route.

2 Click the manual injection icon.
3 Navigate to the Part-4-10-Orders.txt file and inject it into your route as direct:file.
4

Check the logs. If you scroll down the top pane of the log summary, you should be able to see three different types of log messages, as shown in figure below.

Caution: Don't uncomment your call to the mapping yet. One more thing to take care of.

Understand  what the ${body} of a route is

As Camel sees it, the body is an object rooted within a range of XML statements. The content of ${body} changes during the processing of a route. In the Order route, there are four distinct definitions of the body.

Evolution of the Body

The four states of the body in this route are:

  1. Data arrival – As it arrives from the direct:file statement, the body contains every line of the data file, all in one undifferentiated heap. 

  2. Unmarshalled data –The effect of the unmarshal command is to split the input into individual units. In the csv formation, that means that the body now consists of a list of events, one line for each event. 

  3. Separate data elements accessed based on their column number in the log files –After the split commands, the body consists of a single line at a time from the unmarshalled list broken apart into separate data elements, defined by the delimiter character. Within the section, access to the individual elements is by the column sequence number. For example, body[4] selects the Step from the line currently in existence inside the commands. 

  4. Conditional processing – After the closing statement, the data remains a single line, but (and this is an important but) the means to access elements is via the mapentry key provided in the third section of the map, not the column sequence number. The highlighted boxes show the relationship between the declaration and use of the key field.

3. Read New Order events with the rouOrder route

Time to run your Route and bring the data into your application.

Step

Action

1

In the rouOrder route, uncomment the statement that sends data to the Order mapping. 

2

Save and run your route.

Did your route succeed? If you see errors in the logs, you missed some step leading up to this point. Go back, debug your route and come back here again.

If you see only Info logs and no errors, you can continue.

Validate your data

What is the next step after loading data? That's right. Validate what you see.

Whenever possible, validation should be a white box test. A white box test is one when you know both the input data and what to expect for results from that data.

Your Selected Orders section should show this information:

4. Add attributes to the Search for Orders dashboard

The new data file added a new attribute for the New Order events. Update your search dashboard to show the new relation to Step.

Step

Action

1

Open your Search for Orders dashboard and go into edit mode.

2

Edit the Selected orders pagelet.

3

Click the Add value button.

4

Click the Select an attribute hyperlink.

5

Follow the relation to Step and select the step Name attribute.

6

Change the label to Current Step.

7 Click Done and Save until the dashboard is out of edit mode.

The selected orders pagelet should look like this:


 

Related Links