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,326 +0,0 @@
1
- import { UnviredAccountManager } from "../helper/unviredAccountManager";
2
- import { Logger } from "../helper/logger";
3
- import FrameworkHelper from "../helper/frameworkHelper";
4
- import DatabaseManager, { DatabaseType } from "../database/databaseManager";
5
-
6
- const fileName = "AttachmentHelper";
7
-
8
- export default class AttachmentHelper {
9
- private static readonly ATTACHMENT_DIR = 'Attachment/';
10
-
11
- // Helper method to create directories recursively
12
- private static async createDirectoriesRecursively(dirPath: string): Promise<string> {
13
- return new Promise((resolve, reject) => {
14
- // Split the path into parts
15
- const pathParts = dirPath.split(/[\\\/]/).filter(part => part.length > 0);
16
- let currentPath = '';
17
-
18
- // Handle Windows drive letter
19
- if (pathParts.length > 0 && pathParts[0].includes(':')) {
20
- currentPath = pathParts[0] + '/';
21
- pathParts.shift();
22
- }
23
-
24
- const createNextDirectory = (index: number) => {
25
- if (index >= pathParts.length) {
26
- // All directories created, resolve with the final path
27
- resolve(dirPath);
28
- return;
29
- }
30
-
31
- currentPath += pathParts[index] + '/';
32
-
33
- window.resolveLocalFileSystemURL(currentPath,
34
- (dirEntry) => {
35
- // Directory exists, continue to next
36
- Logger.logInfo(fileName, "createDirectoriesRecursively", "Directory exists: " + currentPath);
37
- createNextDirectory(index + 1);
38
- },
39
- (error) => {
40
- // Directory doesn't exist, create it
41
- Logger.logInfo(fileName, "createDirectoriesRecursively", "Creating directory: " + currentPath);
42
-
43
- // Get parent directory
44
- const trimmedPath = currentPath.replace(/\/$/, ''); // Remove trailing slash if present
45
- const parentPath = trimmedPath.substring(0, trimmedPath.lastIndexOf('/'));
46
- window.resolveLocalFileSystemURL(parentPath,
47
- (parentDir) => {
48
- parentDir.getDirectory(pathParts[index], { create: true },
49
- (newDir) => {
50
- Logger.logInfo(fileName, "createDirectoriesRecursively", "Directory created: " + newDir.fullPath);
51
- createNextDirectory(index + 1);
52
- },
53
- (createError) => {
54
- Logger.logError(fileName, "createDirectoriesRecursively", "Failed to create directory: " + currentPath + " Error: " + createError);
55
- reject(createError);
56
- }
57
- );
58
- },
59
- (parentError) => {
60
- Logger.logError(fileName, "createDirectoriesRecursively", "Failed to get parent directory: " + parentPath + " Error: " + parentError);
61
- reject(parentError);
62
- }
63
- );
64
- }
65
- );
66
- };
67
-
68
- createNextDirectory(0);
69
- });
70
- }
71
-
72
- static getAttachmentDirectory(): Promise<string> {
73
- return new Promise(async (resolve, reject) => {
74
- if (FrameworkHelper.getPlatform() === "electron") {
75
- const mobileUserSettings: any[] = await DatabaseManager.getInstance().select(DatabaseType.FrameworkDb, "MobileUserSettings", "keyName = 'ATTACHMENT_STORAGE_PATH'" );
76
- if (mobileUserSettings.length > 0) {
77
- const attachmentStoragePath = mobileUserSettings[0].description;
78
-
79
- // Check if the path exists, if not create directories recursively
80
- try {
81
- const pathExists = await this.fileExists(attachmentStoragePath);
82
- if (pathExists) {
83
- Logger.logInfo(fileName, "getAttachmentDirectory", "Path exists: " + attachmentStoragePath);
84
- resolve(attachmentStoragePath);
85
- } else {
86
- Logger.logInfo(fileName, "getAttachmentDirectory", "Path does not exist, creating directories: " + attachmentStoragePath);
87
- const createdPath = await this.createDirectoriesRecursively(attachmentStoragePath);
88
- resolve(createdPath);
89
- }
90
- } catch (error) {
91
- Logger.logError(fileName, "getAttachmentDirectory", "Error checking/creating path: " + error);
92
- resolve("");
93
- }
94
- return;
95
- }
96
- }
97
-
98
- const account = UnviredAccountManager.getInstance().getLastLoggedInAccount()
99
- const userDirectory = await FrameworkHelper.getFolderBasedOnUserId(account.getAccountId());
100
- const inboxDir = `${userDirectory}${AttachmentHelper.ATTACHMENT_DIR}`;
101
- window.resolveLocalFileSystemURL(inboxDir, (dir) => {
102
- Logger.logInfo(fileName, "getAttachmentDirectory", "Directory exists: " + dir.fullPath);
103
- resolve(dir.nativeURL);
104
- }, (error) => {
105
- Logger.logInfo(fileName, "getAttachmentDirectory", "Directory did not exist. Error: " + error);
106
- // Directory did not exist, so creating it.
107
- Logger.logInfo(fileName, "getAttachmentDirectory", "Directory did not exist, so creating it: " + inboxDir);
108
- window.resolveLocalFileSystemURL(userDirectory, (parentDir) => {
109
- parentDir.getDirectory(AttachmentHelper.ATTACHMENT_DIR, {create: true}, (newDir) => {
110
- Logger.logInfo(fileName, "getAttachmentDirectory", "Directory created: " + newDir.nativeURL);
111
- resolve(newDir.nativeURL);
112
- }, (error) => {
113
- Logger.logError(fileName, "getAttachmentDirectory", "Unable to create Attachment directory. Error: " + error);
114
- resolve("");
115
- })
116
- }, (error) => {
117
- Logger.logError(fileName, "getAttachmentDirectory", "Unable to get Attachment directory. Error: " + error);
118
- resolve("");
119
- })
120
- })
121
- })
122
- }
123
-
124
- static addAttachment(attachmentName: string, attachmentData: ArrayBuffer): Promise<string> {
125
- return new Promise(async (resolve, reject) => {
126
- const attachmentDir = await this.getAttachmentDirectory();
127
- window.resolveLocalFileSystemURL(attachmentDir, (dirEntry) => {
128
- dirEntry.getFile(`${attachmentName}`, { create: true }, (fileEntry) => {
129
- fileEntry.createWriter((fileWriter) => {
130
- fileWriter.onwriteend = () => {
131
- Logger.logInfo("AttachmentHelper", "addAttachment", "Write completed");
132
- resolve(fileEntry.nativeURL);
133
- };
134
- fileWriter.onerror = (e) => {
135
- Logger.logError("AttachmentHelper", "addAttachment", "Write error: " + e);
136
- reject(e);
137
- };
138
- const blob = new Blob([attachmentData]);
139
- fileWriter.write(blob);
140
- },
141
- (error) => {
142
- Logger.logError("AttachmentHelper", "addAttachment", "Create writer error: " + error);
143
- reject(error);
144
- }
145
- );
146
- },
147
- (error) => {
148
- Logger.logError("AttachmentHelper", "addAttachment", "Get file error: " + error);
149
- reject(error);
150
- });
151
- },
152
- (error) => {
153
- Logger.logError("AttachmentHelper", "addAttachment", "Resolve file system URL error: " + error);
154
- reject(error);
155
- });
156
- });
157
- }
158
-
159
- static getAttachment(attachmentName: string): Promise<ArrayBuffer> {
160
- return new Promise(async (resolve, reject) => {
161
- const attachmentDir = await this.getAttachmentDirectory();
162
- window.resolveLocalFileSystemURL(attachmentDir, (dirEntry) => {
163
- dirEntry.getFile(`${attachmentName}`, { create: false }, (fileEntry) => {
164
- fileEntry.file((file) => {
165
- const reader = new FileReader();
166
- reader.onloadend = () => {
167
- Logger.logInfo("AttachmentHelper", "getAttachment", "Read completed");
168
- resolve(reader.result as ArrayBuffer);
169
- };
170
- reader.onerror = (e) => {
171
- Logger.logError("AttachmentHelper", "getAttachment", "Read error: " + e);
172
- reject(e);
173
- };
174
- reader.readAsArrayBuffer(file);
175
- },
176
- (error) => {
177
- Logger.logError("AttachmentHelper", "getAttachment", "Get file error: " + error);
178
- reject(error);
179
- });
180
- },
181
- (error) => {
182
- Logger.logError("AttachmentHelper", "getAttachment", "Get file error: " + error);
183
- reject(error);
184
- });
185
- },
186
- error => {
187
- Logger.logError("AttachmentHelper", "getAttachment", "Resolve file system URL error: " + error);
188
- reject(error);
189
- });
190
- });
191
- }
192
-
193
- static deleteAttachment(attachmentName: string): Promise<void> {
194
- return new Promise(async (resolve, reject) => {
195
- const attachmentDir = await this.getAttachmentDirectory();
196
- window.resolveLocalFileSystemURL(attachmentDir, (dirEntry) => {
197
- dirEntry.getFile(`${attachmentName}`, { create: false }, (fileEntry) => {
198
- fileEntry.remove(() => {
199
- Logger.logInfo("AttachmentHelper", "deleteAttachment", "File removed");
200
- resolve();
201
- },
202
- (error) => {
203
- Logger.logError("AttachmentHelper", "deleteAttachment", "Remove file error: " + error);
204
- reject(error);
205
- }
206
- );
207
- },
208
- (error) => {
209
- Logger.logError("AttachmentHelper", "deleteAttachment", "Get file error: " + error);
210
- reject(error);
211
- });
212
- },
213
- (error) => {
214
- Logger.logError("AttachmentHelper", "deleteAttachment", "Resolve file system URL error: " + error);
215
- reject(error);
216
- });
217
- });
218
- }
219
-
220
- static readFileAsArrayBuffer(filePath: string): Promise<ArrayBuffer> {
221
- return new Promise((resolve, reject) => {
222
- window.resolveLocalFileSystemURL(filePath, (fileEntry) => {
223
- fileEntry.file((file) => {
224
- const reader = new FileReader();
225
- reader.onloadend = function() {
226
- Logger.logInfo("AttachmentHelper", "readFileAsArrayBuffer", "Read completed");
227
- resolve(this.result as ArrayBuffer);
228
- };
229
- reader.onerror = function(err) {
230
- Logger.logError("AttachmentHelper", "readFileAsArrayBuffer", "Read error: " + err);
231
- reject(err);
232
- };
233
- reader.readAsArrayBuffer(file);
234
- },
235
- (error) => {
236
- Logger.logError("AttachmentHelper", "readFileAsArrayBuffer", "Get file error: " + error);
237
- reject(error);
238
- });
239
- },
240
- (error) => {
241
- Logger.logError("AttachmentHelper", "readFileAsArrayBuffer", "Resolve file system URL error: " + error);
242
- reject(error);
243
- });
244
- });
245
- }
246
-
247
- static async fileExists(filePath: string): Promise<boolean> {
248
- return new Promise((resolve) => {
249
- window.resolveLocalFileSystemURL(filePath,
250
- () => resolve(true), // File exists
251
- () => resolve(false) // File doesn't exist
252
- );
253
- });
254
- }
255
-
256
- // Mainly used for electron/windows platform.
257
- static async readExternalFile(filePath: string): Promise<ArrayBuffer> {
258
- return new Promise((resolve, reject) => {
259
- window.resolveLocalFileSystemURL(filePath, (fileEntry) => {
260
- fileEntry.file((file) => {
261
- const reader = new FileReader();
262
- reader.onloadend = function() {
263
- Logger.logInfo(fileName, "readExternalFile", "Read completed");
264
- resolve(this.result as ArrayBuffer);
265
- };
266
- reader.onerror = function(err) {
267
- Logger.logError(fileName, "readExternalFile", "Read error: " + err);
268
- reject(err);
269
- };
270
- reader.readAsArrayBuffer(file);
271
- },
272
- (error) => {
273
- Logger.logError(fileName, "readExternalFile", "Get file error: " + error);
274
- reject(error);
275
- });
276
- },
277
- (error) => {
278
- Logger.logError(fileName, "readExternalFile", "Resolve file system URL error: " + error);
279
- reject(error);
280
- });
281
- });
282
- }
283
-
284
- // Mainly used for electron/windows platform.
285
- static async writeExternalFile(filePath: string, fileName: string, data: ArrayBuffer): Promise<void> {
286
- return new Promise((resolve, reject) => {
287
- window.resolveLocalFileSystemURL(filePath, (dirEntry) => {
288
- dirEntry.getFile(`${fileName}`, { create: true }, (fileEntry) => {
289
- fileEntry.createWriter((fileWriter) => {
290
- fileWriter.onwriteend = () => {
291
- Logger.logInfo("AttachmentHelper", "writeExternalFile", "Write completed");
292
- resolve();
293
- };
294
- fileWriter.onerror = (e) => {
295
- Logger.logError("AttachmentHelper", "writeExternalFile", "Write error: " + e);
296
- reject(e);
297
- };
298
- const blob = new Blob([data]);
299
- fileWriter.write(blob);
300
- },
301
- (error) => {
302
- Logger.logError("AttachmentHelper", "writeExternalFile", "Create writer error: " + error);
303
- reject(error);
304
- }
305
- );
306
- },
307
- (error) => {
308
- Logger.logError("AttachmentHelper", "writeExternalFile", "Get file error: " + error);
309
- reject(error);
310
- });
311
- },
312
- (error) => {
313
- Logger.logError("AttachmentHelper", "writeExternalFile", "Resolve file system URL error: " + error);
314
- reject(error);
315
- });
316
- })
317
- }
318
-
319
- static async getAttachmentPath(attachmentName: string): Promise<string> {
320
- return new Promise(async (resolve, reject) => {
321
- const attachmentDir = await this.getAttachmentDirectory();
322
- resolve(`${attachmentDir}${attachmentName}`);
323
- });
324
- }
325
- }
326
-
@@ -1,158 +0,0 @@
1
- import FrameworkHelper from "../helper/frameworkHelper";
2
- import { Logger } from "../helper/logger";
3
- import * as ServiceConstants from "../helper/serviceConstants";
4
- import { DatabaseManager, DatabaseType } from "../database/databaseManager";
5
- import { UnviredAccountManager } from "../helper/unviredAccountManager";
6
- import { AuthenticationService } from "../authenticationService";
7
- import { FrameworkSettingsFields, FrameworkSettingsManager } from "../helper/frameworkSettingsManager";
8
- import { ObjectStatus, SyncStatus } from "../helper/utils";
9
- import { HttpConnection } from "../helper/httpConnection";
10
- import { Status } from "../helper/status";
11
- import AttachmentHelper from "./attachmentHelper";
12
- import { kAttachmentItem, kError, NotificationListenerHelper, NotificationListnerType } from "../helper/notificationListnerHelper";
13
-
14
- const fileName = "AttachmentQHelper";
15
- export default class AttachmentQHelper {
16
- static async checkAttachmentAndQueueForAutoDownload(
17
- attachmentItemName: string, attachmentItem: any): Promise<void> {
18
- if (FrameworkHelper.getPlatform() === "browser") {
19
- await Logger.logError(fileName, "checkAttachmentAndQueueForAutoDownload", "Attachment download is not supported in Web.");
20
- return;
21
- }
22
-
23
- attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusDefault;
24
- try {
25
- await DatabaseManager.getInstance().update(DatabaseType.AppDb, attachmentItemName, attachmentItem, `${ServiceConstants.AttachmentItemFieldUid} = '${attachmentItem[ServiceConstants.AttachmentItemFieldUid]}'`);
26
- } catch (e) {
27
- await Logger.logError(
28
- "AttachmentHelper",
29
- "checkAttachmentAndQueueForAutodownload",
30
- `Error while updating the status of the attachment item. Error: ${e}`);
31
- }
32
-
33
- // Check if it is marked for auto download and queue request if required
34
- const autoDownload = attachmentItem[ServiceConstants.AttachmentItemFieldAutoDownload];
35
- if (autoDownload != null && autoDownload === "true") {
36
- const isDatabaseOperationSuccessful = await AttachmentQHelper.queueForDownload(
37
- attachmentItemName, attachmentItem, ServiceConstants.FwAttachmentAutoDownloadPriority);
38
- if (!isDatabaseOperationSuccessful) {
39
- await Logger.logError(
40
- "AttachmentHelper",
41
- "checkAttachmentAndQueueForAutodownload",
42
- "Failed to Queue Attachment Item for Download");
43
- }
44
- }
45
- }
46
-
47
- static async queueForDownload(attachmentItemName: string, attachmentItem: any, priority: number): Promise<boolean> {
48
- // In Demo Mode, Attachments cannot be queued for Download.
49
- // Therefore we log an Error Message saying that this feature is not supported in demo Mode.
50
-
51
- const demoMode = await FrameworkSettingsManager.getInstance().getFieldValue(FrameworkSettingsFields.isDemo);
52
- if (demoMode) {
53
- // Create an Error Object.
54
- attachmentItem[ServiceConstants.AttachmentItemFieldMessage] =
55
- "Downloading of attachments is not supported in demo mode.";
56
- attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] =
57
- ServiceConstants.AttachmentStatusErrorInDownload;
58
-
59
- // Update the Attachment in the Database as well.
60
- try {
61
- await DatabaseManager.getInstance().update(DatabaseType.AppDb, attachmentItemName, attachmentItem, `${ServiceConstants.AttachmentItemFieldUid} = '${attachmentItem[ServiceConstants.AttachmentItemFieldUid]}'`);
62
- } catch (e) {
63
- await Logger.logError("AttachmentHelper", "queueForDownload",
64
- `There was an error while downloading Attachments. Error: ${e}`);
65
- }
66
- const notifData = {
67
- [kAttachmentItem]: attachmentItem,
68
- [kError]: "Downloading of attachments is not supported in demo mode."
69
- }
70
- NotificationListenerHelper.postDataSenderNotification(notifData, NotificationListnerType.attachmentDownloadError);
71
- return true;
72
- }
73
- if (attachmentItem == null || Object.keys(attachmentItem).length === 0) {
74
- throw new Error("Attachment Item is null.");
75
- }
76
- await AttachmentQHelper.addAttachmentQForDownload(attachmentItemName, attachmentItem, priority);
77
- return true;
78
- }
79
-
80
- private static async addAttachmentQForDownload(attachmentItemName: string, attachmentItem: any, priority: number): Promise<void> {
81
- const structMetas = await DatabaseManager.getInstance().select(DatabaseType.FrameworkDb, "StructureMeta");
82
- //get AttachmentStructure
83
- const attachmentStructMeta = structMetas.find(
84
- (element) => element.structureName === attachmentItemName);
85
- if (!attachmentStructMeta) {
86
- await Logger.logError("AttachmentDownloader", "queueForDownload",
87
- `Structure Meta for Attachment Item (${attachmentItemName}) is not found.`);
88
- return;
89
- }
90
- //get BEHeader
91
- const headerStructMeta = structMetas.find(
92
- (element) =>
93
- element.beName === attachmentStructMeta.beName &&
94
- element.isHeader === "1");
95
- if (!headerStructMeta) {
96
- await Logger.logError("AttachmentDownloader", "queueForDownload",
97
- `Header Structure Meta for Attachment Item (${attachmentItemName}) is not found.`);
98
- return;
99
- }
100
- const timestamp = Date.now();
101
- const uid = attachmentItem[ServiceConstants.AttachmentItemFieldUid] ?? "";
102
-
103
- //create attachmentQObject and save it
104
- const attachmentQObjectData = {
105
- lid: FrameworkHelper.getUUID(),
106
- timestamp: timestamp,
107
- objectStatus: ObjectStatus.add,
108
- syncStatus: SyncStatus.none,
109
- uid: uid,
110
- beName: attachmentStructMeta.beName,
111
- beHeaderName: headerStructMeta.structureName,
112
- beAttachmentStructName: attachmentStructMeta.structureName,
113
- priority: priority,
114
- timeStamp: timestamp
115
- };
116
- await Logger.logDebug("AttachmentDownloader", "queueForDownload",
117
- `ATTACHMENT QUEUED LID ${attachmentQObjectData.lid} HEADER NAME : ${headerStructMeta.structureName} STRUCT NAME : ${attachmentStructMeta.structureName}`);
118
-
119
- try {
120
- // Add the Attachment Q Object to the Attachment Q
121
- await DatabaseManager.getInstance().insert(DatabaseType.FrameworkDb, "AttachmentQObject", attachmentQObjectData, true);
122
- } catch (e) {
123
- await Logger.logDebug("AttachmentDownloader", "queueForDownload",
124
- `ATTACHMENT QUEUE FAILED...... LID ${attachmentQObjectData.lid} HEADER NAME : ${headerStructMeta.structureName} STRUCT NAME : ${attachmentStructMeta.structureName}`);
125
- await Logger.logError("AttachmentDownloader", "queueForDownload",
126
- `Error while adding attachment Q object to the Attachment Q. Error: ${e}`);
127
- return;
128
- }
129
- //change status to queued for download
130
- attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] =
131
- ServiceConstants.AttachmentStatusQueuedForDownload;
132
-
133
- // Update the Attachment Status
134
- try {
135
- await DatabaseManager.getInstance().update(DatabaseType.AppDb, attachmentItemName, attachmentItem, `${ServiceConstants.AttachmentItemFieldUid} = '${attachmentItem[ServiceConstants.AttachmentItemFieldUid]}'`);
136
- } catch (e) {
137
- await Logger.logError("AttachmentDownloader", "queueForDownload",
138
- `DB Error while trying to mark Attachment as Queued for download. Error: ${e}`);
139
- }
140
- // call start AttachmentDownloadThread
141
- //start();
142
- }
143
-
144
- static async downloadAttachmentAndGetPath(uid: string, fileName: string): Promise<any> {
145
- const result = await new HttpConnection().downloadAttachment(uid);
146
- if (result.status === Status.ok) {
147
- const arrayBuffer = await result.arrayBuffer();
148
- const attachmentPath = await AttachmentHelper.addAttachment(fileName, arrayBuffer);
149
- return attachmentPath;
150
- } else {
151
- await Logger.logDebug("AttachmentHelper", "downloadAttachmentAndGetPath",
152
- `Failed to download attachment. Result: ${result.toString()}`);
153
- await Logger.logError("AttachmentHelper", "downloadAttachmentAndGetPath",
154
- 'Failed to download attachment.');
155
- throw result;
156
- }
157
- }
158
- }