forked from acumenbrands/rest_suite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransform.js.html
221 lines (185 loc) · 6.69 KB
/
transform.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: transform.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: transform.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>var no_internalid_given_error = "No internal id was supplied, cannot source " +
"record for transformation";
/**
* Transformer Class
* @class Transformer
* @param {object} request The body of the HTTP Post request from the client
* @return {Transformer} A new instance of Transformer
*/
this.Transformer = (function() {
/** @constructor */
function Transformer(request) {
this.params = request;
this.record_data = request['record_data'];
this.reply_list = [];
this.exception = null;
}
/**
* Iterates over each record calling `executeTransformRequest()`
*
* @method
* @memberof Transformer
* @return {null}
*/
Transformer.prototype.transformRecords = function() {
for(index in this.record_data) {
request_data = this.record_data[index];
this.executeTransformRequest(request_data);
}
}
/**
* Executes a new TransformRequest, accumulating the result
*
* @method
* @memberof Transformer
* @param {object} The request data
* @return {null}
*/
Transformer.prototype.executeTransformRequest = function(request_data) {
transform_request = new TransformRequest(request_data);
transform_request.execute();
this.accumulateResult(transform_request.generateReply());
}
/**
* Adds a result to the `reply_list`
*
* @method
* @memberof Transformer
* @param {object} The result
* @return {null}
*/
Transformer.prototype.accumulateResult = function(result) {
this.reply_list.push(result);
}
/**
* Wrapper for `NetsuiteToolkit.formatReply()`
*
* @method
* @memberof Transformer
* @return {object} The formatted reply from Netsuite
*/
Transformer.prototype.generateReply = function() {
return NetsuiteToolkit.formatReply(this.params, this.replyList);
}
return Transformer;
})();
/**
* TransformRequest Class
* @class TransformRequest
* @param {object} the required information to transform a record
* @return {TransformRequest} A new instance of TransformRequest
*/
this.TransformRequest = (function() {
/** @constructor */
function TransformRequest(record_data) {
this.params = record_data;
this.record = null;
this.written_id = null;
this.internalid = record_data['internalid'] || null;
this.source_type = record_data['source_type'];
this.result_type = record_data['result_type'];
this.transform_values = record_data['transform_values'];
this.literal_field_data = record_data['literal_fields'];
this.sublist_data = record_data['sublists'];
}
/**
* Transform a record for TransformRequest, alters its data
* using the given data and submits it for writing.
*
* @method
* @memberof TransformRequest
* @return {null}
*/
TransformRequest.prototype.execute = function() {
if(!this.internalid) { throw TransformRequest.NoInternalIdGiven; }
this.record = NetsuiteToolkit.transformRecord(this.source_type, this.internalid,
this.result_type, this.transform_values);
NetsuiteToolkit.RecordProcessor.updateLiterals(this.record, this.literal_field_data);
this.processSublists();
this.written_id = NetsuiteToolkit.submitRecord(this.record);
}
/**
* Iterate over the list of sublist operations and call `executeSublistProcessor()`
* for each
*
* @method
* @memberof TransformRequest
* @return {null}
*/
TransformRequest.prototype.processSublists = function() {
for(index in this.sublist_data) {
sublist = this.sublist_data[index];
this.executeSublistProcessor(sublist);
}
}
/**
* Initialize a new `NetsuiteToolkit.SublistProcessor` using the given
* sublist data and execute it
*
* @method
* @memberof TransformRequest
* @return {null}
*/
TransformRequest.prototype.executeSublistProcessor = function(sublist_data) {
sublist_processor = new NetsuiteToolkit.SublistProcessor(this.record, sublist_data);
sublist_processor.execute();
}
/**
* Wrapper for `NetsuiteToolkit.formatReply()`
*
* @method
* @memberof Transformer
* @return {object} The formatted reply from Netsuite
*/
TransformRequest.prototype.generateReply = function() {
return NetsuiteToolkit.formatReply(this.params, this.written_id);
}
return TransformRequest;
})();
this.TransformRequest.NoInternalIdGiven = new Error(no_internalid_given_error);
/** @namespace global */
/**
* The script function that Netsuite will call to execute the Transformer process
*
* @method
* @param {object} request The object representing the HTTP request body
* @memberof global
* @return {object} The formatted results of the request
*/
var transformPostHandler = function(request) {
transformer = new Transformer(request);
transformer.transformRecord();
return transformer.generateReply();
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="Deleter.html">Deleter</a></li><li><a href="DeleteRequest.html">DeleteRequest</a></li><li><a href="Initializer.html">Initializer</a></li><li><a href="Loader.html">Loader</a></li><li><a href="LoadRequest.html">LoadRequest</a></li><li><a href="NetsuiteToolkit.SublistProcessor.html">SublistProcessor</a></li><li><a href="SavedSearch.html">SavedSearch</a></li><li><a href="Searcher.html">Searcher</a></li><li><a href="Transformer.html">Transformer</a></li><li><a href="TransformRequest.html">TransformRequest</a></li><li><a href="Upserter.html">Upserter</a></li><li><a href="UpsertRequest.html">UpsertRequest</a></li></ul><h3>Namespaces</h3><ul><li><a href="global.html">global</a></li><li><a href="NetsuiteToolkit.html">NetsuiteToolkit</a></li><li><a href="NetsuiteToolkit.RecordProcessor.html">RecordProcessor</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.1.1</a> on Thu May 16 2013 11:16:09 GMT-0500 (CDT)
</footer>
<script> prettyPrint(); </script>
</body>
</html>