How to use attribute source priorities in custom composite views of IBM MDM -- There is a cache to catch.....
While working on my current project, I came across the requirement where we were asked to design real time services to return customer entities based on the source priorities.
Without going into details, when data in coming from multiple sources in to MDM registry, then we may end up having multiple versions of same attributes for a single customer. For example, legal name of customer is having different values for source A and B. There can be n reasons for this but what happens when we expose the customer entities to other applications who would be interested only single view/versions of data. Again it depends on case by case and also there might be certain business rules in organisation which says that data in Source System A is having higher priority then data in Source System B and so on.
We had similar requirement while exposing real time services to return customer attribute based on source priorities. The design decision was to implement source priorities using custom composite views.
IBM standard edition configuration allows user to define and implement custom composite views where user can define filters on response being returned as part of customer enquiry services (GET and Search). Going by documentation it seems to be very simple and as follows;
- Define Composite view in MDM configuration
- Select the implementation type custom
- Select the attributes to be returned from view (Filter on view)
- Define attribute priorities for each source in view configuration.
And workbench will generate the basic skeleton of dummy code for your view. It will be Java Class extending IMemAttrRowView. A init() method with input as IMetaData, attrCode, view arguments srcrecnos etc.
When we define a composite view the details are saved in 2 tables (mpi_cvwhead and mpi_cvwxseg) in MDM. cvwhead will store view details and cvwxseg contains filter details i.e. attributes defined in view and priorities etc. However in handler code , we could not get any handle to the priorities defined on attributes level. But all this information is there in MDM metadata.
We need CvwXseg data for this view to get the priorities of each attribute and apply business rules in our composite view. After some debugging and analysis of API, I found the catch.
"There is cache to Catch"
MDM exposes a osgi service called "MetadataCache" and with the help of this cache service user can get the required metadata from MDM.
In order to retrieve the attribute priorities in my custom view, I used the this metadata cache to get view metadata.
So in my init() of custom handler, I invoke this service just as normal osgi service.
public void init(method args){
//Get the cache
MetadataCache cache = (MetadataCache) context.lookup("osgi:service/com.iniitiatesystems.hub.metadata.MetadataCache")
//Get view details
CvwHead cvwHead = cache.getCvwHead("viewname");
List<String> segCodes = new List<String>();
segCodes.add("CvwXseg");
//Get the CvwXseg Rows. which will have source priorities
List<DicRow> cvwXsegRows = cache.getDicRows(segCodes);
//Apply rules
}
That's it.
Thanks for reading this. Do let me know your comments.
Paul, Context used above is the instance of InitialContext class of the J2ee JNDI API. if you wish to get mdm context inside view then it could be created using engine manager osgi service or if i recall correctly could be retrieved from view parameters.
Sachin, very useful post. One question, within the custom handler, how are you retrieving the "context" object being used to get the MetadataCache: "context.lookup("osgi:service/com.iniitiatesystems.hub.metadata.MetadataCache")" ?