Adding content to the content management system

You can add content to the content management system by using the external content reference attribute Add Content screen. In order to select a particular content to be associated with an IBM® Product Master item or category you need to add content to the content management system.

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.

If you want to perform a case insensitive search, configure the system before you add content to it. When you configure your system, for example, adding the custom properties, anything you add to the content management system after you have configured your properties, those added items are the only things that you can search on.

Procedure

Add content to the content management system. Use either of the following methods: user interface or Java™ API.
Option Description
User interface
  1. Open an item or category in the Single Edit screen using one of the following ways:
    1. Click an item or category in the pane navigation.
    2. Open an item to edit from the Item View screen.
    3. Select a step from the collaboration area.
  2. Click + next to an external content reference attribute on the Single Edit screen.
    Note: When you edit an item in a catalog, you can click +, ensure that you enter a number that represents a time, for example, 1111111111 for date attribute.
  3. Find the content file from the local file system.
  4. Select a content management system that you want to add the content to.
  5. Ensure that the values for the metadata attributes display on the content management system screen.
  6. Click Upload to add the content and the metadata to the content management system repository under the folder that is configured for this repository.
Java API
The following sample Java API code populates the metadata attributes and adds a content to repository by using the CMSManager and CMSInstance Java interfaces.
Note: The following two statements should not be called repeatedly in a Java API.
CMSManager CMSMgr = ctx.getCMSManager();
    CMSInstance CMSInst = CMSMgr.getCMSInstance();
Otherwise, this might 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";



    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);
    String cmsURN = CMSInst.addContent(repositoryName, fileToBeAdded, displayFileName, metaDataAttribsValuesHM);
    String addedContentReference = cmsURN.getURN();
    System.out.println(" The content reference of the added file is : \n" + addedContentReference);
    
}
catch (PIMAuthorizationException ae)
{
    // Expected a failure
    System.out.println("Authorization Failure");
    return;
}
catch(IllegalArgumentException iae)
{
    System.out.println(" Passed argument is null or empty ");
    return;
}
    
catch(PIMInternalException ie)
{
    System.out.println(" Internal Error ");
    return;
}
To provide metadata information programmatically through Java API, set the item-attribute values on the Add Content screen.
Note: If the selected content management system is set as your default system during configuration, the metadata attributes are already set when the Add Content screen displays. For more information, see content_management_system_properties.xml File.

The following sample Java API code checks to see whether a specified URN is a valid one syntactically and also checks the URN's existence by using the CMSContentURN Java interface.

Context ctx = null;
try
{

    ctx = PIMContextFactory.getContext("Admin", "xxx", "MyCompany");
    CMSManager CMSMgr = ctx.getCMSManager();
    CMSInstance CMSInst = CMSMgr.getCMSInstance();
// login to all the repositories through single sign on
CMSInst.logon();        

System.out.println("\n\n ------------ Displaying cases for validation of URN ------------ ");
    // sample for APIs on validation of URN
String URN1 = "vbr:/firstItemType.A1001001A09B24B35145B46524.A09B24B35145B46524.1022/1/CONTENT"; // invalid URN
String URN2 = "vbr:/DB2PAL/firstItemType.A4B35145B46524.A09B24B35145B46524.1022/1/CONTENT"; // valid but non-existing URN
String URN3 = "vbr:/DB2PAL/firstItemType.A1001001A09B24B35145B46524.A09B24B35145B46524.1022/1/CONTENT"; // valid and existing URN

CMSContentURN urnObj1 = CMSInst.getCMSContentURN(URN1);
System.out.println(" The URN1 " + URN1 + " is valid? : " + urnObj1.isValid());

CMSContentURN urnObj2 = CMSInst.getCMSContentURN(URN2);
System.out.println(" The URN2 " + URN2 + " is valid? : " + urnObj2.isValid());
System.out.println(" The URN2 " + URN2 + " is existing? : " + urnObj2.isExisting());

CMSContentURN urnObj1 = CMSInst.getCMSContentURN(URN1);
System.out.println(" The URN1 " + URN1 + " is valid? : " + urnObj1.isValid());

CMSContentURN urnObj2 = CMSInst.getCMSContentURN(URN2);
System.out.println(" The URN2 " + URN2 + " is valid? : " + urnObj2.isValid());
System.out.println(" The URN2 " + URN2 + " is existing? : " + urnObj2.isExisting());

CMSContentURN urnObj3 = CMSInst.getCMSContentURN(URN3);
System.out.println(" The URN3 " + URN3 + " is valid? : " + urnObj3.isValid());
System.out.println(" The URN3 " + URN3 + " is existing? : " + urnObj3.isExisting());

}
catch (Throwable e)
{
throw new PIMInternalException(e.getLocalizedMessage(), e);
}

The following sample Java API code retrieves an already uploaded document from its URL through Java API. Assume that URN is the string URL for the content management system object that is stored within the content management system.

CMSContentURN URNobj = CMSInst.getCMSContentURN(“urn”);
   /*content object holds the reference of that object in CMS */
  
   InputStream content = CMSInst.getURNContentAsStream(URNobj);
   /* one can use this stream to redirect the contents to a file */

What to do next

Now you can associate a content management system document to an item.