Binary Object Manipulations using MDM APIs in Webdynpro Java
Environment: Webdynpro Java Portal and SAP MDM
Scenario 1: Create
- Create the BinaryBlobRecord instance(blob_instance) from RecordFactory.createEmptyBinaryObjectRecord(BINARY_OBJECTS_TABLE_ID);
- Set all the values that are to be updated in the same instance (blob_instance).**
- blob_instance.setDataGroupId(<value>)
- blob_instance.setBinary(<Binary Object Byte[]>);
- blob_instance.setHasOriginal(<boolean>);
3. Use CreateRecordCommand create = new CreateRecordCommand(<user session context>); to create the Binary Object Record (B1)
CreateRecordCommand (MDM Java API Library)
4. Set the value and Update the Main Table Record (R1) with the Link (B1) Result : We have a record (B1) in the Binary Object table linked to the main table* record (R1).
*Can be table of any type
Scenario 2: Update
To update the BLOB object of that particular Binary Object record (B1).Steps:
- Search the Binary Objects table with for the record to be updated
- Get the link from the main table record (R1)
- The return value is Rec ID of the BLOB (B1).
- Create the BinaryBlobRecord instance(blob_instance) from RecordFactory.createEmptyBinaryObjectRecord(BINARY_OBJECTS_TABLE_ID,B1);
- Set all the values that are to be updated in the same instance (blob_instance).**
- blob_instance.setDataGroupId(<value>)
- blob_instance.setBinary(<Binary Object Byte[]>);
- blob_instance.setHasOriginal(<boolean>);
- Use the ModifyRecordCommand to update the Record.
ModifyRecordCommand (MDM Java API Library)
Result: The Binary Object is updated and hence there is no need to re-link again.
**For the details about the different Parameters of Binary Objects – Working with Binary Large Objects (BLOBs) – SAP NetWeaver Master Data Management (MDM) 7.1 – SAP Library
to set the setDataGroupId(Mandate for all types of BLOBs)
RetrieveGroupTreeCommand tree = new RetrieveGroupTreeCommand(<usersession context>););
tree.setGroupType(GroupTypes.DATA_GROUP_TYPE);
tree.execute();
HierGroupNode node = tree.getGroupTree();
//As per our requirement we just placed all the BLOBs in the first leaf of the node
//you can various options in the HierGroupNode (MDM Java API Library) to traverse and select the relevant leaf.
GroupNodeId gID = node.getAllLeafs()[0].getId();
blob_instance.setDataGroupId(gID);
to set the setDataLocationId (Mandatory only for Binary Objects)
RetrieveGroupTreeCommand location = new RetrieveGroupTreeCommand(<usersession context>);
location.setGroupType(GroupTypes.DATA_LOCATION_TYPE);
location.execute();
HierGroupNode lTree = location.getGroupTree();
//As per our requirement we just placed all the BLOBs in the first leaf of the node
//you can various options in the HierGroupNode (MDM Java API Library) to traverse and select the relevant leaf.
GroupNodeId lID = lTree.getAllLeafs()[0].getId();
blob_instance.setDataLocationId(lID);
Scenario 3: Deletion
Note : we can delete a Binary Object only if it is not linked anywhere.
Delete the orphaned or the unused records from the Binary Objects table.
- Get the Record ID’s from the Binary Object Table
Using the RetrieveLimitedRecordsExCommand objExCommand_allData = new RetrieveLimitedRecordsExCommand(<UserSessionContext>); Command.
2. Use the below code to get usage of the Binary Object Record (B1).
RetrieveBinaryObjectUsageCommand objUsageCommand =new RetrieveBinaryObjectUsageCommand(<UserSessionContext>);
- objUsageCommand.setTableId(BinaryObjects_tableID));
- objUsageCommand.setRecordId(B1);
- objUsageCommand.execute();
RepositoryItemUsageResult objUsageResult = objUsageCommand .getUsageResult();
RepositoryItemUsage[] repoUsage=objUsageResult.getUsages();
Refer the link for the return values : Constant Field Values (MDM Java API Library)
If the length of repoUsage is 0 then the Binary Object Record (B1) has no usage. And therefore can be erased.
3.Use the
DeleteRecordsCommand objDeleteBLOBRecordsCommand = new DeleteRecordsCommand((<UserSessionContext>);
DeleteRecordsCommand (MDM Java API Library)
To delete the Record.
Note : Trying to delete Binary Object records which are linked will result into an Exception .
FYI: For your information you can use the Pagination technique for searching Pagination of MDM search result in Java
just copy paste, what's the point?
do you know how to populate the data group id?
Hi Jun Wu,
It has nit been copy pasted from anywhere.
I have clearly mentioned in the post on how to populate the dataGrupID
You can find the line
in the post.
Also I have included the technique to figure out on how to seperate the orphan records from the dependent ones.
Hope I answer to your query or have I messed out any point?
Thanks for the feedback. Its much appreciated.
Arjun Nair
http://help.sap.com/javadocs/MDM71/com/sap/mdm/blobs/BinaryBlobRecord.html
if you look at the api
setDataLocationId(GroupNodeId nodeId)
Sets the data location node where the blob originally came from (required).
do you know what it is?
do you really use that api in real life?
and I am asking how to get the datagroupid....
to understand and set the parameters and the binary objects https://help.sap.com/saphelp_nwmdm71/helpdata/en/d5/d54b0d4c674c58ab2bab55d11d7ac6/content.htm
The extra information that I have provided here is the deletion of the Orphaned Blobs.
Please reply if you still have missing points, I would be happy to help you with more information.
Thanks
Arjun Nair
I believe you haven't used that api.
I have implemented the API and also that its now working perfectly in the production system.
So I do believe that I have used this API.
As i said earlier, I have put some extra infromation on the deletion of the Orpaned Binary Records.
wow, that sounds great,
then can you show me a few line of code regarding how the data group and data location is calculated? Hopefully you know what I am talking about.
setHasOriginal
hasOriginal
-true
if the blob is store in the repository, otherwisefalse
check what you said in your blog, that kind of code can run in production?
Hi Jun Wu
Thanks for Highlighting my mistake.Apologies for that. 🙂
I have updated the blog correcting them and also included the code for setting the datagroupID and the LocationID.
Please comment.
Thanks
just be a honest man.
Till today I have been honest. And I will be hereafter.
I need not proove anyone about that.
Request you to appreciate others efforts rather than berating and underestimating new comers.
I respect you seniorty and expect a professional interaction.
Thanks
Hi,
please act according to "The SCN Rules of Engagement" http://scn.sap.com/docs/DOC-18590.
Thanks
Michael