Create and populate the Step entity

At the moment, your application contains only 10 purchase orders. 

When starting out, a restricted set of data like the one you have currently is great to check the logic of your integration routes, mappings, and dashboard content.


To make effective use of evaluations, you need more purchase orders in the product. In a real-world situation, you would expect:

  • A greater volume of data, even during the early development phase of your application 
  • A more complex structure of entities in your model.

In the diagram below, you can see your two existing entities – Orders, Global, and the relation between them. 

There is one significant missing part: the order process workflow itself. Each of the stages an order moves through represents a step in the process.

To monitor this workflow,  include an entity for steps in your model.  If you apply the same sort of thinking about steps that you did for orders, it might be that the model requires not just an entity for steps, but also a relationship between steps and Global. Something like the diagram below. Adding the relation to Global would enable you to summarize information about all steps.

Adding a relationship between orders and steps is also good to add visibility into what orders are in a step. This is the more complete picture of what your model will include:

The direction of the relations you are going to create will be:

  • From Step to Global (many to one) 
  • From Order to Step (because there can be more than one order in a step, but an order can never be in more than one step).

Create a checklist

The steps you are about to follow to add new data in your application are essentially the steps you will follow every time you want to add new data to an application.

Making a checklist of these steps could be useful. If you skip a step, or don't check your work carefully, you could spend time running down the problem. If you build your checklist, make sure to update it as you encounter new situations where the expected data behaved in unexpected ways.



1. Create the Step entity

As you've seen before an entity is only part of the process. You must also create instances of that entity.

Before you can read  data in your model, you need to first create the location where that data will be held. 

transactional vs configuration

Steps in the process are not transactional data. Steps are a part of the process, not a part of the transactions or orders that move through the process. You will choose the configuration entity type. One of the benefits of having steps marked as Configuration is that they will be exported and imported when you save / restore your application.

Step Action
1

Click the Configuration   icon > Entities.

2

Click the New Entity button.

  • Create a new [mono or multi] dimensional entity:
  • Name: Step
  • Space: Model
  • Description: Process Step
  • Type: Configuration
3 On the Attributes tab, add the following observed attribute:
  • Name: step Name
  • Type: String
  • Description: Name of this process step
4 Add the following observed relation attribute:
  • Name: Global
  • Reverse Name: Steps
  • Description: Links steps to global
  • Target: Global
5 On the Keys tab, create a key for the Step entity.
  • Name: Step
  • Attribute: step Name
6 Click Save.


2. Create a mapping and a route for Step

Now that the Step entity is created, create the means to populate the entity. To create the instances of the Step entity, you need to know the names of the process steps.

The test data you used in prior parts of the tutorial did not include information on the step names. 

There are new data files, supplied as part of this tutorial. Unzip the DI_tutorial_Part4.zip .zip file into a directory. This will create three files:

  • Part-4-11-Steps.txt
  • Part-4-31-Days.txt
  • Part-4-10-Orders

The Part-4-11-Steps.txt file is the first one you will use. Note that in this data file there is no header record, only data fields. You have an entity, and you have data.

To populate the Step entity, you're missing a mapping and a route.

By creating the mapping first, you benefit from having the parameter names carried forward from the mapping to the route.

Create a mapping for Step

Step Action
1

Click the Data Integration icon > Mappings.

2

Click the New Mapping button.

3

Give your mapping the following characteristics:

  • Name: Step
  • Parameter: step Name, Type: String
4

Click the Add Instance Operation button:

  • Select the Step entity.
  • DEFAULT TIMES area – In the Resolution and Operations begin fields, , select Constant, then enter {{app_start_date}}.
  • RESOLUTION area:
    • Click the choose a key hyperlink and select the parameter you created for the step Name attribute.
    • Select the Create an instance option. This is the correct option for what to do if an instance of Step is not found.
  • OPERATIONS area – Create the following two operations.
5

For the first operation:

  • Add an operation set for the Global attribute to change the value of the relation to the Global entity.
  • In the line for Value, select Constant, Global.
6

For the second operation:

  • Add a set space operation.
  • In the line for Space name, select Constant, Instances .
7 Click Save.
8 Click the Copy Snippet icon.

Create a route for Step

Step Action
1

On the left menu, click Routes.

2

Click the New Routing Context button and give your new route the following characteristics:

  • Name: Step.
3

In the body of the route, enter the following:

  • A from uri statement that uses direct:file.
  • Specify the csv delimeter with skipHeaderRecord="false".
  • Wrap the csv delimiter line in an unmarshal statement.
  • Add log message information:  <log message="csv - ${body}"/>.
  • <split> the route.
  • Add a simple statement to retrieve the body of the file.
  • Add log message information to know whether the split is successful: <log message="split - ${body}"/>.
  • Paste the snippet from the Step mapping. The step information is in body[0].
  • Close the split statement, close the route.
4 Click Save.

Once you're done, start the route, and use the sample text file as an input.

Check the results

To check the results, you can look at the logs and or click the Explore icon on the main menu to explore the Step entity. The order of the step names may vary.

If you do not see these results, you can check that the Step route you created matches the one below:

<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <from uri="direct:file"/>
        <unmarshal>
            <csv delimiter="," skipHeaderRecord="false"/>
        </unmarshal>
        <log message="csv - ${body}"/>
        <split>
            <simple> ${body}</simple>
            <log message="split - ${body}"/>
            <setBody>
                <u:map-create>
                    <u:map-entry key="Name">
                        <simple>${body[0]}</simple>
                    </u:map-entry>
                </u:map-create>
            </setBody>
            <to uri="tnd-absorption:Step"/>
        </split>
    </route>
</routes>



Related Links