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.
- package/package.json +1 -1
- package/plugin.xml +2 -14
- package/www/kernel.js +38344 -1243
- package/aar/README.md +0 -3
- package/aar/Unvired_Kernel_Android.aar +0 -0
- package/aar/Unvired_Kernel_HTML5_Android.aar +0 -0
- package/src/android/build.gradle +0 -35
- package/src/android/xml/provider_paths.xml +0 -21
- package/src/browser/UnviredPluginProxy.js +0 -2430
- package/src/browser/bootstrap.min.js +0 -17
- package/src/browser/codemirror.js +0 -9755
- package/src/browser/jquery-3.2.1.js +0 -10253
- package/src/browser/sql-wasm.wasm +0 -0
- package/src/browser/sql.js +0 -203
- package/src/browser/src_index_worker_js.unvired-db-worker.js +0 -231
- package/src/browser/unvired-db-worker.js +0 -166
- package/src/browser/vendors-node_modules_comlink_dist_esm_comlink_mjs.unvired-db-worker.js +0 -22
- package/src/ios/AttachmentPlugin.h +0 -21
- package/src/ios/AttachmentPlugin.m +0 -180
- package/src/ios/DataStructureHelper.h +0 -28
- package/src/ios/DataStructureHelper.m +0 -188
- package/src/ios/IOSAuthPlugin.h +0 -14
- package/src/ios/IOSAuthPlugin.m +0 -13
- package/src/ios/IOSDatabasePlugin.h +0 -28
- package/src/ios/IOSDatabasePlugin.m +0 -253
- package/src/ios/IOSFWSettingsPlugin.h +0 -65
- package/src/ios/IOSFWSettingsPlugin.m +0 -363
- package/src/ios/IOSLoggerPlugin.h +0 -34
- package/src/ios/IOSLoggerPlugin.m +0 -198
- package/src/ios/IOSLoginPlugin.h +0 -29
- package/src/ios/IOSLoginPlugin.m +0 -480
- package/src/ios/IOSProxyPlugin.h +0 -21
- package/src/ios/IOSProxyPlugin.m +0 -172
- package/src/ios/IOSSyncEnginePlugin.h +0 -54
- package/src/ios/IOSSyncEnginePlugin.m +0 -847
- package/src/ios/PluginConstants.h +0 -195
- package/src/ios/PluginHelper.h +0 -29
- package/src/ios/PluginHelper.m +0 -74
- package/src/ios/SyncHTML5Response.h +0 -50
- package/src/ios/SyncHTML5Response.m +0 -68
- package/www/applicationMeta/applicationMetadataParser.ts +0 -285
- package/www/applicationMeta/fieldConstants.ts +0 -92
- package/www/attachment/attachmentHelper.ts +0 -326
- package/www/attachment/attachmentQHelper.ts +0 -158
- package/www/attachment/attachmentService.ts +0 -259
- package/www/authenticationService.ts +0 -751
- package/www/database/appDatabaseManager.ts +0 -54
- package/www/database/databaseManager.ts +0 -616
- package/www/helper/dbCreateTablesManager.ts +0 -354
- package/www/helper/frameworkHelper.ts +0 -127
- package/www/helper/frameworkSettingsManager.ts +0 -287
- package/www/helper/getMessageTimerManager.ts +0 -81
- package/www/helper/httpConnection.ts +0 -1051
- package/www/helper/logger.ts +0 -312
- package/www/helper/notificationListnerHelper.ts +0 -56
- package/www/helper/passcodeGenerator.ts +0 -61
- package/www/helper/reconciler.ts +0 -1062
- package/www/helper/serverResponseHandler.ts +0 -677
- package/www/helper/serviceConstants.ts +0 -254
- package/www/helper/settingsHelper.ts +0 -386
- package/www/helper/status.ts +0 -83
- package/www/helper/syncInputDataManager.ts +0 -205
- package/www/helper/unviredAccount.ts +0 -104
- package/www/helper/unviredAccountManager.ts +0 -120
- package/www/helper/urlService.ts +0 -43
- package/www/helper/userSettingsManager.ts +0 -172
- package/www/helper/utils.ts +0 -110
- package/www/inbox/downloadMessageService.ts +0 -270
- package/www/inbox/inboxHelper.ts +0 -132
- package/www/inbox/inboxService.ts +0 -223
- package/www/outbox/outboxAttachmentManager.ts +0 -152
- package/www/outbox/outboxHelper.ts +0 -67
- package/www/outbox/outboxService.ts +0 -519
- package/www/subtract.ts +0 -5
- package/www/sum.ts +0 -4
- package/www/syncEngine.ts +0 -687
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import DatabaseManager, { DatabaseType } from "../database/databaseManager";
|
|
2
|
-
import FrameworkHelper from "../helper/frameworkHelper";
|
|
3
|
-
import { Logger } from "../helper/logger";
|
|
4
|
-
import ServerResponseHandler from "../helper/serverResponseHandler";
|
|
5
|
-
import { ObjectStatus, SyncStatus } from "../helper/utils";
|
|
6
|
-
import DownloadMessageService from "./downloadMessageService";
|
|
7
|
-
import * as ServiceConstants from "../helper/serviceConstants";
|
|
8
|
-
import * as FieldConstants from "../applicationMeta/fieldConstants";
|
|
9
|
-
import InboxHelper from "./inboxHelper";
|
|
10
|
-
import AttachmentService from "../attachment/attachmentService";
|
|
11
|
-
import { NotificationListenerHelper, NotificationListnerType } from "../helper/notificationListnerHelper";
|
|
12
|
-
|
|
13
|
-
const fileName = "InboxService"
|
|
14
|
-
export default class InboxService {
|
|
15
|
-
|
|
16
|
-
private static instance: InboxService;
|
|
17
|
-
private isProcessing: boolean = false;
|
|
18
|
-
private shouldStop: boolean = false;
|
|
19
|
-
|
|
20
|
-
private constructor() {}
|
|
21
|
-
|
|
22
|
-
public static getInstance(): InboxService {
|
|
23
|
-
if (!InboxService.instance) {
|
|
24
|
-
InboxService.instance = new InboxService();
|
|
25
|
-
}
|
|
26
|
-
return InboxService.instance;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public start(): void {
|
|
30
|
-
if (!this.isProcessing) {
|
|
31
|
-
this.isProcessing = true;
|
|
32
|
-
this.shouldStop = false;
|
|
33
|
-
this.startInboxProcessing();
|
|
34
|
-
} else {
|
|
35
|
-
Logger.logInfo(fileName, "start", "Inbox processing is already running.");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public stop(): void {
|
|
40
|
-
if (this.isProcessing) {
|
|
41
|
-
this.shouldStop = true;
|
|
42
|
-
Logger.logInfo(fileName, "stop", "Stopping inbox processing...");
|
|
43
|
-
} else {
|
|
44
|
-
Logger.logInfo(fileName, "stop", "Inbox processing is not running.");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async startInboxProcessing(): Promise<void> {
|
|
49
|
-
Logger.logInfo(fileName, "startInboxProcessing", "Starting inbox processing...");
|
|
50
|
-
let isInboxEmpty = false;
|
|
51
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
52
|
-
const inboxCount = await databaseManager.count(DatabaseType.FrameworkDb, "InObject");
|
|
53
|
-
var currentIndex = 0;
|
|
54
|
-
try {
|
|
55
|
-
do {
|
|
56
|
-
if (this.shouldStop) {
|
|
57
|
-
Logger.logInfo(fileName, "startInboxProcessing", "Stopping inbox processing...");
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
const inObject = await databaseManager.getFirstEntity(DatabaseType.FrameworkDb, "InObject");
|
|
61
|
-
isInboxEmpty = inObject === null;
|
|
62
|
-
if (!isInboxEmpty) {
|
|
63
|
-
currentIndex++;
|
|
64
|
-
const currentProcessingNumber = inboxCount - currentIndex;
|
|
65
|
-
if (currentProcessingNumber > 0) {
|
|
66
|
-
NotificationListenerHelper.postSynchronizationStateNotification(`processing (${currentProcessingNumber})`);
|
|
67
|
-
}
|
|
68
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Processing LID : ${inObject.lid}. Conversation ID : ${inObject.conversationId}.`);
|
|
69
|
-
try {
|
|
70
|
-
if (inObject.type !== -1 && inObject.subtype !== -1) {
|
|
71
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Admin service messages. Starting in-object processing.`);
|
|
72
|
-
await DownloadMessageService.handleMessageTypes(inObject);
|
|
73
|
-
await databaseManager.delete(DatabaseType.FrameworkDb, "InObject", `conversationId = '${inObject.conversationId}'`);
|
|
74
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Admin service messages. Deleting from in-object.`);
|
|
75
|
-
await InboxHelper.deleteInBoxData(inObject.conversationId);
|
|
76
|
-
} else {
|
|
77
|
-
let jsonData: any = {};
|
|
78
|
-
try {
|
|
79
|
-
const inboxData = await InboxHelper.getInBoxData(inObject.conversationId);
|
|
80
|
-
jsonData = JSON.parse(inboxData);
|
|
81
|
-
} catch (e) {
|
|
82
|
-
Logger.logError(fileName, "startInboxProcessing", `Application messages. Error while getting inbox data: ${JSON.stringify(e)}.`);
|
|
83
|
-
await databaseManager.delete(DatabaseType.FrameworkDb, "InObject", `lid = '${inObject.lid}'`);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Application messages. Starting in-object processing.`);
|
|
89
|
-
// map["currentConvId"] = inObject.conversationId;
|
|
90
|
-
await ServerResponseHandler.handleResponseData(jsonData, true, false, inObject.beLid, inObject.jsonData, inObject.requestType);
|
|
91
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Application messages. In-object successfully processed.`);
|
|
92
|
-
} catch (e) {
|
|
93
|
-
Logger.logError(fileName, "startInboxProcessing", `Application messages. Error while processing in-object: ${JSON.stringify(e)}.`);
|
|
94
|
-
const infoMessage = {
|
|
95
|
-
lid: FrameworkHelper.getUUID(),
|
|
96
|
-
timestamp: Date.now(),
|
|
97
|
-
objectStatus: ObjectStatus.global,
|
|
98
|
-
syncStatus: SyncStatus.none,
|
|
99
|
-
type: inObject.type.toString(),
|
|
100
|
-
subtype: inObject.subtype.toString(),
|
|
101
|
-
category: FieldConstants.InfoMessageFailure,
|
|
102
|
-
message: `Deleted the InObject from the inobject Queue. Could not handle the In Object because the XML data had a parsing Issue: ${JSON.stringify(e)}. Conversation ID: ${inObject.conversationId}. `,
|
|
103
|
-
bename: inObject.jsonData,
|
|
104
|
-
belid: inObject.beLid,
|
|
105
|
-
messagedetails: new Uint8Array(0)
|
|
106
|
-
};
|
|
107
|
-
await databaseManager.insert(DatabaseType.FrameworkDb, "InfoMessage", infoMessage, true);
|
|
108
|
-
await this.updateSyncStatusToEntityObjects(inObject, SyncStatus.error);
|
|
109
|
-
}
|
|
110
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Application messages. Deleting from in-object.`);
|
|
111
|
-
const result: number = await databaseManager.delete(DatabaseType.FrameworkDb, "InObject", `conversationId = '${inObject.conversationId}'`);
|
|
112
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Application messages. in-object deleted. Result: ${result}`);
|
|
113
|
-
await InboxHelper.deleteInBoxData(inObject.conversationId);
|
|
114
|
-
}
|
|
115
|
-
} catch (e) {
|
|
116
|
-
Logger.logError(fileName, "startInboxProcessing", `Application messages. Error while processing in-object: ${JSON.stringify(e)}.`);
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Inbox is empty. Stopping inbox processing.`);
|
|
120
|
-
}
|
|
121
|
-
} while (!isInboxEmpty);
|
|
122
|
-
await this.checkAndUpdateHeaderSyncStatus();
|
|
123
|
-
Logger.logInfo(fileName, "startInboxProcessing", `Inbox processing completed.`);
|
|
124
|
-
NotificationListenerHelper.postSynchronizationStateNotification(`idle`);
|
|
125
|
-
if (inboxCount > 0) {
|
|
126
|
-
NotificationListenerHelper.postDataSenderNotification(null, NotificationListnerType.incomingDataProcessingFinished);
|
|
127
|
-
}
|
|
128
|
-
AttachmentService.getInstance().start();
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
Logger.logError(fileName, "startInboxProcessing", `Error while starting inbox processing. Error: ${e}`);
|
|
132
|
-
}
|
|
133
|
-
finally {
|
|
134
|
-
this.isProcessing = false;
|
|
135
|
-
this.shouldStop = false;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private async checkAndUpdateHeaderSyncStatus(): Promise<void> {
|
|
140
|
-
try {
|
|
141
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
142
|
-
const headerStructMetas: any[] = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `isHeader = '1'`);
|
|
143
|
-
const allBusinessEntityMetas: any[] = await databaseManager.select(DatabaseType.FrameworkDb, "BusinessEntityMeta");
|
|
144
|
-
const allSentItems = await databaseManager.select(DatabaseType.FrameworkDb, "SentItems");
|
|
145
|
-
const allBeLids: string[] = allSentItems.map(e => e.beHeaderLid);
|
|
146
|
-
let beLidsSting = "";
|
|
147
|
-
if (allBeLids.length > 0) {
|
|
148
|
-
beLidsSting = "'" + allBeLids.join("','") + "'";
|
|
149
|
-
}
|
|
150
|
-
for (const headerStructure of headerStructMetas) {
|
|
151
|
-
try {
|
|
152
|
-
const currentBeMeta = allBusinessEntityMetas.find(element => element.beName === headerStructure.beName);
|
|
153
|
-
if (currentBeMeta?.save === "false") {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
Logger.logInfo(fileName, "checkAndUpdateHeaderSyncStatus", `headerStructure: ${JSON.stringify(headerStructure)}.`);
|
|
157
|
-
const allData: any[] = await databaseManager.select(DatabaseType.AppDb, headerStructure.structureName, `${FieldConstants.FieldSyncStatus}=${SyncStatus.sent} AND ${FieldConstants.FieldObjectStatus}=${ObjectStatus.modify}` +
|
|
158
|
-
(beLidsSting.length > 0 ? ` AND ${FieldConstants.FieldLid} NOT IN (${beLidsSting})` : ""))
|
|
159
|
-
for (const headerData of allData) {
|
|
160
|
-
try {
|
|
161
|
-
await databaseManager.update(DatabaseType.AppDb, headerStructure.structureName, {
|
|
162
|
-
[FieldConstants.FieldSyncStatus]: SyncStatus.error,
|
|
163
|
-
[FieldConstants.FieldInfoMsgCat]: FieldConstants.InfoMessageFailure
|
|
164
|
-
}, `${FieldConstants.FieldLid} = '${headerData[FieldConstants.FieldLid]}'`, true); // isFromApp is true because it just need to update the data and should not set the missing fields to null.
|
|
165
|
-
const infoMessage = {
|
|
166
|
-
lid: FrameworkHelper.getUUID(),
|
|
167
|
-
timestamp: Date.now(),
|
|
168
|
-
objectStatus: ObjectStatus.global,
|
|
169
|
-
syncStatus: SyncStatus.none,
|
|
170
|
-
type: "",
|
|
171
|
-
subtype: "",
|
|
172
|
-
category: FieldConstants.InfoMessageFailure,
|
|
173
|
-
message: "The connection was interrupted. Please try again.",
|
|
174
|
-
bename: headerStructure.structureName,
|
|
175
|
-
belid: headerData[FieldConstants.FieldLid],
|
|
176
|
-
messagedetails: new Uint8Array(0)
|
|
177
|
-
};
|
|
178
|
-
await databaseManager.insert(DatabaseType.FrameworkDb, "InfoMessage", infoMessage, true);
|
|
179
|
-
} catch (e) {
|
|
180
|
-
Logger.logError(fileName, "checkAndUpdateHeaderSyncStatus", `Error while updating header (${headerStructure.structureName}) Sync Status to ERROR into database. Error: ${JSON.stringify(e)}`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
} catch (e) {
|
|
184
|
-
Logger.logError(fileName, "checkAndUpdateHeaderSyncStatus", `Error while getting BE Meta for header (${headerStructure.structureName}). Error: ${JSON.stringify(e)}`);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} catch (e) {
|
|
188
|
-
Logger.logError(fileName, "checkAndUpdateHeaderSyncStatus", `Error while updating header Sync Status to ERROR. Error: ${JSON.stringify(e)}`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async updateSyncStatusToEntityObjects(inObject: any, syncStatus: SyncStatus): Promise<void> {
|
|
193
|
-
const requestType = inObject.requestType;
|
|
194
|
-
const entityName = inObject.jsonData; // BE Name is set in the jsonData field
|
|
195
|
-
const beLid = inObject.beLid;
|
|
196
|
-
|
|
197
|
-
if (requestType === ServiceConstants.RequestType.RQST.toString()) {
|
|
198
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
199
|
-
const structureMetaData = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `structureName = '${entityName}'`)
|
|
200
|
-
if (structureMetaData.length === 0) {
|
|
201
|
-
Logger.logError(fileName, "updateSyncStatusToEntityObjects", `No structure meta found for BE-NAME: ${entityName}, BE-LID: ${beLid}`);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const structName = structureMetaData[0].structureName;
|
|
205
|
-
const structureFieldData = await databaseManager.select(DatabaseType.AppDb, structName, `${FieldConstants.FieldLid} = '${beLid}'`);
|
|
206
|
-
if (structureFieldData.length === 0) {
|
|
207
|
-
Logger.logError(fileName, "updateSyncStatusToEntityObjects", `No Business Entity got from database, BE-NAME: ${entityName}, BE-LID: ${beLid}`);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const data = structureFieldData[0];
|
|
211
|
-
|
|
212
|
-
data[FieldConstants.FieldSyncStatus] = syncStatus;
|
|
213
|
-
await databaseManager.update(DatabaseType.AppDb, structName, data, `${FieldConstants.FieldLid} = '${beLid}'`);
|
|
214
|
-
|
|
215
|
-
const childStructureMetas = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `beName = '${entityName}' AND isHeader != '1'`);
|
|
216
|
-
for (const childStructureMetaData of childStructureMetas) {
|
|
217
|
-
await databaseManager.update(DatabaseType.AppDb, childStructureMetaData.structureName, {
|
|
218
|
-
[FieldConstants.FieldSyncStatus]: syncStatus
|
|
219
|
-
}, `${FieldConstants.FieldLid}='${beLid}' AND ${FieldConstants.FieldObjectStatus} != ${ObjectStatus.global}`, true); // isFromApp is true because it just need to update the data and should not set the missing fields to null.
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import DatabaseManager, { DatabaseType } from "../database/databaseManager";
|
|
2
|
-
import { Logger } from "../helper/logger";
|
|
3
|
-
import * as FieldConstants from '../applicationMeta/fieldConstants';
|
|
4
|
-
import * as ServiceConstants from '../helper/serviceConstants';
|
|
5
|
-
import { UnviredAccountManager } from "../helper/unviredAccountManager";
|
|
6
|
-
import { HttpConnection, bearerAuth } from "../helper/httpConnection";
|
|
7
|
-
import { UserSettingsFields, UserSettingsManager } from "../helper/userSettingsManager";
|
|
8
|
-
import { isServerReachable, LoginType, ObjectStatus, SyncStatus } from "../helper/utils";
|
|
9
|
-
import FrameworkHelper from "../helper/frameworkHelper";
|
|
10
|
-
import { Status } from "../helper/status";
|
|
11
|
-
import { AuthenticationService } from "../authenticationService";
|
|
12
|
-
|
|
13
|
-
export default class OutboxAttachmentManager {
|
|
14
|
-
async checkAndUploadAttachmentsInOutBox(entityName:string, inputData: any): Promise<boolean> {
|
|
15
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
16
|
-
const structureMetas = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta");
|
|
17
|
-
const structureMeta = structureMetas.find(element => element.structureName === entityName);
|
|
18
|
-
// Invalid condition. Should never occur.
|
|
19
|
-
if (!structureMeta) {
|
|
20
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Invalid BE. Cannot Upload Attachments. Table Name: ${entityName}`);
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
// If attachments are not supported do not do anything
|
|
24
|
-
const isAttachmentSupported: boolean = await this.isAttachmentSupportedForBEName(structureMeta.beName);
|
|
25
|
-
if (!isAttachmentSupported) {
|
|
26
|
-
Logger.logInfo("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `This BE: ${structureMeta.beName} does not support attachments.`);
|
|
27
|
-
return true; // Return true since no attachments to upload
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Logger.logDebug("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `This BE: ${structureMeta.beName} supports attachments.`);
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const attachmentEntityNames: string[] = structureMetas
|
|
34
|
-
.filter(element => element.beName === structureMeta.beName && element.structureName.endsWith(ServiceConstants.AttachmentBE))
|
|
35
|
-
.map(e => e.structureName);
|
|
36
|
-
|
|
37
|
-
for (const attachmentEntityName of attachmentEntityNames) {
|
|
38
|
-
let attachmentItems: any[] = [];
|
|
39
|
-
try {
|
|
40
|
-
attachmentItems = await this.getAttachmentsMarkedForUploadOutbox(attachmentEntityName, inputData);
|
|
41
|
-
} catch (e) {
|
|
42
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Error when trying to get attachments marked for upload ${JSON.stringify(e)}`);
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
for (const attachmentItem of attachmentItems) {
|
|
47
|
-
try {
|
|
48
|
-
if (!navigator.onLine) {
|
|
49
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", "No Internet connection.");
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
const lastLoggedInAccount = UnviredAccountManager.getInstance().getLastLoggedInAccount();
|
|
53
|
-
if (!(await isServerReachable(lastLoggedInAccount.getServerURL()))) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const response = await new HttpConnection().uploadAttachment(attachmentItem);
|
|
57
|
-
if (response.status === Status.ok || response.status === Status.created) {
|
|
58
|
-
const isSuccess: boolean = await this.updateAttachmentStatusOutBox(attachmentEntityName, attachmentItem, ServiceConstants.AttachmentStatusUploaded);
|
|
59
|
-
if (!isSuccess) {
|
|
60
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Failed to update status in ${attachmentEntityName} LID : ${attachmentItem[FieldConstants.FieldLid]}`);
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
} else {
|
|
64
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", "Error while uploading attachment.");
|
|
65
|
-
const infoMessage = {
|
|
66
|
-
lid: FrameworkHelper.getUUID(),
|
|
67
|
-
timestamp: Date.now(),
|
|
68
|
-
objectStatus: ObjectStatus.global,
|
|
69
|
-
syncStatus: SyncStatus.none,
|
|
70
|
-
type: "",
|
|
71
|
-
subtype: "",
|
|
72
|
-
category: 'InfoMessageFailure',
|
|
73
|
-
message: "Error while uploading attachment.",
|
|
74
|
-
bename: entityName,
|
|
75
|
-
belid: attachmentItem[FieldConstants.FieldLid],
|
|
76
|
-
messagedetails: new Uint8Array(0)
|
|
77
|
-
};
|
|
78
|
-
await databaseManager.insert(DatabaseType.FrameworkDb, "InfoMessage", infoMessage, true);
|
|
79
|
-
const isSuccess: boolean = await this.updateAttachmentStatusOutBox(attachmentEntityName, attachmentItem, ServiceConstants.AttachmentStatusErrorInUpload);
|
|
80
|
-
if (!isSuccess) {
|
|
81
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Failed to update status in ${attachmentEntityName} LID : ${attachmentItem[FieldConstants.FieldLid]}`);
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
} catch (e) {
|
|
86
|
-
const isSuccess: boolean = await this.updateAttachmentStatusOutBox(attachmentEntityName, attachmentItem, ServiceConstants.AttachmentStatusErrorInUpload);
|
|
87
|
-
if (!isSuccess) {
|
|
88
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Failed to update status in ${attachmentEntityName} LID : ${attachmentItem[FieldConstants.FieldLid]}`);
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
} catch (e) {
|
|
96
|
-
Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Error when trying to check and upload attachments in outbox ${JSON.stringify(e)}`);
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async updateAttachmentStatusOutBox(attachmentItemName: string, attachmentItem: any, attachmentStatus: string): Promise<boolean> {
|
|
102
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = attachmentStatus;
|
|
103
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
104
|
-
return await databaseManager.update(DatabaseType.AppDb, attachmentItemName, attachmentItem, `${FieldConstants.FieldLid} = '${attachmentItem[FieldConstants.FieldLid]}'`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async isAttachmentSupportedForBEName(beName: string): Promise<boolean> {
|
|
108
|
-
if (!beName) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
113
|
-
const beMeta = await databaseManager.select(DatabaseType.FrameworkDb, "BusinessEntityMeta", `beName = '${beName}'`)
|
|
114
|
-
if (beMeta.length === 0) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return beMeta[0].attachments === "1";
|
|
118
|
-
} catch (e) {
|
|
119
|
-
Logger.logError("OutboxAttachmentManager", "isAttachmentSupportedForBEName", `Error when trying to get BusinessEntityMeta. Error: ${JSON.stringify(e)}`);
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async getAttachmentsMarkedForUploadOutbox(attachmentEntityName: string, inputData: any): Promise<any[]> {
|
|
125
|
-
const parsedData: any = JSON.parse(inputData[ServiceConstants.QueryParamInputMessage]);
|
|
126
|
-
const inputDataKeys: Iterable<string> = Object.keys(parsedData);
|
|
127
|
-
const beData: any = parsedData[inputDataKeys[0]];
|
|
128
|
-
|
|
129
|
-
let headerData: any ;
|
|
130
|
-
for (const key in beData[0]) {
|
|
131
|
-
if (key.endsWith("_HEADER")) {
|
|
132
|
-
headerData = beData[0][key];
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (!headerData) {
|
|
137
|
-
Logger.logError("OutboxAttachmentManager", "getAttachmentsMarkedForUploadOutbox", "Header data not available.");
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
// Check if the header supports attachments, if yes, check if it has any, if yes send to server.
|
|
141
|
-
const whereClause: string = `${FieldConstants.FieldFid} = '${headerData[FieldConstants.FieldLid]}' AND ${ServiceConstants.AttachmentItemFieldAttachmentStatus} = '${ServiceConstants.AttachmentStatusSavedForUpload}'`;
|
|
142
|
-
let attachmentItems: any[] = [];
|
|
143
|
-
try {
|
|
144
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
145
|
-
attachmentItems = await databaseManager.select(DatabaseType.AppDb, attachmentEntityName, whereClause);
|
|
146
|
-
} catch (e) {
|
|
147
|
-
Logger.logError("OutboxAttachmentManager", "getAttachmentsMarkedForUploadOutbox", `Error when trying to get attachments marked for upload ${JSON.stringify(e)}`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return attachmentItems;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import DatabaseManager, { DatabaseType } from "../database/databaseManager";
|
|
2
|
-
import * as FieldConstants from "../applicationMeta/fieldConstants";
|
|
3
|
-
import { ObjectStatus, SyncStatus } from "../helper/utils";
|
|
4
|
-
import { RequestType } from "../helper/serviceConstants";
|
|
5
|
-
import { Logger } from "../helper/logger";
|
|
6
|
-
|
|
7
|
-
const fileName = "OutBoxHelper";
|
|
8
|
-
export default class OutBoxHelper {
|
|
9
|
-
static async checkIsInOutBox(beLid: string): Promise<any> {
|
|
10
|
-
if (beLid === "") {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const databaseManager = await DatabaseManager.getInstance();
|
|
14
|
-
const outObjectData = await databaseManager.select(DatabaseType.FrameworkDb, "OutObject", `beHeaderLid = '${beLid}'`);
|
|
15
|
-
return outObjectData.length > 0 ? outObjectData[0] : null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static async checkIsInSentItems(beLid: string): Promise<any> {
|
|
19
|
-
if (beLid === "") {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
const databaseManager = await DatabaseManager.getInstance();
|
|
23
|
-
const sentItem = await databaseManager.select(DatabaseType.FrameworkDb, "SentItems", `beHeaderLid = '${beLid}'`);
|
|
24
|
-
return sentItem.length > 0 ? sentItem[0] : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static async updateSyncStatusToEntityObjects(outObject: any, syncStatus: SyncStatus): Promise<void> {
|
|
28
|
-
const requestType = outObject.requestType;
|
|
29
|
-
const entityName = outObject.beName;
|
|
30
|
-
const beLid = outObject.beHeaderLid;
|
|
31
|
-
|
|
32
|
-
if (requestType === RequestType.RQST.toString()) {
|
|
33
|
-
const databaseManager = await DatabaseManager.getInstance();
|
|
34
|
-
const structureMetaData = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `structureName = '${entityName}'`);
|
|
35
|
-
if (structureMetaData.length === 0) {
|
|
36
|
-
await Logger.logDebug(
|
|
37
|
-
"OutboxHelper",
|
|
38
|
-
"updateSyncStatusToEntityObjects",
|
|
39
|
-
"No Business Entity got from database, BE-NAME: " +
|
|
40
|
-
outObject.beName +
|
|
41
|
-
", BE-LID: " +
|
|
42
|
-
beLid);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const structureFieldData = await databaseManager.select(DatabaseType.AppDb, structureMetaData[0].structureName, `${FieldConstants.FieldLid} = '${beLid}'`);
|
|
46
|
-
if (structureFieldData.length === 0) {
|
|
47
|
-
await Logger.logDebug(
|
|
48
|
-
"OutboxHelper",
|
|
49
|
-
"updateSyncStatusToEntityObjects",
|
|
50
|
-
`No Business Entity got from database, BE-NAME: ${outObject.beName}, BE-LID: ${beLid}`
|
|
51
|
-
);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const data = structureFieldData[0];
|
|
55
|
-
|
|
56
|
-
data[FieldConstants.FieldSyncStatus] = syncStatus;
|
|
57
|
-
await databaseManager.update(DatabaseType.AppDb, entityName, data, `${FieldConstants.FieldLid} = '${beLid}'`);
|
|
58
|
-
|
|
59
|
-
const childStructureMetas = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `beName = '${structureMetaData[0].beName}' AND isHeader != 1`);
|
|
60
|
-
for (const childStructureMetaData of childStructureMetas) {
|
|
61
|
-
await databaseManager.update(DatabaseType.AppDb, childStructureMetaData.structureName, {
|
|
62
|
-
[FieldConstants.FieldSyncStatus]: syncStatus
|
|
63
|
-
}, `${FieldConstants.FieldFid}='${beLid}' AND ${FieldConstants.FieldObjectStatus} <> ${ObjectStatus.global}`, true); // isFromApp is true because it just need to update the data and should not set the missing fields to null.
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|