Multidomain MDM
- Multidomain MDM 10.4 HotFix 3
- Todos los productos
package com.informatica.mdm.sample.cs; import java.util.List; import java.util.Map; import com.informatica.mdm.sdo.co.base.BaseObject; import com.informatica.mdm.sdo.co.base.CompositeObjectBase; import com.informatica.mdm.sdo.co.base.KeysAndOverrides; import com.informatica.mdm.sdo.co.base.MergedRecord; import com.informatica.mdm.sdo.co.base.MergedRecordPager; import com.informatica.mdm.sdo.co.base.Pager; import com.informatica.mdm.sdo.cs.base.BusinessEntityKey; import com.informatica.mdm.sdo.cs.base.Key; import com.informatica.mdm.spi.cs.StepException; import com.informatica.mdm.spi.externalcall.CustomLogic; import commonj.sdo.ChangeSummary; import commonj.sdo.DataObject; import commonj.sdo.Property; import commonj.sdo.helper.HelperContext; import org.eclipse.persistence.sdo.SDOChangeSummary; /** * Call this piece of code before the Person business entity record merge or the previewMerge API call. */ public class MergePerson implements CustomLogic { public static final String KEYS_AND_OVERRIDES = "keysAndOverrides"; public static final String OVERRIDES = "overrides"; public static final String MERGE = "MERGE"; @Override public DataObject process(HelperContext helperContext, DataObject inputSdo, Map<String, Object> inParams, Map<String, Object> outParams) throws StepException { DataObject keysAndOverrides = (DataObject) inParams.get(KEYS_AND_OVERRIDES); if (keysAndOverrides != null) { explainMerge(inParams); DataObject overrides = keysAndOverrides.getDataObject(OVERRIDES); if (overrides != null) { // if "overrides" are provided, then user is not simply merging several records, but // tryes to merge some child records or provides some winner override List<DataObject> list = overrides.getList("Person/TelephoneNumbers/item"); if ((list != null) && !list.isEmpty()) { SDOChangeSummary changeSummary = (SDOChangeSummary) overrides.getChangeSummary(); changeSummary.resumeLogging(); // remove "MERGE" element from all "Telephone" items, this will prevent mering of "Telephone" child records for (DataObject dataObject : list) { if (dataObject.isSet(MERGE)) { dataObject.unset(MERGE); } } // send updated "overrides" back to Hub outParams.put(KEYS_AND_OVERRIDES, keysAndOverrides); } } } return inputSdo; } private void explainMerge(Map<String, Object> inParams) { BusinessEntityKey businessEntityKey = (BusinessEntityKey) inParams.get("businessEntityKey"); System.out.println(String.format("%s:%s", businessEntityKey.getName(), businessEntityKey.getKey().getRowid())); KeysAndOverrides keysAndOverrides = (KeysAndOverrides) inParams.get("keysAndOverrides"); List<Key> keys = keysAndOverrides.getKeys(); for (Key key : keys) { System.out.println(String.format(" | <- %s", key.getRowid())); } CompositeObjectBase overrides = keysAndOverrides.getOverrides(); if(overrides != null) { DataObject co = (DataObject) overrides; ChangeSummary changeSummary = co.getChangeSummary(); DataObject root = co.getDataObject(co.getType().getName()); dumpOne("", co.getType().getName(), root, changeSummary); } } private void dumpOne(String prefix, String name, DataObject dataObject, ChangeSummary changeSummary) { String rowidObject = dataObject.getString("rowidObject"); if(rowidObject != null) { System.out.println(String.format("%s%s:%s", prefix, name, rowidObject)); } List<MergedRecord> mergeItems = dataObject.getList("MERGE/item"); if(mergeItems != null) { for (MergedRecord mergeItem : mergeItems) { System.out.println(String.format("%s | <- %s", prefix, mergeItem.getKey().getRowid())); } } List<Property> properties = dataObject.getInstanceProperties(); for (Property property : properties) { Object o = dataObject.get(property); if((o instanceof Pager) && !(o instanceof MergedRecordPager)) { DataObject pager = (DataObject) o; System.out.println(prefix + property.getName()); List<DataObject> items = pager.getList("item"); for (int i = 0; i < items.size(); i++) { DataObject item = items.get(i); dumpOne(prefix + " " ,"[" + i + "]", item, changeSummary); } } if(o instanceof BaseObject) { dumpOne(prefix + " ", property.getName(), (DataObject) o, changeSummary); } } if(changeSummary.isModified(dataObject)) { List<ChangeSummary.Setting> oldValues = changeSummary.getOldValues(dataObject); for (ChangeSummary.Setting setting : oldValues) { Property property = setting.getProperty(); if(!"MERGE".equals(property.getName())) { Object value = dataObject.get(property); System.out.println(String.format("%s manual override: %s = %s", prefix, property.getName(), value)); } } } } }
POST: http://localhost:8080/cmx/cs/localhost-orcl103-MDM_SAMPLE/Person/{{person1_id}}?action=previewMerge { "keys": [ { "rowid": "{{person2_id}}" } ], "overrides": { "Person": { "Addresses": { "item":[ { "rowidObject": "{{person1_Addresses1_id}}", "MERGE": { "item":[{"key":{"rowid": "{{person2_Addresses1_id}}"}}], "$original": { "item":[null] } } } ] }, "TelephoneNumbers": { "item":[ { "rowidObject": "{{person1_TelephoneNumbers1_id}}", "phoneNum": "777-77-77", "$original": { "phoneNum":null }, "MERGE": { "item":[{"key":{"rowid": "{{person2_TelephoneNumbers1_id}}"}}], "$original": { "item":[null] } } } ] } } } }
2020-03-20 11:59:49,631 INFO [stdout] (default task-55) Person:401924 2020-03-20 11:59:49,631 INFO [stdout] (default task-55) | <- 401925 2020-03-20 11:59:49,632 INFO [stdout] (default task-55) | <- 401926 2020-03-20 11:59:49,632 INFO [stdout] (default task-55) TelephoneNumbers 2020-03-20 11:59:49,632 INFO [stdout] (default task-55) [0]:1724 2020-03-20 11:59:49,632 INFO [stdout] (default task-55) | <- 1725 2020-03-20 11:59:49,633 INFO [stdout] (default task-55) | <- 1726 2020-03-20 11:59:49,633 INFO [stdout] (default task-55) manual override: phoneNum = 777-77-77 2020-03-20 11:59:49,633 INFO [stdout] (default task-55) Addresses 2020-03-20 11:59:49,633 INFO [stdout] (default task-55) [0]:2124 2020-03-20 11:59:49,633 INFO [stdout] (default task-55) | <- 2125 2020-03-20 11:59:49,634 INFO [stdout] (default task-55) | <- 2126