GetUnzip.ds

Review the GetUnzip.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.
/**
 * GetUnzip.ds
 * 
 * Unzip a file.
 *
 * @input ZIPFileName    : String  The file name of the .zip file
 * @input SourceDirectory : dw.io.File    The processing directory where the file is located
 * @input sampleLogger  : Object  Sample logger
 * @output UnzipDirectory : dw.io.File    The unzip directory where the extracted import file is located
 * @output ZIPFile  : dw.io.File The .zip file
 * @output sampleLogger  : Object  Sample logger
 * @output sampleError  : Object  Sample error
 */
importPackage(dw.system);
importPackage(dw.io);
importScript("bc_sample:library/impex/libImpExConstants.ds");
// 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 {
 var _context : String = new Context("GetUnzip.ds");
 var _logger : Log = Log.getLogger(pdict);
 
 var sourceDirectory : File = pdict.SourceDirectory;
 var zipFileName : String = pdict.ZIPFileName;
  
 var sourceFile : File = new File(sourceDirectory, zipFileName);
 var targetFile : File = new File(File.TEMP + File.SEPARATOR + 'IMPEX_UNZIP' + File.SEPARATOR + zipFileName);
 var zipFile : File  = new File(sourceDirectory, zipFileName);
 
 var unzipDirectory : File = new File(File.TEMP + File.SEPARATOR + 'IMPEX_UNZIP' + File.SEPARATOR + zipFileName);
 unzipDirectory.mkdirs();
 
 var fileExtension : String = sourceFile.name.substring(sourceFile.name.length-4, sourceFile.name.length);
 
 if (!sourceFile.exists()) {
  _logger.error(_context, "Source file '" + sourceFile.name + "' in path '" + sourceFile.path + "' cannot be found!");
  return PIPELET_ERROR;
 }
 
 // check for file extension .zip
 if ((fileExtension == '.zip') || (fileExtension == '.ZIP')) {
 
  try {
  
   sourceFile.unzip(targetFile);
   pdict.UnzipDirectory = unzipDirectory;
   pdict.ZIPFile = zipFile;
  }
  catch (e) {
  
   var exception : sampleException = new sampleException(_context, "Error occurred calling unzip: ", e);
   _logger.error(_context, "Error occurred calling unzip: " + exception);
   pdict.sampleError = exception; 
  
   return PIPELET_ERROR;
  } 
  
  return PIPELET_NEXT;
 }
 
 _logger.info(_context, "No .zip file :" + zipFile.name); 
 return PIPELET_NEXT;
}
X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.