Harmonizing the Order Data
Now that we have modeled the Order entity we can use the Data Hub Framework’s code scaffolding to create a boilerplate for Harmonizing our data.
Click on the Flows tab in the top navigation bar.
- Click on the + icon next to Harmonize Flows
- Type Harmonize Orders into the Harmonize Flow Name field
- Click the CREATE button
Note that this time we used the default option of Create Structure from Entity Definition. This means that the Data Hub Framework will create boilerplate code based on our Enity model. The code will pre-populate the fields we need to add.
- Click on the Harmonize Orders flow.
- Click on the Collector tab.
Because each Order can consist of multiple rows which are then turned into multiple documents in MarkLogic, we cannot do a 1:1 mapping like we did for Products. This means we cannot simply return a list of URIs. Instead we need to return a unique list of all of the values from the relation id column.
We will use the jsearch library to run our query.
This code is simply returning all unique values in the id field. The one tricky bit is the
By default jsearch will paginate results. The slice is telling it to return all results from 0 to a really big number.
The final collector.sjs code:
- Make the code change.
- Click on SAVE button.
- Click on the Content tab.
For the Order entity the id is the id from the original relational system. Instead of a 1:1 mapping of source documents, we must find all source documents that match the given id.
After we get all of the matching documents we must then build up an array of the Products while also summing the total price.
Once again we will use the jsearch library to run our query.
Note how we query all Order documents containing the matching id. We use the
map function to extract out the original content (stored in the instance part of the envelope). The
orders variable will contain an array of original json objects.
You can also see how we iterate over the orders to sum up the price and add pointers to the Product entities into the
The Final content plugin looks like:
- Change the code.
- Click SAVE.
Now Click on the Flow Info tab.
Let’s Run the flow. Click the RUN HARMONIZE button to start the flow.
Check out the Harmonized Orders
Similar to what we did after running the other flows you might want to verify that the job finished.
- Click on the Jobs tab.
- Make sure the job finished.
You may also want to explore your Harmonized Data.
- Click on the Browse tab.
- Change Database to FINAL.
- Click the Search button.
- Click on the Order Facet to filter the results.
You should see harmonized documents in the search results.
Click on a result to see the raw data.