Step 1 - Set the Country Connector to Incremental Mode
-
In the Administration Console, go to Connectors and click the
country JDBC connector.
-
In Query parameters:
-
For Synchronization mode, select Query-based incremental synchronization
-
For Initial Query, enter:
select country_id, ico_status, name, timestamp from countries
-
For Checkpoint query, enter:
select max(timestamp) from countries
-
For Incremental variable, enter:
TIMESTAMP
-
For Incremental query, enter:
select country_id, ico_status, name, timestamp from countries where timestamp > "$(TIMESTAMP)"
-
Click Apply.
Step 2 - Create Organization from Countries
Configure the Transformation Processor
-
Go to Index > Consolidation
-
Add a new transformation processor:
-
Select Groovy as format
-
For Name, enter
Countries
-
Click Accept
-
For Source connector, select
country
-
Replace the default code by the following one:
// Process all nodes
process("") {
// Link country documents to the correct organization depending on its membership status
if (it.metas.getValue("ico_status").equals("Member"))
{
// create the organization document.
// This is a managed document, meaning that if no more links are pointing to this object,
// it deletes itself automatically
organization = createDocument("organization_ICO", "organization")
organization.metas.org_id="ICO"
organization.metas.name="International Coffee Organization"
organization.directives.datamodel_class = "organization"
// It is required to "yield" created documents explicitly if they should be pushed to
// the aggregation step
yield organization
// create the link to the created document
it.addArcTo("isMemberOf", "organization_ICO");
} else {
// create the organization document.
// This is a managed document, meaning that if no more links are pointing to this object,
// it deletes itself automatically
organization = createDocument("organization_NONE", "organization")
organization.metas.org_id="NONE"
organization.metas.name="not member"
organization.directives.datamodel_class = "organization"
// It is required to "yield" created documents explicitly if they should be pushed to
// the aggregation step
yield organization
// create the link to the created document
it.addArcTo("isMemberOf", "organization_NONE");
}
}
Organization documents are generated from countries. If you delete countries, they
are deleted too, automatically.
Configure the Aggregation Processor
-
Add an aggregation processor:
-
Select Groovy as format
-
For Name, enter Organization_UC_6
-
Click Accept
-
Replace the default code by the following one:
// Process nodes having the “organization” type
process("organization") {
// Log the content of the document passing through this processor
log.info "Organization: " + it
// Add all members of Countries to Organization
it.metas.members +=
// Get all paths of related country nodes
match(it, "-isMemberOf[country]") *.last() // fetch last node
.collect{n-> n.metas.getValue("name") }
it.metas.number +=
// Get all paths to related country nodes
match(it, "-isMemberOf[country]").size();
}
-
Save and apply the configuration.
Step 3 - Rescan the Country Connector and Check What Is Indexed
-
Go to the Home page and under the connectors list, click
Clear documents for the
country JDBC
connector.
-
Once the clear operation is done, click Scan for the
country JDBC connector.
Wait for data to be fully indexed.
-
Check that if you click Scan once again for the
country JDBC connector, nothing more is pushed to the index.
-
Go to the analytics page:
http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/analytics_v1
-
Select the ICO Membership tab. The tab displays the members count and a list of members.
Note:
You can also check existing arcs in the Index > Consolidation > Introspect tab.
The following graphic shows what we achieved on the object graph at step 3. Arcs (of type isMemberOf ) are added to a managed document
(called organization_ICO ) linked to countries that are part of the ICO.
Step 4 - Update the Membership of a Country
Before you begin: For this operation, you need to access the server.
-
Go to the
<INPUTDIR> containing the coffee sample data.
-
Change the membership of a country in the coffee database, for example, Brazil.
-
In your command-line tool, run
sqlite3 ./coffee.db
-
Run the following commands one after the other:
delete from countries where country_id="Brazil";
insert into countries(country_id, name, ico_status) values ("Brazil", "Brazil", "Non Member");
.exit
Note:
The insert statement adds the current timestamp to the record
automatically. The JDBC connector uses it to detect this modification.
Step 5 - Rescan the Country Connector and Check What Is Indexed
-
Go to the Home page and under the connectors list, click
Scan for the
country JDBC connector.
Wait for data to be fully indexed.
-
Open the Mashup UI application:
http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/searchcountry_v3
-
Search for Brazil, and click its see details link.
- In the detail page, the ICO Status is Non Member.
- If you select the Trade volume per Year (Kg) > Table tab, every trade now has
its membership updated to Non Member.
-
Go to the analytics page:
http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/analytics_v1
-
Choose the ICO Membership tab.
Brazil is not present in the list anymore.
|