Skip to content

Creating a SBO

Below are the steps to create a SBO . Go through the prerequisite link for creating the workspace.

Below are the steps for creating the SBO.

  1. Create the Implementation and Interface class for SBO
  2. Create the Jar definition for Implementation and Interface
  3. Create SBO module
  4. Install the Documentum project

Create the Implementation and Interface class for SBO

1. SBO Project Structure

As shown below create two source folders one for Implementation class and one for Interface class. It is not mandatory but is just a good practice.

sbo2

2. Source Code

IDCTMGurusSBO.java

package com.dctmgurus.modules.sbo;

import com.documentum.fc.client.IDfService;
import com.documentum.fc.common.DfException;

public interface IDCTMGurusSBO extends IDfService{
	public static final String AMERICAN_EXPRESS = "American Express";
	public static final String VISA = "VISA";
	public static final String MASTERCARD = "MasterCard";
	
	public boolean validateCreditCardNumber (String ccNumber, String ccType);
	
	public void setCCNumberToSubject(String documentId, 
		String ccNumber, String repositoryName) throws DfException;
	
}

DCTMGurusSBO.java

package com.dctmgurus.modules.sbo;

import com.documentum.fc.client.DfService;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSysObject;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;

public class DCTMGurusSBO extends DfService implements IDCTMGurusSBO{

	public static final String versionString = "1.0";
	
	public String getVersion(){
		return versionString;
	}

	@Override
	public void setCCNumberToSubject(String documentId, String ccNumber,
			String repositoryName) throws DfException {
		
		try {
			IDfSession session = getSession(repositoryName);
			IDfSysObject sysObject = (IDfSysObject) session.getObject(new DfId(documentId));
			sysObject.setSubject(ccNumber);
			sysObject.save();
			
		} catch(DfException exp) {
			exp.printStackTrace();
			throw exp;
		}
		
	}

	@Override
	public boolean validateCreditCardNumber(String ccNumber, String ccType) {
		
		//Simple method for validating a Credit card Number
		//Logic taken from
		//www.freeformatter.com/credit-card-number-generator-validator.html
		
		if(ccNumber == null || ccType == null) {
			return false;
		}
		if(IDCTMGurusSBO.AMERICAN_EXPRESS.equals(ccType)) {
			if((ccNumber.startsWith("34") || ccNumber.startsWith("37")) 
					&& ccNumber.length()==15) {
				return true;
			} else {
				return false;
			}
		}
		
		if(IDCTMGurusSBO.MASTERCARD.equals(ccType)) {
			if((ccNumber.startsWith("51") 
					|| ccNumber.startsWith("52")
					|| ccNumber.startsWith("53")
					|| ccNumber.startsWith("54")
					|| ccNumber.startsWith("55"))
					&& (ccNumber.length() >= 16
							&& ccNumber.length() <= 19)) {
				return true;
			} else {
				return false;
			}
		}
		
		if(IDCTMGurusSBO.VISA.equals(ccType)) {
			if(ccNumber.startsWith("4") 
					&& (ccNumber.length() <= 13
							&& ccNumber.length() >= 16)) {
				return true;
			} else {
				return false;
			}
		}
		
		return false;
	}

}

3. Create Jar Files

Export the implementation class as dctmgurus_sbo_impl.jar
Export the interface class as dctmgurus_sbo_int.jar

Create the Jar definition for Implementation and Interface

1. Right Click the project -> New -> Jar Definition

sbo3

2. Give name for the “Jar Definition”, this will be used as “Jar definition” for Implementation jar

sbo4

3. Click Browse and select the Jar

sbo5

4. Now the Jar is selected and the “Type” should be selected as “Implementation” as shown below

sbo6

5. Similarly do it for the Interface jar

sbo7

Create SBO module

1. Right Click the project -> New -> Module

sbo8

2. Give name for the module.

sbo9
3. Change/Set the values of “Type” , “Implementation Jars” , “Interface Jars” and “Class Name” as below

sbo10
4. Install the Documentum Project

sbo11

Give the credenials and click “Login” and “Finish”

newtype1
6. You can verify whether the TBO is created or not by checking the “/System/Modules/SBO” folder as shown below

sbo12

Create SBO Client

Lets create a client to check whether the SBO is working or not

1. Client Project Structure

sbo1

2. Source Code

DCTMGurusClient.java

package com.dctmgurus.modules.client.tbo;

import com.dctmgurus.modules.tbo.IDCTMGurusDoc;
import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.IDfSysObject;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfLoginInfo;

public class DCTMGurusClient {
	
	private IDfSessionManager sessionMrg = null;
	
	public void execute(){
		IDfSession session = null;
		try {
			//Initializing the Session Manager
			init();
			
			//Getting the Session
			session = getSession();
			
			//Getting IDfSysObject object for the document
			IDfSysObject sysObj = (IDfSysObject) session.getObject(new DfId("09XXXXXXXXXXXXXX"));
			
			//Setting value for the dg_demo_attr attribute
			sysObj.setString("dg_demo_attr", "DEMO");
			
			//Saving the Object 
			//This method will in turn invoke DCTMGurusDoc.doSave() method
			//By checking the logs you can confirm it
			sysObj.save();
			
			
			//This is another way of getting the Object
			IDCTMGurusDoc dctmgurusDoc = (IDCTMGurusDoc)session.getObject(new DfId("09XXXXXXXXXXXXXX"));
			
			//Using our custom method to set the dg_demo_attr attribute
			dctmgurusDoc.setDemoAttr("DEMO");
			
			//Saving the Object
			//This method will in turn invoke DCTMGurusDoc.doSave() method
			//By checking the logs you can confirm it
			dctmgurusDoc.save();
			
		} catch (DfException e) {
			//Printing the Stacktrace
			e.printStackTrace();
		} finally {
			//Releasing the session
			releaseSession(session);
		}
	}


	//Generic Method for Initializing the session manager
	public void init() throws DfException{
		IDfLoginInfo loginInfo = new DfLoginInfo();
		try {
			sessionMrg = DfClient.getLocalClient().newSessionManager();
			//TODO Change the User Name according to your docbase
			loginInfo.setUser("dctmgurus");
			//TODO Change the Password according to your requirement
			loginInfo.setPassword("dctmgurus");
			//TODO Change the docbase name
			sessionMrg.setIdentity("dctm", loginInfo);
		} catch (DfException e) {
			e.printStackTrace();
			throw e;
		}
	}
	
	//This method will return the Documentum Session
	public IDfSession getSession(String repoName) throws DfException{
		return sessionMrg.getSession(repoName);
	}
	
	//This method will release the session
	public void releaseSession(IDfSession session) {
		
		if(session != null)
		{
			session.getSessionManager().release(session);
		}
	}
	
	//This method will return the Documentum Session for the dctm repository
	public IDfSession getSession() throws DfException{
		return getSession("dctm");
	}
	

	public static void main(String[] args) {
		new DCTMGurusClient().execute();
	}

}

3. Result

The added sysouts appear in the below order

Logging from DCTMGurusDoc TBO
Setting the value of the dg_demo_attr attribute
Logging from DCTMGurusDoc TBO
Published inMISC