Ben Knox Posted January 18, 2019 Posted January 18, 2019 This post is aimed at showing how to incorporate attributes marked as type file within the MDM UI Builder. As of the writing of this post MDM Studio 5.1.0.001 (MDM version 9.1) does not have a working out of the box file type widget, therefore it is up to the developer to implement this functionality. Implementation of this functionality comes in three distinct pieces. 1. The UI visualization of the control. 2. The uploading of the file to MDM. 3. The downloading of the file from MDM. Piece 1 -- The UI visualization of the control. This piece is completely up to the developer and/or the UX designer. The only requirement is that there exists a file control (input type = file) that handles the selection of file(s) to upload. For the purposes of my implementation I choose to have a div tag that when clicked triggers the file type input click event and an ag-grid to display any selected files. Piece 2 -- The uploading of the file to MDM MDM leverages a RESTful service to transmit files from the client session. The URL for this service is (the protocol/hostname/domain will vary based on your implementation): https://mdmdev/eml/FileUpload This RESTful service takes the following URL parameters when called destinationDir isAjax hiddenAttributesId Each of these are discussed below destinationDir -- this is the path on the server that will contain the uploaded file. You need to know 4 pieces of information to make this work. 1. The directory name to your rulebase directory. I am using a Linux implementation so this would look like this: /opt/tibco910/mdm/9.1/common/shaw/catalog/master/ 2. The id of the repository you are in. 3. The key of the record you are editing. 4. The id of the file attribute you are uploading for. I have chose to create a REST service that can be called via the UI and return back items 2, 3, and 4. In order to get these ids you will need to execute the below queries against the MDM Database: Repository ID: select distinct ID from CATALOG where name = [your repository name] Record Key: select distinct cproductkeyid from [repository table] p inner join goldencopy g on p.cproductkeyid = g.productkey and p.cmodversion = g.version where cproductid = [id of your record] and cproductidext = [id ext of your record] Attribute ID: select distinct id from CATALOGATTRIBUTE where name = [name of attribute] and catalogid = [repository id] All four of these items combine to form the upload path. Assuming your repository ID is 12345, your product key is 98765 and your attribute ID is 4567 The complete path to the upload directory would be: /opt/tibco910/mdm/9.1/common/shaw/catalog/master/12345/98765/4567/ATTACHMENTS isAjax -- this is always set to Yes hiddenAttributesId -- this is the ID of the attribute you are uploading. In the example above that would be 4567. Knowing all these values the completed URL to upload a file is: https://mdmdev/eml/FileUploaddestinationDir=/opt/tibco910/mdm/9.1/commo... The physical file to upload will come from the file input on the screen, and is passed to the service in a FormData jQuery object. The Javascript code to format this object is: let formDataObj = new FormData(); formDataObj.append("sourcefile", _file); where _file is the FileObject that was selected via the file input. The ajax call to call the upload service and pass the file looks like: jQuery.ajax({ url: uploadURL, type: "POST", contentType:false, processData: false, cache: false, data: formDataObj, success: function(data){ //successful logic here }, error: function(data){ //failed logic here } }); Piece 3 -- The downloading of the file from MDM. MDM leverages a RESTful service to download files from MDM to the client. The URL for this service is (the protocol/hostname/domain will vary based on your implementation): https://mdmdev/eml/Download This RESTful service takes the following URL parameters when called downloaddoc This is discussed below downloaddoc -- This is the master catalog path to download the file from. This path using the same values as the upload path (repository id, record key, and attribute key). Assuming the same values from above and a file name of test.txt this value would look like: master/12345/98765/4567/ATTACHEMNTS/text.txt Give the above complete URL would look like: https://mdmdev/eml/Downloaddownloaddoc=master/12345/98765/4567/ATTACHEM... To start the download you call window.open("https://mdmdev/eml/Downloaddownloaddoc=master/12345/98765/4567/ATTACHEM..."). That sums up how to communicate with MDM with files. The only value that is stored on the MDM record and subsequently in the database is the name of the file. If you have any questions please feel free to respond to this and I will answer. Thanks, Ben
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now