Step 1 - Check Existing Data
You can see the provided application sample. To access its front page:
-
Open the Mashup UI application:
http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/searchcountry_v1
Countries are displayed with their ICO status and yes flags show if they have associated PDF files (UC-1).
-
You can click the see details link of a country. It provides a 360° view of all known data for this country.
Step 2 - Add Trade Info on Countries
This procedure describes how to calculate for each country: the quantity of
imported coffee for the last year, and the average quantity of imported coffee through time.
-
Add an aggregation processor:
- Select Groovy as format
- For Name, enter Countries_UC_3_1
- Click Accept
-
Replace the default code by the following one:
// Process nodes having the “country” type
process("country") {
// Add the import volume value of the last year
// Goal: Be able to sort countries based on import trade activity
year = 0;
volume = 0;
nbTrade = 0;
// Big Integer
def avgVolume = 0G;
// Get import trade only, using the path label, i.e., "import"
for (path in match(it, "import[trade]")) {
// If a valid path is found, retrieve its last element
last = path.last();
log.info "trade found: " + last.getUri();
// Get trade volume for the last year
if (last.metas.getValue("year")?.toInteger() > year ) {
year = last.metas.getValue("year")?.toInteger();
}
// Add volume to calculate the total import trade volume
volume = last.metas.getValue("volume")?.toInteger();
avgVolume += volume;
nbTrade++;
}
// Add metas to countries having import trade
if (nbTrade!=0) {
it.metas.import_lastvolume = volume;
it.metas.import_lastyear = year;
avgVolume = Math.ceil(avgVolume / nbTrade).intValue();
it.metas.import_averagevolume = avgVolume;
}
}
-
Save and apply the configuration.
Step 3 - Scan the Source Connector and Check What Is Indexed
-
Go to the Home page.
-
Click Force aggregation, and enter
country as
type.
-
Open the following Mashup UI application search page:
http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/searchcountry_v2
-
Check that countries now have the following metas: Last import year,
Last import volume, Average import volume.
-
You can now use the average import volume as search criteria. For example, sort by Avg import volume.
Step 4 - Add New Categories on Countries
Define the Connector for the Prices Source
-
In the Administration Console, go to Index > Connectors and click Add connector.
-
In Name, enter prices.
-
For Type, select the JDBC connector.
-
For Push to PAPI server, select the
Consolidation server cbx0 instance.
-
Click Accept.
-
For Store documents in data model class, choose the price class.
-
In Connection parameters:
-
For Driver, enter org.sqlite.JDBC
-
For Connection string, enter jdbc:sqlite://<INPUTDIR>/coffee.db
-
Click Test connection. The database connector automatically connects to the database.
-
In Query parameters:
-
For Synchronization mode, select Full synchronization
-
For Initial query, enter select country_id, coffee_type, year, price from price
-
Click Retrieve fields.
-
Define the
coffee_type , country_id , and
year fields as primary keys.
-
Click the
coffee_type field to expand it.
-
Select Use as primary key.
-
Repeat the operation for the
country_id and
year fields.
-
Click Apply.
Configure the Transformation Processor
-
Go to Index > Consolidation
-
Add a new transformation processor:
-
Select Groovy as format
-
For Name, enter
Prices
-
Click Accept
-
For Source connector, select
prices
-
Replace the default code by the following one:
// Process all nodes
process("") {
// Link prices records to nodes having the “country” type
it.addArcTo("producedBy", "country_id=" + it.metas.getValue("country_id") + "&");
}
Configure the Aggregation Processor
-
Add an aggregation processor:
-
Select Groovy as format
-
For Name, enter Countries_UC_3_2
-
Click Accept
-
Replace the default code by the following one:
// Process nodes having the “country” type
process("country") {
// Add all trade types on countries
if (match(it, "import[trade]")) {
it.metas.tradetype.add("import")
}
if (match(it, "export[trade]")) {
it.metas.tradetype.add("export");
}
if (match(it, "reExport[trade]")) {
it.metas.tradetype.add("reExport")
}
// Add all coffee types to producing countries
it.metas.coffeetype +=
// Get all paths to price nodes
match(it, "-producedBy[price]") *.last()
// fetch the last node of each path
// retrieve the coffee_type meta values for all price nodes
.collect{n-> n.metas.getValue("coffee_type") }
.unique() // dedup collected meta values
// or if multi valued: .collect{n-> n.metas.coffee_type}.flatten().unique()
}
-
Save and apply the configuration.
Step 5 - Rescan Source Connectors and Check What Is Indexed
-
Go to the Home page and under the connectors list, click
Scan for the country JDBC connector and
the
prices JDBC connector.
-
Open the Mashup UI application search page:
http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/searchcountry_v3
-
Check that countries now have the following facets:
Country Trade type and Country Coffee types (the metas created previously in the aggregation processor are mapped to these facets).
|