GetImpExProcessingPath.ds
Review the GetImpExProcessingPath.ds referenced script files when scheduling inventory imports.
Note: This code is provided as a sample. It isn't a supported
part of the SiteGenesis application.
/**
* GetImpExProcessingPath.ds
* Get the import processing path.
*
* @input TaskDirectoryName : String Task directory name
* @input SiteID : String Site ID
* @input FileName : String File name
* @input ImpexRoot : Boolean Root directory is IMPEX [default: false]
* @input FileExtension : String Processing File Extension [.processing]
* @input sampleLogger : Object Sample logger
* @output ImpExProcessing : dw.io.File Import/Export processing file
* @output ImpExProcessingPath : String Import/Export processing file path
* @output sampleLogger : Object Debug output for Sample logger
* @output sampleError : Object Error output for Sample logger
*/
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("GetImpExProcessingPath.ds");
var _logger : Log = Log.getLogger(pdict);
// check for mandatory pipelet input parameters
if(empty(pdict.TaskDirectoryName) || empty(pdict.SiteID) || empty(pdict.FileName)) {
_logger.error(_context, "Mandatory pipelet input parameters are missing or null.");
return PIPELET_ERROR;
}
// get site id
var siteId : String = pdict.SiteID;
// processing file extension
var processingFileExtension : String = pdict.FileExtension;
// impex file path
var impexPath : String = File.IMPEX + File.SEPARATOR + 'src' + File.SEPARATOR;
// IMPEX is root directory
var impexRoot : Boolean = empty(pdict.ImpexRoot) || (pdict.ImpexRoot == false) ? false : true;
_logger.debug(_context,"Impex Root: " + impexRoot + " -- Impex Root Dictionary Value: "+pdict.ImpexRoot);
var rootPath : String = impexRoot ? impexPath + 'datafeeds' : 'datafeeds';
// site specific impex base path
var impexBasePath : String = rootPath + File.SEPARATOR + siteId + File.SEPARATOR;
_logger.debug(_context,"UNA: " + impexBasePath);
// get import processing path
var impexProcessingPath : String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'processing' + File.SEPARATOR + pdict.FileName;
if(!empty(processingFileExtension)) {
impexProcessingPath += processingFileExtension;
}
_logger.debug(_context,"Processing Path: " + impexProcessingPath);
var filePath = impexPath + siteId + File.SEPARATOR + pdict.TaskDirectoryName + File.SEPARATOR + 'processing' + File.SEPARATOR + pdict.FileName;
_logger.debug(_context,"File Path: " + filePath);
try {
pdict.ImpExProcessing = new File(filePath);
pdict.ImpExProcessingPath = impexProcessingPath;
}
catch(e) {
var exception : sampleException = new sampleException(_context, "Error occurred while creating ImpEx processing file", e);
pdict.sampleError = exception;
return PIPELET_ERROR;
}
return PIPELET_NEXT;
}