Hello, folks:
I am new to this forum. At a Federal agency in Washington DC, where I work, we are trying to import bulk PDF documents in Documentum through a Java program that I wrote. The Java program is mainly a sample that I downloaded from here.
Documentum 6.7
Windows Server 8
JRE 1.6.0_27
While my program is able to get various info about the target repository, it cannot find the target folder. I am using the same folder as it appears when I log into Documentum WebTop. I would greatly appreciate your help. Here is the working source code:
import java.io.Console;import java.io.IOException;import org.apache.log4j.Logger;import com.documentum.fc.common.DfException;import com.documentum.fc.common.IDfList;import com.documentum.fc.common.IDfLoginInfo;import com.documentum.fc.client.IDfClient;import com.documentum.fc.client.IDfDocument;import com.documentum.fc.client.IDfFolder;import com.documentum.fc.client.IDfSession;import com.documentum.fc.client.IDfSessionManager;import com.documentum.com.DfClientX;import com.documentum.com.IDfClientX;import com.documentum.operations.IDfFile;import com.documentum.operations.IDfImportNode;import com.documentum.operations.IDfImportOperation;import com.documentum.operations.IDfOperationError;public class FileImporter { private static final Logger LOGGER = Logger.getLogger( FileImporter.class ); // Documentum target repository where the files will be imported private static final String REPO_NAME = "myrepo"; private static final String TARGET_FOLDER = "Cabinets/IDA/NAPA"; // Document types in Documentum private static final String DOC_TYPE = "ida_document.type"; private static final String DOC_FORMAT = "pdf"; /** * @param args */ public static void main( String[] args ) throws Exception { // Get the console Console console = System.console( ); if( console == null ) { System.err.println( "No console was detected." ); LOGGER.error( "No console was detected." ); System.exit( 1 ); } try { String username = console.readLine( "Enter Documentum login: " ); String password = new String( console.readPassword( "Enter password: " ) ); String[] filenames = { "C:\\Users\\xuser\\documentum\\ADH00003.pdf", "C:\\Users\\xuser\\documentum\\ADH00002.pdf" }; LOGGER.info( "Starting to connect ..." ); IDfSessionManager sessMgr = createSessionManager( ); addIdentity( sessMgr, username, password, REPO_NAME ); LOGGER.info( "Successfully connected to the server. Starting to import files ..." ); importFiles( sessMgr, REPO_NAME, filenames ); } catch( Exception ex ) { LOGGER.error( ex ); ex.printStackTrace( ); } } /** * Imports file in the repository * */ private static void importFiles( final IDfSessionManager sessMgr, final String repoName, final String[] filenames ) throws Exception { IDfSession sess = null; try { sess = sessMgr.getSession( repoName ); IDfClientX clientX = new DfClientX( ); IDfImportOperation operation = clientX.getImportOperation( ); LOGGER.info( "Got import operation from client." ); // The Import Opertion requires a session operation.setSession( sess ); LOGGER.info( "Got the session to the repo: " + sess.getDocbaseName( ) ); IDfClient client = sess.getClient( ); LOGGER.info( "Broker map ID: " + client.getDocbrokerMap( ).getObjectId( ).getId( ) ); LOGGER.info( "Client info: " + client.getClientConfig( ).getObjectId( ).getId( ) ); LOGGER.info( "Database name: " + sess.getDBMSName().toString() ); LOGGER.info( "Docbase name: " + sess.getDocbaseName( ) ); LOGGER.info( "Login username: " + sess.getLoginUserName( ) ); //if( sess.isRestricted( ) ) { // LOGGER.info( "Session is restricted." ); //} //IDfPersistentObject folderObj = (IDfFolder) sess.getObjectByPath( TARGET_FOLDER ); //if( folderObj != null ) { // LOGGER.info( "Folder type: " + folderObj.getType( ).toString( ) ); //} IDfFolder folder = sess.getFolderByPath( TARGET_FOLDER ); if( folder == null ) { LOGGER.error( "Could not obtain path to the target folder: " + TARGET_FOLDER ); throw new Exception( "Could not obtain path to the target folder: " + TARGET_FOLDER ); } LOGGER.info( "Folder ID: " + folder.getObjectId( ).toString( ) ); //IDfImportOperation operation = new DfImportOperation( ); //importOpr.setSession( sess ); operation.setDestinationFolderId( folder.getObjectId( ) ); // This will import all files to a single destination. // To import each file to a different destination, // set call this method on the import node. // impOper.setDestinationFolderId(destId); for( int i = 0; i < filenames.length; i++ ) { IDfFile localFile = clientX.getFile( filenames[ i ] ); IDfImportNode impNode = (IDfImportNode) operation.add( localFile ); LOGGER.info( "Adding this file for import: " + localFile.getName( ) ); //You can set different destination ids here for each import node //This way files get imported to different destinations. //impNode.setDestinationFolderId( destId ); // Set custom object type. impNode.setDocbaseObjectType( DOC_TYPE ); //set custom object name. impNode.setNewObjectName( localFile.getName( ) + "" + ( (int) (Math.random( ) * 100 ) ) ); //The import operation determines the file format. //It is also possible to explicitly set the format. impNode.setFormat( DOC_FORMAT ); } //impOper.setSession( sess ); if( operation.execute( ) ) { LOGGER.info( "Import operation succeeded. Now you can sleep easy." ); IDfList newObjLst = operation.getNewObjects( ); for( int i = 0; i< newObjLst.getCount( ); i++ ) { IDfDocument newObj = (IDfDocument) newObjLst.get( i ); // Get the file name that you set earlier during import, look it up // in local hash table, and then set its attributes //String fileName = newObj.getObjectName( ); //you can set any custom/standard attr values on the document now //newObj.setString("my_attr","someValue"); //newObj.save(); LOGGER.info( "Created object: " + newObj.getObjectId( ) ); } } else { System.out.println( "Import Operation Failed." ); LOGGER.error( "Import Operation Failed." ); IDfList errList = operation.getErrors( ); for( int i = 0; i< errList.getCount( ); i++ ) { IDfOperationError err = (IDfOperationError) errList.get( i ); LOGGER.error( err.getMessage( ) ); } } } finally { if( sess != null ) { sessMgr.release( sess ); LOGGER.info( "Session is closed." ); } } } /** * Creates a new session manager instance. The session manager does not have * any identities associated with it. * * @return a new session manager object. * @throws DfException */ private static IDfSessionManager createSessionManager( ) throws Exception { IDfClientX clientX = new DfClientX( ); IDfClient localClient = clientX.getLocalClient( ); IDfSessionManager sessMgr = localClient.newSessionManager( ); LOGGER.info( "Created session manager." ); return sessMgr; } /** * Adds a new identity to the session manager. * */ private static void addIdentity( final IDfSessionManager sm, final String username, final String password, final String repoName ) throws Exception { IDfClientX clientX = new DfClientX( ); IDfLoginInfo li = clientX.getLoginInfo( ); li.setUser( username ); li.setPassword( password ); // check if session manager already has an identity. // if yes, remove it. if( sm.hasIdentity( repoName ) ) { sm.clearIdentity( repoName ); LOGGER.info( "Cleared identity on :" + repoName ); } sm.setIdentity( repoName, li ); LOGGER.info( "Set up identity for the user." ); }}
My program is throwing exception here (in the above code):
if( folder == null ) { LOGGER.error( "Could not obtain path to the target folder: " + TARGET_FOLDER ); throw new Exception( "Could not obtain path to the target folder: " + TARGET_FOLDER ); }
Thanks in advance.
Asif