cordova-plugin-unvired-universal-sdk 1.0.6 → 1.0.9

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 (76) hide show
  1. package/package.json +1 -1
  2. package/plugin.xml +2 -14
  3. package/www/kernel.js +38344 -1243
  4. package/aar/README.md +0 -3
  5. package/aar/Unvired_Kernel_Android.aar +0 -0
  6. package/aar/Unvired_Kernel_HTML5_Android.aar +0 -0
  7. package/src/android/build.gradle +0 -35
  8. package/src/android/xml/provider_paths.xml +0 -21
  9. package/src/browser/UnviredPluginProxy.js +0 -2430
  10. package/src/browser/bootstrap.min.js +0 -17
  11. package/src/browser/codemirror.js +0 -9755
  12. package/src/browser/jquery-3.2.1.js +0 -10253
  13. package/src/browser/sql-wasm.wasm +0 -0
  14. package/src/browser/sql.js +0 -203
  15. package/src/browser/src_index_worker_js.unvired-db-worker.js +0 -231
  16. package/src/browser/unvired-db-worker.js +0 -166
  17. package/src/browser/vendors-node_modules_comlink_dist_esm_comlink_mjs.unvired-db-worker.js +0 -22
  18. package/src/ios/AttachmentPlugin.h +0 -21
  19. package/src/ios/AttachmentPlugin.m +0 -180
  20. package/src/ios/DataStructureHelper.h +0 -28
  21. package/src/ios/DataStructureHelper.m +0 -188
  22. package/src/ios/IOSAuthPlugin.h +0 -14
  23. package/src/ios/IOSAuthPlugin.m +0 -13
  24. package/src/ios/IOSDatabasePlugin.h +0 -28
  25. package/src/ios/IOSDatabasePlugin.m +0 -253
  26. package/src/ios/IOSFWSettingsPlugin.h +0 -65
  27. package/src/ios/IOSFWSettingsPlugin.m +0 -363
  28. package/src/ios/IOSLoggerPlugin.h +0 -34
  29. package/src/ios/IOSLoggerPlugin.m +0 -198
  30. package/src/ios/IOSLoginPlugin.h +0 -29
  31. package/src/ios/IOSLoginPlugin.m +0 -480
  32. package/src/ios/IOSProxyPlugin.h +0 -21
  33. package/src/ios/IOSProxyPlugin.m +0 -172
  34. package/src/ios/IOSSyncEnginePlugin.h +0 -54
  35. package/src/ios/IOSSyncEnginePlugin.m +0 -847
  36. package/src/ios/PluginConstants.h +0 -195
  37. package/src/ios/PluginHelper.h +0 -29
  38. package/src/ios/PluginHelper.m +0 -74
  39. package/src/ios/SyncHTML5Response.h +0 -50
  40. package/src/ios/SyncHTML5Response.m +0 -68
  41. package/www/applicationMeta/applicationMetadataParser.ts +0 -285
  42. package/www/applicationMeta/fieldConstants.ts +0 -92
  43. package/www/attachment/attachmentHelper.ts +0 -326
  44. package/www/attachment/attachmentQHelper.ts +0 -158
  45. package/www/attachment/attachmentService.ts +0 -259
  46. package/www/authenticationService.ts +0 -751
  47. package/www/database/appDatabaseManager.ts +0 -54
  48. package/www/database/databaseManager.ts +0 -616
  49. package/www/helper/dbCreateTablesManager.ts +0 -354
  50. package/www/helper/frameworkHelper.ts +0 -127
  51. package/www/helper/frameworkSettingsManager.ts +0 -287
  52. package/www/helper/getMessageTimerManager.ts +0 -81
  53. package/www/helper/httpConnection.ts +0 -1051
  54. package/www/helper/logger.ts +0 -312
  55. package/www/helper/notificationListnerHelper.ts +0 -56
  56. package/www/helper/passcodeGenerator.ts +0 -61
  57. package/www/helper/reconciler.ts +0 -1062
  58. package/www/helper/serverResponseHandler.ts +0 -677
  59. package/www/helper/serviceConstants.ts +0 -254
  60. package/www/helper/settingsHelper.ts +0 -386
  61. package/www/helper/status.ts +0 -83
  62. package/www/helper/syncInputDataManager.ts +0 -205
  63. package/www/helper/unviredAccount.ts +0 -104
  64. package/www/helper/unviredAccountManager.ts +0 -120
  65. package/www/helper/urlService.ts +0 -43
  66. package/www/helper/userSettingsManager.ts +0 -172
  67. package/www/helper/utils.ts +0 -110
  68. package/www/inbox/downloadMessageService.ts +0 -270
  69. package/www/inbox/inboxHelper.ts +0 -132
  70. package/www/inbox/inboxService.ts +0 -223
  71. package/www/outbox/outboxAttachmentManager.ts +0 -152
  72. package/www/outbox/outboxHelper.ts +0 -67
  73. package/www/outbox/outboxService.ts +0 -519
  74. package/www/subtract.ts +0 -5
  75. package/www/sum.ts +0 -4
  76. package/www/syncEngine.ts +0 -687
