CreateImpExFolderStructure.ds

Note: This code is provided as a sample. It isn't a supported part of the SiteGenesis application.
/**
 * Create the ImpEx folder structure.
 *
 * @input TaskDirectoryName 		: String		Task directory name
 * @input SiteID  			: String		Site ID
 * @input sampleLogger  		: Object		Sample logger
 * @input Scope				: String		Scope [import/export]
 * @output DirectoryIncoming 		: dw.io.File	Incoming folder for the file (import tasks)
 * @output DirectoryOutgoing 		: dw.io.File	Outgoing folder for the file (export tasks)
 * @output DirectoryProcessing 	: dw.io.File	Processing folder for the file
 * @output DirectoryArchive 		: dw.io.File	Archive folder for the file
 * @output DirectoryError 		: dw.io.File	Directory folder for the file
 * @output sampleLogger 		: Object		Debug output for Sample logger
 * @output sampleError 			: Object		Error output for Sample logger
 * @output DirectoryOutgoingPath 	: String
 * @output DirectoryIncomingPath 	: String
 * @output DirectoryProcessingPath 	: String
 * @output DirectoryArchivePath 	: String
 * @output DirectoryErrorPath 	: String
 */
importPackage(dw.system);
importPackage(dw.io);
importPackage(dw.util);



// Sample Logging ImportScript
importScript("bc_sample:library/common/libContext.ds");
importScript("bc_sample:library/utility/exception/libsampleException.ds");
importScript("bc_sample:library/utility/logging/libLog.ds");



function execute(pdict: PipelineDictionary): Number {



    // Sample Logging var
    var _context: String = new Context("CreateImpExFolderStructure.ds");
    var _logger: Log = Log.getLogger(pdict);

    // check for mandatory pipelet input parameters
    if (empty(pdict.TaskDirectoryName) || empty(pdict.SiteID)) {

        _logger.error(_context, "Mandatory pipelet input parameters are missing or null.");
        return PIPELET_ERROR;
    }

    // get impex scope
    var scope: String = pdict.Scope;

    // get site id
    var siteId: String = pdict.SiteID;

    // site specific impex base path
    var impexBasePath: String = File.IMPEX + File.SEPARATOR + 'src' + File.SEPARATOR + 'datafeeds' + File.SEPARATOR + siteId + File.SEPARATOR;

    var directoryIncomingPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'incoming';
    var directoryOutgoingPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'outgoing';
    var directoryProcessingPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'processing';
    var directoryArchivePath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'archive';
    var directoryErrorPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'error';

    var directoryIncoming: File = new File(directoryIncomingPath);
    var directoryOutgoing: File = new File(directoryOutgoingPath);
    var directoryProcessing: File = new File(directoryProcessingPath);
    var directoryArchive: File = new File(directoryArchivePath);
    var directoryError: File = new File(directoryErrorPath);

    try {

        switch (scope) {

        case Scope.IMPORT:
            directoryIncoming.mkdirs();
            break;
        case Scope.EXPORT:
            directoryOutgoing.mkdirs();
            break;
        default:
            directoryIncoming.mkdirs();
            directoryOutgoing.mkdirs();
            break;
        }
        directoryProcessing.mkdirs();
        directoryArchive.mkdirs();
        directoryError.mkdirs();

        switch (scope) {

        case Scope.IMPORT:
            pdict.DirectoryIncoming = directoryIncoming;
            break;
        case Scope.EXPORT:
            pdict.DirectoryOutgoing = directoryOutgoing;
            break;
        default:
            pdict.DirectoryIncoming = directoryIncoming;
            pdict.DirectoryOutgoing = directoryOutgoing;
            break;
        }
        pdict.DirectoryProcessing = directoryProcessing;
        pdict.DirectoryArchive = directoryArchive;
        pdict.DirectoryError = directoryError;

        switch (scope) {

        case Scope.IMPORT:
            pdict.DirectoryIncomingPath = directoryIncomingPath;
            break;
        case Scope.EXPORT:
            pdict.DirectoryOutgoingPath = directoryOutgoingPath;
            break;
        default:
            pdict.DirectoryIncomingPath = directoryIncomingPath;
            pdict.DirectoryOutgoingPath = directoryOutgoingPath;
            break;
        }
        pdict.DirectoryProcessingPath = directoryProcessingPath;
        pdict.DirectoryArchivePath = directoryArchivePath;
        pdict.DirectoryErrorPath = directoryErrorPath;
    } catch (e) {

        var exception: sampleException = new sampleException(_context, "Error occurred calling create ImpEx folder", e);
        _logger.error(_context, "Error occurred calling  create ImpEx folder: " + exception);
        pdict.sampleError = exception;

        return PIPELET_ERROR;
    }

    return PIPELET_NEXT;
}



// Constant for IMPEX scope
var Scope = {



    IMPORT: 'import',
    EXPORT: 'export'
};