cordova-plugin-unvired-universal-sdk 1.0.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.
- package/README.md +59 -0
- package/aar/README.md +3 -0
- package/aar/Unvired_Kernel_Android.aar +0 -0
- package/aar/Unvired_Kernel_HTML5_Android.aar +0 -0
- package/package.json +69 -0
- package/plugin.xml +23 -0
- package/src/android/build.gradle +35 -0
- package/src/android/xml/provider_paths.xml +21 -0
- package/src/browser/UnviredPluginProxy.js +2430 -0
- package/src/browser/bootstrap.min.js +17 -0
- package/src/browser/codemirror.js +9755 -0
- package/src/browser/jquery-3.2.1.js +10253 -0
- package/src/browser/sql-wasm.wasm +0 -0
- package/src/browser/sql.js +203 -0
- package/src/browser/src_index_worker_js.unvired-db-worker.js +231 -0
- package/src/browser/unvired-db-worker.js +166 -0
- package/src/browser/vendors-node_modules_comlink_dist_esm_comlink_mjs.unvired-db-worker.js +22 -0
- package/src/ios/AttachmentPlugin.h +21 -0
- package/src/ios/AttachmentPlugin.m +180 -0
- package/src/ios/DataStructureHelper.h +28 -0
- package/src/ios/DataStructureHelper.m +188 -0
- package/src/ios/IOSAuthPlugin.h +14 -0
- package/src/ios/IOSAuthPlugin.m +13 -0
- package/src/ios/IOSDatabasePlugin.h +28 -0
- package/src/ios/IOSDatabasePlugin.m +253 -0
- package/src/ios/IOSFWSettingsPlugin.h +65 -0
- package/src/ios/IOSFWSettingsPlugin.m +363 -0
- package/src/ios/IOSLoggerPlugin.h +34 -0
- package/src/ios/IOSLoggerPlugin.m +198 -0
- package/src/ios/IOSLoginPlugin.h +29 -0
- package/src/ios/IOSLoginPlugin.m +480 -0
- package/src/ios/IOSProxyPlugin.h +21 -0
- package/src/ios/IOSProxyPlugin.m +172 -0
- package/src/ios/IOSSyncEnginePlugin.h +54 -0
- package/src/ios/IOSSyncEnginePlugin.m +847 -0
- package/src/ios/PluginConstants.h +195 -0
- package/src/ios/PluginHelper.h +29 -0
- package/src/ios/PluginHelper.m +74 -0
- package/src/ios/SyncHTML5Response.h +50 -0
- package/src/ios/SyncHTML5Response.m +68 -0
- package/www/applicationMeta/applicationMetadataParser.ts +285 -0
- package/www/applicationMeta/fieldConstants.ts +92 -0
- package/www/attachment/attachmentHelper.ts +326 -0
- package/www/attachment/attachmentQHelper.ts +158 -0
- package/www/attachment/attachmentService.ts +259 -0
- package/www/authenticationService.ts +746 -0
- package/www/bootstrap.min.js +17 -0
- package/www/codemirror.js +9755 -0
- package/www/database/appDatabaseManager.ts +54 -0
- package/www/database/databaseManager.ts +616 -0
- package/www/helper/dbCreateTablesManager.ts +354 -0
- package/www/helper/frameworkHelper.ts +127 -0
- package/www/helper/frameworkSettingsManager.ts +287 -0
- package/www/helper/getMessageTimerManager.ts +81 -0
- package/www/helper/httpConnection.ts +1051 -0
- package/www/helper/logger.ts +312 -0
- package/www/helper/notificationListnerHelper.ts +56 -0
- package/www/helper/passcodeGenerator.ts +61 -0
- package/www/helper/reconciler.ts +1062 -0
- package/www/helper/serverResponseHandler.ts +677 -0
- package/www/helper/serviceConstants.ts +254 -0
- package/www/helper/settingsHelper.ts +386 -0
- package/www/helper/status.ts +83 -0
- package/www/helper/syncInputDataManager.ts +205 -0
- package/www/helper/unviredAccount.ts +104 -0
- package/www/helper/unviredAccountManager.ts +120 -0
- package/www/helper/urlService.ts +43 -0
- package/www/helper/userSettingsManager.ts +172 -0
- package/www/helper/utils.ts +110 -0
- package/www/inbox/downloadMessageService.ts +270 -0
- package/www/inbox/inboxHelper.ts +132 -0
- package/www/inbox/inboxService.ts +223 -0
- package/www/jquery-3.2.1.js +10253 -0
- package/www/kernel.js +1380 -0
- package/www/outbox/outboxAttachmentManager.ts +152 -0
- package/www/outbox/outboxHelper.ts +67 -0
- package/www/outbox/outboxService.ts +519 -0
- package/www/sql-wasm.wasm +0 -0
- package/www/sql.js +209 -0
- package/www/subtract.ts +5 -0
- package/www/sum.ts +4 -0
- package/www/syncEngine.ts +687 -0
package/www/kernel.js
ADDED
|
@@ -0,0 +1,1380 @@
|
|
|
1
|
+
import AuthenticationService from './authenticationService';
|
|
2
|
+
import SyncEngine from './syncEngine';
|
|
3
|
+
import { DatabaseManager, DatabaseType } from './database/databaseManager';
|
|
4
|
+
import FrameworkHelper from './helper/frameworkHelper';
|
|
5
|
+
import { FrameworkSettingsFields, FrameworkSettingsManager } from './helper/frameworkSettingsManager';
|
|
6
|
+
import { Logger } from './helper/logger';
|
|
7
|
+
import { UserSettingsManager, UserSettingsFields } from './helper/userSettingsManager';
|
|
8
|
+
import OutboxService from './outbox/outboxService';
|
|
9
|
+
import { NotificationListenerHelper } from './helper/notificationListnerHelper';
|
|
10
|
+
import AttachmentHelper from './attachment/attachmentHelper';
|
|
11
|
+
import AttachmentQHelper from './attachment/attachmentQHelper';
|
|
12
|
+
import * as ServiceConstants from "./helper/serviceConstants";
|
|
13
|
+
import * as FieldConstants from './applicationMeta/fieldConstants';
|
|
14
|
+
import InboxHelper from './inbox/inboxHelper';
|
|
15
|
+
import OutBoxHelper from './outbox/outboxHelper';
|
|
16
|
+
import HttpConnection from './helper/httpConnection';
|
|
17
|
+
import SettingsHelper from './helper/settingsHelper';
|
|
18
|
+
|
|
19
|
+
var parameters;
|
|
20
|
+
|
|
21
|
+
var UMP = function () { };
|
|
22
|
+
|
|
23
|
+
var helper = function () { };
|
|
24
|
+
|
|
25
|
+
const listenerType = {
|
|
26
|
+
auth_activation_required: 0,
|
|
27
|
+
app_requires_login: 1,
|
|
28
|
+
auth_activation_success: 2,
|
|
29
|
+
auth_activation_error: 3,
|
|
30
|
+
login_success: 4,
|
|
31
|
+
login_error: 5
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* loginMode is used to check for specific parameters for different mode
|
|
36
|
+
*/
|
|
37
|
+
const loginMode = {
|
|
38
|
+
authActivate: 0,
|
|
39
|
+
authLocal: 1,
|
|
40
|
+
forgotPassword: 2,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const loginType = {
|
|
44
|
+
unvired: "UNVIRED_ID",
|
|
45
|
+
ads: "ADS",
|
|
46
|
+
sap: "SAP",
|
|
47
|
+
custom: "CUSTOM",
|
|
48
|
+
email: "EMAIL",
|
|
49
|
+
saml2: "SAML2"
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* result type in returned callbackResult
|
|
54
|
+
*/
|
|
55
|
+
const resultType = {
|
|
56
|
+
success: 0,
|
|
57
|
+
error: 1,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const requestType = {
|
|
61
|
+
RQST: "RQST",
|
|
62
|
+
PULL: "PULL",
|
|
63
|
+
PUSH: "PUSH",
|
|
64
|
+
QUERY: "QUERY",
|
|
65
|
+
REQ: "REQ"
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
UMP.prototype.loginMode = loginMode;
|
|
69
|
+
UMP.prototype.loginType = loginType;
|
|
70
|
+
UMP.prototype.resultType = resultType;
|
|
71
|
+
UMP.prototype.requestType = requestType;
|
|
72
|
+
UMP.prototype.listenerType = listenerType;
|
|
73
|
+
|
|
74
|
+
UMP.prototype.isMobile = function () {
|
|
75
|
+
if (window.cordova.platformId == 'browser') { // TODO: add condition for electron
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Mobile platform only
|
|
84
|
+
* Returns the location of the log file.
|
|
85
|
+
*/
|
|
86
|
+
UMP.prototype.getLogFilePath = function (success, fail) {
|
|
87
|
+
try {
|
|
88
|
+
// TODO: Implement this LoggerPlugin
|
|
89
|
+
success("test")
|
|
90
|
+
} catch (error) {
|
|
91
|
+
fail(error)
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Mobile platform only
|
|
97
|
+
* Returns the location of the log file.
|
|
98
|
+
*/
|
|
99
|
+
UMP.prototype.testPushNotification = function (success, fail) {
|
|
100
|
+
try {
|
|
101
|
+
// TODO: Implement this SettingsPlugin
|
|
102
|
+
success("test")
|
|
103
|
+
} catch (error) {
|
|
104
|
+
fail(error)
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Returns the current log level.
|
|
110
|
+
*/
|
|
111
|
+
UMP.prototype.getLogLevel = async function (success, fail) {
|
|
112
|
+
try {
|
|
113
|
+
const logLevel = await FrameworkSettingsManager.getInstance().getFieldValue(FrameworkSettingsFields.logLevel);
|
|
114
|
+
success(logLevel)
|
|
115
|
+
} catch (error) {
|
|
116
|
+
fail(error)
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Set the log level of the app.
|
|
122
|
+
* @param logLevel The log level to set
|
|
123
|
+
*/
|
|
124
|
+
UMP.prototype.setLogLevel = async function (logLevel, success, fail) {
|
|
125
|
+
try {
|
|
126
|
+
await SettingsHelper.setLogLevel(logLevel);
|
|
127
|
+
success(true)
|
|
128
|
+
} catch (error) {
|
|
129
|
+
fail(error)
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
UMP.prototype.logDebug = function (sourceClass, method, message) {
|
|
134
|
+
Logger.logDebug(sourceClass, method, message);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
UMP.prototype.logError = function (sourceClass, method, message) {
|
|
138
|
+
Logger.logError(sourceClass, method, message);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
UMP.prototype.logInfo = function (sourceClass, method, message) {
|
|
142
|
+
Logger.logInfo(sourceClass, method, message);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
UMP.prototype.logRead = function (success, fail) {
|
|
146
|
+
try {
|
|
147
|
+
// TODO: Implement this LoggerPlugin
|
|
148
|
+
success("")
|
|
149
|
+
} catch (error) {
|
|
150
|
+
fail(error)
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
UMP.prototype.logDelete = function () {
|
|
155
|
+
try {
|
|
156
|
+
// TODO: Implement this LoggerPlugin
|
|
157
|
+
success("")
|
|
158
|
+
} catch (error) {
|
|
159
|
+
fail(error)
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
UMP.prototype.sendLogToServer = function (success, fail) {
|
|
164
|
+
try {
|
|
165
|
+
// TODO: Implement this LoggerPlugin
|
|
166
|
+
success(true)
|
|
167
|
+
} catch (error) {
|
|
168
|
+
fail(error)
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
UMP.prototype.sendLogViaEmail = function (success, fail) {
|
|
173
|
+
try {
|
|
174
|
+
// TODO: Implement this LoggerPlugin
|
|
175
|
+
success(true)
|
|
176
|
+
} catch (error) {
|
|
177
|
+
fail(error)
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
UMP.prototype.login = async function (loginParameters, success, fail) {
|
|
182
|
+
parameters = loginParameters;
|
|
183
|
+
try {
|
|
184
|
+
console.log(document.body)
|
|
185
|
+
const result = await AuthenticationService.login(loginParameters);
|
|
186
|
+
success(result)
|
|
187
|
+
} catch (error) {
|
|
188
|
+
// Handle login failure
|
|
189
|
+
fail(error)
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
UMP.prototype.loginWithDemoData = async function (loginParameters, success, fail) {
|
|
194
|
+
parameters = loginParameters;
|
|
195
|
+
try {
|
|
196
|
+
const result = await AuthenticationService.loginWithDemoData(loginParameters);
|
|
197
|
+
// Handle successful login (optional, result might not be used)
|
|
198
|
+
success(result)
|
|
199
|
+
} catch (error) {
|
|
200
|
+
// Handle login failure
|
|
201
|
+
fail(error)
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**;
|
|
206
|
+
* logout() - Close all database and shut down all thread
|
|
207
|
+
*/
|
|
208
|
+
UMP.prototype.logout = async function (success, fail) {
|
|
209
|
+
try {
|
|
210
|
+
const result = await AuthenticationService.logout();
|
|
211
|
+
// Handle successful login (optional, result might not be used)
|
|
212
|
+
success(result)
|
|
213
|
+
} catch (error) {
|
|
214
|
+
// Handle login failure
|
|
215
|
+
fail(error)
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* authenticateAndActivate - authenticate and activate application against ump. Framework gives callback to registered LoginListener
|
|
221
|
+
* Returns response object with Type (success/failure) and message
|
|
222
|
+
*
|
|
223
|
+
* Example - ump.login.parameters.appName = "SAP_ERP_SO_TEMPLATE";
|
|
224
|
+
* ump.login.parameters.username ="TARAK";
|
|
225
|
+
* ump.login.parameters.url = "http://demo.unvired.io/UMP";
|
|
226
|
+
* ump.login.parameters.company = "UNVIRED";
|
|
227
|
+
*
|
|
228
|
+
* ump.login.authenticateAndActivate(callback(res){ });
|
|
229
|
+
*
|
|
230
|
+
* in Login listener callback check if(res.type === ump.login.listenerType.auth_success){ //Navigate to Application Home }
|
|
231
|
+
*
|
|
232
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
233
|
+
*/
|
|
234
|
+
UMP.prototype.authenticateAndActivate = async function (loginParameters, success, fail) {
|
|
235
|
+
try {
|
|
236
|
+
const result = await AuthenticationService.authenticateAndActivate(loginParameters);
|
|
237
|
+
// Handle successful login (optional, result might not be used)
|
|
238
|
+
success(result)
|
|
239
|
+
} catch (error) {
|
|
240
|
+
// Handle login failure
|
|
241
|
+
fail(error)
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* authenticateLocal - Authenticate with username,password saved in database
|
|
246
|
+
*
|
|
247
|
+
* Example - ump.login.parameters.username ="TARAK";
|
|
248
|
+
* ump.login.parameters.password = "MS123*";
|
|
249
|
+
*
|
|
250
|
+
* ump.login.authenticateLocal(callback(res){ });
|
|
251
|
+
*
|
|
252
|
+
* in Login listener callback check if(res.type === ump.login.listenerType.login_success){ //Handle login success }
|
|
253
|
+
*
|
|
254
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
255
|
+
*
|
|
256
|
+
* Mobile Only api
|
|
257
|
+
*/
|
|
258
|
+
UMP.prototype.authenticateLocal = async function (loginParameters, success, fail) {
|
|
259
|
+
try {
|
|
260
|
+
const result = await AuthenticationService.authenticateLocal(loginParameters);
|
|
261
|
+
// Handle successful login (optional, result might not be used)
|
|
262
|
+
success(result)
|
|
263
|
+
} catch (error) {
|
|
264
|
+
// Handle login failure
|
|
265
|
+
fail(error)
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* getAllAccount - Get all existing Account
|
|
270
|
+
*
|
|
271
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
272
|
+
*
|
|
273
|
+
* Mobile Only api
|
|
274
|
+
*/
|
|
275
|
+
UMP.prototype.getAllAccounts = async function (success, fail) {
|
|
276
|
+
try {
|
|
277
|
+
const result = await AuthenticationService.getAllAccounts();
|
|
278
|
+
// Handle successful login (optional, result might not be used)
|
|
279
|
+
success(result)
|
|
280
|
+
} catch (error) {
|
|
281
|
+
// Handle login failure
|
|
282
|
+
fail(error)
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* switchAccount - Switch to given Account.
|
|
287
|
+
*
|
|
288
|
+
* @param {object} account - Account to switch
|
|
289
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
290
|
+
*
|
|
291
|
+
* Mobile Only api
|
|
292
|
+
*/
|
|
293
|
+
UMP.prototype.switchAccount = async function (account, success, fail) {
|
|
294
|
+
try {
|
|
295
|
+
const result = await AuthenticationService.switchAccount(account);
|
|
296
|
+
// Handle successful login (optional, result might not be used)
|
|
297
|
+
success(result)
|
|
298
|
+
} catch (error) {
|
|
299
|
+
// Handle login failure
|
|
300
|
+
fail(error)
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* deleteAccount - Delete given Account
|
|
305
|
+
*
|
|
306
|
+
* @param {object} account - Account to switch
|
|
307
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
308
|
+
*
|
|
309
|
+
* Mobile Only api
|
|
310
|
+
*/
|
|
311
|
+
UMP.prototype.deleteAccount = async function (account, success, fail) {
|
|
312
|
+
try {
|
|
313
|
+
const result = await AuthenticationService.deleteAccount(account);
|
|
314
|
+
// Handle successful login (optional, result might not be used)
|
|
315
|
+
success(result)
|
|
316
|
+
} catch (error) {
|
|
317
|
+
// Handle login failure
|
|
318
|
+
fail(error)
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
/*
|
|
323
|
+
* setClientCredentials - Set array of client credentials
|
|
324
|
+
*/
|
|
325
|
+
UMP.prototype.setClientCredentials = async function (credentials, success, fail) {
|
|
326
|
+
try {
|
|
327
|
+
const result = await AuthenticationService.setClientCredentials(credentials);
|
|
328
|
+
// Handle successful login (optional, result might not be used)
|
|
329
|
+
success(result)
|
|
330
|
+
} catch (error) {
|
|
331
|
+
// Handle login failure
|
|
332
|
+
fail(error)
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/*
|
|
337
|
+
* isClientCredentialsSet - Returns true if client credentials already set else false
|
|
338
|
+
*/
|
|
339
|
+
UMP.prototype.isClientCredentialsSet = async function (success, fail) {
|
|
340
|
+
try {
|
|
341
|
+
const result = await AuthenticationService.isClientCredentialsSet();
|
|
342
|
+
// Handle successful login (optional, result might not be used)
|
|
343
|
+
success(result)
|
|
344
|
+
} catch (error) {
|
|
345
|
+
// Handle login failure
|
|
346
|
+
fail(error)
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* getInfoMessages - Get list of InfoMessages
|
|
352
|
+
*/
|
|
353
|
+
UMP.prototype.getInfoMessages = async function (headerName, lid, success, fail) {
|
|
354
|
+
try {
|
|
355
|
+
// TODO: Implement this SettingsPlugin
|
|
356
|
+
success([])
|
|
357
|
+
} catch (error) {
|
|
358
|
+
// Handle login failure
|
|
359
|
+
fail(error)
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* userSettings - Get current User information
|
|
364
|
+
* @param {function} callback
|
|
365
|
+
*/
|
|
366
|
+
UMP.prototype.userSettings = async function (success, fail) {
|
|
367
|
+
try {
|
|
368
|
+
var jwtToken = HttpConnection.jwtAuthToken;
|
|
369
|
+
if (jwtToken === "") {
|
|
370
|
+
jwtToken = await UserSettingsManager.getInstance().getFieldValue(UserSettingsFields.jwtToken);
|
|
371
|
+
}
|
|
372
|
+
const unviredUserId = await UserSettingsManager.getInstance().getFieldValue(UserSettingsFields.unviredUserId);
|
|
373
|
+
const unviredPassword = await UserSettingsManager.getInstance().getFieldValue(UserSettingsFields.unviredPassword);
|
|
374
|
+
const userSettings = {
|
|
375
|
+
"UNVIRED_ID": unviredUserId,
|
|
376
|
+
"USER_ID": AuthenticationService.loginParameters.username,
|
|
377
|
+
"FULL_NAME": "",
|
|
378
|
+
"EMAIL": "",
|
|
379
|
+
"SERVER_URL": AuthenticationService.loginParameters.url,
|
|
380
|
+
"SAP_USER_ID": "",
|
|
381
|
+
"SAP_PORT_NAME": "",
|
|
382
|
+
"LOGIN_TYPE": AuthenticationService.loginParameters.loginType,
|
|
383
|
+
"ADS_USER_ID": "",
|
|
384
|
+
"ADS_DOMAIN": "",
|
|
385
|
+
"UNVIRED_PASSWORD": unviredPassword,
|
|
386
|
+
"JWT_TOKEN": jwtToken
|
|
387
|
+
}
|
|
388
|
+
success({data: userSettings})
|
|
389
|
+
} catch (error) {
|
|
390
|
+
fail(error)
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* updateSystemCredentials - Save System Credentials
|
|
395
|
+
*/
|
|
396
|
+
UMP.prototype.updateSystemCredentials = function (credentials, success, fail) {
|
|
397
|
+
try {
|
|
398
|
+
// TODO: Implement this SettingsPlugin
|
|
399
|
+
success(true)
|
|
400
|
+
} catch (error) {
|
|
401
|
+
fail(error)
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
/**
|
|
405
|
+
* getSystemCredentials - Get all System Credentials
|
|
406
|
+
*/
|
|
407
|
+
UMP.prototype.getSystemCredentials = function (success, fail) {
|
|
408
|
+
try {
|
|
409
|
+
// TODO: Implement this SettingsPlugin
|
|
410
|
+
success([])
|
|
411
|
+
} catch (error) {
|
|
412
|
+
fail(error)
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Get Version Infrmation
|
|
417
|
+
*/
|
|
418
|
+
UMP.prototype.getVersionNumbers = function (success, fail) {
|
|
419
|
+
try {
|
|
420
|
+
// TODO: Implement this SettingsPlugin
|
|
421
|
+
success("")
|
|
422
|
+
} catch (error) {
|
|
423
|
+
fail(error)
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* clearData - clear application databases and files
|
|
428
|
+
*/
|
|
429
|
+
UMP.prototype.clearData = async function (success, fail) {
|
|
430
|
+
try {
|
|
431
|
+
// TODO: Implement this SettingsPlugin
|
|
432
|
+
const result = await AuthenticationService.clearData();
|
|
433
|
+
success(result)
|
|
434
|
+
} catch (error) {
|
|
435
|
+
fail(error)
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* Check for Internet connection
|
|
440
|
+
*/
|
|
441
|
+
UMP.prototype.hasInternet = function (success, fail) {
|
|
442
|
+
try {
|
|
443
|
+
// TODO: Implement this SettingsPlugin
|
|
444
|
+
success(true)
|
|
445
|
+
} catch (error) {
|
|
446
|
+
fail(error)
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* pullDb - pull database file to "temp" folder for development purpose only
|
|
452
|
+
*
|
|
453
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
454
|
+
*/
|
|
455
|
+
UMP.prototype.pullDb = function (success, fail) {
|
|
456
|
+
try {
|
|
457
|
+
// TODO: Implement this SettingsPlugin
|
|
458
|
+
success(true)
|
|
459
|
+
} catch (error) {
|
|
460
|
+
fail(error)
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* pushDB - push updated database file from "temp" folder to application directory for development purpose only
|
|
465
|
+
*
|
|
466
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
467
|
+
*/
|
|
468
|
+
UMP.prototype.pushDb = function (success, fail) {
|
|
469
|
+
try {
|
|
470
|
+
// TODO: Implement this SettingsPlugin
|
|
471
|
+
success(true)
|
|
472
|
+
} catch (error) {
|
|
473
|
+
fail(error)
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* encrypt - Get encrypted string
|
|
478
|
+
*/
|
|
479
|
+
UMP.prototype.encrypt = function (input, success, fail) {
|
|
480
|
+
try {
|
|
481
|
+
// TODO: Implement this SettingsPlugin
|
|
482
|
+
success("")
|
|
483
|
+
} catch (error) {
|
|
484
|
+
fail(error)
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* decrypt - Get decrypted string
|
|
489
|
+
*/
|
|
490
|
+
UMP.prototype.decrypt = function (input, success, fail) {
|
|
491
|
+
try {
|
|
492
|
+
// TODO: Implement this SettingsPlugin
|
|
493
|
+
success("")
|
|
494
|
+
} catch (error) {
|
|
495
|
+
fail(error)
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* encrypt - Get encrypted string
|
|
501
|
+
* @param {function} callback
|
|
502
|
+
*/
|
|
503
|
+
UMP.prototype.decrypt = function (input, success, fail) {
|
|
504
|
+
try {
|
|
505
|
+
// TODO: Implement this SettingsPlugin
|
|
506
|
+
success("")
|
|
507
|
+
} catch (error) {
|
|
508
|
+
fail(error)
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Guid
|
|
514
|
+
*/
|
|
515
|
+
UMP.prototype.guid = function () {
|
|
516
|
+
return helper.guid();
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* select - select records from table
|
|
521
|
+
*
|
|
522
|
+
* Example - ump.db.select("CUSTOMERS_RESULTS_HEADER",{'F_NAME':'TARAK','EMP_NO':'0039'},function(result){});
|
|
523
|
+
*
|
|
524
|
+
* @param {string} tableName table name
|
|
525
|
+
* @param {object} whereClause Json object contains field name-value
|
|
526
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
527
|
+
*
|
|
528
|
+
* e.g.
|
|
529
|
+
*/
|
|
530
|
+
//TODO Handle != clause
|
|
531
|
+
UMP.prototype.dbSelect = async function (tableName, whereClause, success, fail) {
|
|
532
|
+
if (typeof whereClause == 'object') {
|
|
533
|
+
whereClause = buildWhereClause(whereClause)
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
const result = await DatabaseManager.getInstance().select(DatabaseType.AppDb, tableName, whereClause);
|
|
537
|
+
success({data: result, type: resultType.success})
|
|
538
|
+
} catch (error) {
|
|
539
|
+
fail({error: error, type: resultType.error})
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* insert - insert record into table
|
|
544
|
+
* In borwser insert always insert or update based on gid
|
|
545
|
+
* Example - ump.db.insert("CUSTOMER_HEADER",{"NAME":"TARAK","NO":"0039"....},true/false,callback);
|
|
546
|
+
*
|
|
547
|
+
* @param {string} tableName table name
|
|
548
|
+
* @param {Object} structureObject - Json object contains field name-value
|
|
549
|
+
* @param {boolean} isHeader - is dataStructure a header or item?
|
|
550
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
551
|
+
*
|
|
552
|
+
*/
|
|
553
|
+
UMP.prototype.dbInsert = async function (tableName, structureObject, isHeader, success, fail) {
|
|
554
|
+
try {
|
|
555
|
+
const result = await DatabaseManager.getInstance().insert(DatabaseType.AppDb, tableName, structureObject, isHeader);
|
|
556
|
+
success({message: result, type: resultType.success})
|
|
557
|
+
} catch (error) {
|
|
558
|
+
fail({error: error, type: resultType.error})
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* insertOrUpdate - insert record or update record if exists into table
|
|
563
|
+
*
|
|
564
|
+
* Example - ump.db.insert("CUSTOMER_HEADER",{"NAME":"TARAK","NO":"0039"....},true/false,callback);
|
|
565
|
+
*
|
|
566
|
+
* @param {string} tableName table name
|
|
567
|
+
* @param {Object} structureObject - Json object contains field name-value
|
|
568
|
+
* @param {boolean} isHeader - is dataStructure a header or item?
|
|
569
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
570
|
+
*
|
|
571
|
+
*/
|
|
572
|
+
UMP.prototype.dbInsertOrUpdate = async function (tableName, structureObject, isHeader, success, fail) {
|
|
573
|
+
try {
|
|
574
|
+
const result = await DatabaseManager.getInstance().insertOrUpdate(DatabaseType.AppDb, tableName, structureObject, isHeader);
|
|
575
|
+
success({message: result, type: resultType.success})
|
|
576
|
+
} catch (error) {
|
|
577
|
+
fail({error: error, type: resultType.error})
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
/**
|
|
581
|
+
* deleteRecord - delete record entry from table
|
|
582
|
+
*
|
|
583
|
+
* Example - ump.db.deleteRecord("CUSTOMER_HEADER",{'EMP_NO':'0039'},callback);
|
|
584
|
+
*
|
|
585
|
+
* @param {string} tableName - table name
|
|
586
|
+
* @param {object} whereClause - (Optional)Json object contains field name-value
|
|
587
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
588
|
+
*/
|
|
589
|
+
UMP.prototype.dbDelete = async function (tableName, whereClause, success, fail) {
|
|
590
|
+
if (typeof whereClause == 'object') {
|
|
591
|
+
whereClause = buildWhereClause(whereClause)
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
const result = await DatabaseManager.getInstance().delete(DatabaseType.AppDb, tableName, whereClause);
|
|
595
|
+
success({message: result, type: resultType.success})
|
|
596
|
+
} catch (error) {
|
|
597
|
+
fail({error: error, type: resultType.error})
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* update - update existing record entry in table
|
|
602
|
+
*
|
|
603
|
+
* Example - ump.db.update("CUSTOMER_HEADER",{'SSN':'0097658'},{'EMP_NO':'0039'},callback);
|
|
604
|
+
*
|
|
605
|
+
* @param {string} tableName - table name
|
|
606
|
+
* @param {object} updatedObject - Json object contains only updated field name-value
|
|
607
|
+
* @param {object} whereClause - Json object contains field name-value
|
|
608
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
609
|
+
*
|
|
610
|
+
*/
|
|
611
|
+
UMP.prototype.dbUpdate = async function (tableName, updatedObject, whereClause, success, fail) {
|
|
612
|
+
if (typeof whereClause == 'object') {
|
|
613
|
+
whereClause = buildWhereClause(whereClause)
|
|
614
|
+
}
|
|
615
|
+
try {
|
|
616
|
+
const result = await DatabaseManager.getInstance().update(DatabaseType.AppDb, tableName, updatedObject, whereClause);
|
|
617
|
+
success({message: result, type: resultType.success})
|
|
618
|
+
} catch (error) {
|
|
619
|
+
fail({error: error, type: resultType.error})
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
/**
|
|
623
|
+
* executeStatement - execure raw query
|
|
624
|
+
*
|
|
625
|
+
* Example - ump.db.executeStatement("SELECT name,COUNT(*) as COUNT FROM CUSTOMERS_RESULTS_HEADER",function(result){// check result.data});
|
|
626
|
+
*
|
|
627
|
+
* @parem {string} query - complete sql query to be executed
|
|
628
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
629
|
+
*
|
|
630
|
+
* Mobile Only api
|
|
631
|
+
*/
|
|
632
|
+
UMP.prototype.dbExecuteStatement = async function (query, success, fail) {
|
|
633
|
+
try {
|
|
634
|
+
const result = await DatabaseManager.getInstance().executeStatement(DatabaseType.AppDb, query);
|
|
635
|
+
Logger.logDebug("UMP", "dbExecuteStatement", "result: " + JSON.stringify(result));
|
|
636
|
+
success({data: result, type: resultType.success})
|
|
637
|
+
} catch (error) {
|
|
638
|
+
Logger.logDebug("UMP", "dbExecuteStatement", "error: " + error);
|
|
639
|
+
fail({error: error, type: resultType.error})
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
/**
|
|
643
|
+
* createSavePoint - create a save point for db transaction
|
|
644
|
+
*/
|
|
645
|
+
UMP.prototype.dbCreateSavePoint = async function (savePoint) {
|
|
646
|
+
try {
|
|
647
|
+
await DatabaseManager.getInstance().createSavePoint(DatabaseType.AppDb, savePoint);
|
|
648
|
+
} catch (error) {
|
|
649
|
+
Logger.logError("UMP", "dbCreateSavePoint", error);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
/**
|
|
653
|
+
* releaseSavePoint - release a save point for db transaction
|
|
654
|
+
*/
|
|
655
|
+
UMP.prototype.dbReleaseSavePoint = async function (savePoint) {
|
|
656
|
+
try {
|
|
657
|
+
await DatabaseManager.getInstance().releaseSavePoint(DatabaseType.AppDb, savePoint);
|
|
658
|
+
} catch (error) {
|
|
659
|
+
Logger.logError("UMP", "dbReleaseSavePoint", error);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
/**
|
|
663
|
+
* rollbackSavePoint - rollback a save point for db transaction
|
|
664
|
+
*/
|
|
665
|
+
UMP.prototype.dbRollbackToSavePoint = async function (savePoint) {
|
|
666
|
+
try {
|
|
667
|
+
await DatabaseManager.getInstance().rollbackToSavePoint(DatabaseType.AppDb, savePoint);
|
|
668
|
+
} catch (error) {
|
|
669
|
+
Logger.logError("UMP", "dbRollbackToSavePoint", error);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
/**
|
|
673
|
+
* beginTransaction - Begin a db transaction
|
|
674
|
+
*/
|
|
675
|
+
UMP.prototype.dbBeginTransaction = async function () {
|
|
676
|
+
try {
|
|
677
|
+
await DatabaseManager.getInstance().beginTransaction(DatabaseType.AppDb);
|
|
678
|
+
} catch (error) {
|
|
679
|
+
Logger.logError("UMP", "dbBeginTransaction", error);
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* endTransaction - End a db transaction
|
|
684
|
+
*/
|
|
685
|
+
UMP.prototype.dbEndTransaction = async function () {
|
|
686
|
+
try {
|
|
687
|
+
await DatabaseManager.getInstance().endTransaction(DatabaseType.AppDb);
|
|
688
|
+
} catch (error) {
|
|
689
|
+
Logger.logError("UMP", "dbEndTransaction", error);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* dbSaveWebData - Save Web Database
|
|
695
|
+
*/
|
|
696
|
+
UMP.prototype.dbSaveWebData = function (success, fail) {
|
|
697
|
+
try {
|
|
698
|
+
// TODO: Implement this SettingsPlugin
|
|
699
|
+
success(true)
|
|
700
|
+
} catch (error) {
|
|
701
|
+
fail(error)
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* dbExportWebData - Export Web Database
|
|
707
|
+
*/
|
|
708
|
+
UMP.prototype.dbExportWebData = function (success, fail) {
|
|
709
|
+
try {
|
|
710
|
+
// TODO: Implement this SettingsPlugin
|
|
711
|
+
success("")
|
|
712
|
+
} catch (error) {
|
|
713
|
+
fail(error)
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* launchFile - Luanch file in deafult system application
|
|
719
|
+
* @param filePath File complete path
|
|
720
|
+
* @param callback (Optional) user supplied async callback / error handler
|
|
721
|
+
*/
|
|
722
|
+
UMP.prototype.launchFile = function (filePath, success, fail) {
|
|
723
|
+
try {
|
|
724
|
+
// TODO: Implement this SettingsPlugin
|
|
725
|
+
success(true)
|
|
726
|
+
} catch (error) {
|
|
727
|
+
fail(error)
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* launchBase64 - Save Base64 string in a file and luanch the file in deafult system application
|
|
732
|
+
* @param {string} base64 File content as base64 string
|
|
733
|
+
* @param {string} fileName (Optional) file name to be saves as. Default name is "Temp"
|
|
734
|
+
* @param {string} extension (Optional) file extension to be saves as. Default extension is ".pdf"
|
|
735
|
+
* @param callback (Optional) user supplied async callback / error handler
|
|
736
|
+
*/
|
|
737
|
+
UMP.prototype.launchBase64 = function (base64String, fileName, extension, success, fail) {
|
|
738
|
+
try {
|
|
739
|
+
// TODO: Implement this SettingsPlugin
|
|
740
|
+
success(true)
|
|
741
|
+
} catch (error) {
|
|
742
|
+
fail(error)
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* unzip - Unzip source file to destination path
|
|
747
|
+
* @param srcPath Source file complete path
|
|
748
|
+
* @param destPath Destination path
|
|
749
|
+
* @param callback (Optional) user supplied async callback / error handler
|
|
750
|
+
*/
|
|
751
|
+
UMP.prototype.unzip = function (srcPath, destPath, success, fail) {
|
|
752
|
+
try {
|
|
753
|
+
// TODO: Implement this SettingsPlugin
|
|
754
|
+
success(true)
|
|
755
|
+
} catch (error) {
|
|
756
|
+
fail(error)
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* getAttachmentFolderPath - Get attachment directory path
|
|
762
|
+
* Required to get complete attachment file path in iOS. cancatenate this path with file name to get complete file path
|
|
763
|
+
*/
|
|
764
|
+
UMP.prototype.getAttachmentFolderPath = async function (success, fail) {
|
|
765
|
+
try {
|
|
766
|
+
const attachmentDir = await AttachmentHelper.getAttachmentDirectory();
|
|
767
|
+
success(attachmentDir)
|
|
768
|
+
} catch (error) {
|
|
769
|
+
fail(error)
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* createAttachmentItem - Copy attachment file to application folder and insert attachment item to database with updated local path
|
|
774
|
+
* @param {string} tableName attachment item table name
|
|
775
|
+
* @param {Object} structureObject - Attachment Item Json object contains field name-value
|
|
776
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
777
|
+
*
|
|
778
|
+
*/
|
|
779
|
+
UMP.prototype.createAttachmentItem = async function (tableName, structureObject, success, fail) {
|
|
780
|
+
// Table name is required
|
|
781
|
+
if (tableName == null || tableName == "") {
|
|
782
|
+
fail("Table name is null or empty")
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// Structure object is required
|
|
787
|
+
if (structureObject == null || Object.keys(structureObject).length === 0) {
|
|
788
|
+
fail("Structure object is null or empty")
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
if (structureObject[ServiceConstants.AttachmentItemFieldFileName] == null || structureObject[ServiceConstants.AttachmentItemFieldFileName] == "") {
|
|
793
|
+
fail("File Name is null or empty")
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// if (structureObject[ServiceConstants.AttachmentItemFieldMimeType] == null || structureObject[ServiceConstants.AttachmentItemFieldMimeType] == "") {
|
|
798
|
+
// fail("MIME Type is null or empty")
|
|
799
|
+
// return;
|
|
800
|
+
// }
|
|
801
|
+
|
|
802
|
+
if (structureObject[ServiceConstants.AttachmentItemFieldLocalPath] == null || structureObject[ServiceConstants.AttachmentItemFieldLocalPath] == "") {
|
|
803
|
+
fail("Local Path is null or empty")
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
try {
|
|
808
|
+
|
|
809
|
+
const arrayBuffer = await AttachmentHelper.readFileAsArrayBuffer(structureObject[ServiceConstants.AttachmentItemFieldLocalPath]);
|
|
810
|
+
if (arrayBuffer == null) {
|
|
811
|
+
fail(`Attachment file could not be read at the location: ${structureObject[ServiceConstants.AttachmentItemFieldLocalPath]}`)
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
let attachmentName = structureObject[ServiceConstants.AttachmentItemFieldUid];
|
|
816
|
+
if (structureObject[ServiceConstants.AttachmentItemFieldFileName] != null && structureObject[ServiceConstants.AttachmentItemFieldFileName] != "") {
|
|
817
|
+
attachmentName = structureObject[ServiceConstants.AttachmentItemFieldFileName];
|
|
818
|
+
}
|
|
819
|
+
const attachmentPath = await AttachmentHelper.addAttachment(attachmentName, arrayBuffer);
|
|
820
|
+
structureObject[ServiceConstants.AttachmentItemFieldLocalPath] = attachmentPath;
|
|
821
|
+
structureObject[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusSavedForUpload;
|
|
822
|
+
await DatabaseManager.getInstance().insert(DatabaseType.AppDb, tableName, structureObject, false);
|
|
823
|
+
success({data: structureObject, type: resultType.success})
|
|
824
|
+
} catch (error) {
|
|
825
|
+
fail({type: resultType.error, error: `There was an error saving the created attachment in DB: ${error}`})
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* uploadAttachment - Upload attachment
|
|
830
|
+
* @param {string} tableName attachment item table name
|
|
831
|
+
* @param {Object} structureObject - Attachment Item Json object contains field name-value
|
|
832
|
+
* @param {boolean} isAsync - Upload attachment in Async or Sync. Default to Async
|
|
833
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
834
|
+
*
|
|
835
|
+
*/
|
|
836
|
+
UMP.prototype.uploadAttachment = function (tableName, structureObject, isAsync, success, fail) {
|
|
837
|
+
try {
|
|
838
|
+
// TODO: Implement this SettingsPlugin
|
|
839
|
+
// NOT IMPLEMENTED IN NATIVE ALSO
|
|
840
|
+
success(true)
|
|
841
|
+
} catch (error) {
|
|
842
|
+
fail(error)
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
/**
|
|
846
|
+
* downloadAttachment - Download attachment
|
|
847
|
+
* @param {string} tableName attachment item table name
|
|
848
|
+
* @param {Object} structureObject - Attachment Item Json object contains field name-value
|
|
849
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
850
|
+
*
|
|
851
|
+
*/
|
|
852
|
+
UMP.prototype.downloadAttachment = async function (tableName, structureObject, success, fail) {
|
|
853
|
+
try {
|
|
854
|
+
await AttachmentQHelper.queueForDownload(tableName, structureObject, ServiceConstants.FwAttachmentForceDownloadPriority);
|
|
855
|
+
success({data: structureObject, type: resultType.success})
|
|
856
|
+
await AttachmentService().start();
|
|
857
|
+
} catch (error) {
|
|
858
|
+
fail({type: resultType.error, error: `There was an error downloading the attachment: ${error}`})
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* submitInSync - submit data to ump server in sync mode
|
|
864
|
+
*
|
|
865
|
+
* Example - ump.sync.submitInSync(CUSTOMER_INPUT_HEADER,"","UNVIRED_CUSTOMER_SEARCH_ECC_PA_GET_CUSTOMERS", true, callback);
|
|
866
|
+
*
|
|
867
|
+
* @param {requestType} reqype - Message request type(RQST/PULL/PUSH/QUERY/REQ) to be sent to the server.
|
|
868
|
+
* @param {object} header - Header Datastructure {"Header name": {field name : field value,...}}
|
|
869
|
+
* @param {string} customData - custome data as string
|
|
870
|
+
* @param {string} paFunction - Name of the process agent that is required to be called in the server.
|
|
871
|
+
* @param {boolean} autoSave - flag to decide whether framework should save the data in databse or not.
|
|
872
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
873
|
+
*
|
|
874
|
+
*/
|
|
875
|
+
UMP.prototype.syncForeground = async function (reqype, header, customData, paFunction, autoSave, success, fail) {
|
|
876
|
+
try {
|
|
877
|
+
const result = await SyncEngine.syncForeground(reqype, header, customData == null ? "" : customData, paFunction, autoSave);
|
|
878
|
+
success(result)
|
|
879
|
+
} catch (error) {
|
|
880
|
+
fail(error)
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
/*
|
|
884
|
+
* submitDataInASync - submit data to ump server in async mode. Application will be notified through register NotificationListener callback.
|
|
885
|
+
*
|
|
886
|
+
* Example - ump.sync.submitInAsync(requestType.RQST,CUSTOMER_HEADER,"","UNVIRED_CUSTOMER_SEARCH_ECC_PA_GET_CUSTOMERS","CUSTOMER",CUSTOMER_HEADER.LID, true, callback);
|
|
887
|
+
*
|
|
888
|
+
* @param {requestType} reqType - Message request type (RQST/PULL/PUSH/QUERY) to be sent to the server.
|
|
889
|
+
* @param {object} header - Header Datastructure object {"Header name": {field name : field value,...}}
|
|
890
|
+
* @param {string} customData - custom data
|
|
891
|
+
* @param {string} paFunction - Name of the process agent that is required to be called in the server.
|
|
892
|
+
* @param {string} beName - Name of the BusinessEntity
|
|
893
|
+
* @param {string} beLid - LID of Header
|
|
894
|
+
* @param {boolean} bypassAttachment - boolean whether to ignore attachment while sending data to server
|
|
895
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
896
|
+
*/
|
|
897
|
+
UMP.prototype.syncBackground = async function (reqype, header, customData, paFunction, beName, belid, bypassAttachment, success, fail) {
|
|
898
|
+
try {
|
|
899
|
+
const result = await SyncEngine.syncBackground(reqype, header, customData == null ? "" : customData, paFunction, beName);
|
|
900
|
+
success(result)
|
|
901
|
+
} catch (error) {
|
|
902
|
+
fail(error)
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Returns an observable containing the state of the synchronisation along with count (if applicable). Possible values are as follows:
|
|
908
|
+
* 1. Sending (count) // Ex: sending(3), there are 3 items in outbox and device is online. i.e datasender thread running
|
|
909
|
+
* 2. Receiving // There are items to be received from server & device is online
|
|
910
|
+
* 3. Processing (count) // Ex: processing (5), there are 5 items in inbox and they are being processed.
|
|
911
|
+
* 4. Waiting to connect // The device is offline & there are items in outbox
|
|
912
|
+
* 5. Idle // there is no synchronisation activity going on.
|
|
913
|
+
*/
|
|
914
|
+
UMP.prototype.getSynchronizationState = function (success, fail) {
|
|
915
|
+
NotificationListenerHelper.synchronizationStateListener = success;
|
|
916
|
+
NotificationListenerHelper.synchronizationStateListener("idle")
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* For Mobile platform only
|
|
921
|
+
* Starts Inbox handler if there are items in inbox.
|
|
922
|
+
*/
|
|
923
|
+
UMP.prototype.startInboxHandler = function (success, fail) {
|
|
924
|
+
InboxService.getInstance().start();
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* For Mobile platform only
|
|
929
|
+
* Starts Data sender if there are items in outbox
|
|
930
|
+
*/
|
|
931
|
+
UMP.prototype.startDataSender = function (success, fail) {
|
|
932
|
+
OutboxService.getInstance().start();
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* getMessages - Request for downloading messages in ready state from server and will be notified through Notification Listener
|
|
937
|
+
*
|
|
938
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
939
|
+
*
|
|
940
|
+
* Mobile Only api
|
|
941
|
+
*/
|
|
942
|
+
UMP.prototype.getMessages = function () {
|
|
943
|
+
SyncEngine.getMessages();
|
|
944
|
+
};
|
|
945
|
+
/**
|
|
946
|
+
* registerNotificationListener - Register for callback on GetMessage status
|
|
947
|
+
*
|
|
948
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
949
|
+
*
|
|
950
|
+
* Mobile Only api
|
|
951
|
+
*/
|
|
952
|
+
UMP.prototype.registerNotifListener = function (success, fail) {
|
|
953
|
+
NotificationListenerHelper.dataSenderListener = success;
|
|
954
|
+
};
|
|
955
|
+
/**
|
|
956
|
+
* unRegisterNotificationListener - UnRegister for callback on GetMessage status
|
|
957
|
+
*
|
|
958
|
+
* @param {function} callback - (Optional) user supplied async callback / error handler
|
|
959
|
+
*
|
|
960
|
+
* Mobile Only api
|
|
961
|
+
*/
|
|
962
|
+
UMP.prototype.unRegisterNotifListener = function () {
|
|
963
|
+
NotificationListenerHelper.dataSenderListener = null;
|
|
964
|
+
};
|
|
965
|
+
/**
|
|
966
|
+
* isInOutbox - Check whether BE is already in OutBox or not.
|
|
967
|
+
*
|
|
968
|
+
* @param {string} beLid - LID of BE Header
|
|
969
|
+
*
|
|
970
|
+
* returns true/false
|
|
971
|
+
*/
|
|
972
|
+
UMP.prototype.isInOutBox = async function (beLid, success, fail) {
|
|
973
|
+
try {
|
|
974
|
+
const outObject = await OutBoxHelper.checkIsInOutBox(beLid);
|
|
975
|
+
success(outObject !== null);
|
|
976
|
+
} catch (error) {
|
|
977
|
+
fail(error);
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
/**
|
|
981
|
+
* outBoxItemCount - Get count of items in OutBox
|
|
982
|
+
*
|
|
983
|
+
* returns count
|
|
984
|
+
*/
|
|
985
|
+
UMP.prototype.outBoxItemCount = async function (success, fail) {
|
|
986
|
+
try {
|
|
987
|
+
const count = await DatabaseManager.getInstance().count(DatabaseType.FrameworkDb, "OutObject");
|
|
988
|
+
success(count);
|
|
989
|
+
} catch (error) {
|
|
990
|
+
fail(error);
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
/**
|
|
994
|
+
* isInSentItem - Check whether BE is already in SentItem or not.
|
|
995
|
+
*
|
|
996
|
+
* @param {string} beLid - LID of BE Header
|
|
997
|
+
*
|
|
998
|
+
* returns true/false
|
|
999
|
+
*/
|
|
1000
|
+
UMP.prototype.isInSentItem = async function (beLid, success, fail) {
|
|
1001
|
+
try {
|
|
1002
|
+
const sentItem = await OutBoxHelper.checkIsInSentItems(beLid);
|
|
1003
|
+
success(sentItem !== null);
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
fail(error);
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
/**
|
|
1009
|
+
* sentItemCount - Get count of items in Sentitem
|
|
1010
|
+
*
|
|
1011
|
+
* returns count
|
|
1012
|
+
*/
|
|
1013
|
+
UMP.prototype.sentItemCount = async function (success, fail) {
|
|
1014
|
+
try {
|
|
1015
|
+
const count = await DatabaseManager.getInstance().count(DatabaseType.FrameworkDb, "SentItems");
|
|
1016
|
+
success(count);
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
fail(error);
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
/**
|
|
1022
|
+
* inBoxItemCount - Get count of items in InBox
|
|
1023
|
+
*
|
|
1024
|
+
* returns count
|
|
1025
|
+
*/
|
|
1026
|
+
UMP.prototype.inBoxItemCount = async function (success, fail) {
|
|
1027
|
+
try {
|
|
1028
|
+
const count = await DatabaseManager.getInstance().count(DatabaseType.FrameworkDb, "InObject");
|
|
1029
|
+
success(count);
|
|
1030
|
+
} catch (error) {
|
|
1031
|
+
fail(error);
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* deleteOutBoxEntry - Delete BE from OutBox.
|
|
1036
|
+
*
|
|
1037
|
+
* @param {string} beLid - LID of BE Header
|
|
1038
|
+
*
|
|
1039
|
+
* returns true/false
|
|
1040
|
+
*/
|
|
1041
|
+
UMP.prototype.deleteOutBoxEntry = async function (beLid, success, fail) {
|
|
1042
|
+
try {
|
|
1043
|
+
const result = await OutBoxHelper.deleteOutBoxEntry(beLid);
|
|
1044
|
+
success(result);
|
|
1045
|
+
} catch (error) {
|
|
1046
|
+
fail(error);
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* registerForPushNotification - Register for browser push
|
|
1052
|
+
* Response types - open, error and message
|
|
1053
|
+
*/
|
|
1054
|
+
UMP.prototype.registerForPushNotification = function (success, fail) {
|
|
1055
|
+
try {
|
|
1056
|
+
// TODO: Implement this SettingsPlugin
|
|
1057
|
+
success(true)
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
fail(error)
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
/**
|
|
1064
|
+
* resetApplicationSyncData - Reset application Sync related data(OutObject,SentItemObject,InObject,AttachmentOutObject,AttachmentQObject,Attachment folder).
|
|
1065
|
+
*/
|
|
1066
|
+
UMP.prototype.resetApplicationSyncData = function (success, fail) {
|
|
1067
|
+
try {
|
|
1068
|
+
// TODO: Implement this SettingsPlugin
|
|
1069
|
+
success(true)
|
|
1070
|
+
} catch (error) {
|
|
1071
|
+
fail(error)
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
UMP.prototype.generateUBJson = function (headerName, header, itemName, items, success, fail) {
|
|
1076
|
+
try {
|
|
1077
|
+
// TODO: Implement this SettingsPlugin
|
|
1078
|
+
success(true)
|
|
1079
|
+
} catch (error) {
|
|
1080
|
+
fail(error)
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
|
|
1084
|
+
UMP.prototype.parseRawUBJson = function (json, sucess, fail) {
|
|
1085
|
+
try {
|
|
1086
|
+
// TODO: Implement this SettingsPlugin
|
|
1087
|
+
success(true)
|
|
1088
|
+
} catch (error) {
|
|
1089
|
+
fail(error)
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
UMP.prototype.lockDataSender = async function (beLid, success, fail) {
|
|
1094
|
+
try {
|
|
1095
|
+
const result = await SyncEngine.lockDataSender(beLid);
|
|
1096
|
+
success(result)
|
|
1097
|
+
} catch (error) {
|
|
1098
|
+
fail(error)
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
UMP.prototype.unlockDataSender = async function (success, fail) {
|
|
1103
|
+
try {
|
|
1104
|
+
const result = await SyncEngine.unlockDataSender();
|
|
1105
|
+
success(result)
|
|
1106
|
+
} catch (error) {
|
|
1107
|
+
fail(error)
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
UMP.prototype.dbReload = function (sucess, fail) {
|
|
1112
|
+
try {
|
|
1113
|
+
// TODO: Implement this SettingsPlugin
|
|
1114
|
+
success(true)
|
|
1115
|
+
} catch (error) {
|
|
1116
|
+
fail(error)
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
UMP.prototype.reCreateAppDB = function (success, fail) {
|
|
1120
|
+
try {
|
|
1121
|
+
// TODO: Implement this SettingsPlugin
|
|
1122
|
+
success(true)
|
|
1123
|
+
} catch (error) {
|
|
1124
|
+
fail(error)
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
UMP.prototype.platform = function (success, fail) {
|
|
1129
|
+
try {
|
|
1130
|
+
const result = FrameworkHelper.getPlatform();
|
|
1131
|
+
success(result)
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
fail(error)
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
UMP.prototype.removeOutObjectBasedOnLid = function (lid, success, fail) {
|
|
1138
|
+
try {
|
|
1139
|
+
// TODO: Implement this SettingsPlugin
|
|
1140
|
+
success(true)
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
fail(error)
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
UMP.prototype.startDiscoveryService = function (timeout, success, fail) {
|
|
1147
|
+
try {
|
|
1148
|
+
// TODO: Implement this SettingsPlugin
|
|
1149
|
+
success("")
|
|
1150
|
+
} catch (error) {
|
|
1151
|
+
fail(error)
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Refresh JWT Token. THe updated JWT Token would be sent through the NotificationListener methods.
|
|
1157
|
+
* @param {*} success Success Callback
|
|
1158
|
+
* @param {*} fail Failure Callback
|
|
1159
|
+
*/
|
|
1160
|
+
UMP.prototype.refreshJWTToken = function (success, fail) {
|
|
1161
|
+
try {
|
|
1162
|
+
// TODO: Implement this SettingsPlugin
|
|
1163
|
+
success("")
|
|
1164
|
+
} catch (error) {
|
|
1165
|
+
fail(error)
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Set JWT Token.
|
|
1171
|
+
* @param {string} token JWT Token
|
|
1172
|
+
* @param {*} success Success Callback
|
|
1173
|
+
* @param {*} fail Failure Callback
|
|
1174
|
+
*/
|
|
1175
|
+
UMP.prototype.setJWTToken = function (token, success, fail) {
|
|
1176
|
+
HttpConnection.jwtAuthToken = token;
|
|
1177
|
+
UserSettingsManager.getInstance().setFieldValue(UserSettingsFields.jwtToken, token);
|
|
1178
|
+
success(true)
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* Get UMP request configuration with authentication headers
|
|
1183
|
+
* @param {string} endpoint - The API endpoint
|
|
1184
|
+
* @param {Object} [options] - Optional configuration object
|
|
1185
|
+
* @param {string} [options.customUrl] - Optional custom base URL to override server URL
|
|
1186
|
+
* @param {function} success - Success callback
|
|
1187
|
+
* @param {function} fail - Failure callback
|
|
1188
|
+
*
|
|
1189
|
+
* Example -
|
|
1190
|
+
*
|
|
1191
|
+
* // with auth api
|
|
1192
|
+
* ump.getUMPRequestConfig("/auth/getmodel/tenex/tenex_model.json", function (config) {
|
|
1193
|
+
* console.log(config); // https://sandbox.unvired.io/auth/getmodel/tenex/tenex_model.json
|
|
1194
|
+
* }, function (error) {
|
|
1195
|
+
* console.error(error);
|
|
1196
|
+
* });
|
|
1197
|
+
*
|
|
1198
|
+
* // with rest api end point
|
|
1199
|
+
* // variation: 1
|
|
1200
|
+
* ump.getUMPRequestConfig("/api/v1/users", function (config) {
|
|
1201
|
+
* console.log(config); // https://sandbox.unvired.io/UMP/api/v1/users
|
|
1202
|
+
* }, function (error) {
|
|
1203
|
+
* console.error(error);
|
|
1204
|
+
* });
|
|
1205
|
+
*
|
|
1206
|
+
* // variation: 2
|
|
1207
|
+
* ump.getUMPRequestConfig("/UMP/api/v1/users", function (config) {
|
|
1208
|
+
* console.log(config); // https://sandbox.unvired.io/UMP/api/v1/users
|
|
1209
|
+
* }, function (error) {
|
|
1210
|
+
* console.error(error);
|
|
1211
|
+
* });
|
|
1212
|
+
*/
|
|
1213
|
+
UMP.prototype.getUMPRequestConfig = function (endpoint, success, fail) {
|
|
1214
|
+
|
|
1215
|
+
// Sanitize the input.
|
|
1216
|
+
if (!endpoint) {
|
|
1217
|
+
endpoint = '';
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
this.userSettings(function (settings) {
|
|
1221
|
+
let url = settings.data.SERVER_URL;
|
|
1222
|
+
let md5Password = settings.data.UNVIRED_PASSWORD;
|
|
1223
|
+
let jwtToken = settings.data.JWT_TOKEN;
|
|
1224
|
+
let unviredId = settings.data.UNVIRED_ID;
|
|
1225
|
+
|
|
1226
|
+
// Remove trailing UMP or UMP/ from url if present
|
|
1227
|
+
url = url.replace(/\/UMP\//, '');
|
|
1228
|
+
url = url.replace(/\/UMP$/, '');
|
|
1229
|
+
|
|
1230
|
+
// Remove leading slash from endpoint if present
|
|
1231
|
+
endpoint = endpoint.replace(/^\/+/, '');
|
|
1232
|
+
|
|
1233
|
+
// Add a special case for api endpoints
|
|
1234
|
+
// always prefix with UMP/
|
|
1235
|
+
if (endpoint.startsWith("API/")) {
|
|
1236
|
+
endpoint = 'UMP/' + endpoint
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
let authHeader = "";
|
|
1240
|
+
if (unviredId && unviredId.length > 0 && md5Password && md5Password.length > 0) {
|
|
1241
|
+
authHeader = `Basic ${window.btoa(parameters.company + "\\" + unviredId + ":" + md5Password)}`;
|
|
1242
|
+
}
|
|
1243
|
+
else if (jwtToken && jwtToken.length > 0) {
|
|
1244
|
+
authHeader = `Bearer ${jwtToken}`;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
if (authHeader.length == 0) {
|
|
1248
|
+
console.error("No valid authentication headers found");
|
|
1249
|
+
fail("No valid authentication headers found: userId: " + unviredId + ", md5Password: " + md5Password + ", jwtToken: " + jwtToken);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
let requestConfig = {
|
|
1254
|
+
url: `${url}/${endpoint}`,
|
|
1255
|
+
headers: {
|
|
1256
|
+
Authorization: authHeader
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
success(requestConfig);
|
|
1261
|
+
|
|
1262
|
+
}, function (error) {
|
|
1263
|
+
fail(error);
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
helper.isEmpty = function (value) {
|
|
1268
|
+
if (value == undefined || value === null || value === "") return true;
|
|
1269
|
+
return false;
|
|
1270
|
+
};
|
|
1271
|
+
helper.validateLoginParameters = function (mode, callback) {
|
|
1272
|
+
if (this.isEmpty(parameters.loginType)) {
|
|
1273
|
+
this.sendError("No Login Type specified in LoginParameters!", callback);
|
|
1274
|
+
return false;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
if (parameters.loginType === loginType.sap || parameters.loginType === loginType.ads) {
|
|
1278
|
+
if (!parameters.domain) {
|
|
1279
|
+
this.sendError("Please provide Domain!", callback);
|
|
1280
|
+
return false;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
if (this.isEmpty(mode)) {
|
|
1284
|
+
this.sendError("Please set Login Mode!", callback);
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
var err = undefined;
|
|
1288
|
+
switch (mode) {
|
|
1289
|
+
case loginMode.authActivate:
|
|
1290
|
+
|
|
1291
|
+
if (parameters.loginType == loginType.saml2) {
|
|
1292
|
+
if (this.isEmpty(parameters.url)) err = "Please provide Url!";
|
|
1293
|
+
else if (this.isEmpty(parameters.company)) err = "Please provide Company Name!";
|
|
1294
|
+
else if (this.isEmpty(parameters.redirectURL)) err = "Please provide SAML redirect URL!";
|
|
1295
|
+
break;
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
if (this.isEmpty(parameters.url)) err = "Please provide Url!";
|
|
1299
|
+
else if (this.isEmpty(parameters.company)) err = "Please provide Company Name!";
|
|
1300
|
+
else if (this.isEmpty(parameters.username)) err = "Please provide User Id!";
|
|
1301
|
+
else if (this.isEmpty(parameters.password)) err = "Please provide Password!";
|
|
1302
|
+
}
|
|
1303
|
+
if (err) {
|
|
1304
|
+
this.sendError(err, callback);
|
|
1305
|
+
return false;
|
|
1306
|
+
}
|
|
1307
|
+
break;
|
|
1308
|
+
case loginMode.authLocal:
|
|
1309
|
+
if (this.isEmpty(parameters.username)) err = "Please provide User Id!";
|
|
1310
|
+
else if (this.isEmpty(parameters.password)) err = "Please provide Password!";
|
|
1311
|
+
if (err) {
|
|
1312
|
+
this.sendError(err, callback);
|
|
1313
|
+
return false;
|
|
1314
|
+
}
|
|
1315
|
+
break;
|
|
1316
|
+
case loginMode.forgotPassword:
|
|
1317
|
+
break;
|
|
1318
|
+
}
|
|
1319
|
+
return true;
|
|
1320
|
+
};
|
|
1321
|
+
helper.guid = function () {
|
|
1322
|
+
function s4() {
|
|
1323
|
+
return Math.floor((1 + Math.random()) * 0x10000)
|
|
1324
|
+
.toString(16)
|
|
1325
|
+
.substring(1)
|
|
1326
|
+
.toUpperCase();
|
|
1327
|
+
}
|
|
1328
|
+
return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Clear loki databases
|
|
1333
|
+
*/
|
|
1334
|
+
helper.clearLokiDbs = function () {
|
|
1335
|
+
localStorage.removeItem("APP_LOKI_DB");
|
|
1336
|
+
localStorage.removeItem("FW_LOKI_DB");
|
|
1337
|
+
localStorage.removeItem(login.parameters.appName);
|
|
1338
|
+
webDb.appDb = null;
|
|
1339
|
+
webDb.fwDb = null;
|
|
1340
|
+
};
|
|
1341
|
+
|
|
1342
|
+
helper.sendError = function (msg, callback) {
|
|
1343
|
+
var cbResult = {};
|
|
1344
|
+
cbResult.type = resultType.error;
|
|
1345
|
+
cbResult.error = msg;
|
|
1346
|
+
callback(cbResult);
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
helper.sanitizeUMPURL = function (url) {
|
|
1350
|
+
if (!url) {
|
|
1351
|
+
return "";
|
|
1352
|
+
}
|
|
1353
|
+
if (url.endsWith("/UMP") || url.endsWith("/UMP/") || url.endsWith("?local")) {
|
|
1354
|
+
return url;
|
|
1355
|
+
}
|
|
1356
|
+
return url + "/UMP";
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
function buildWhereClause(conditions) {
|
|
1360
|
+
if (!conditions || Object.keys(conditions).length === 0) {
|
|
1361
|
+
return '';
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
return Object.entries(conditions)
|
|
1365
|
+
.map(([key, value]) => {
|
|
1366
|
+
// Handle null values
|
|
1367
|
+
if (value === null) {
|
|
1368
|
+
return `${key} IS NULL`;
|
|
1369
|
+
}
|
|
1370
|
+
// Handle string values (add quotes)
|
|
1371
|
+
if (typeof value === 'string') {
|
|
1372
|
+
return `${key} = '${value}'`;
|
|
1373
|
+
}
|
|
1374
|
+
// Handle numbers and other types
|
|
1375
|
+
return `${key} = ${value}`;
|
|
1376
|
+
})
|
|
1377
|
+
.join(' AND ');
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
module.exports = new UMP();
|