@sapui5/sap.ushell_abap 1.97.1 → 1.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/package.json +1 -1
  2. package/src/main/js/sap/ushell_abap/.library +2 -2
  3. package/src/main/js/sap/ushell_abap/adapters/abap/AdapterContainer.js +1 -1
  4. package/src/main/js/sap/ushell_abap/adapters/abap/AppStateAdapter.js +2 -2
  5. package/src/main/js/sap/ushell_abap/adapters/abap/ClientSideTargetResolutionAdapter.js +2 -2
  6. package/src/main/js/sap/ushell_abap/adapters/abap/ConfigurationDefaultsAdapter.js +2 -2
  7. package/src/main/js/sap/ushell_abap/adapters/abap/ContainerAdapter.js +2 -2
  8. package/src/main/js/sap/ushell_abap/adapters/abap/LaunchPageAdapter.js +37 -4
  9. package/src/main/js/sap/ushell_abap/adapters/abap/MenuAdapter.js +1 -1
  10. package/src/main/js/sap/ushell_abap/adapters/abap/NavTargetResolutionAdapter.js +2 -2
  11. package/src/main/js/sap/ushell_abap/adapters/abap/PageBuildingAdapter.js +2 -2
  12. package/src/main/js/sap/ushell_abap/adapters/abap/PagePersistenceAdapter.js +35 -15
  13. package/src/main/js/sap/ushell_abap/adapters/abap/PersonalizationAdapter.js +2 -2
  14. package/src/main/js/sap/ushell_abap/adapters/abap/SearchAdapter.js +2 -2
  15. package/src/main/js/sap/ushell_abap/adapters/abap/SupportTicketAdapter.js +2 -2
  16. package/src/main/js/sap/ushell_abap/adapters/abap/Ui5ComponentLoaderAdapter.js +2 -2
  17. package/src/main/js/sap/ushell_abap/adapters/abap/UserInfoAdapter.js +1 -1
  18. package/src/main/js/sap/ushell_abap/adapters/hana/ContainerAdapter.js +2 -2
  19. package/src/main/js/sap/ushell_abap/bootstrap/evo/XhrLogonEventHandler.js +1 -1
  20. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap-def-dev.js +1 -1
  21. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap-def-loader.js +7 -0
  22. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap-def.js +1 -1
  23. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.bootstrap.utils.js +1 -1
  24. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.configure.ushell.js +2 -2
  25. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.constants.js +1 -1
  26. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.get.server.config.Urls.js +1 -1
  27. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.js +1 -1
  28. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.load.launchpad.js +2 -17
  29. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.request.pageset.js +1 -1
  30. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.request.server.config.js +1 -1
  31. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.request.startup.js +1 -1
  32. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.theme.handler.js +1 -1
  33. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.ui5.boot.handler.js +1 -1
  34. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.validate.Url.js +1 -1
  35. package/src/main/js/sap/ushell_abap/bootstrap/evo/abap.xhr.handler.js +1 -1
  36. package/src/main/js/sap/ushell_abap/bootstrap/evo/boottask.js +6 -12
  37. package/src/main/js/sap/ushell_abap/library.js +3 -3
  38. package/src/main/js/sap/ushell_abap/pbServices/ui2/AllCatalogs.js +1 -1
  39. package/src/main/js/sap/ushell_abap/pbServices/ui2/Bag.js +1 -6
  40. package/src/main/js/sap/ushell_abap/pbServices/ui2/Catalog.js +1 -1
  41. package/src/main/js/sap/ushell_abap/pbServices/ui2/Chip.js +127 -15
  42. package/src/main/js/sap/ushell_abap/pbServices/ui2/ChipDefinition.js +1 -1
  43. package/src/main/js/sap/ushell_abap/pbServices/ui2/ChipInstance.js +14 -6
  44. package/src/main/js/sap/ushell_abap/pbServices/ui2/Error.js +1 -1
  45. package/src/main/js/sap/ushell_abap/pbServices/ui2/Factory.js +1 -1
  46. package/src/main/js/sap/ushell_abap/pbServices/ui2/ODataService.js +1 -1
  47. package/src/main/js/sap/ushell_abap/pbServices/ui2/ODataWrapper.js +1 -1
  48. package/src/main/js/sap/ushell_abap/pbServices/ui2/Page.js +1 -8
  49. package/src/main/js/sap/ushell_abap/pbServices/ui2/PageBuildingService.js +1 -1
  50. package/src/main/js/sap/ushell_abap/pbServices/ui2/PageSet.js +1 -1
  51. package/src/main/js/sap/ushell_abap/pbServices/ui2/RemoteCatalogService.js +1 -1
  52. package/src/main/js/sap/ushell_abap/pbServices/ui2/Utils.js +1 -8
  53. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/actions.js +1 -1
  54. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/bag.js +1 -1
  55. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/configuration.js +1 -1
  56. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/configurationUi.js +1 -1
  57. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/fullscreen.js +1 -1
  58. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/preview.js +1 -1
  59. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/refresh.js +1 -1
  60. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/search.js +1 -1
  61. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/types.js +1 -1
  62. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/url.js +1 -1
  63. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/visible.js +1 -1
  64. package/src/main/js/sap/ushell_abap/support/plugins/app-infra/AppInfraOnSapNetWeaverSupportPlugin.js +1 -1
  65. package/src/main/js/sap/ushell_abap/ui5appruntime/AppInfoAdapter.js +1 -1
  66. package/ui5.yaml +376 -30
  67. package/src/main/js/sap/ui2/srvc/ODataService.js +0 -267
  68. package/src/main/js/sap/ui2/srvc/ODataWrapper.js +0 -1283
  69. package/src/main/js/sap/ui2/srvc/PageBuildingService.js +0 -1508
  70. package/src/main/js/sap/ui2/srvc/RemoteCatalogService.js +0 -49
  71. package/src/main/js/sap/ui2/srvc/allcatalogs.js +0 -197
  72. package/src/main/js/sap/ui2/srvc/bag.js +0 -711
  73. package/src/main/js/sap/ui2/srvc/catalog.js +0 -946
  74. package/src/main/js/sap/ui2/srvc/chip.js +0 -1035
  75. package/src/main/js/sap/ui2/srvc/chipdefinition.js +0 -228
  76. package/src/main/js/sap/ui2/srvc/chipinstance.js +0 -944
  77. package/src/main/js/sap/ui2/srvc/contracts/actions.js +0 -239
  78. package/src/main/js/sap/ui2/srvc/contracts/bag.js +0 -145
  79. package/src/main/js/sap/ui2/srvc/contracts/configuration.js +0 -161
  80. package/src/main/js/sap/ui2/srvc/contracts/configurationUi.js +0 -326
  81. package/src/main/js/sap/ui2/srvc/contracts/fullscreen.js +0 -69
  82. package/src/main/js/sap/ui2/srvc/contracts/navigation.js +0 -48
  83. package/src/main/js/sap/ui2/srvc/contracts/preview.js +0 -289
  84. package/src/main/js/sap/ui2/srvc/contracts/refresh.js +0 -42
  85. package/src/main/js/sap/ui2/srvc/contracts/search.js +0 -109
  86. package/src/main/js/sap/ui2/srvc/contracts/searchProvider.js +0 -46
  87. package/src/main/js/sap/ui2/srvc/contracts/types.js +0 -9
  88. package/src/main/js/sap/ui2/srvc/contracts/url.js +0 -104
  89. package/src/main/js/sap/ui2/srvc/contracts/visible.js +0 -122
  90. package/src/main/js/sap/ui2/srvc/error.js +0 -54
  91. package/src/main/js/sap/ui2/srvc/factory.js +0 -656
  92. package/src/main/js/sap/ui2/srvc/page.js +0 -934
  93. package/src/main/js/sap/ui2/srvc/pageset.js +0 -466
  94. package/src/main/js/sap/ui2/srvc/utils.js +0 -923
  95. package/src/main/js/sap/ushell_abap/pbServices/ui2/contracts/navigation.js +0 -50
