Home > DOCUMENTUM > BOF in Documentum: TBO & SBO implementation

BOF in Documentum: TBO & SBO implementation

May 6, 2010

TBO/SBO implementation will have two java components associated with them, one will be the interface exposing methods (if necessary) to other TBO/SBO created in the application. The other component will be the implementation of the interface.

In this section, we will implement TBO for a custom object type com_test_document. The java class used for the custom object type will let you apply custom lifecycle ‘test_lifecycle’ already defined in DocBase to the document at the time of creation of document. The TBO class implemented for this custom object type will get instantiated when creating a document of the custom object type using WebTop.

To create custom object type, one can use Documentum DA. The custom object type ‘com_test_document’ will extend ‘dm_document’ (default object type) provided in the Documentum.

Following is the code snippet for the TBO interface and implementation class.

package com.test;
import com.documentum.fc.client.*;
import com.documentum.fc.common.DfException;
public interface ICacirTBO extends IDfBusinessObject {
// no methods to be exposed in this example
}

The first four methods in the next code snippet are mandatory, as these are abstract
methods in the class hierarchy.

package com.test;
import com.documentum.fc.client.*;
import com.documentum.fc.common.*;
import com.documentum.com.*;
import java.util.HashMap ;
import java.util.ArrayList ;
public class DocTestTBO extends DfSysObject implements IDocTestTBO {
public static final String strCOPYRIGHT = “Copyright (c) Documentum, Inc., 2002”;
public static final String strVERSION = “1.0”;
IDfClient client = null;
public String getVersion() {
return strVERSION;
}
public String getVendorString() {
return strCOPYRIGHT;
}
public boolean isCompatible( String s ) {
return s.equals(“1.0”);
}
public boolean supportsFeature( String s ) {
String strFeatures = “dm_document, subclassing”;
if( strFeatures.indexOf( s )== -1 )
return false;
return true;
}

/**
* Can be overridden for business logic implementation
*/

public void save() throws DfException {
super.save();
}

/**
* Can be overridden for business logic implementation
*/

public void saveLock() throws DfException{
super.saveLock() ;
}

/**
* Lifecycle applied to the document is hardcoded in this method.
* Best Practice would be to pick the lifecyle name from properties file, based on
* document type.
*/

public IDfId checkinEx( boolean fRetainLock, String
strVersionLabels, String strOldCompoundArchValue,
String strOldSpecialAppValue, String strNewCompoundArchValue,
String strNewSpecialAppValue ) throws DfException {
IDfId documentId = getObjectId() ;

// APPLYING LIFE CYCLE TO THE DOCUMENT

applyLifeCycle(documentId, “test_lifecycle”);
IDfId docId = super.checkinEx( fRetainLock, strVersionLabels,
strOldCompoundArchValue,strOldSpecialAppValue,
strNewCompoundArchValue, strNewSpecialAppValue );
return docId ;
}

/**
* The method applies lifecycle to the document, before it is
* checked in.
* The method attaches the lifecycle to the document.
* @param IDfId objectId of the document
* @param String lifecycleName, can be from properties file
* @throws DfException
*/

private void applyLifeCycle(IDfId docId, String lifecycleName)
throws DfException {
if ((lifecycleName == null) || (lifecycleName.length() == 0)){
throw new IllegalArgumentException(“No lifecycle name specified.”);
}

IDfSession session = getSession();
StringBuffer bufQual = new StringBuffer();
bufQual.append(“dm_policy where object_name='”).append(
lifecycleName).append(“‘”);

IDfId policyId =
session.getIdByQualification(bufQual.toString());
if ((policyId == null) || (policyId.isNull()))
{
String msg = “Unable to locate the lifecycle to be
applied”;
}
IDfSysObject policyObj = (IDfSysObject)
session.getObject(policyId);
String firstStateName =
policyObj.getRepeatingString(“state_name”, 0);

//apply lifecycle to the new version.

IDfSysObject sysObj = (IDfSysObject) session.getObject(docId);
sysObj.attachPolicy(policyId, firstStateName, “”);
}
}

The compiled classes should be in class path of Application server. Once the TBO classes are
written, make sure you put the entries for the object type in dbor.properties file, as mentioned above in section 2.

com_test_document=type,com.test.DocTestTBO,1.0

* 1.0 mentioned in the code snippet matches with the version mentioned in dbor.properties.

Following is the code snippet for the SBO interface and implementation class . The SBO code snippet below is for creating folder and linking the ‘document id’ passed as input parameter in the new sub folder thus created.

package com.test;
import com.documentum.fc.client.*;
import com.documentum.fc.common.*;
import java.util.* ;
public interface ICreateFolderSBO extends IDfService {

/**
* The method is exposed, can be used in other business objects.
*/

public IDfId createFolder(String objectId, String docBase) throws DfException ;
}

package com.test;
import com.documentum.fc.client.*;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.*;
import com.documentum.com.*;
import java.util.*;
public class CreateFolderSBO extends DfService implements ICreateFolderSBO {

/**
* A string providing information regarding the vendor of the BO.
*/

private String m_strVendorDescription = “Documentum Developer Program”;

/**
* Version of the service-base BO
*/

private String m_strVersion = “1.0”;
public String getVendorString() {
return “Copyright (c) Documentum, Inc., 2002”;
}
public static final String strVersion = “1.0”;
public String getVersion() {
return strVersion;
}
public boolean isCompatible(String str) {
int i =strVersion.compareTo(getVersion() );
if(i <= 0 )
return true;
else
return false;
}

/**
* The method gets called from the TBO's, for creating folder structures.
* The method unlinks the document object passed as input parameter from the current
* folder.
* The method creates subfolder under the current folder and links the document to the
* new folder.
* @ param String objectId
* @ param String DocBase Name
* @ throws DfException
*/

public void createFolder(String objectId , String docBase) throws DfException{
IDfSession session = getSession(docBase);

// dm_folder is existing object type in docbase

IDfSysObject docObject = (IDfSysObject)
session.getObject(objectId);

// Get the immediate parent folder to the document

String strSourceFolder = docObject.getFolder(0);
IDfFolder newSubFolder1 = (IDfFolder)
session.newObject(“dm_folder”);
newSubFolder1.setObjectName(“test_folder”);
newSubFolder1.link(strSourceFolder);
newSubFolder1.save() ;

// remove link from parent folder

docObject.unlink(strSourceFolder);
String strDestFolder = newSubFolder1.getObjectId().getId());

// Add link to subfolder

docObject.link(strDestFolder);
docObject.save() ;
}
}

The compiled classes should be in class path of Application server. Once the SBO classes are
written, make sure you put the entries for the object type in dbor.properties file, as mentioned above in section 2.

com.test.ICreateFolderSBO=service,com.test.CreateFolderSBO,1.0

* 1.0 mentioned in the code snippet matches with the version mentioned in dbor.properties.

Once SBO and TBO classes are properly configured, restart the Application Server. To check whether TBO is getting invoked on creation of new document (of type com_test_document) using WebTop, look at the Weblogic console for instantiation of the TBO class, alternatively check whether lifecycle is attached to the new document object created using WebTop.

Categories: DOCUMENTUM Tags: , , , , ,
%d bloggers like this: