GetUnzip.ds

Review the GetUnzip.ds referenced script files when scheduling inventory imports.

This code is provided as a sample. It isn’t a supported part of the SiteGenesis application.

Note

1/**
2 * GetUnzip.ds
3 *
4 * Unzip a file.
5 *
6 * @input ZIPFileName    : String  The file name of the .zip file
7 * @input SourceDirectory : dw.io.File    The processing directory where the file is located
8 * @input sampleLogger  : Object  Sample logger
9 * @output UnzipDirectory : dw.io.File    The unzip directory where the extracted import file is located
10 * @output ZIPFile  : dw.io.File The .zip file
11 * @output sampleLogger  : Object  Sample logger
12 * @output sampleError  : Object  Sample error
13 */
14importPackage(dw.system);
15importPackage(dw.io);
16importScript("bc_sample:library/impex/libImpExConstants.ds");
17// Sample Logging ImportScript
18importScript("bc_sample:library/common/libContext.ds");
19importScript("bc_sample:library/utility/exception/libsampleException.ds");
20importScript("bc_sample:library/utility/logging/libLog.ds");
21function execute(pdict : PipelineDictionary) : Number {
22 var _context : String = new Context("GetUnzip.ds");
23 var _logger : Log = Log.getLogger(pdict);
24
25 var sourceDirectory : File = pdict.SourceDirectory;
26 var zipFileName : String = pdict.ZIPFileName;
27
28 var sourceFile : File = new File(sourceDirectory, zipFileName);
29 var targetFile : File = new File(File.TEMP + File.SEPARATOR + 'IMPEX_UNZIP' + File.SEPARATOR + zipFileName);
30 var zipFile : File  = new File(sourceDirectory, zipFileName);
31
32 var unzipDirectory : File = new File(File.TEMP + File.SEPARATOR + 'IMPEX_UNZIP' + File.SEPARATOR + zipFileName);
33 unzipDirectory.mkdirs();
34
35 var fileExtension : String = sourceFile.name.substring(sourceFile.name.length-4, sourceFile.name.length);
36
37 if (!sourceFile.exists()) {
38  _logger.error(_context, "Source file '" + sourceFile.name + "' in path '" + sourceFile.path + "' cannot be found!");
39  return PIPELET_ERROR;
40 }
41
42 // check for file extension .zip
43 if ((fileExtension == '.zip') || (fileExtension == '.ZIP')) {
44
45  try {
46
47   sourceFile.unzip(targetFile);
48   pdict.UnzipDirectory = unzipDirectory;
49   pdict.ZIPFile = zipFile;
50  }
51  catch (e) {
52
53   var exception : sampleException = new sampleException(_context, "Error occurred calling unzip: ", e);
54   _logger.error(_context, "Error occurred calling unzip: " + exception);
55   pdict.sampleError = exception;
56
57   return PIPELET_ERROR;
58  }
59
60  return PIPELET_NEXT;
61 }
62
63 _logger.info(_context, "No .zip file :" + zipFile.name);
64 return PIPELET_NEXT;
65}