Hi,
Just a mini-post concerning an utility class to communicate with DCTM DCTMUtil:
package com.huo.lu.db.extract.dctm; import java.io.IOException; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.log4j.Logger; import com.documentum.com.DfClientX; import com.documentum.com.IDfClientX; import com.documentum.fc.client.DfClient; import com.documentum.fc.client.DfQuery; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfQuery; import com.documentum.fc.client.IDfSession; import com.documentum.fc.client.IDfSessionManager; import com.documentum.fc.client.IDfType; import com.documentum.fc.client.IDfTypedObject; import com.documentum.fc.client.IDfValidator; import com.documentum.fc.client.IDfValueAssistance; import com.documentum.fc.common.DfException; import com.documentum.fc.common.DfLoginInfo; import com.documentum.fc.common.IDfList; import com.documentum.fc.common.IDfLoginInfo; /** * Utility class to communicate with DCTM */ public class DCTMUtil { // logger private static Logger LOG = Logger.getLogger(DCTMUtil.class); public DCTMUtil(){} /** * Connect to Documentum docbase * @param userName : User to connect * @param passWd : password * @return * @throws DfException */ public IDfSessionManager connectToDocumentum(String dfcPrimaryHost, String dfcPrimaryPort, String dfcGlobalRegistryRepository, String dfcGlobalRegistryUsername, String dfcGlobalRegistryPassword, String dfcSessionSecureConnectDefault, String userName, String passWd) throws DfException { IDfClientX cx = new DfClientX(); LOG.info("Get DfClient : " + dfcPrimaryHost+ ":" + dfcPrimaryPort +"..."); IDfClient client = cx.getLocalClient(); LOG.info("Get DfClient : " + dfcPrimaryHost+ ":" + dfcPrimaryPort + " : done"); // dfc.properties LOG.info("Get DfClientConfig : " + dfcPrimaryHost+ ":" + dfcPrimaryPort +"..."); IDfTypedObject cfg = client.getClientConfig(); LOG.info("Get DfClientConfig : " + dfcPrimaryHost+ ":" + dfcPrimaryPort + " : done"); LOG.info("Set DfClientConfig.primary_host=" + dfcPrimaryHost); cfg.setString("primary_host", dfcPrimaryHost); LOG.info("Set DfClientConfig.primary_port=" + dfcPrimaryPort); cfg.setString("primary_port", dfcPrimaryPort); LOG.info("Set DfClientConfig.dfc.globalregistry.repository=" + dfcGlobalRegistryRepository); cfg.setString("dfc.globalregistry.repository", dfcGlobalRegistryRepository); LOG.info("Set DfClientConfig.dfc.globalregistry.username=" + dfcGlobalRegistryUsername); cfg.setString("dfc.globalregistry.username", dfcGlobalRegistryUsername); LOG.info("Set DfClientConfig.dfc.globalregistry.password=" + dfcGlobalRegistryPassword); cfg.setString("dfc.globalregistry.password", dfcGlobalRegistryPassword); LOG.info("Set DfClientConfig.dfc.session.secure_connect_default=" + dfcSessionSecureConnectDefault); cfg.setString("dfc.session.secure_connect_default", dfcSessionSecureConnectDefault); // documentum session manager LOG.info("Get SessionManager : " + dfcPrimaryHost+ ":" + dfcPrimaryPort +"..."); IDfSessionManager sessionMgr = client.newSessionManager(); LOG.info("Get SessionManager : " + dfcPrimaryHost+ ":" + dfcPrimaryPort + " : done"); //sessionMgr.setLocale("fr"); //sessionMgr.setIdentity(docbaseName, login); // // Setup login details. IDfLoginInfo login = new DfLoginInfo(); login.setUser(userName); login.setPassword(passWd); //login.setDomain(null); // LOG.info("Get SessionManager.setIdentity(ALL_DOCBASES) : " + dfcPrimaryHost+ ":" + dfcPrimaryPort +" / " + userName +"..."); sessionMgr.setIdentity(IDfSessionManager.ALL_DOCBASES, login); return sessionMgr; } /** * Disconnect from documentum docbase */ public void disconnect(IDfSessionManager sessionMgr, IDfSession session) { if (session!=null && sessionMgr!=null) { LOG.info("[disconnect] Closing session ..."); sessionMgr.release(session); LOG.info("[disconnect] Session closed"); LOG.info("[disconnect] SessionMgr clearing identities ..."); sessionMgr.clearIdentities(); LOG.info("[disconnect] SessionMgr clear identities done"); } } /** * Execute une requête DQL et retourne son résultat. * * @throws DfException * @throws IOException */ public IDfTypedObject runDQLQuery(IDfSession session, String dqlQuery) throws Throwable { LOG.info("Starting runDQLQuery : "+ dqlQuery); IDfTypedObject objectToReturn = null; try { IDfQuery query = new DfQuery(); query.setDQL(dqlQuery); objectToReturn = query.execute(session, IDfQuery.DF_READ_QUERY); } catch (Throwable th) { LOG.fatal("ERROR: " + ExceptionUtils.getFullStackTrace(th)); throw th; } LOG.info("Exiting runDQLQuery : " + dqlQuery); return objectToReturn; } public String getValueMapping(IDfType type, String attrName, String attrValue) throws DfException { String display = attrValue; IDfValidator validator = type.getTypeValidator(null, ""); IDfValueAssistance va = validator.getValueAssistance(attrName, null); if (va != null) { IDfList list = va.getActualValues(); for (int i = 0; i < list.getCount(); i++) { String value = list.getString(i); if (value.equals(display)) { if (LOG.isDebugEnabled()) LOG.info("Value: "+value); display = va.getDisplayValue(value); if (LOG.isDebugEnabled()) LOG.info("Display: "+display); break; } } } return display.replace(" - ", "_"); } /** * Affiche les informations de connection */ public void getSessionInfo(IDfSession session) throws Throwable { try { LOG.info(""); LOG.info("DM Session Properties: "); LOG.info("DM Server Version: " + session.getServerVersion()); LOG.info("DM Session ID: " + session.getSessionId()); LOG.info("DFC Version: " + DfClient.getDFCVersion()); LOG.info(""); } catch (Throwable th) { LOG.error("[getSessionInfo] Unable to retrieve DM server info: " + ExceptionUtils.getFullStackTrace(th)); throw th; } } }
That’s all!!!!
Huseyin OZVEREN