CreateImpExFolderStructure.ds

Review the CreateImpExFolderStructure.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 * Create the ImpEx folder structure.
3 *
4 * @input TaskDirectoryName 		: String		Task directory name
5 * @input SiteID  			: String		Site ID
6 * @input sampleLogger  		: Object		Sample logger
7 * @input Scope				: String		Scope [import/export]
8 * @output DirectoryIncoming 		: dw.io.File	Incoming folder for the file (import tasks)
9 * @output DirectoryOutgoing 		: dw.io.File	Outgoing folder for the file (export tasks)
10 * @output DirectoryProcessing 	: dw.io.File	Processing folder for the file
11 * @output DirectoryArchive 		: dw.io.File	Archive folder for the file
12 * @output DirectoryError 		: dw.io.File	Directory folder for the file
13 * @output sampleLogger 		: Object		Debug output for Sample logger
14 * @output sampleError 			: Object		Error output for Sample logger
15 * @output DirectoryOutgoingPath 	: String
16 * @output DirectoryIncomingPath 	: String
17 * @output DirectoryProcessingPath 	: String
18 * @output DirectoryArchivePath 	: String
19 * @output DirectoryErrorPath 	: String
20 */
21importPackage(dw.system);
22importPackage(dw.io);
23importPackage(dw.util);
24
25
26
27// Sample Logging ImportScript
28importScript("bc_sample:library/common/libContext.ds");
29importScript("bc_sample:library/utility/exception/libsampleException.ds");
30importScript("bc_sample:library/utility/logging/libLog.ds");
31
32
33
34function execute(pdict: PipelineDictionary): Number {
35
36
37
38    // Sample Logging var
39    var _context: String = new Context("CreateImpExFolderStructure.ds");
40    var _logger: Log = Log.getLogger(pdict);
41
42    // check for mandatory pipelet input parameters
43    if (empty(pdict.TaskDirectoryName) || empty(pdict.SiteID)) {
44
45        _logger.error(_context, "Mandatory pipelet input parameters are missing or null.");
46        return PIPELET_ERROR;
47    }
48
49    // get impex scope
50    var scope: String = pdict.Scope;
51
52    // get site id
53    var siteId: String = pdict.SiteID;
54
55    // site specific impex base path
56    var impexBasePath: String = File.IMPEX + File.SEPARATOR + 'src' + File.SEPARATOR + 'datafeeds' + File.SEPARATOR + siteId + File.SEPARATOR;
57
58    var directoryIncomingPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'incoming';
59    var directoryOutgoingPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'outgoing';
60    var directoryProcessingPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'processing';
61    var directoryArchivePath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'archive';
62    var directoryErrorPath: String = impexBasePath + pdict.TaskDirectoryName + File.SEPARATOR + 'error';
63
64    var directoryIncoming: File = new File(directoryIncomingPath);
65    var directoryOutgoing: File = new File(directoryOutgoingPath);
66    var directoryProcessing: File = new File(directoryProcessingPath);
67    var directoryArchive: File = new File(directoryArchivePath);
68    var directoryError: File = new File(directoryErrorPath);
69
70    try {
71
72        switch (scope) {
73
74        case Scope.IMPORT:
75            directoryIncoming.mkdirs();
76            break;
77        case Scope.EXPORT:
78            directoryOutgoing.mkdirs();
79            break;
80        default:
81            directoryIncoming.mkdirs();
82            directoryOutgoing.mkdirs();
83            break;
84        }
85        directoryProcessing.mkdirs();
86        directoryArchive.mkdirs();
87        directoryError.mkdirs();
88
89        switch (scope) {
90
91        case Scope.IMPORT:
92            pdict.DirectoryIncoming = directoryIncoming;
93            break;
94        case Scope.EXPORT:
95            pdict.DirectoryOutgoing = directoryOutgoing;
96            break;
97        default:
98            pdict.DirectoryIncoming = directoryIncoming;
99            pdict.DirectoryOutgoing = directoryOutgoing;
100            break;
101        }
102        pdict.DirectoryProcessing = directoryProcessing;
103        pdict.DirectoryArchive = directoryArchive;
104        pdict.DirectoryError = directoryError;
105
106        switch (scope) {
107
108        case Scope.IMPORT:
109            pdict.DirectoryIncomingPath = directoryIncomingPath;
110            break;
111        case Scope.EXPORT:
112            pdict.DirectoryOutgoingPath = directoryOutgoingPath;
113            break;
114        default:
115            pdict.DirectoryIncomingPath = directoryIncomingPath;
116            pdict.DirectoryOutgoingPath = directoryOutgoingPath;
117            break;
118        }
119        pdict.DirectoryProcessingPath = directoryProcessingPath;
120        pdict.DirectoryArchivePath = directoryArchivePath;
121        pdict.DirectoryErrorPath = directoryErrorPath;
122    } catch (e) {
123
124        var exception: sampleException = new sampleException(_context, "Error occurred calling create ImpEx folder", e);
125        _logger.error(_context, "Error occurred calling  create ImpEx folder: " + exception);
126        pdict.sampleError = exception;
127
128        return PIPELET_ERROR;
129    }
130
131    return PIPELET_NEXT;
132}
133
134
135
136// Constant for IMPEX scope
137var Scope = {
138
139
140
141    IMPORT: 'import',
142    EXPORT: 'export'
143};