IBM FileNet P8, Version 5.2            

Working with Containment

This section provides information about, and code examples for, creating and working with folders and referential containment relationship objects.

Creating Folder Objects

To create a folder, do one of the following:

Retrieving Folder Objects

You can retrieve a persisted Folder object in the following ways:

You can retrieve a folder collection (directly contained folders) in the following ways:

You can get the folders that are containers or containees in a relationship. These methods return a ReferentialContainmentRelationshipSet collection:

Retrieving Documents or Custom Objects from a Folder

Documents and custom objects are always referentially contained in a folder. You can retrieve (using fetchInstance) or instantiate (using getInstance) documents or custom objects using the following methods:

Filing an Object into a Folder

To file a Containable object into a folder, call the Folder.file method on the object. When the object is filed, a relationship between the object and the containing folder is automatically created for reference: ReferentialContainmentRelationship for Folder and CustomObject instances; DynamicReferentialContainmentRelationship for Document instances. The relationship object is returned by the Folder.file method.

Note: Although it is possible to create a referentially contained folder, in practice, the use case is rare, and applications generally assume a folder is directly contained.

If you are filing a Document (or a subclass of Document), the contained document will be the current document version. In this case, the current document version is (in order of use): the released version (if there is one), else the current version (if there is one), otherwise, the reservation version. You cannot use the Folder.file method to file a specific document version into the folder.

The Folder.file method requires a containment name (which can be null) for the object you are filing, and a DefineSecurityParentage property setting. For more information on how the containment name is set in various scenarios, see the ReferentialContainmentRelationship.ContainmentName property. The defineSecurityParentage parameter determines whether the containing folder is to be the security parent for the filed object. For more information, see the Security Inheritance topic in Security.

The Folder.file method also includes the autoUniqueName parameter, which you can set to force the Content Engine to supply a unique containment name if naming collisions occur in the folder. As noted in Containment Names, setting this parameter to force the Content Engine to resolve duplicate names can result in severe performance degradation.

The following code fragment retrieves a document from a folder and files it into another folder. If this call succeeds, the document's containment name is returned. Note that in the Folder.file method, the autoUniqueName parameter is set to NOT_AUTO_UNIQUE. So if the target folder contains an object with the same containment name as the incoming document, then an exception is thrown with a message about duplicate containment names.

Java Example

String folderPath = "/ExistingLoans/MyLoans";
String newFolderPath = "/NewLoans/MyNewLoans";
String newContainmentName = "Loan1";

Document myDoc = Factory.Document.fetchInstance(os, folderPath + "/MyLoan_1", null);
Folder newFolder = Factory.Folder.fetchInstance(os, newFolderPath, null);

// Files the document into the folder with the autoUniqueName parameter disabled and the 
// defineSecurityParentage parameter set to inherit permissions from the folder. You need to 
// cast the returned ReferentialContainmentRelationship object as a DynamicReferentialContainmentRelationship 
// object to get the correct relationship object for the document filed. 
try {
   DynamicReferentialContainmentRelationship drcr = 
      (DynamicReferentialContainmentRelationship) newFolder.file(
         myDoc, AutoUniqueName.NOT_AUTO_UNIQUE, newContainmentName, DefineSecurityParentage.DEFINE_SECURITY_PARENTAGE);
   drcr.save(RefreshMode.NO_REFRESH);
}
catch (Exception ex) 
{   
   if (ex instanceof EngineRuntimeException) {
  EngineRuntimeException fnEx = (EngineRuntimeException) ex;
      if (fnEx.getExceptionCode().equals(ExceptionCode.E_NOT_UNIQUE) ) {
         System.out.println("Exception: " + ex.getMessage() + "\n" +
            "The name " + "\"" + newContainmentName + "\"" + " is already used.\n" + 
            "Please file the document with a unique name.");
      }
      else
         System.out.println("Exception: " + ex.getMessage());
   }
   else
      // A standard Java exception.
      System.out.println("Exception: " + ex.getMessage());
}
        

C# Example

String folderPath = "/ExistingLoans/MyLoans";
String newFolderPath = "/NewLoans/MyNewLoans";
String newContainmentName = "Loan1";
IDocument myDoc = Factory.Document.FetchInstance(os, folderPath + "/MyLoan_1", null);
IFolder newFolder = Factory.Folder.FetchInstance(os, newFolderPath, null);

// Files the document into the folder with the autoUniqueName parameter enabled and the 
// defineSecurityParentage parameter set to inherit permissions from the folder. You need to 
// cast the returned ReferentialContainmentRelationship object as a DynamicReferentialContainmentRelationship 
// object to get the correct relationship object for the document filed.
try {
   IDynamicReferentialContainmentRelationship drcr = 
     (IDynamicReferentialContainmentRelationship) newFolder.File(
        myDoc, AutoUniqueName.NOT_AUTO_UNIQUE, newContainmentName, DefineSecurityParentage.DEFINE_SECURITY_PARENTAGE);
   drcr.Save(RefreshMode.NO_REFRESH);
}
catch (Exception ex) 
{   
   if (ex is EngineRuntimeException) {
      EngineRuntimeException fnEx = (EngineRuntimeException) ex;
         if (fnEx.GetExceptionCode().Equals(ExceptionCode.E_NOT_UNIQUE) ) {
            System.Console.WriteLine("Exception: " + ex.Message + "\n" +
               "The name " + "\"" + NewContainmentName + "\"" + " is already used.\n" + 
               "Please file the document with a unique name.");
         }
         else
            System.Console.WriteLine("Exception: " + ex.Message);
    }
    else
       // A standard Java exception.
       System.Console.WriteLine("Exception: " + ex.Message);
}
 

