Associating a content management system document to an item

When you add or update an item, you can associate a content management system document to an item after you locate the document in the content management system. Unstructured content, for example, product images, specification data sheets, warranty documents, flash and video demonstrations provides relevant and necessary context to products, and hence must be associated with products.

Before you begin

  1. Install and configure IBM® Content Integrator.
  2. Configure the content management system by using the configuration file.
  3. Define a spec.
  4. Add an external content reference type attribute to the spec.

Procedure

Associate a document to an item. Use any one of the following methods: search results, adding content or Java™ API.
Option Description
Search results
  1. Search for the content in the content management system. For more information, see Searching the content management system.
  2. Select the document from the search results table and click Associate Document.
Adding content
  1. Add the content to the content management system. For more information, see Adding content to the content management system.
  2. Click Populate value to associate the reference of the content added to the item.
Java API
The following sample Java API code associates a content reference to an item attribute after you add a content.
Note: The following two statements should not be called repeatedly in a Java API.
CMSManager CMSMgr = ctx.getCMSManager();
    CMSInstance CMSInst = CMSMgr.getCMSInstance();
Otherwise, this can lead to OutOfMemory or an increase in the number of applications that are connecting to the Content Management System from collaborative MDM. The following sample code uses these statements correctly.
Context ctx = null;
try
{

    ctx = PIMContextFactory.getContext("Admin", "xxx", "MyCompany");
    CMSManager CMSMgr = ctx.getCMSManager();
    CMSInstance CMSInst = CMSMgr.getCMSInstance();
    String repositoryName = "DB2CM";
    String fileToBeAdded = Configuration.getValue("tmp_dir") + "/test.xml";
    String displayFileName = "test.xml";

    CatalogManager mgr = m_ctx.getCatalogManager();
    Catalog ctg1 = mgr.getCatalog("Catalog1");
    Item item1 = ctg1.getItemByPrimaryKey("pk1");

    AttributeInstance attrInst = item1.getAttributeInstance(EXTERNAL_CONTENT_REFERENCE_ATTRIBUTE_PATH); 

    HashMap<String, String> metadataAttributesHM = new HashMap<String, String>();
    Map<String, String> metaProps =
              CMSInst. getMetaDataAttributes(repositoryName);
    
    Iterator<String> it = metaProps.keySet().iterator();

    while (it.hasNext())
    {
        // meta data attribute
        property = (String) it.next();

        // meta data attribute value
        value = "val1";

        metadataAttributesHM.put(property, value);
    }

    File file1 = new File(fileToBeAdded);
    //Add the file to CMS
    String cmsURN = CMSInst.addContent(repositoryName, fileToBeAdded, displayFileName, metaDataAttribsValuesHM);

    //Associate this URN to the item's external content reference attribute
    attrInst.setValue(cmsURN);

    item1.save();
    
}