@@ -1,847 +0,0 @@
1
- //
2
- // IOSSyncEnginePlugin.m
3
- // HTML5_KERNEL_iOS
4
- //
5
- // Created by Srinidhi Anand Rao on 03/10/12.
6
- // Copyright (c) 2012 Unvired Software India Pvt. Ltd. All rights reserved.
7
- //
8
-
9
- #import "IOSSyncEnginePlugin.h"
10
- #import "PluginConstants.h"
11
- #import "DataStructure.h"
12
- #import "DataStructureHelper.h"
13
- #import "IDataManager.h"
14
- #import "ApplicationManager.h"
15
- #import "Logger.h"
16
- #import "IOSDatabasePlugin.h"
17
- #import "SyncEngine.h"
18
- #import "IBXMLHelper.h"
19
- #import "DataRetreiverService.h"
20
- #import "OutObject.h"
21
- #import "StructureMeta.h"
22
- #import "DataNotification.h"
23
- #import "StructureMeta.h"
24
- #import "FrameworkManager.h"
25
- #import "SyncBEResponse.h"
26
- #import "ConnectionHelper.h"
27
- #import "FrameworkHelper.h"
28
- #import "FrameworkSettingsManager.h"
29
- #import "SentItems.h"
30
- #import "SyncHTML5Response.h"
31
- #import "NotificationListener.h"
32
- #import "AuthenticationService.h"
33
- #import "PluginHelper.h"
34
- #import "MessageType.h"
35
- #import "SyncEngine.h"
36
- #import "Inbox.h"
37
- #import "InfoMessage.h"
38
- #import "InboxHandler.h"
39
- #import "OutObject.h"
40
- #import "DataSender.h"
41
- #import "Reachability.h"
42
- #import "LoginParameters.h"
43
-
44
- @interface IOSSyncEnginePlugin () <NotificationListener, DataSenderDelegate, DataRetreiverMessageDelegate, InboxHandlerDelegate>
45
- @property (nonatomic, strong) NSString *dataSenderListenerCallback;
46
- @property (nonatomic, strong) NSString *syncStateListenerCallback;
47
- @end
48
-
49
- @implementation IOSSyncEnginePlugin
50
-
51
- #pragma mark - Private Methods
52
-
53
-
54
- - (NSString *)getValidCustomData:(NSString *)customData {
55
- NSError *error = NULL;
56
-
57
- [Logger loggerWithlog:LEVEL_IMPORTANT
58
- ClassName:[self class]
59
- MethodName:NSStringFromSelector(_cmd)
60
- msg:@"Checking for Valid Custom Data..."];
61
-
62
- // If Custom Data is Actually a String. Return as is.
63
- if ([customData isKindOfClass:[NSString class]]) {
64
- [Logger loggerWithlog:LEVEL_IMPORTANT
65
- ClassName:[self class]
66
- MethodName:NSStringFromSelector(_cmd)
67
- msg:@"Done.. Custom Data is Proper NSString."];
68
-
69
- return customData;
70
- }
71
-
72
- // If the Custom Data is a Dictionary or an Array convert it into a Proper Json String.
73
- if ([customData isKindOfClass:[NSDictionary class]] || [customData isKindOfClass:[NSArray class]]) {
74
- [Logger loggerWithlog:LEVEL_IMPORTANT
75
- ClassName:[self class]
76
- MethodName:NSStringFromSelector(_cmd)
77
- msg:[NSString stringWithFormat:@"Custom Data is Not a String. It is %@. Converting into JSON String.....", NSStringFromClass([customData class])]];
78
-
79
- NSData *jsoNData = [NSJSONSerialization dataWithJSONObject:customData options:0 error:&error];
80
- customData = [[NSString alloc] initWithData:jsoNData encoding:NSUTF8StringEncoding];
81
-
82
- if (customData != NULL) {
83
- [Logger loggerWithlog:LEVEL_IMPORTANT
84
- ClassName:[self class]
85
- MethodName:NSStringFromSelector(_cmd)
86
- msg:@"Done. Converted Custom Data into a JSON String."];
87
- }
88
- else {
89
- [Logger loggerWithlog:LEVEL_ERROR
90
- ClassName:[self class]
91
- MethodName:NSStringFromSelector(_cmd)
92
- msg:[NSString stringWithFormat:@"Error while Getting JSON Object. Setting Custom Data to an Empty String. Error: %@", [error localizedDescription]]];
93
- customData = @"";
94
- }
95
- }
96
-
97
- return customData;
98
- }
99
-
100
- #pragma mark - S Y N C
101
-
102
- - (void)submitInSync:(CDVInvokedUrlCommand *)command {
103
- // Has to be Run In background, Because Its a Sync Operation
104
-
105
- [self.commandDelegate runInBackground: ^{
106
- NSDictionary *dataObject;
107
- NSString *processAgentFunctionName = nil;
108
- NSError *error = NULL;
109
- NSString *customData = NULL;
110
- NSDictionary *beObject = NULL;
111
- BOOL autoSave = NO;
112
- NSDictionary *headerObject = NULL;
113
-
114
- dataObject = [command.arguments objectAtIndex:0];
115
- customData = dataObject[CUSTOM_DATA];
116
- customData = [self getValidCustomData:customData];
117
-
118
- processAgentFunctionName = dataObject[PROCESS_AGENT_FUNCTION_NAME];
119
- MESSAGE_REQUEST_TYPE requestTypeEnum = [SyncConstantsStringConversion MESAGE_REQUEST_TYPEForString:dataObject[REQUEST_TYPE]];
120
- beObject = dataObject[BE];
121
- DataStructure *headerDataStructure = NULL;
122
-
123
- // dataObject[AUTO_SAVE] type received as NSNumber which set autoSave value to 'true' always. So converted into BOOL.
124
- autoSave = [dataObject[AUTO_SAVE] boolValue];
125
-
126
- headerObject = dataObject[HEADER];
127
- if ([headerObject isKindOfClass:[NSDictionary class]]) {
128
-
129
- // We allow sending of only one Header Data Structure.
130
- NSString *headerTableName = headerObject.allKeys.firstObject;
131
- headerObject = headerObject.allValues.firstObject;
132
- headerDataStructure = [DataStructureHelper createJSDataStructure:headerObject
133
- tableName:headerTableName
134
- andIsHeader:TRUE];
135
- }
136
-
137
- SyncHTML5Response *serverResponse = (SyncHTML5Response *)[[SyncEngine sharedInstance] submitInForegroundWithRequestType:requestTypeEnum
138
- dataStructure:headerDataStructure
139
- customData:customData
140
- processAgentFunctionName:processAgentFunctionName
141
- autosave:autoSave
142
- error:&error];
143
- if (error == nil) {
144
- [self processSyncDataResponse:serverResponse callbackId:command.callbackId];
145
- }
146
- else {
147
- [PluginHelper sendListenerCallback:self.commandDelegate
148
- callbackId:command.callbackId
149
- type:error_result
150
- data:nil
151
- message:@""
152
- error:[error localizedDescription]
153
- errorDetail:@""];
154
- }
155
- }];
156
- }
157
-
158
- #pragma mark - A S Y N C
159
-
160
- - (void)submitInASync:(CDVInvokedUrlCommand *)command {
161
- [self.commandDelegate runInBackground: ^{
162
- NSDictionary *dataObject;
163
- NSString *processAgentFunctionName = nil;
164
- NSError *error = NULL;
165
- NSString *beName = NULL;
166
- NSString *beLid = NULL;
167
- NSString *customData = NULL;
168
- NSDictionary *beObject = NULL;
169
- NSDictionary *headerObject = NULL;
170
- BOOL bypassAttachment = false;
171
-
172
- dataObject = [command.arguments objectAtIndex:0];
173
- customData = dataObject[CUSTOM_DATA];
174
- customData = [self getValidCustomData:customData];
175
- processAgentFunctionName = dataObject[PROCESS_AGENT_FUNCTION_NAME];
176
- beName = dataObject[BE_NAME];
177
- MESSAGE_REQUEST_TYPE requestTypeEnum = [SyncConstantsStringConversion MESAGE_REQUEST_TYPEForString:dataObject[REQUEST_TYPE]];
178
- beObject = dataObject[BE];
179
- beLid = dataObject[BE_LID];
180
- bypassAttachment = [dataObject[BYPASS_ATTACHMENT] boolValue];
181
- DataStructure *headerDataStructure = NULL;
182
-
183
- headerObject = dataObject[HEADER];
184
- if (headerObject != nil && [headerObject isKindOfClass:[NSDictionary class]] && [headerObject count] > 0) {
185
-
186
- // We allow sending of only one Header Data Structure.
187
- NSString *headerTableName = headerObject.allKeys.firstObject;
188
- headerObject = headerObject.allValues.firstObject;
189
- headerDataStructure = [DataStructureHelper createJSDataStructure:headerObject
190
- tableName:headerTableName
191
- andIsHeader:TRUE];
192
- }
193
-
194
- BOOL status = false;
195
- if (headerDataStructure) {
196
- status = [[SyncEngine sharedInstance] submitInBackgroundWithRequestType:requestTypeEnum
197
- dataStructure:headerDataStructure
198
- customData:nil
199
- processAgentFunctionName:processAgentFunctionName
200
- bypassAttachment:bypassAttachment
201
- error:&error];
202
-
203
- }
204
- else if (customData) {
205
- status = [[SyncEngine sharedInstance] sendToServerInBackground:MESSAGE_TYPE_APPLICATION
206
- messageSubType:MESSAGE_SUBTYPE_APPLICATION_DATA_IBXML
207
- requestType:requestTypeEnum
208
- customData:customData
209
- processAgentFunctionName:processAgentFunctionName
210
- beName:beName
211
- lid:beLid
212
- bypassAttachment:bypassAttachment
213
- error:&error];
214
-
215
- }
216
-
217
- else {
218
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"Specify Either Custom Data or Data Structure" error:[error localizedDescription] errorDetail:@""];
219
- return;
220
- }
221
-
222
- if (status) {
223
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:success_result data:nil message:@"" error:@"" errorDetail:@""];
224
- }
225
- else {
226
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:[error localizedDescription] errorDetail:@""];
227
- }
228
- }];
229
- }
230
-
231
- #pragma mark - H E L P E R S
232
-
233
- - (void)lockDataSender:(CDVInvokedUrlCommand *)command {
234
- [self.commandDelegate runInBackground: ^{
235
- NSString *beLid = [command.arguments objectAtIndex:0];
236
- if (beLid == NULL || beLid.length == 0) {
237
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:success_result data:nil message:@"" error:@"" errorDetail:@""];
238
- return;
239
- }
240
- OutboxLockResult result = [[SyncEngine sharedInstance] lockDataSender:beLid];
241
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:success_result data:@(result) message:@"" error:@"" errorDetail:@""];
242
- }];
243
- }
244
-
245
- - (void)unlockDataSender:(CDVInvokedUrlCommand *)command {
246
- [self.commandDelegate runInBackground: ^{
247
- [[SyncEngine sharedInstance] unlockDataSender];
248
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:success_result data:@"" message:@"" error:@"" errorDetail:@""];
249
- }];
250
- }
251
-
252
- - (StructureMeta *)getStructureMeta:(NSString *)beName {
253
- NSError *error = NULL;
254
- StructureMeta *structureMeta = nil;
255
- NSString *whereClause = nil;
256
- ApplicationManager *applicationManager = [ApplicationManager sharedInstance];
257
-
258
- whereClause = [NSString stringWithFormat:@"%@ = '%@'", STRUCT_BE_NAME, beName];
259
- structureMeta = [applicationManager getHeaderStructureMeta:beName error:&error];
260
-
261
- return structureMeta;
262
- }
263
-
264
- - (void)notifyDataSendInMainThread:(OutObject *)outObject {
265
- NSArray *jsonArray = nil;
266
- NSError *error = NULL;
267
-
268
- // Notify only for Request Type RQST
269
- if (outObject.requestType != MESSAGE_REQUEST_TYPE_RQST) {
270
- return;
271
- }
272
-
273
- // Get the Application Manager
274
- id <IDataManager> dataManager = [[ApplicationManager sharedInstance] getDataManagerWithError:&error];
275
-
276
- if (error == nil) {
277
- StructureMeta *headerStructureMeta = [self getStructureMeta:[outObject getBEName]];
278
- NSString *tableName = [headerStructureMeta getStructName];
279
-
280
- NSString *beHeaderLid = [outObject getBE_HEADER_LID];
281
- if (beHeaderLid != NULL && beHeaderLid.length > 0) {
282
- NSString *whereClause = [NSString stringWithFormat:@"LID = '%@'", [outObject getBE_HEADER_LID]];
283
- NSArray *dataStructures = [dataManager get:tableName whereClause:whereClause error:&error];
284
-
285
- if (dataStructures && [dataStructures count] > 0) {
286
- jsonArray = [DataStructureHelper getJsonFromDataStructure:dataStructures];
287
- }
288
- }
289
- }
290
- else {
291
- [Logger loggerWithlog:LEVEL_ERROR
292
- ClassName:[self class]
293
- MethodName:NSStringFromSelector(_cmd)
294
- msg:[NSString stringWithFormat:@"Unable to retreive the Notified data. Reason: %@", [error localizedDescription]]];
295
- }
296
-
297
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:self.dataSenderListenerCallback type:data_send data:jsonArray message:@"" error:@"" errorDetail:@""];
298
- }
299
-
300
- - (void)notifyDataAttachmentDownloadSuccessInMainThread:(AttachmentItem *)attachmentItem {
301
- NSDictionary *jsonData = [FrameworkHelper getJSONDataOutput:attachmentItem];
302
- [PluginHelper sendListenerCallback:self.commandDelegate
303
- callbackId:self.dataSenderListenerCallback
304
- type:attachmentDownloadSuccess
305
- data:jsonData
306
- message:@""
307
- error:@""
308
- errorDetail:@""];
309
- }
310
-
311
- - (void)notifyDataAttachmentDownloadFailureInMainThread:(NSDictionary *)infoDictionary {
312
- AttachmentItem *attachmentItem = infoDictionary[kAttachmentItem];
313
- NSString *errorMessage = infoDictionary[kError];
314
- NSDictionary *jsonData = [FrameworkHelper getJSONDataOutput:attachmentItem];
315
- [PluginHelper sendListenerCallback:self.commandDelegate
316
- callbackId:self.dataSenderListenerCallback
317
- type:attachmentDownloadError
318
- data:jsonData
319
- message:@""
320
- error:errorMessage
321
- errorDetail:@""];
322
- }
323
-
324
- - (void)notifyDataChangeInMainThread:(NSArray *)dataNotifications {
325
- NSMutableArray *jsonArray = [[NSMutableArray alloc]init];
326
- for (DataNotification *dataNotification in dataNotifications) {
327
- NSError *error = NULL;
328
- id <IDataManager> dataManager = [[ApplicationManager sharedInstance]getDataManagerWithError:&error];
329
-
330
- StructureMeta *headerStructureMeta = [self getStructureMeta:[dataNotification beName]];
331
- NSString *tableName = [headerStructureMeta getStructName];
332
- NSString *whereClause = [NSString stringWithFormat:@"LID = '%@'", dataNotification.lid];
333
- NSArray *dataStructures = [dataManager get:tableName whereClause:whereClause error:&error];
334
-
335
- if (error == nil) {
336
- if (dataStructures && [dataStructures count] > 0) {
337
- NSArray *tempJsonArray = [DataStructureHelper getJsonFromDataStructure:dataStructures];
338
- if ([tempJsonArray count] > 0) {
339
- [jsonArray addObject:[tempJsonArray objectAtIndex:0]];
340
- }
341
- }
342
- }
343
- else {
344
- [Logger loggerWithlog:LEVEL_ERROR
345
- ClassName:[self class]
346
- MethodName:NSStringFromSelector(_cmd)
347
- msg:[NSString stringWithFormat:@"Unable to retreive the Notified data. Reason: %@", [error localizedDescription]]];
348
- }
349
- }
350
- NSMutableDictionary *notifyObject = [[NSMutableDictionary alloc]init];
351
- @try {
352
- [notifyObject setValue:DATA_RECEIVE forKey:TYPE];
353
- [notifyObject setValue:jsonArray forKey:DATA];
354
- }
355
- @catch (NSException *exception)
356
- {
357
- [Logger loggerWithlog:LEVEL_ERROR
358
- ClassName:[self class]
359
- MethodName:NSStringFromSelector(_cmd)
360
- msg:[NSString stringWithFormat:@"Unable to create notify object. Reason: %@", [exception reason]]];
361
- }
362
-
363
- [PluginHelper sendListenerCallback:self.commandDelegate
364
- callbackId:self.dataSenderListenerCallback
365
- type:data_changed
366
- data:jsonArray
367
- message:@""
368
- error:@""
369
- errorDetail:@""];
370
- }
371
-
372
- -(void)notifyJWTTokenUpdated:(NSString *)jwtToken {
373
- [PluginHelper sendListenerCallback:self.commandDelegate
374
- callbackId:self.dataSenderListenerCallback
375
- type:jwtTokenUpdated
376
- data:jwtToken
377
- message:@""
378
- error:@""
379
- errorDetail:@""];
380
- }
381
-
382
- - (id)init {
383
- self = [super init];
384
-
385
- if (self) {
386
- // Register this Class as the Notification Listener in Sync Engine
387
- [[SyncEngine sharedInstance] registerNotificationListener:self];
388
- [DataRetreiverService sharedInstance].delegate = self;
389
- [DataSender sharedInstance].delegate = self;
390
- [InboxHandler sharedInstance].delegate = self;
391
- [[NSNotificationCenter defaultCenter] addObserver:self
392
- selector:@selector(checkNetworkStatus:)
393
- name:kReachabilityChangedNotification
394
- object:nil];
395
- }
396
- return self;
397
- }
398
-
399
- #pragma mark - NotificationListener Implementation
400
-
401
- - (void)notifyInboxProcessingCompletion {
402
- [PluginHelper sendListenerCallback:self.commandDelegate
403
- callbackId:self.dataSenderListenerCallback
404
- type:incomingDataProcessingFinished
405
- data:nil
406
- message:@""
407
- error:@""
408
- errorDetail:@""];
409
- }
410
-
411
- - (void)notifyAttachmentDownloadFailure:(NSDictionary *)infoDictionary {
412
- [self performSelectorOnMainThread:@selector(notifyDataAttachmentDownloadFailureInMainThread:)
413
- withObject:infoDictionary
414
- waitUntilDone:YES];
415
- }
416
-
417
- - (void)notifyAttachmentDownloadSuccess:(AttachmentItem *)attachmentItem {
418
- [self performSelectorOnMainThread:@selector(notifyDataAttachmentDownloadSuccessInMainThread:)
419
- withObject:attachmentItem
420
- waitUntilDone:YES];
421
- }
422
-
423
- - (void)notifyDataChange:(NSArray *)dataNotifications {
424
- [self performSelectorOnMainThread:@selector(notifyDataChangeInMainThread:)
425
- withObject:dataNotifications
426
- waitUntilDone:YES];
427
- }
428
-
429
- - (void)notifyDataReceiveCompletion {
430
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:self.dataSenderListenerCallback type:data_received data:nil message:@"" error:@"" errorDetail:@""];
431
- }
432
-
433
- - (void)notifyDataSend:(OutObject *)outObject {
434
- [self performSelectorOnMainThread:@selector(notifyDataSendInMainThread:)
435
- withObject:outObject
436
- waitUntilDone:YES];
437
- }
438
-
439
- - (void)notifyServerMessages:(NSArray *)infoMessages {
440
- NSMutableArray *infoMessagesArray = [NSMutableArray array];
441
- for (InfoMessage *infoMessage in infoMessages) {
442
- NSDictionary *jsonObject = @{
443
- INFO_MESSAGE_FIELD_TYPE: [infoMessage getType]?[infoMessage getType]: @"",
444
- INFO_MESSAGE_FIELD_SUB_TYPE: [infoMessage getSubType]?[infoMessage getSubType]: @"",
445
- INFO_MESSAGE_FIELD_CATEGORY: [infoMessage getCategory]? [infoMessage getCategory]: @"",
446
- INFO_MESSAGE_FIELD_MESSAGE: [infoMessage getMessage]? [infoMessage getMessage]: @"",
447
- INFO_MESSAGE_FIELD_BE_NAME: [infoMessage getBeName]?[infoMessage getBeName]: @"",
448
- INFO_MESSAGE_FIELD_BE_LID: [infoMessage getBeLid]?[infoMessage getBeLid]: @"",
449
- INFO_MESSAGE_FIELD_MESSAGE_BLOB: [infoMessage getMessageBlob]? [infoMessage getMessageBlob]: @""
450
- };
451
- [infoMessagesArray addObject:jsonObject];
452
- }
453
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:self.dataSenderListenerCallback type:infoMessage data:infoMessagesArray message:@"" error:@"" errorDetail:@""];
454
- }
455
-
456
- - (void)notifyApplicationReset {
457
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:self.dataSenderListenerCallback type:app_reset data:nil message:@"" error:@"" errorDetail:@""];
458
- }
459
-
460
- - (void)checkNetworkStatus:(NSNotification *)notice {
461
- NetworkStatus internetStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
462
- if (internetStatus == NotReachable) {
463
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"waiting to connect"];
464
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
465
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
466
- return;
467
- }
468
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
469
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
470
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
471
-
472
- }
473
-
474
- -(void)notifyOutBoxItemDiscarded:(InfoMessage *)infoMessage {
475
- [self notifyServerMessages:@[infoMessage]];
476
- }
477
-
478
- #pragma mark - Inbox Handler Delegate
479
-
480
- - (void)inboxProcessingWithCurrentMessageIndex:(int)currentMessageIndex_
481
- andTotalMessageCount:(int)totalMsg {
482
-
483
- NSString *displayCount = [NSString stringWithFormat:@"processing (%i)", totalMsg - currentMessageIndex_ + 1];
484
-
485
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:displayCount];
486
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
487
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
488
- }
489
-
490
- - (void)didFinishInboxProcessing {
491
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
492
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
493
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
494
- }
495
-
496
- #pragma mark - DataSender Delegate
497
-
498
- - (void)didDeletedOutObjectItem {
499
- NSError *error = NULL;
500
- int count = [[Outbox sharedInstance] countWithError:&error];
501
- if (count > 0) {
502
- NSString *sendingCount = [NSString stringWithFormat:@"sending (%i)", count];
503
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:sendingCount];
504
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
505
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
506
- return;
507
- }
508
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
509
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
510
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
511
- }
512
-
513
- - (void)didFinishedSendingDataToServer {
514
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
515
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
516
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
517
- }
518
-
519
- #pragma mark - Data Retreiver Message Delegate
520
-
521
- - (void)dataRetreiverServiceExecutingWithCurrentMessageIndex: (int)currentlyProcessingMessageIndex
522
- andTotalMessageCount:(int)totalMessagesCount {
523
- NSString *displayCount = [NSString stringWithFormat:@"receiving (%i)", currentlyProcessingMessageIndex];
524
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:displayCount];
525
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
526
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
527
- }
528
-
529
- - (void)didNotReceiveAnyMessageFromServer {
530
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
531
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
532
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
533
- }
534
-
535
- - (void)didFinishedReceivingMessagesFromServer {
536
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
537
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
538
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
539
- }
540
-
541
- - (void)dataRetreiverServiceFailedWithError:(NSError *)error {
542
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
543
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
544
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
545
- }
546
-
547
- #pragma mark - Plugin Methods
548
-
549
- - (void)registerNotifListener:(CDVInvokedUrlCommand *)command {
550
- [self.commandDelegate runInBackground:^{
551
-
552
- // Register this Class as the Notification Listener in Sync Engine
553
- [[SyncEngine sharedInstance] registerNotificationListener:self];
554
-
555
- // Store the Call back ID
556
- self.dataSenderListenerCallback = command.callbackId;
557
- }];
558
- }
559
-
560
- - (void)unRegisterNotifListener:(CDVInvokedUrlCommand *)command {
561
- [self.commandDelegate runInBackground:^{
562
- // Register this Class as the Notification Listener in Sync Engine
563
- [[SyncEngine sharedInstance] registerNotificationListener:self];
564
-
565
- // Do not do anything
566
- // self.dataSenderListenerCallback = nil;
567
- }];
568
- }
569
-
570
- - (void)processSyncDataResponse:(SyncHTML5Response *)serverResponse callbackId:(NSString *)callbackId {
571
- NSError *error = NULL;
572
- NSDictionary *jsonObject = nil;
573
-
574
- // If Server Response is NULL.
575
- if (serverResponse == NULL) {
576
- [PluginHelper sendListenerCallback:self.commandDelegate
577
- callbackId:callbackId
578
- type:error_result
579
- data:nil message:@""
580
- error:NSLocalizedString(@"No response from server", nil)
581
- errorDetail:@""];
582
- return;
583
- }
584
-
585
- if ([serverResponse isKindOfClass:[SyncBEResponse class]]) {
586
-
587
- // If Server Response is FAILURE.
588
- if ([serverResponse getResponseCode] == RESPONSE_STATUS_FAILURE) {
589
- [PluginHelper sendListenerCallback:self.commandDelegate
590
- callbackId:callbackId
591
- type:error_result
592
- data:nil
593
- message:[[(SyncBEResponse *)serverResponse errorMessage] localizedDescription]
594
- error:@""
595
- errorDetail:@""];
596
- return;
597
- }
598
-
599
- // If InfoMessage but no response bytes.(e.g. Demo message)
600
- NSArray *infoMessages = ((SyncBEResponse *)serverResponse).infoMessages;
601
- if (infoMessages.count == 0) { // If Response Bytes is NULL
602
-
603
- NSData *responseBytes = ((SyncBEResponse *)serverResponse).responseBytes;
604
- if (responseBytes == NULL) {
605
- [PluginHelper sendListenerCallback:self.commandDelegate
606
- callbackId:callbackId
607
- type:error_result
608
- data:nil
609
- message:@""
610
- error:NSLocalizedString(@"Server responded with empty data", nil)
611
- errorDetail:@""];
612
- return;
613
- }
614
-
615
- jsonObject = [NSJSONSerialization JSONObjectWithData:responseBytes options:NSJSONReadingAllowFragments error:&error];
616
-
617
- if (jsonObject == nil) {
618
- [PluginHelper sendListenerCallback:self.commandDelegate
619
- callbackId:callbackId
620
- type:error_result
621
- data:nil
622
- message:@"There was an error while retreiving JSON object from the server response"
623
- error:[error localizedDescription]
624
- errorDetail:[error debugDescription]];
625
- return;
626
- }
627
-
628
- if (error == nil) {
629
- [PluginHelper sendListenerCallback:self.commandDelegate
630
- callbackId:callbackId
631
- type:success_result
632
- data:jsonObject
633
- message:@""
634
- error:[error localizedDescription]
635
- errorDetail:@""];
636
- return;
637
- }
638
- }
639
-
640
- if (infoMessages.count > 0) {
641
- BOOL isFailure = false;
642
- NSString *messageString = @"";
643
- for (InfoMessage *infoMessage in infoMessages) {
644
- [Logger loggerWithlog:LEVEL_IMPORTANT
645
- ClassName:[self class]
646
- MethodName:NSStringFromSelector(_cmd)
647
- msg:[NSString stringWithFormat:@"Found InfoMessage. Message: %@ Category: %@. Sending the Info Message Object down to the Application.", [infoMessage getMessage], [infoMessage getCategory]]];
648
-
649
- // Set the Message Type to ERROR only if the Info message is a Error.
650
- if ([[infoMessage getCategory] isEqualToString:INFO_MESSAGE_CATEGORY_FAILURE]) {
651
- isFailure = true;
652
- }
653
- messageString = [NSString stringWithFormat:@"%@%@\n",messageString,[infoMessage getMessage]];
654
- }
655
- messageString = [messageString stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
656
-
657
- [PluginHelper sendListenerCallback:self.commandDelegate
658
- callbackId:callbackId
659
- type:(isFailure ? error_result : success_result)
660
- data:jsonObject
661
- message:messageString
662
- error:[[(SyncBEResponse *)serverResponse errorMessage] localizedDescription]
663
- errorDetail:@""];
664
- }
665
- }
666
- else {
667
-
668
- NSString *serverData = [[NSString alloc] initWithData:[serverResponse responseBytes] encoding:NSUTF8StringEncoding];
669
- if (serverData.length > 0) {
670
- [PluginHelper sendListenerCallback:self.commandDelegate
671
- callbackId:callbackId
672
- type:success_result
673
- data:serverData
674
- message:@""
675
- error:@""
676
- errorDetail:@""];
677
- }
678
- else {
679
- [PluginHelper sendListenerCallback:self.commandDelegate
680
- callbackId:callbackId
681
- type:error_result
682
- data:jsonObject
683
- message:@""
684
- error:[NSString stringWithFormat:@"Invalid data returned from Server. Data Length: %lu", (unsigned long)serverResponse.responseBytes.length]
685
- errorDetail:[NSString stringWithFormat:@"Invalid data returned from Server. Data Length: %lu", (unsigned long)serverResponse.responseBytes.length]];
686
- }
687
- }
688
- }
689
-
690
- - (void)getMessages:(CDVInvokedUrlCommand *)command {
691
- [self.commandDelegate runInBackground: ^{
692
- [[DataRetreiverService sharedInstance] getMessagesInBackground];
693
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:success_result data:nil message:@"" error:@"" errorDetail:@""];
694
- }];
695
- }
696
-
697
- - (void)isInOutBox:(CDVInvokedUrlCommand *)command {
698
- [self.commandDelegate runInBackground: ^{
699
- NSString *beLid = [command.arguments objectAtIndex:0];
700
- if (beLid == NULL || beLid.length == 0) {
701
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:@"Invalid BE LID" errorDetail:@""];
702
- return;
703
- }
704
- NSError *error = NULL;
705
- BOOL isInQueue = [[Outbox sharedInstance] isInQueue:beLid error:&error];
706
- if (error != NULL) {
707
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:[error localizedDescription] errorDetail:@""];
708
- return;
709
- }
710
- NSString *result = isInQueue? @"true": @"false";
711
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:success_result data:result message:@"" error:@"" errorDetail:@""];
712
- }];
713
- }
714
-
715
- - (void)isInSentItem:(CDVInvokedUrlCommand *)command {
716
- [self.commandDelegate runInBackground: ^{
717
- NSString *beLid = [command.arguments objectAtIndex:0];
718
- if (beLid == NULL || beLid.length == 0) {
719
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:@"Invalid BE LID" errorDetail:@""];
720
- return;
721
- }
722
- NSError *error = NULL;
723
- BOOL isInQueue = [[SentItems sharedInstance] contains:beLid];
724
- if (error != NULL) {
725
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:[error localizedDescription] errorDetail:@""];
726
- return;
727
- }
728
- NSString *result = isInQueue? @"true": @"false";
729
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:success_result data:result message:@"" error:@"" errorDetail:@""];
730
- }];
731
- }
732
-
733
- - (void)outBoxItemCount:(CDVInvokedUrlCommand *)command {
734
- [self.commandDelegate runInBackground: ^{
735
- NSError *error = NULL;
736
- int count = [[Outbox sharedInstance] countWithError:&error];
737
- if (error != NULL) {
738
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:[error localizedDescription] errorDetail:@""];
739
- return;
740
- }
741
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"%d", count]];
742
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
743
- }];
744
- }
745
-
746
- - (void)sentItemCount:(CDVInvokedUrlCommand *)command {
747
- [self.commandDelegate runInBackground: ^{
748
- NSError *error = NULL;
749
- int count = [[SentItems sharedInstance] countWithError:&error];
750
- if (error != NULL) {
751
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:[error localizedDescription] errorDetail:@""];
752
- return;
753
- }
754
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"%d", count]];
755
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
756
- }];
757
- }
758
-
759
- - (void)inBoxItemCount:(CDVInvokedUrlCommand *)command {
760
- [self.commandDelegate runInBackground: ^{
761
- NSError *error = NULL;
762
- int count = [[Inbox sharedInstance] countWithError:&error];
763
- if (error != NULL) {
764
- [PluginHelper sendListenerCallback:self.commandDelegate callbackId:command.callbackId type:error_result data:nil message:@"" error:[error localizedDescription] errorDetail:@""];
765
- return;
766
- }
767
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"%d", count]];
768
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
769
- }];
770
- }
771
-
772
- - (void)getSynchronizationState:(CDVInvokedUrlCommand *)command {
773
- self.syncStateListenerCallback = command.callbackId;
774
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"idle"];
775
- [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
776
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.syncStateListenerCallback];
777
- }
778
-
779
- - (void)startInboxHandler:(CDVInvokedUrlCommand *)command {
780
- id<IDataManager> dataManager = [[FrameworkManager sharedInstance] getDataManager];
781
- NSError *error = NULL;
782
- int count = [dataManager count:@"INBOX" whereClause:NULL error:&error];
783
- if (count > 0) {
784
- [[InboxHandler sharedInstance] start];
785
- }
786
- else {
787
- [Logger loggerWithlog:LEVEL_IMPORTANT ClassName:[self class] MethodName:NSStringFromSelector(_cmd) msg:@"Not starting inbox handler thread since there are no inbox items."];
788
- }
789
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
790
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
791
- }
792
-
793
- - (void)startDataSender:(CDVInvokedUrlCommand *)command {
794
- id<IDataManager> dataManager = [[FrameworkManager sharedInstance] getDataManager];
795
- NSError *error = NULL;
796
- int count = [dataManager count:OUT_OBJECT_TABLE_NAME whereClause:NULL error:&error];
797
- if (count > 0) {
798
- [[DataSender sharedInstance] start];
799
- }
800
- else {
801
- [Logger loggerWithlog:LEVEL_IMPORTANT ClassName:[self class] MethodName:NSStringFromSelector(_cmd) msg:@"Not starting DataSender thread since there are no outbox items."];
802
- }
803
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
804
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
805
- }
806
-
807
- - (void)removeOutObjectBasedOnLid:(CDVInvokedUrlCommand *)command {
808
- [self.commandDelegate runInBackground: ^{
809
- NSDictionary *dataObject = [command.arguments objectAtIndex:0];
810
- NSString *beLid = dataObject[CUSTOM_FIELD_LID];
811
- NSError *error = nil;
812
- BOOL status = [[Outbox sharedInstance] removeBasedOnBELid:beLid error:&error];
813
- if (status) {
814
- [PluginHelper sendListenerCallback:self.commandDelegate
815
- callbackId:command.callbackId
816
- type:success_result
817
- data:nil
818
- message:@""
819
- error:@""
820
- errorDetail:@""];
821
- }
822
- else {
823
- [PluginHelper sendListenerCallback:self.commandDelegate
824
- callbackId:command.callbackId
825
- type:error_result
826
- data:nil
827
- message:@""
828
- error:[error localizedDescription]
829
- errorDetail:@""];
830
- }
831
- }];
832
- }
833
-
834
- - (void)refreshJWTToken:(CDVInvokedUrlCommand *)command {
835
- [self.commandDelegate runInBackground: ^{
836
- [[SyncEngine sharedInstance] handleJWTTokenRetrieval];
837
- [PluginHelper sendListenerCallback:self.commandDelegate
838
- callbackId:command.callbackId
839
- type:success_result
840
- data:nil
841
- message:@""
842
- error:@""
843
- errorDetail:@""];
844
- }];
845
- }
846
-
847
- @end