Creating ReferentialContainmentRelationship Objects

You create a ReferentialContainmentRelationship object and persist it to a Content Engine object store by calling createInstance on the Factory.ReferentialContainmentRelationship class. The primary use case for creating a ReferentialContainmentRelationship object is to create a referential containment relationship between a folder and a specific version of a document or custom object.

Note: Although it is possible to create a referentially contained folder, in practice, the use case is rare, and applications generally assume a folder is directly contained.

When you create a ReferentialContainmentRelationship object, you must set the object's Head and Tail properties. Set the Head property to the object you want to contain in the folder, and set the Tail property to the containing folder.

The following example creates a ReferentialContainmentRelationship object, and sets a document as the contained object:

Java Example

String parentFolderPath = "/Loans";

// Create a document as the containee for the folder, and check it in.
Document myDoc = Factory.Document.createInstance(os, null);
myDoc.checkin(null, null);
myDoc.save(RefreshMode.REFRESH);

// Retrieve the containment folder.
Folder container = Factory.Folder.getInstance(os, null, parentFolderPath); 

// Retrieve the current version of the document to contain in the folder. The
// relationship is only with this specific document version.
Document docVer = Factory.Document.getInstance(os, null,(myDoc.get_Id())); 

// Create the ReferentialContainmentRelationship instance.
ReferentialContainmentRelationship rcr =     
    Factory.ReferentialContainmentRelationship.createInstance(os, null); 

// Populate the ReferentialContainmentRelationship object with the required Head 
// (containee) and Tail (container) objects, and save it.
rcr.set_Head(docVer); 
rcr.set_Tail(container); 
rcr.save(RefreshMode.NO_REFRESH);

C# Example

String parentFolderPath = "/Loans";

// Create a document as the containee for the folder, and check it in.
IDocument myDoc = Factory.Document.CreateInstance(os, null);
myDoc.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
myDoc.Save(RefreshMode.REFRESH);

// Retrieve the containment folder.
IFolder container = Factory.Folder.GetInstance(os, null, parentFolderPath);

// Retrieve the current version of the document to contain in the folder. The
// relationship is only with this specific document version.
IDocument docVer = Factory.Document.GetInstance(os, null, myDoc.Id);

// Create the ReferentialContainmentRelationship instance.
IReferentialContainmentRelationship rcr = 
    Factory.ReferentialContainmentRelationship.CreateInstance(os, null);

// Populate the ReferentialContainmentRelationship object with the required Head 
// (containee) and Tail (container) objects, and save it.
rcr.Head = (docVer);
rcr.Tail= (container);
rcr.Save(RefreshMode.NO_REFRESH);
        

Creating DynamicReferentialContainmentRelationship Objects

You create a DynamicReferentialContainmentRelationship object and persist it to a Content Engine object store by calling createInstance on the Factory.DynamicReferentialContainmentRelationship class.

You must set the DynamicReferentialContainmentRelationship object's Head property to the current version of the document that you want to contain, and the Tail property to the containing folder.

Java Example

String parentFolderPath = "/Loans";

// Create a document as the containee for the folder.
Document doc = Factory.Document.createInstance(os, null);
doc.save(RefreshMode.NO_REFRESH); 

// Retrieve the containment folder.
Folder container = Factory.Folder.getInstance(os, null, parentFolderPath); 

// Create the DynamicReferentialContainmentRelationship instance.
DynamicReferentialContainmentRelationship drcr = 
    Factory.DynamicReferentialContainmentRelationship.createInstance(os, null); 

// Populate the DynamicReferentialContainmentRelationship object with the required Head  
// (current version of the document) and Tail (container) objects, and save it.
drcr.set_Head(doc); 
drcr.set_Tail(container); 
drcr.save(RefreshMode.NO_REFRESH);

C# Example

String parentFolderPath = "/Loans";

// Create a document as the containee for the folder.
IDocument doc = Factory.Document.CreateInstance(os, null);
doc.Save(RefreshMode.NO_REFRESH);

// Retrieve the containment folder.
IFolder container = Factory.Folder.GetInstance(os, null, parentFolderPath);

// Create the DynamicReferentialContainmentRelationship instance.
IDynamicReferentialContainmentRelationship drcr =  
        Factory.DynamicReferentialContainmentRelationship.CreateInstance(os, null);

// Populate the DynamicReferentialContainmentRelationship object with the required Head  
// (current version of the document) and Tail (container) objects, and save it.
drcr.Head=(doc);
drcr.Tail=(container);
drcr.Save(RefreshMode.NO_REFRESH);

Associating a Specific Document Version with a Folder

You cannot file a specific document version using the Folder.file method. If your application requires a specific version of a document to be associated with a folder, you must create a ReferentialContainmentRelationship object to create that relationship. (DynamicReferentialContainmentRelationship objects apply only to the current version of a document.) See Creating DynamicReferentialContainmentRelationship Objects.

The document can then be retrieved using the Folder.get_Containees method, or by retrieving the ReferentialContainmentRelationship.Tail property for the relationship. See Retrieving Folder Objects.



Feedback

Last updated: October 2013
containment_procedures.htm

© Copyright IBM Corporation 2014.
This information center is powered by Eclipse technology. (http://www.eclipse.org)