@@ -1,1283 +0,0 @@
1
- // Copyright (c) 2009-2020 SAP SE, All Rights Reserved
2
-
3
- /**
4
- * @fileOverview A wrapper around <code>OData</code>, providing CSRF token handling, caching and
5
- * generic batch support.
6
- */
7
- (function () {
8
- "use strict";
9
-
10
- /* global OData */
11
-
12
- jQuery.sap.declare("sap.ui2.srvc.ODataWrapper");
13
-
14
- // Note: Only the section between @begin and @end is included in pbs-template.js.
15
- // In pbs-template fnRequire is differently initialized (in case UI5 is not available)!
16
- // Thus this variable is used in the coding below and not directly jQuery.sap.require.
17
- // avoid fnRequire = jQuery.sap.require as require cannot be spied on afterwards
18
- var fnRequire = function () {
19
- jQuery.sap.require.apply(this, arguments);
20
- };
21
- function nop () { /* null object pattern */ }
22
-
23
- sap.ui2.srvc.testPublishAt = sap.ui2.srvc.testPublishAt || function () {
24
- // intentionally left blank
25
- };
26
-
27
- /// @begin
28
- // if OData is missing, automatically require SAPUI5's datajs implementation
29
- if (typeof OData !== "object") {
30
- fnRequire("sap.ui.thirdparty.datajs");
31
- }
32
-
33
- /**
34
- * Reject the given <code>jQuery.Deferred</code> object(s) (array or single one) with the
35
- * given error response.
36
- *
37
- * @param {jQuery.Deferred|jQuery.Deferred[]} vDeferred
38
- * deferred or array of deferreds to be rejected
39
- * @param {object} oResponse
40
- * parameter of (each) reject call
41
- */
42
- function reject (vDeferred, oResponse) {
43
- if (sap.ui2.srvc.isArray(vDeferred)) {
44
- // a failed change set: reject each single jQuery.Deferred in the same way
45
- vDeferred.forEach(function (oDeferred) {
46
- oDeferred.reject(oResponse);
47
- });
48
- } else {
49
- // a failed GET request
50
- vDeferred.reject(oResponse);
51
- }
52
- }
53
-
54
- // "public class" ************************************************************
55
-
56
- /**
57
- * Constructs a wrapper around <code>OData</code>, providing CSRF token handling, caching and
58
- * generic batch support. The sap-statistics header is automatically added to all requests if
59
- * the URL query parameter <code>sap-statistics=true</code> is set (see
60
- * <a href="http://help.sap.com/saphelp_nw74/helpdata/de/40/93b81292194d6a926e105c10d5048d/content.htm">
61
- * SAP Performance Statistics</a>).
62
- * If <code>OData</code> is missing, "sap.ui.thirdparty.datajs" is required automatically.
63
- * <p>
64
- * The preferred way to call the constructor is from a "sub-class" of
65
- * {@link sap.ui2.srvc.ODataService}:
66
- * <pre>
67
- * function Service() {
68
- * var oWrapper = new sap.ui2.srvc.ODataWrapper(oSettings, this);
69
- * sap.ui2.srvc.ODataService.call(this, oWrapper, fnDefaultFailure);
70
- * }
71
- * var myService = new Service();
72
- * </pre>
73
- * This provides public inheritance of <code>sap.ui2.srvc.ODataService</code> methods and
74
- * private inheritance of <code>sap.ui2.srvc.ODataWrapper</code> methods. In case you are not
75
- * providing a public "sub-class" of <code>sap.ui2.srvc.ODataService</code> but only want to
76
- * use methods from <code>sap.ui2.srvc.ODataWrapper</code>,
77
- * {@link sap.ui2.srvc.createODataWrapper} is the preferred way to construct an instance.
78
- *
79
- * @param {object} oSettings
80
- * An object containing various properties:
81
- * <pre>
82
- * {
83
- * baseUrl: "/OData/OData.svc", // Mandatory base URL of the OData service
84
- * supportsChangeSets: false, // Type: boolean, Default: false
85
- * // Whether the OData service supports change sets with <b>multiple</b>
86
- * // operations bundled into a single logical unit of work. Otherwise
87
- * // each modifying operation is isolated in a change set of its own.
88
- * "sap-language": "EN", // header which is set for all requests sent
89
- * "sap-client": 120, // header which is set for all requests sent
90
- * "sap-statistics": true // header which is set for all requests sent; in order to receive
91
- * // some performance statistics
92
- * }
93
- * </pre>
94
- * @param {sap.ui2.srvc.ODataService} oODataService
95
- * facade to any OData service, keeping track of CSRF token and default error handler
96
- * (see {@link #getODataService})
97
- *
98
- * @class
99
- * @public
100
- * @since 1.19.0
101
- */
102
- // OLD API: function (sBaseUrl, oODataService, bSupportsChangeSets)
103
- sap.ui2.srvc.ODataWrapper = function (oSettings, oODataService) {
104
- var S_STICKY_SESSION_HEADER = "saplb", // header to check during sticky session
105
- aBatchQueue, // corresponds to data.__batchRequests
106
- bChangeSetOpen, // whether a change set is currently open at the end of our batch queue
107
- aDeferredQueue, // jQuery.Deferred() objects corresponding to each request
108
- that = this,
109
- sBaseUrl,
110
- bSupportsChangeSets;
111
-
112
- // BEWARE: constructor code below!
113
-
114
- // "private" methods -------------------------------------------------------
115
-
116
- /**
117
- * Converts old api calls of the ODataWrapper constructor to the current one.
118
- * @param {object} oArgs
119
- * An arguments object containing the parameters of the constructor function. See Constructor for details.
120
- * @returns {object}
121
- * Settings for ODataWrapper in an object instead of arguments
122
- * @private
123
- */
124
- function handleOldConstructorApi (oArgs) {
125
- var oSettings = {};
126
-
127
- oSettings.baseUrl = oArgs[0];
128
- // This is not a mandatory parameter and might be undefined
129
- if (typeof oArgs[2] === "boolean") {
130
- oSettings.supportsChangeSets = oArgs[2];
131
- }
132
-
133
- return oSettings;
134
- }
135
-
136
- /* eslint-disable no-unused-vars */
137
- /**
138
- * Getter mainly used for testing.
139
- *
140
- * @returns {object}
141
- */
142
- sap.ui2.srvc.testPublishAt(that);
143
- function getBatchQueue () {
144
- return aBatchQueue;
145
- }
146
- /* eslint-enable no-unused-vars */
147
-
148
- /**
149
- * Iterates over the given headers map and returns the first value for the requested key (case
150
- * insensitive). If no such key is found, <code>undefined</code> is returned.
151
- *
152
- * @param {string} sKey
153
- * the requested key
154
- * @param {object} [mHeaders={}]
155
- * an object treated as a <code>map&lt;string, object&gt;</code>
156
- * @returns {string}
157
- * the header value or <code>undefined</code> if the header was not found
158
- */
159
- sap.ui2.srvc.testPublishAt(that);
160
- function headerValue (sKey, mHeaders) {
161
- sKey = sKey.toLowerCase();
162
- for (var sCurrentKey in mHeaders) {
163
- if (Object.prototype.hasOwnProperty.call(mHeaders, sCurrentKey)
164
- && sCurrentKey.toLowerCase() === sKey) {
165
- return mHeaders[sCurrentKey];
166
- }
167
- }
168
- return undefined;
169
- }
170
-
171
- /**
172
- * Gets an object supposed to be the headers object used for OData requests.
173
- * Adds headers set as static properties of sap.ui2.srvc.ODataWrapper or as part of Constructor settings.
174
- * The following headers may be added:
175
- * - sap-language
176
- * - sap-statistics
177
- * - sap-client
178
- *
179
- * @param {object} [oHeaders={}]
180
- * optional object supposed to be the headers object used for OData requests
181
- * @returns {object}
182
- * returns oHeader (if not given, a new object is created) additional headers may be added as
183
- * properties to the object.
184
- */
185
- function addGlobalSapHeaders (oHeaders) {
186
- var sSapLanguage = oSettings["sap-language"] || sap.ui2.srvc.ODataWrapper["sap-language"],
187
- sSapStatistics = oSettings["sap-statistics"] || sap.ui2.srvc.ODataWrapper["sap-statistics"],
188
- sSapClient = oSettings["sap-client"] || sap.ui2.srvc.ODataWrapper["sap-client"];
189
-
190
- oHeaders = oHeaders || {};
191
- if (sSapLanguage) {
192
- oHeaders["sap-language"] = sSapLanguage;
193
- }
194
- if (sSapStatistics || (sSapStatistics === "false")) {
195
- // If sSapStatistics is set, all requests done via ODataWrapper, will contain the
196
- // sap-statistics header. See
197
- // http://help.sap.com/saphelp_nw74/helpdata/de/40/93b81292194d6a926e105c10d5048d/content.htm
198
- oHeaders["sap-statistics"] = "" + sSapStatistics;
199
- }
200
- if (sSapClient) {
201
- oHeaders["sap-client"] = sSapClient;
202
- }
203
- return oHeaders;
204
- }
205
-
206
- /**
207
- * Adds previously detected sticky session headers to the given object
208
- * (which is supposed to be the headers object used for OData requests).
209
- *
210
- * @param {object} [oHeaders={}]
211
- * optional object supposed to be the headers object used for OData requests
212
- * @returns {object}
213
- * returns oHeader (if not given, a new object is created) additional
214
- * headers may be added as properties to the object.
215
- */
216
- function addStickySessionHeader (oHeaders) {
217
- oHeaders = oHeaders || {};
218
-
219
- var oStickySessionConfiguration =
220
- sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration[sBaseUrl];
221
-
222
- /*
223
- * NOTE: not assuming oStickySessionConfiguration is defined (see comment
224
- * on assigment of sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration)
225
- * down in this file.
226
- */
227
- if (typeof oStickySessionConfiguration === "undefined") {
228
- return oHeaders;
229
- }
230
-
231
- if (oStickySessionConfiguration && oStickySessionConfiguration.enabled &&
232
- typeof oStickySessionConfiguration.value !== "undefined") {
233
- oHeaders[S_STICKY_SESSION_HEADER] = oStickySessionConfiguration.value;
234
- }
235
-
236
- return oHeaders;
237
- }
238
-
239
- /**
240
- * Detects sticky session based on the given response headers and, in case
241
- * of success, updates the static
242
- * sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration with the sticky
243
- * session value found in the header.
244
- *
245
- * @param {object} oResponseHeaders
246
- * the response headers
247
- */
248
- sap.ui2.srvc.testPublishAt(that);
249
- function detectStickySession (oResponseHeaders) {
250
- var sHeaderValue,
251
- oStickySessionConfiguration =
252
- sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration[sBaseUrl];
253
-
254
- if (!oStickySessionConfiguration || !oStickySessionConfiguration.enabled) {
255
- return;
256
- }
257
-
258
- // add sticky session header value if found
259
- sHeaderValue = headerValue(S_STICKY_SESSION_HEADER, oResponseHeaders);
260
- if (typeof sHeaderValue === "undefined") {
261
- return;
262
- }
263
-
264
- if (oStickySessionConfiguration.value !== sHeaderValue) { // take the last value from server
265
- oStickySessionConfiguration.value = sHeaderValue;
266
- }
267
- }
268
-
269
- /**
270
- * Iterates over the given headers map and returns the first value for the well-known
271
- * "X-CSRF-Token" key (case insensitive). If no such key is found, <code>""</code> is
272
- * returned.
273
- *
274
- * @param {object} [mHeaders={}]
275
- * an object treated as a <code>map&lt;string, object&gt;</code>
276
- * @returns {string}
277
- */
278
- sap.ui2.srvc.testPublishAt(that);
279
- function csrfTokenValue (mHeaders) {
280
- var sCsrfHeader = headerValue("x-csrf-token", mHeaders);
281
-
282
- if (sCsrfHeader === "Required") {
283
- return sCsrfHeader;
284
- }
285
-
286
- var sCacheControlHeader = headerValue("cache-control", mHeaders);
287
- if (sCacheControlHeader === undefined || sCacheControlHeader.indexOf("max-age=0") > -1 || sCacheControlHeader.indexOf("no-cache") > -1) {
288
- return sCsrfHeader || "";
289
- }
290
-
291
- return "";
292
- }
293
-
294
- /**
295
- * Wrapper around
296
- * <a href="http://datajs.codeplex.com/wikipage?title=datajs%20OData%20API#OData.request">
297
- * <code>OData.request</code></a> which is able to automatically fetch a CSRF token if
298
- * required.
299
- *
300
- * @param {string} sRequestUrl
301
- * a string containing the <b>absolute</b> URL
302
- * @param {string} sMethod
303
- * the HTTP method to use, e.g. "POST"
304
- * @param {object} oPayload
305
- * payload of the request (in intermediate format)
306
- * @param {function(object)} [fnSuccess]
307
- * callback function that is executed if the request succeeds, taking the processed data
308
- * @param {function (string, object=)} [fnFailure]
309
- * error handler taking an error message and, since version 1.28.6, an
310
- * optional object containing the complete error information as delivered
311
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
312
- * for more details.
313
- * Defaults to the OData service facade's default error handler
314
- * @param {object} [oHandler]
315
- * (OData/datajs) handler for the response data
316
- * @param {boolean} [bIsRepeatedRequest]
317
- * This function recursively calls itself to re-execute it in case the CSRF token was invalid and has been fetched.
318
- * To prevent endless loops when the server returns an invalid token, this flag is used.
319
- */
320
- sap.ui2.srvc.testPublishAt(that);
321
- function doRequest (sRequestUrl, sMethod, oPayload, fnSuccess, fnFailure, oHandler, bIsRepeatedRequest) {
322
- var oHeaders;
323
- fnSuccess = fnSuccess || nop;
324
- fnFailure = fnFailure || oODataService.getDefaultErrorHandler();
325
- that.check(fnSuccess, fnFailure);
326
- oHeaders = {
327
- Accept: "application/json",
328
- "Accept-Language": (sap.ui && sap.ui.getCore().getConfiguration().getLanguage()) || "",
329
- "X-CSRF-Token": oODataService.getCsrfToken()
330
- };
331
-
332
- addGlobalSapHeaders(oHeaders);
333
- addStickySessionHeader(oHeaders);
334
-
335
- OData.request({
336
- requestUri: sRequestUrl,
337
- method: sMethod,
338
- data: oPayload,
339
- headers: oHeaders
340
- },
341
- function (oData, oResponse) {
342
- detectStickySession((oResponse || {}).headers);
343
- jQuery.sap.log.debug("Received OData response for " + sMethod + ' "' + sRequestUrl + '"',
344
- null,
345
- "sap.ui2.srvc.ODataWrapper");
346
- // Note: drop excess parameters; try/catch
347
- sap.ui2.srvc.call(fnSuccess.bind(null, oData), fnFailure);
348
- },
349
- function (oError) {
350
- // wrappers for success & failure handlers to reset flag
351
- function failure () {
352
- fnFailure.apply(null, arguments);
353
- }
354
- function success () {
355
- fnSuccess.apply(null, arguments);
356
- }
357
-
358
- if (!bIsRepeatedRequest
359
- && oError.response.statusCode === 403
360
- && csrfTokenValue(oError.response.headers).toLowerCase() === "required") {
361
- // refresh CSRF token and repeat original request
362
- jQuery.sap.log.debug("CSRF token required for " + sMethod + ' "' + sRequestUrl
363
- + '", refreshing it', JSON.stringify(oError.response),
364
- "sap.ui2.srvc.ODataWrapper");
365
-
366
- oODataService.refreshCsrfToken(
367
- doRequest.bind(that, sRequestUrl, sMethod, oPayload, success, failure, oHandler, /*bIsRepeatedRequest*/ true),
368
- failure
369
- );
370
- } else {
371
- that.onError(sMethod, sRequestUrl, fnFailure, /*oDeferred*/null, oError);
372
- }
373
- },
374
- oHandler);
375
- jQuery.sap.log.debug("Sent OData request for " + sMethod + ' "' + sRequestUrl + '"', null,
376
- "sap.ui2.srvc.ODataWrapper");
377
- }
378
-
379
- /**
380
- * Transforms the given absolute URL into a relative URL w.r.t. this OData wrapper's base URL,
381
- * removing protocol, host, port, and base URL, but preserving query parameters and a fragment
382
- * part.
383
- *
384
- * @param {string} sRequestUrl
385
- * a string containing an <b>absolute</b> URL, e.g.
386
- * "http://acme.corp/OData/OData.svc/Products(1)?$foo=bar#abc"
387
- * @returns {string}
388
- * a string containing the <b>relative</b> URL w.r.t. this OData wrapper's base URL, e.g.
389
- * "Products(1)?$foo=bar#abc"
390
- */
391
- sap.ui2.srvc.testPublishAt(that);
392
- function toRelativeUrl (sRequestUrl) {
393
- var i = sRequestUrl.indexOf(sBaseUrl);
394
- if (i < 0) {
395
- throw new sap.ui2.srvc.Error('Not relative to base URL "' + sBaseUrl + '": ' + sRequestUrl,
396
- "sap.ui2.srvc.ODataWrapper");
397
- }
398
- return sRequestUrl.slice(i + sBaseUrl.length);
399
- }
400
-
401
- /**
402
- * Transforms the given relative URL into an absolute URL w.r.t. this OData wrapper's base URL,
403
- * making sure there is exactly one slash in between.
404
- *
405
- * @param {string} sRelativeUrl
406
- * a string containing the <b>relative</b> URL w.r.t. this OData wrapper's base URL, e.g.
407
- * "Products(1)"
408
- * @returns {string}
409
- * a string containing the <b>absolute</b> URL, e.g. "/OData/OData.svc/Products(1)"
410
- */
411
- sap.ui2.srvc.testPublishAt(that);
412
- function toRequestUrl (sRelativeUrl) {
413
- if (/^\//.test(sRelativeUrl)) {
414
- throw new sap.ui2.srvc.Error("Not a relative URL: " + sRelativeUrl,
415
- "sap.ui2.srvc.ODataWrapper");
416
- }
417
- return sBaseUrl + sRelativeUrl;
418
- }
419
-
420
- /**
421
- * Wrapper around
422
- * <a href="http://datajs.codeplex.com/wikipage?title=datajs%20OData%20API#OData.read">
423
- * <code>OData.read</code></a> which supports queuing up for "$batch" requests.
424
- *
425
- * @param {string} sRelativeUrl
426
- * a string containing the <b>relative</b> URL w.r.t. this OData wrapper's base URL, e.g.
427
- * "Products(1)"
428
- * @param {function(object,object)} fnRawSuccess
429
- * a callback function that is executed if the request succeeds, taking the processed data
430
- * and the response object
431
- * @param {function (object)} fnRawFailure
432
- * a callback function that is executed if the request fails, taking an error object
433
- */
434
- sap.ui2.srvc.testPublishAt(that);
435
- function readOrBatch (sRelativeUrl, fnRawSuccess, fnRawFailure) {
436
- var oDeferred,
437
- sRequestUrl = toRequestUrl(sRelativeUrl),
438
- oHeaders = addStickySessionHeader(addGlobalSapHeaders()); // may return an empty object
439
-
440
- if (aBatchQueue) {
441
- jQuery.sap.log.debug('Queued OData request for GET "' + sRelativeUrl + '"', null,
442
- "sap.ui2.srvc.ODataWrapper");
443
- aBatchQueue.push({
444
- method: "GET",
445
- requestUri: sRelativeUrl,
446
- headers: oHeaders
447
- });
448
- oDeferred = (new jQuery.Deferred()).done(fnRawSuccess).fail(fnRawFailure);
449
- aDeferredQueue.push(oDeferred);
450
- bChangeSetOpen = false;
451
- return;
452
- }
453
-
454
- // add specifc headers for read request
455
- oHeaders.Accept = "application/json";
456
- oHeaders["Accept-Language"] = (sap.ui && sap.ui.getCore().getConfiguration().getLanguage()) || "";
457
- // always fetch a new token with GET requests;
458
- // this avoids using old tokens from responses served from browser cache
459
- // see internal BCP incident 1570753380
460
- oHeaders["X-CSRF-Token"] = "Fetch";
461
-
462
- OData.read({
463
- requestUri: sRequestUrl,
464
- headers: oHeaders
465
- }, fnRawSuccess, fnRawFailure);
466
- jQuery.sap.log.debug('Sent OData request for GET "' + sRequestUrl + '"', null,
467
- "sap.ui2.srvc.ODataWrapper");
468
- }
469
-
470
- /**
471
- * Wrapper around {@link #doRequest} which supports queuing up for "$batch" requests.
472
- *
473
- * @param {string} sRelativeUrl
474
- * a string containing the <b>relative</b> URL w.r.t. this OData wrapper's base URL, e.g.
475
- * "Products"
476
- * @param {string} sMethod
477
- * the HTTP method to use, either "POST", "PUT" or "DELETE" (retrieve requests using "GET"
478
- * must be made via {@link #readOrBatch} instead!)
479
- * @param {object} oPayload
480
- * payload of the request (in intermediate format)
481
- * @param {function(object)} [fnSuccess]
482
- * callback function that is executed if the request succeeds, taking the processed data
483
- * @param {function (string, object=)} [fnFailure]
484
- * error handler taking an error message and, since version 1.28.6, an
485
- * optional object containing the complete error information as delivered
486
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
487
- * for more details.
488
- * Defaults to the OData service facade's default error handler
489
- */
490
- sap.ui2.srvc.testPublishAt(that);
491
- function requestOrBatch (sRelativeUrl, sMethod, oPayload, fnSuccess, fnFailure) {
492
- /*jslint nomen:true */
493
- var oDeferred,
494
- oChangeRequest = {
495
- data: oPayload,
496
- method: sMethod,
497
- requestUri: sRelativeUrl,
498
- headers: addStickySessionHeader(addGlobalSapHeaders()) // may return an empty object
499
- },
500
- sRequestUrl = toRequestUrl(sRelativeUrl);
501
-
502
- if (aBatchQueue) {
503
- fnSuccess = fnSuccess || nop;
504
- fnFailure = fnFailure || oODataService.getDefaultErrorHandler();
505
- that.check(fnSuccess, fnFailure);
506
- jQuery.sap.log.debug("Queued OData request for " + sMethod + ' "' + sRelativeUrl + '"',
507
- null, "sap.ui2.srvc.ODataWrapper");
508
- if (!bChangeSetOpen) {
509
- aBatchQueue.push({ __changeRequests: [] });
510
- aDeferredQueue.push([]);
511
- bChangeSetOpen = bSupportsChangeSets;
512
- }
513
- aBatchQueue[aBatchQueue.length - 1].__changeRequests.push(oChangeRequest);
514
- oDeferred = (new jQuery.Deferred())
515
- .done(function (oData, oResponse) {
516
- jQuery.sap.log.debug("Received OData response for "
517
- + sMethod + ' "' + sRequestUrl + '"', null, "sap.ui2.srvc.ODataWrapper");
518
- // Note: drop excess parameters; try/catch
519
- sap.ui2.srvc.call(fnSuccess.bind(null, oData), fnFailure);
520
- })
521
- .fail(that.onError.bind(that, sMethod, sRequestUrl, fnFailure, /*oDeferred*/null));
522
- aDeferredQueue[aDeferredQueue.length - 1].push(oDeferred);
523
- return;
524
- }
525
-
526
- doRequest(sRequestUrl, sMethod, oPayload, fnSuccess, fnFailure);
527
- }
528
-
529
- // "public" methods --------------------------------------------------------
530
-
531
- /**
532
- * Checks whether session stickyness is configured and enabled
533
- *
534
- * @returns {boolean}
535
- * whether the sticky session header is configured and active
536
- *
537
- * @public
538
- *
539
- * @since 1.30.0
540
- */
541
- this.isStickySessionEnabled = function () {
542
- return (sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration[sBaseUrl] || {}).enabled || false;
543
- };
544
-
545
- /**
546
- * <p>
547
- * Configures and activates session stickiness.
548
- * </p>
549
- * <p>
550
- * Session stickiness allows the client to execute OData requests to the
551
- * same application server. This is achieved by copying a certain sticky
552
- * session header
553
- * (found in the OData response from the server) to the OData request made
554
- * by ODataWrapper, indicating the load balancer that requests should be
555
- * made against a certain application server. Once detected, the sticky
556
- * header is automatically shared by all instances of
557
- * <code>sap.ui2.srvc.ODataWrapper</code> connected to exactly the same
558
- * base URL.
559
- * </p>
560
- * <p>
561
- * NOTE: The sticky session header sent from the server always overrides
562
- * the last sticky session header requested. This is to avoid that the
563
- * feature is disabled if the load balancer returns another value for the
564
- * sticky session header for some reason (e.g. the application server goes
565
- * offline).
566
- * </p>
567
- * <p>
568
- * NOTE: In line with {@link sap.ui2.srvc.PageBuildingService}, session
569
- * stickiness is only supported in scopes different from PERS.
570
- * </p>
571
- * <p>
572
- * Currently, session stickiness is affected by the following restrictions:
573
- * <ul>
574
- * <li>If the client caches the response headers for certain requests, these
575
- * cached headers will be used instead of the headers sent from the server
576
- * (as in if cache was disabled).</li>
577
- * <li>If initial requests to different URLs that share the same base URL are
578
- * performed asynchronously (e.g. through multiple instances of
579
- * ODataWrapper), sticky session may be disabled for a part or all of these
580
- * initial requests. This is because the requests are made before the first
581
- * response with a sticky session header is obtained.</li>
582
- * <li>This mechanism only guarantees that requests are forwarded to the
583
- * specified application server. For example, if the application server in
584
- * turn contacts further load balanced servers, the session may not be
585
- * maintain and load balancing may still occur.</li>
586
- * </ul>
587
- * </p>
588
- * @public
589
- *
590
- * @since 1.30.0
591
- */
592
- this.enableStickySession = function () {
593
- sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration[sBaseUrl].enabled = true;
594
- };
595
-
596
- /**
597
- * Checks that the given callback functions are really functions. This check
598
- * is useful to "fail fast" because these callbacks are not called immediately.
599
- *
600
- * @param {function} fnSuccess
601
- * success callback
602
- * @param {function} fnFailure
603
- * error callback
604
- *
605
- * @public
606
- * @since 1.19.0
607
- */
608
- this.check = function (fnSuccess, fnFailure) {
609
- if (!fnSuccess) {
610
- throw new sap.ui2.srvc.Error("Missing success callback",
611
- "sap.ui2.srvc.ODataWrapper");
612
- }
613
- if (typeof fnSuccess !== "function") {
614
- throw new sap.ui2.srvc.Error("Success callback is not a function",
615
- "sap.ui2.srvc.ODataWrapper");
616
- }
617
- if (!fnFailure) {
618
- throw new sap.ui2.srvc.Error("Missing error callback",
619
- "sap.ui2.srvc.ODataWrapper");
620
- }
621
- if (typeof fnFailure !== "function") {
622
- throw new sap.ui2.srvc.Error("Error callback is not a function",
623
- "sap.ui2.srvc.ODataWrapper");
624
- }
625
- };
626
-
627
- /**
628
- * Wrapper around <code>OData.request</code> which is able to automatically fetch a CSRF token
629
- * if required. It uses POST as a method.
630
- *
631
- * @param {string} sRelativeUrl
632
- * a string containing the <b>relative</b> URL w.r.t. this OData wrapper's base URL, e.g.
633
- * "Products"
634
- * @param {object} oPayload
635
- * payload of the request (in intermediate format)
636
- * @param {function(object)} [fnSuccess]
637
- * callback function that is executed if the request succeeds, taking the processed data
638
- * @param {function (string, object=)} [fnFailure]
639
- * error handler taking an error message and, since version 1.28.6, an
640
- * optional object containing the complete error information as delivered
641
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
642
- * for more details.
643
- * Defaults to the OData service facade's default error handler
644
- *
645
- * @public
646
- * @since 1.19.0
647
- */
648
- this.create = function (sRelativeUrl, oPayload, fnSuccess, fnFailure) {
649
- requestOrBatch(sRelativeUrl, "POST", oPayload, fnSuccess, fnFailure);
650
- };
651
-
652
- /**
653
- * Wrapper around <code>OData.request</code> which is able to automatically fetch a CSRF token
654
- * if required. It uses DELETE as a method.
655
- *
656
- * @param {string|object} vEntity
657
- * either a string containing the <b>relative</b> URL w.r.t. this OData wrapper's base URL,
658
- * e.g. "Products(1)", or the datajs representation of the entity
659
- * @param {function()} [fnSuccess]
660
- * callback function that is executed if the request succeeds, taking no data
661
- * @param {function (string, object=)} [fnFailure]
662
- * error handler taking an error message and, since version 1.28.6, an
663
- * optional object containing the complete error information as delivered
664
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
665
- * for more details.
666
- * Defaults to the OData service facade's default error handler
667
- *
668
- * @public
669
- * @since 1.19.0
670
- */
671
- this.del = function (vEntity, fnSuccess, fnFailure) {
672
- /*jslint nomen:true */
673
- var sRelativeUrl = vEntity;
674
-
675
- if (typeof sRelativeUrl !== "string") {
676
- sRelativeUrl = toRelativeUrl(vEntity.__metadata.uri);
677
- }
678
-
679
- requestOrBatch(sRelativeUrl, "DELETE", null, function (oData) {
680
- if (fnSuccess) {
681
- // Note: try/catch already done by doRequest()
682
- fnSuccess(); // drop excess parameters (oData === undefined)
683
- }
684
- }, fnFailure);
685
- };
686
-
687
- /**
688
- * Returns the wrapper's base URL.
689
- *
690
- * @returns {string}
691
- * base URL of the OData service, e.g. "/OData/OData.svc/"
692
- *
693
- * @public
694
- * @since 1.19.0
695
- */
696
- this.getBaseUrl = function () {
697
- return sBaseUrl;
698
- };
699
-
700
- /**
701
- * Returns this wrapper's facade to an OData service (which was passed to the constructor
702
- * {@link sap.ui2.srvc.ODataWrapper}).
703
- *
704
- * @returns {sap.ui2.srvc.ODataService}
705
- * this wrapper's facade to an OData service.
706
- *
707
- * @public
708
- * @since 1.19.1
709
- */
710
- this.getODataService = function () {
711
- return oODataService;
712
- };
713
-
714
- /**
715
- * Wraps the given generic OData failure handler. It processes the raw
716
- * OData error response object, calls the given failure handler with an
717
- * error message and, since version 1.28.6, an object containing additional
718
- * technical details. If a Deferred object is given, it is rejected with
719
- * the same arguments passed to the failure handler call.
720
- *
721
- * This method logs technical information to the console if this is
722
- * available at the time the error occurs.
723
- *
724
- * @param {string} sMethod
725
- * the HTTP method used in the OData request, e.g. "POST"
726
- * @param {string} sRequestUrl
727
- * the <b>absolute</b> URL the request is sent to
728
- * @param {function (string, object=)} fnFailure
729
- * the wrapped failure handler that will be called synchronously. The
730
- * first parameter is a human-readable error message containing technical
731
- * information, including sMethod and sRequestUrl; the second parameter
732
- * is an <b>optional</b> object containing the complete error information
733
- * returned in the <code>error</code> value contained in the body of the
734
- * OData error response object, plus the HTTP response status code.
735
- *
736
- * For example, the returned error object has the following structure:
737
- * <pre>
738
- * {
739
- * httpStatus: 404,
740
- * // ... other keys and values from oError.response.body.error
741
- * }
742
- * </pre>
743
- *
744
- * Please refer to the documentation of the specific OData service used
745
- * for details about keys and values returned in
746
- * <code>oError.response.body.error</code>.<br />
747
- *
748
- * <b>IMPORTANT:</b> the second parameter may be undefined if the error
749
- * cannot be parsed or is not returned in the OData error response.<br />
750
- *
751
- * <b>NOTE:</b> the second parameter is returned since version 1.28.6.
752
- * @param {jQuery.Deferred} [oDeferred]
753
- * a <code>jQuery.Deferred</code> object that will be rejected with the
754
- * same arguments fnFailure is called
755
- * @param {object} oError
756
- * error object provided by datajs, should contain the response
757
- *
758
- * @public
759
- * @since 1.19.0
760
- */
761
- this.onError = function (sMethod, sRequestUrl, fnFailure, oDeferred, oError) {
762
- var oParsedErrorInformation,
763
- sMessage = "Error ";
764
-
765
- if (oError.response && oError.response.statusCode) {
766
- sMessage += "(" + oError.response.statusCode + ", " + oError.response.statusText + ") ";
767
- }
768
- sMessage += "in OData response for " + sMethod + ' "' + sRequestUrl + '": ' + oError.message;
769
-
770
- if (oError.response && oError.response.body) {
771
- try {
772
- oParsedErrorInformation = JSON.parse(oError.response.body).error;
773
-
774
- if (oParsedErrorInformation) {
775
- if (oParsedErrorInformation.hasOwnProperty("message") &&
776
- oParsedErrorInformation.message.hasOwnProperty("value")) {
777
- sMessage += "\nDetails: " + oParsedErrorInformation.message.value;
778
- }
779
-
780
- // NOTE: there was an agreement to not alter the data in
781
- // oError.response.body.error (except from adding the status if
782
- // it's not there already)
783
- if (oError.response.statusCode && !oParsedErrorInformation.httpStatus) {
784
- oParsedErrorInformation.httpStatus = oError.response.statusCode;
785
- }
786
- }
787
- } catch (ex) {
788
- // do not rely on subtleties of error response, treat error details as optional
789
- }
790
- }
791
-
792
- jQuery.sap.log.error(sMessage, JSON.stringify(oError.response),
793
- "sap.ui2.srvc.ODataWrapper");
794
-
795
- if (oDeferred) {
796
- oDeferred.reject(sMessage, oParsedErrorInformation);
797
- }
798
- fnFailure(sMessage, oParsedErrorInformation);
799
- };
800
-
801
- /**
802
- * Opens a new queue where all requests are parked until a call to {@link #submitBatchQueue}.
803
- *
804
- * @public
805
- * @since 1.19.0
806
- *
807
- * @see #isBatchQueueOpen
808
- * @see #submitBatchQueue
809
- */
810
- this.openBatchQueue = function () {
811
- if (aBatchQueue) {
812
- throw new sap.ui2.srvc.Error("Batch queue already open", "sap.ui2.srvc.ODataWrapper");
813
- }
814
-
815
- aBatchQueue = [];
816
- aDeferredQueue = [];
817
- bChangeSetOpen = false;
818
- };
819
-
820
- /**
821
- * Checks whether the queue of requests is already open or not
822
- *
823
- * @returns {boolean}
824
- * true if batchQueue is already open
825
- *
826
- * @public
827
- * @since 1.34.0
828
- *
829
- * @see #openBatchQueue
830
- * @see #submitBatchQueue
831
- */
832
- this.isBatchQueueOpen = function () {
833
- return !!aBatchQueue;
834
- };
835
-
836
- /**
837
- * Wrapper around
838
- * <a href="http://datajs.codeplex.com/wikipage?title=datajs%20OData%20API#OData.read">
839
- * <code>OData.read</code></a> which supports caching.
840
- *
841
- * @param {string} sRelativeUrl
842
- * a string containing the <b>relative</b> URL w.r.t. this OData wrapper's base URL, e.g.
843
- * "Products(1)"
844
- * @param {function(object)} fnSuccess
845
- * a callback function that is executed if the request succeeds, taking the processed data
846
- * @param {function (string, object=)} [fnFailure]
847
- * error handler taking an error message and, since version 1.28.6, an
848
- * optional object containing the complete error information as delivered
849
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
850
- * for more details.
851
- * Defaults to the OData service facade's default error handler
852
- * ({@link sap.ui2.srvc.ODataService#getDefaultErrorHandler})
853
- * @param {boolean} [bCache=false]
854
- * whether the response is cached for further calls (since 1.11.0) in
855
- * <code>OData.read.$cache</code>, a <code>sap.ui2.srvc.Map</code> from
856
- * <code>sRequestUrl</code> to a <code>jQuery.Deferred</code> object created on demand;
857
- * without this flag, the cache is neither written nor read!
858
- *
859
- * @public
860
- * @since 1.19.0
861
- */
862
- this.read = function (sRelativeUrl, fnSuccess, fnFailure, bCache) {
863
- var oDeferred,
864
- sRequestUrl = toRequestUrl(sRelativeUrl),
865
- sSapMessage;
866
-
867
- /*
868
- * Success handler for <code>OData.read</code>.
869
- */
870
- function success (oData, oResponse) {
871
- detectStickySession(oResponse.headers);
872
- oODataService.setCsrfToken(
873
- csrfTokenValue(oResponse.headers) || oODataService.getCsrfToken() // prefer a new token
874
- );
875
- jQuery.sap.log.debug('Received OData response for GET "' + sRequestUrl + '"', null,
876
- "sap.ui2.srvc.ODataWrapper");
877
- // The sap-message header is a Gateway feature used e.g. by the INTEROP service
878
- // It returns structured information (as XML). We don't evaluate it, we only log it.
879
- // Severity is also part of the structure, but we simply assume warning.
880
- sSapMessage = headerValue("sap-message", oResponse.headers);
881
- if (sSapMessage) {
882
- jQuery.sap.log.warning("SAP message for GET " + sRequestUrl, sSapMessage,
883
- "sap.ui2.srvc.ODataWrapper");
884
- }
885
- if (oDeferred) {
886
- // put arguments for fnSuccess into cache; clone oData first
887
- oDeferred.resolve(JSON.parse(JSON.stringify(oData)), oODataService.getCsrfToken());
888
- }
889
- // Note: drop excess parameters; try/catch
890
- sap.ui2.srvc.call(fnSuccess.bind(null, oData), fnFailure);
891
- }
892
-
893
- fnFailure = fnFailure || oODataService.getDefaultErrorHandler();
894
- this.check(fnSuccess, fnFailure);
895
-
896
- if (bCache) {
897
- OData.read.$cache = OData.read.$cache || new sap.ui2.srvc.Map();
898
- oDeferred = OData.read.$cache.get(sRequestUrl); // the promise is cached
899
- if (oDeferred) {
900
- jQuery.sap.log.debug('Using cached response for GET "' + sRequestUrl + '"', null,
901
- "sap.ui2.srvc.ODataWrapper");
902
- oDeferred.done(function (oData, sCachedCsrfToken) {
903
- // prefer our own token
904
- oODataService.setCsrfToken(oODataService.getCsrfToken() || sCachedCsrfToken);
905
- // clone cached oData before passing to success handler
906
- // Note: try/catch
907
- sap.ui2.srvc.call(fnSuccess.bind(null, JSON.parse(JSON.stringify(oData))), fnFailure);
908
- }).fail(fnFailure);
909
- return;
910
- }
911
- oDeferred = new jQuery.Deferred();
912
- OData.read.$cache.put(sRequestUrl, oDeferred.promise());
913
- }
914
-
915
- readOrBatch(
916
- sRelativeUrl,
917
- success,
918
- this.onError.bind(this, "GET", sRequestUrl, fnFailure, oDeferred)
919
- );
920
- };
921
-
922
- /**
923
- * Performs a batch request with the given payload.
924
- *
925
- * <b>Warning:</b> This bypasses the batch queue.
926
- *
927
- * @param {object} oPayload
928
- * payload of the request (in intermediate format)
929
- * @param {function(object)} [fnSuccess]
930
- * callback function that is executed if the request succeeds, taking the processed data
931
- * @param {function (string, object=)} [fnFailure]
932
- * error handler taking an error message and, since version 1.28.6, an
933
- * optional object containing the complete error information as delivered
934
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
935
- * for more details.
936
- * Defaults to the OData service facade's default error handler
937
- * @private
938
- */
939
- this.batch = function (oPayload, fnSuccess, fnFailure) {
940
- var sRequestUrl = toRequestUrl("$batch");
941
-
942
- doRequest(sRequestUrl, "POST", oPayload, fnSuccess, fnFailure, OData.batchHandler);
943
- };
944
-
945
- /**
946
- * Submits the current batch queue opened by {@link #openBatchQueue} by sending a single
947
- * "$batch" request to the OData service and deletes the current batch queue immediately.
948
- *
949
- * @param {function()} [fnBatchAccepted]
950
- * A callback function that is executed if the batch request is accepted by the
951
- * server, no matter whether individual operations fail. It will be called <b>after</b> all
952
- * success or failure handlers of individual operations.
953
- * @param {function(string, object=)} [fnBatchItselfFailed]
954
- * A callback function that is executed if the batch request itself
955
- * fails, error handler taking an error message and, since version
956
- * 1.28.6, an optional object containing the complete error information
957
- * as delivered by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
958
- * for more details.<br />
959
- *
960
- * Defaults to the OData service facade's default
961
- * error handler ({@link sap.ui2.srvc.ODataService#getDefaultErrorHandler}).<br />
962
- *
963
- * This is called <b>instead</b> of individual failure handlers in this case!
964
- *
965
- * @public
966
- * @since 1.19.0
967
- *
968
- * @see #openBatchQueue
969
- * @see #isBatchQueueOpen
970
- */
971
- this.submitBatchQueue = function (fnBatchAccepted, fnBatchItselfFailed) {
972
- /*jslint nomen:true */
973
- var aMyDeferredQueue = aDeferredQueue; // used in closure below
974
-
975
- /*
976
- * Success handler for $batch request.
977
- *
978
- * @param {object} oData
979
- */
980
- function onBatchSuccess (oData) {
981
- var iActual = oData.__batchResponses.length,
982
- iExpected = aMyDeferredQueue.length;
983
-
984
- if (iExpected !== iActual) {
985
- that.onError("POST", toRequestUrl("$batch"), fnBatchItselfFailed, /*oDeferred*/null, {
986
- message: "Protocol error! Expected " + iExpected
987
- + " responses, but received " + iActual
988
- });
989
- return;
990
- }
991
-
992
- oData.__batchResponses.forEach(function (oResponse, i) {
993
- // Note: "raw" success/failure signatures for all requests!
994
- var oDeferred = aMyDeferredQueue[i];
995
- if (oResponse.response) {
996
- // if it contains a nested response, it must be a failure
997
- reject(oDeferred, oResponse);
998
- } else if (oResponse.__changeResponses) {
999
- // successful change set
1000
- oResponse.__changeResponses.forEach(function (oChangeResponse, j) {
1001
- oDeferred[j].resolve(oChangeResponse.data, oChangeResponse);
1002
- });
1003
- } else {
1004
- // successful GET request
1005
- oDeferred.resolve(oResponse.data, oResponse);
1006
- }
1007
- });
1008
-
1009
- if (fnBatchAccepted) {
1010
- sap.ui2.srvc.call(fnBatchAccepted, oODataService.getDefaultErrorHandler());
1011
- }
1012
- }
1013
-
1014
- if (!aBatchQueue) {
1015
- throw new sap.ui2.srvc.Error("No open batch queue to submit", "sap.ui2.srvc.ODataWrapper");
1016
- }
1017
-
1018
- if (aBatchQueue.length > 0) {
1019
- this.batch({ __batchRequests: aBatchQueue }, onBatchSuccess, fnBatchItselfFailed);
1020
- } else if (fnBatchAccepted) {
1021
- // call success handler (if given) directly (async) if batchQueue is empty
1022
- sap.ui2.srvc.call(fnBatchAccepted, oODataService.getDefaultErrorHandler(), /*async=*/true);
1023
- }
1024
-
1025
- aBatchQueue = undefined;
1026
- aDeferredQueue = undefined; // be nice to the garbage collector
1027
- };
1028
-
1029
- /**
1030
- * Returns this wrapper's string representation.
1031
- *
1032
- * @param {boolean} [bVerbose=false]
1033
- * flag whether to show all properties
1034
- * @returns {string}
1035
- * this wrapper's string representation
1036
- *
1037
- * @public
1038
- * @since 1.19.0
1039
- */
1040
- this.toString = function (bVerbose) {
1041
- var aResult = ['sap.ui2.srvc.ODataWrapper({sBaseUrl:"', sBaseUrl, '"'];
1042
- // if (bVerbose) {
1043
- // }
1044
- aResult.push("})");
1045
- return aResult.join("");
1046
- };
1047
-
1048
- /** executes a put request
1049
- *
1050
- * @param {string} sRelativeUrl the relative URL to use
1051
- * @param {object} oPayload the payload
1052
- * @param {function ()} [fnSuccess]
1053
- * callback function that is executed if the request succeeds, taking no data
1054
- * @param {function (string, object=)} [fnFailure]
1055
- * error handler taking an error message and, since version 1.28.6, an
1056
- * optional object containing the complete error information as delivered
1057
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
1058
- * for more details.
1059
- * Defaults to the OData service facade's default error handler
1060
- */
1061
- this.put = function (sRelativeUrl, oPayload, fnSuccess, fnFailure) {
1062
- requestOrBatch(sRelativeUrl, "PUT", oPayload, function (oData) {
1063
- if (fnSuccess) {
1064
- // Note: try/catch already done by doRequest()
1065
- fnSuccess(); // drop excess parameters (oData === undefined)
1066
- }
1067
- }, fnFailure);
1068
- };
1069
- /**
1070
- * Generic entity update method.
1071
- *
1072
- * @param {object} oEntity
1073
- * the datajs representation of the entity
1074
- * @param {function ()} [fnSuccess]
1075
- * callback function that is executed if the request succeeds, taking no data
1076
- * @param {function (string, object=)} [fnFailure]
1077
- * error handler taking an error message and, since version 1.28.6, an
1078
- * optional object containing the complete error information as delivered
1079
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
1080
- * for more details.
1081
- * Defaults to the OData service facade's default error handler
1082
- *
1083
- * @public
1084
- * @since 1.19.0
1085
- */
1086
- this.update = function (oEntity, fnSuccess, fnFailure) {
1087
- /*jslint nomen:true */
1088
- var oPayload = {
1089
- __metadata: {
1090
- type: oEntity.__metadata && oEntity.__metadata.type
1091
- }
1092
- },
1093
- sPropertyName,
1094
- sRelativeUrl = toRelativeUrl(oEntity.__metadata.uri);
1095
-
1096
- // copy all original property values of entity into request data
1097
- for (sPropertyName in oEntity) {
1098
- if (Object.prototype.hasOwnProperty.call(oEntity, sPropertyName)
1099
- && sPropertyName.indexOf("$") !== 0
1100
- && typeof oEntity[sPropertyName] !== "object") {
1101
- oPayload[sPropertyName] = oEntity[sPropertyName];
1102
- }
1103
- }
1104
- this.put(sRelativeUrl, oPayload, fnSuccess, fnFailure);
1105
- };
1106
-
1107
- // constructor code -------------------------------------------------------
1108
- if (!sap.ui2.srvc.Map) {
1109
- fnRequire("sap.ui2.srvc.utils");
1110
- }
1111
-
1112
- // Detect old API and transform it to the current one
1113
- if (typeof oSettings === "string") {
1114
- oSettings = handleOldConstructorApi(arguments);
1115
- } else if (typeof oSettings === "object") {
1116
- // clone to ensure it is not changed afterwards
1117
- oSettings = cloneObject(oSettings);
1118
- }
1119
-
1120
- if (!oSettings || !oSettings.baseUrl || typeof oSettings.baseUrl !== "string") {
1121
- throw new sap.ui2.srvc.Error("Missing base URL", "sap.ui2.srvc.ODataWrapper");
1122
- }
1123
- if (!oODataService || typeof oODataService !== "object") {
1124
- throw new sap.ui2.srvc.Error("Missing OData service facade", "sap.ui2.srvc.ODataWrapper");
1125
- }
1126
-
1127
- // ensure that base URL has a trailing /
1128
- oSettings.baseUrl = oSettings.baseUrl.replace(/\/$/, "") + "/";
1129
-
1130
- sBaseUrl = oSettings.baseUrl;
1131
- bSupportsChangeSets = oSettings.supportsChangeSets;
1132
-
1133
- if (typeof sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration === "undefined") {
1134
- jQuery.sap.log.error("sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration is not defined!",
1135
- "the sap.ui2.srvc.ODataWrapper constructor was called before the static property was defined",
1136
- "sap.ui2.srvc.ODataWrapper");
1137
- } else if (typeof sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration[sBaseUrl] === "undefined") {
1138
- // Define the sticky session configuration for the base URL managed by
1139
- // this ODataWrapper instance.
1140
- sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration[sBaseUrl] = {
1141
- enabled: false, // sticky session disabled by default
1142
- value: undefined // the value detected if enabled = true
1143
- };
1144
- }
1145
- };
1146
-
1147
- /**
1148
- * Detects and, if needed, converts old api calls of the createODataWrapper function to the current one.
1149
- * @param {object} oArgs
1150
- * An arguments object containing the parameters of the createODataWrapper function. See createODataWrapper for details
1151
- * @returns {object}
1152
- * Settings for ODataWrapper and default failure function
1153
- * @private
1154
- */
1155
- function handleOldCreateODataWrapperApi (oArgs) {
1156
- var oSettings = {};
1157
- var oTransformedApi = {};
1158
-
1159
- oSettings.baseUrl = oArgs[0];
1160
- // These are non mandatory parameters and might be undefined
1161
- if (typeof oArgs[1] === "boolean") {
1162
- oSettings.supportsChangeSets = oArgs[1];
1163
- }
1164
- if (typeof oArgs[2] === "function") {
1165
- oTransformedApi.defaultFailure = oArgs[2];
1166
- }
1167
- oTransformedApi.settings = oSettings;
1168
-
1169
- return oTransformedApi;
1170
- }
1171
-
1172
- /**
1173
- * Clones an Object to avoid unwanted changes
1174
- * @param {object} oInputObject
1175
- * The object that needs to be cloned
1176
- * @returns {object}
1177
- * The cloned object
1178
- * @private
1179
- */
1180
- function cloneObject (oInputObject) {
1181
- if (oInputObject === undefined) {
1182
- return undefined;
1183
- }
1184
- try {
1185
- return JSON.parse(JSON.stringify(oInputObject));
1186
- } catch (e) {
1187
- return undefined;
1188
- }
1189
- }
1190
-
1191
- /*
1192
- * Configuration for sticky session is done here as it is a static property
1193
- * that should not rely on the instance initialization. Also, it may happen
1194
- * that an already defined sap.ui2.srvc.ODataWrapper name is re-assigned
1195
- * because this file is re-executed or re-loaded. Such a scenario may be
1196
- * possible if this file is required twice (after being registered to two
1197
- * different module paths).
1198
- */
1199
- if (typeof sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration === "undefined") {
1200
- sap.ui2.srvc.ODataWrapper.oStickySessionConfiguration = {};
1201
- }
1202
-
1203
- // public factory function ***************************************************
1204
-
1205
- /**
1206
- * Checks the sap-statistics setting form UI5's configuration and set it on the ODataWrapper.
1207
- * If UI5 is not available, it is checked if the sap-statistics query parameter is set.
1208
- * Note: this function is directly executed
1209
- * @param {string} getWindowLocationSearch
1210
- * value of window.location.search; to be able to test the behavior of this method with
1211
- * different search strings.
1212
- * @private
1213
- */
1214
- sap.ui2.srvc.testPublishAt(sap.ui2.srvc.ODataWrapper);
1215
- function checkSapStatisticsSetting (sWindowLocationSearch) {
1216
- try {
1217
- // read the value from UI5 as it may be set via [CTRL-SHIFT-ALT-P]
1218
- sap.ui2.srvc.ODataWrapper["sap-statistics"] =
1219
- sap.ui.getCore().getConfiguration().getStatistics();
1220
- } catch (e) {
1221
- // Read sap-statistics directly form query parameter in scenarios without UI5
1222
- sap.ui2.srvc.ODataWrapper["sap-statistics"] =
1223
- /sap-statistics=(true|x|X)/.test(sWindowLocationSearch);
1224
- }
1225
- }
1226
- // call function directly (immediate function pattern will break testPublishAt)
1227
- checkSapStatisticsSetting(window.location.search);
1228
-
1229
- /**
1230
- * Constructs and returns a {@link sap.ui2.srvc.ODataWrapper} which knows its
1231
- * {@link sap.ui2.srvc.ODataService} twin, see {@link sap.ui2.srvc.ODataWrapper#getODataService}.
1232
- *
1233
- * @param {object} oSettings
1234
- * An object containing various properties:
1235
- * <pre>
1236
- * {
1237
- * baseUrl: "/OData/OData.svc", // Mandatory base URL of the OData service
1238
- * supportsChangeSets: false, // Type: boolean, Default: false
1239
- * // Whether the OData service supports change sets with <b>multiple</b>
1240
- * // operations bundled into a single logical unit of work. Otherwise
1241
- * // each modifying operation is isolated in a change set of its own.
1242
- * "sap-language": "EN", // header which is set for all requests sent
1243
- * "sap-client": 120, // header which is set for all requests sent
1244
- * "sap-statistics": true // header which is set for all requests sent; in order to receive
1245
- * // some performance statistics
1246
- * }
1247
- * </pre>
1248
- * @param {function (string, object=)} [fnDefaultFailure]
1249
- * error handler taking an error message and, since version 1.28.6, an
1250
- * optional object containing the complete error information as delivered
1251
- * by the ODataService. See fnFailure parameter of {@link sap.ui2.srvc.ODataWrapper#onError}
1252
- * for more details.
1253
- * @returns {sap.ui2.srvc.ODataWrapper}
1254
- * new instance of ODataWapper/ODataService
1255
- *
1256
- * @public
1257
- * @since 1.19.1
1258
- */
1259
- // OLD API: function (sBaseUrl, bSupportsChangeSets, fnDefaultFailure)
1260
- sap.ui2.srvc.createODataWrapper = function (oSettings, fnDefaultFailure) {
1261
- // If old API is used we need to transform it to the current one.
1262
- if (typeof arguments[0] === "string") {
1263
- var oTransformedApi = handleOldCreateODataWrapperApi(arguments);
1264
- oSettings = oTransformedApi.settings;
1265
- if (oTransformedApi.defaultFailure) {
1266
- fnDefaultFailure = oTransformedApi.defaultFailure;
1267
- }
1268
- } else if (typeof arguments[0] === "object") {
1269
- // clone to ensure it is not changed afterwards
1270
- oSettings = cloneObject(oSettings);
1271
- }
1272
-
1273
- function Service () {
1274
- var oWrapper = new sap.ui2.srvc.ODataWrapper(oSettings, this);
1275
- fnRequire("sap.ui2.srvc.ODataService");
1276
- sap.ui2.srvc.ODataService.call(this, oWrapper, fnDefaultFailure);
1277
- return oWrapper;
1278
- }
1279
-
1280
- return new Service(); // BEWARE: this actually _returns_ the wrapper, not the service!
1281
- };
1282
- /// @end
1283
- }());