Subscribe

Follow Us

Informatica PowerCenter Directory Listing Using a Java Transformation

Sometimes as developers we find ourselves locked out of the Informatica PowerCenter environment preventing us from verifying if a particular folder, target, source or parameter file exists in the PowerMart directory. Using a Java Transformation provides a potential solution to this problem. The following will explain how to build a Java Transformation that takes as input the PowerMart root directory or any directory the Informatica PowerCenter account has access to and return information about all the files within the directory and its sub-directories as rows.

Java Transformation

First, create a Java Transformation with the Input and Output ports illustrated on (A.1). When asked the transformation type make sure Active is selected.

An active Java Transformation will allow for multiple output rows to be generated from a single input row which is the behavior need to generate all directory file entries from the root directory.

Java Libraries

Now let’s begin coding, we need to import the necessary Java libraries that will facilitate the file and directory structure object information as well as a few other libraries. In the Java Transformation select the Java Code tab then the Import Packages sub-tab and add the following:

// Call the traverst function and pass it the rootDir variable to collect all direcory file entries

traverse( rootDir );

// For Every fileObject in the FilePathCollection (loop through all fileObjects)

for ( String fileObject : FilePathCollection ) {

// Get the File Directory and assign it to FILE_DIR

FILE_DIR = getFileDirectory( fileObject );

// Get the File Name and assign it to FILE_NAME

FILE_NAME = getFileName( fileObject );

// Get the File Extension and assign it to FILE_EXT

FILE_EXT = getFileExtension( fileObject );

// Get the File Size and assign it to FILE_SIZE_KB

FILE_SIZE_KB = getFileSize( fileObject );

// Generate and output the data row collected for the current fileObject

generateRow();

}

}

Now the Java Expression has everything it needs to generate all the file directory entries from the PowerMart directory or any directory the Informatica PowerCenter account has access to.

NOTE: In case the path to the PowerMart root directory is unknown a parameter at the mapping level can be created and assigned an initial value of the root directory variable used by Informatica PowerCenter, an Expression can be then used to pass the variable to the input port of the Java Transformation as follows:

In the mapping where the Java Transformation is to be used, select Parameters and Variables… from the Mappings menu bar.

Add a new variable and name it something like $$ROOT_DIR, set it as a type of Parameter, as data type of string and with a precision long enough to hold a directory name, 256 for example. Set the Initial value: as $PMTempDir.

Create an Expression with an output port that uses the variable $$ROOT_DIR and pass it to the Java Expression.