cordova-plugin-unvired-universal-sdk 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/aar/README.md +3 -0
- package/aar/Unvired_Kernel_Android.aar +0 -0
- package/aar/Unvired_Kernel_HTML5_Android.aar +0 -0
- package/package.json +69 -0
- package/plugin.xml +23 -0
- package/src/android/build.gradle +35 -0
- package/src/android/xml/provider_paths.xml +21 -0
- package/src/browser/UnviredPluginProxy.js +2430 -0
- package/src/browser/bootstrap.min.js +17 -0
- package/src/browser/codemirror.js +9755 -0
- package/src/browser/jquery-3.2.1.js +10253 -0
- package/src/browser/sql-wasm.wasm +0 -0
- package/src/browser/sql.js +203 -0
- package/src/browser/src_index_worker_js.unvired-db-worker.js +231 -0
- package/src/browser/unvired-db-worker.js +166 -0
- package/src/browser/vendors-node_modules_comlink_dist_esm_comlink_mjs.unvired-db-worker.js +22 -0
- package/src/ios/AttachmentPlugin.h +21 -0
- package/src/ios/AttachmentPlugin.m +180 -0
- package/src/ios/DataStructureHelper.h +28 -0
- package/src/ios/DataStructureHelper.m +188 -0
- package/src/ios/IOSAuthPlugin.h +14 -0
- package/src/ios/IOSAuthPlugin.m +13 -0
- package/src/ios/IOSDatabasePlugin.h +28 -0
- package/src/ios/IOSDatabasePlugin.m +253 -0
- package/src/ios/IOSFWSettingsPlugin.h +65 -0
- package/src/ios/IOSFWSettingsPlugin.m +363 -0
- package/src/ios/IOSLoggerPlugin.h +34 -0
- package/src/ios/IOSLoggerPlugin.m +198 -0
- package/src/ios/IOSLoginPlugin.h +29 -0
- package/src/ios/IOSLoginPlugin.m +480 -0
- package/src/ios/IOSProxyPlugin.h +21 -0
- package/src/ios/IOSProxyPlugin.m +172 -0
- package/src/ios/IOSSyncEnginePlugin.h +54 -0
- package/src/ios/IOSSyncEnginePlugin.m +847 -0
- package/src/ios/PluginConstants.h +195 -0
- package/src/ios/PluginHelper.h +29 -0
- package/src/ios/PluginHelper.m +74 -0
- package/src/ios/SyncHTML5Response.h +50 -0
- package/src/ios/SyncHTML5Response.m +68 -0
- package/www/applicationMeta/applicationMetadataParser.ts +285 -0
- package/www/applicationMeta/fieldConstants.ts +92 -0
- package/www/attachment/attachmentHelper.ts +326 -0
- package/www/attachment/attachmentQHelper.ts +158 -0
- package/www/attachment/attachmentService.ts +259 -0
- package/www/authenticationService.ts +746 -0
- package/www/bootstrap.min.js +17 -0
- package/www/codemirror.js +9755 -0
- package/www/database/appDatabaseManager.ts +54 -0
- package/www/database/databaseManager.ts +616 -0
- package/www/helper/dbCreateTablesManager.ts +354 -0
- package/www/helper/frameworkHelper.ts +127 -0
- package/www/helper/frameworkSettingsManager.ts +287 -0
- package/www/helper/getMessageTimerManager.ts +81 -0
- package/www/helper/httpConnection.ts +1051 -0
- package/www/helper/logger.ts +312 -0
- package/www/helper/notificationListnerHelper.ts +56 -0
- package/www/helper/passcodeGenerator.ts +61 -0
- package/www/helper/reconciler.ts +1062 -0
- package/www/helper/serverResponseHandler.ts +677 -0
- package/www/helper/serviceConstants.ts +254 -0
- package/www/helper/settingsHelper.ts +386 -0
- package/www/helper/status.ts +83 -0
- package/www/helper/syncInputDataManager.ts +205 -0
- package/www/helper/unviredAccount.ts +104 -0
- package/www/helper/unviredAccountManager.ts +120 -0
- package/www/helper/urlService.ts +43 -0
- package/www/helper/userSettingsManager.ts +172 -0
- package/www/helper/utils.ts +110 -0
- package/www/inbox/downloadMessageService.ts +270 -0
- package/www/inbox/inboxHelper.ts +132 -0
- package/www/inbox/inboxService.ts +223 -0
- package/www/jquery-3.2.1.js +10253 -0
- package/www/kernel.js +1380 -0
- package/www/outbox/outboxAttachmentManager.ts +152 -0
- package/www/outbox/outboxHelper.ts +67 -0
- package/www/outbox/outboxService.ts +519 -0
- package/www/sql-wasm.wasm +0 -0
- package/www/sql.js +209 -0
- package/www/subtract.ts +5 -0
- package/www/sum.ts +4 -0
- package/www/syncEngine.ts +687 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { exec } from "child_process";
|
|
2
|
+
import { DatabaseManager, DatabaseType } from "../database/databaseManager";
|
|
3
|
+
import ApplicationMetaParser from '../applicationMeta/applicationMetadataParser';
|
|
4
|
+
import { Logger } from "./logger";
|
|
5
|
+
import * as FieldConstants from "../applicationMeta/fieldConstants";
|
|
6
|
+
|
|
7
|
+
export default class DbCreateTablesManager {
|
|
8
|
+
fileName = "DbCreateTablesManager"
|
|
9
|
+
parser = ApplicationMetaParser.instance;
|
|
10
|
+
databaseManager: DatabaseManager | null = null;
|
|
11
|
+
|
|
12
|
+
constructor() {}
|
|
13
|
+
|
|
14
|
+
public async createTables(): Promise<boolean> {
|
|
15
|
+
try {
|
|
16
|
+
Logger.logInfo(this.fileName, "createTables", "Creating all DB tables");
|
|
17
|
+
this.databaseManager = DatabaseManager.getInstance();
|
|
18
|
+
var result = await this.createFrameworkTables();
|
|
19
|
+
if(result) {
|
|
20
|
+
result = await this.createAppTables();
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
} catch (e) {
|
|
24
|
+
Logger.logError(this.fileName, "createTables", "Error while creating all DB tables. Error: " + e);
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async createFrameworkTables(): Promise<boolean> {
|
|
30
|
+
try {
|
|
31
|
+
Logger.logInfo(this.fileName, "createFrameworkTables", "Creating all FW DB tables");
|
|
32
|
+
const createTableQueries = [`CREATE TABLE IF NOT EXISTS ApplicationMeta (lid TEXT, timestamp INTEGER, objectStatus INTEGER, syncStatus INTEGER, appId TEXT, appName TEXT, description TEXT, version TEXT, installationDate TEXT, appClassName TEXT, PRIMARY KEY (lid), UNIQUE (appName))`,
|
|
33
|
+
`CREATE TABLE IF NOT EXISTS BusinessEntityMeta (lid TEXT, timestamp INTEGER, objectStatus INTEGER, syncStatus INTEGER, appName TEXT, beName TEXT, description TEXT, addFunction TEXT, modifyFunction TEXT, deleteFunction TEXT, notification TEXT, attachments TEXT, conflictRules TEXT, save TEXT, PRIMARY KEY (lid), UNIQUE (appName, beName))`,
|
|
34
|
+
`CREATE TABLE IF NOT EXISTS StructureMeta (lid TEXT, timestamp INTEGER, objectStatus INTEGER, syncStatus INTEGER, appName TEXT, beName TEXT, structureName TEXT, description TEXT, className TEXT, isHeader TEXT, PRIMARY KEY (lid), UNIQUE (appName, beName, structureName))`,
|
|
35
|
+
`CREATE TABLE IF NOT EXISTS FieldMeta (lid TEXT, timestamp INTEGER, objectStatus INTEGER, syncStatus INTEGER, appName TEXT, beName TEXT, structureName TEXT, fieldName TEXT, description TEXT, length TEXT, mandatory TEXT, sqlType TEXT, isGid TEXT, PRIMARY KEY (lid), UNIQUE (appName, beName, structureName, fieldName))`,
|
|
36
|
+
`CREATE TABLE IF NOT EXISTS Settings (lid TEXT, timestamp INTEGER, objectStatus INTEGER, syncStatus INTEGER, fieldName TEXT, fieldValue TEXT, PRIMARY KEY (lid), UNIQUE (fieldName))`,
|
|
37
|
+
`CREATE TABLE IF NOT EXISTS FrameworkSettings (lid TEXT, timestamp INTEGER, objectStatus INTEGER, syncStatus INTEGER, fieldName TEXT, fieldValue TEXT, PRIMARY KEY (lid), UNIQUE (fieldName))`,
|
|
38
|
+
`CREATE TABLE IF NOT EXISTS MobileUserSettings (lid TEXT, timestamp INTEGER, objectStatus INTEGER, syncStatus INTEGER, keyName TEXT, description TEXT, defaultField TEXT, current TEXT, mandatory TEXT, secure TEXT, PRIMARY KEY (lid), UNIQUE (lid))`,
|
|
39
|
+
`CREATE TABLE IF NOT EXISTS InfoMessage (lid TEXT DEFAULT (UUID()), timestamp INTEGER DEFAULT (strftime('%s', 'now') * 1000), objectStatus INTEGER DEFAULT (0), syncStatus INTEGER DEFAULT (0), type TEXT, subtype TEXT, category TEXT, message TEXT, bename TEXT, belid TEXT, messagedetails BLOB, PRIMARY KEY (lid), UNIQUE (lid))`,
|
|
40
|
+
`CREATE TABLE IF NOT EXISTS ConflictBE (lid TEXT DEFAULT (UUID()), timestamp INTEGER DEFAULT (strftime('%s', 'now') * 1000), objectStatus INTEGER DEFAULT (0), syncStatus INTEGER DEFAULT (0), beName TEXT, beHeaderLid TEXT, data TEXT, PRIMARY KEY (lid), UNIQUE (lid))`,
|
|
41
|
+
`CREATE TABLE IF NOT EXISTS InObject (lid TEXT DEFAULT (UUID()), timestamp INTEGER DEFAULT (strftime('%s', 'now') * 1000), objectStatus INTEGER DEFAULT (0), syncStatus INTEGER DEFAULT (0), conversationId TEXT, subtype INTEGER, type INTEGER, appId TEXT, serverId TEXT, appName TEXT, requestType TEXT, jsonData TEXT, beLid TEXT, PRIMARY KEY (lid, conversationId), UNIQUE (conversationId))`,
|
|
42
|
+
`CREATE TABLE IF NOT EXISTS OutObject (lid TEXT DEFAULT (UUID()), timestamp INTEGER DEFAULT (strftime('%s', 'now') * 1000), objectStatus INTEGER DEFAULT (0), syncStatus INTEGER DEFAULT (0), functionName TEXT, beName TEXT, beHeaderLid TEXT, requestType TEXT, syncType TEXT, conversationId TEXT, messageJson TEXT, companyNameSpace TEXT, sendStatus TEXT, fieldOutObjectStatus TEXT, isAdminServices BOOLEAN, PRIMARY KEY (lid), UNIQUE (lid))`,
|
|
43
|
+
`CREATE TABLE IF NOT EXISTS SentItems (lid TEXT DEFAULT (UUID()), timestamp INTEGER DEFAULT (strftime('%s', 'now') * 1000), objectStatus INTEGER DEFAULT (0), syncStatus INTEGER DEFAULT (0), beName TEXT, beHeaderLid TEXT, conversationId TEXT, entryDate TEXT, attachmentFlag TEXT, PRIMARY KEY (lid), UNIQUE (conversationId))`,
|
|
44
|
+
`CREATE TABLE IF NOT EXISTS AttachmentQObject (lid TEXT DEFAULT (UUID()), timestamp INTEGER DEFAULT (strftime('%s', 'now') * 1000), objectStatus INTEGER DEFAULT (0), syncStatus INTEGER DEFAULT (0), uid TEXT, beName TEXT, beHeaderName TEXT, beAttachmentStructName TEXT, priority INTEGER, PRIMARY KEY (uid), UNIQUE (uid))`,
|
|
45
|
+
`CREATE TABLE IF NOT EXISTS SystemCredentials (lid TEXT DEFAULT (UUID()), timestamp INTEGER DEFAULT (strftime('%s', 'now') * 1000), objectStatus INTEGER DEFAULT (0), syncStatus INTEGER DEFAULT (0), name TEXT, portName TEXT, portType TEXT, portDesc TEXT, systemDesc TEXT, userId TEXT, password TEXT, PRIMARY KEY (lid), UNIQUE (portName))`];
|
|
46
|
+
for (const query of createTableQueries) {
|
|
47
|
+
try {
|
|
48
|
+
var createTableResult = await this.databaseManager.executeStatement(DatabaseType.FrameworkDb, query);
|
|
49
|
+
Logger.logInfo(this.fileName, "createFrameworkTables", "Result: " + createTableResult);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
Logger.logError(this.fileName, "createFrameworkTables", "Error while creating FW DB tables. Error: " + e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
var result = await this.insertParsedDataIntoFrameworkTables();
|
|
56
|
+
return result;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
Logger.logError(this.fileName, "insertParsedDataIntoFrameworkTables", "Error while creating all FW DB tables. Error: " + e);
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async insertParsedDataIntoFrameworkTables(): Promise<boolean> {
|
|
64
|
+
try {
|
|
65
|
+
Logger.logInfo(this.fileName, "insertParsedDataIntoFrameworkTables", "Adding application meta into FW DB");
|
|
66
|
+
const applicationMeta = this.parser.getApplicationMeta();
|
|
67
|
+
const insertApplicationMetaQuery = `INSERT INTO ApplicationMeta (lid, timestamp, objectStatus, syncStatus, appId, appName, description, version, installationDate, appClassName) VALUES ('${applicationMeta.lid}', ${applicationMeta.timestamp}, ${applicationMeta.objectStatus}, ${applicationMeta.syncStatus}, '${applicationMeta.appId}', '${applicationMeta.appName}', '${applicationMeta.description}', '${applicationMeta.version}', '${applicationMeta.installationDate}', '${applicationMeta.appClassName}')`;
|
|
68
|
+
await this.databaseManager.executeStatement(DatabaseType.FrameworkDb, insertApplicationMetaQuery);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
Logger.logError(this.fileName, "insertParsedDataIntoFrameworkTables", "Error while adding Application Meta. Error: " + e);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
Logger.logInfo(this.fileName, "insertParsedDataIntoFrameworkTables", "Adding businessEntityMeta into FW DB");
|
|
76
|
+
const businessEntityMetas = this.parser.getBusinessEntityMetas();
|
|
77
|
+
const insertBusinessEntityMetaQuery = `INSERT INTO BusinessEntityMeta (lid, timestamp, objectStatus, syncStatus, appName, beName, description, addFunction, modifyFunction, deleteFunction, notification, attachments, conflictRules, save) VALUES ${businessEntityMetas.map(meta => `('${meta.lid}', ${meta.timestamp}, ${meta.objectStatus}, ${meta.syncStatus}, '${meta.appName}', '${meta.beName}', '${meta.description}', '${meta.addFunction}', '${meta.modifyFunction}', '${meta.deleteFunction}', '${meta.notification}', '${meta.attachments}', '${meta.conflictRules}', '${meta.save}')`).join(', ')}`;
|
|
78
|
+
await this.databaseManager.executeStatement(DatabaseType.FrameworkDb, insertBusinessEntityMetaQuery);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
Logger.logError(this.fileName, "insertParsedDataIntoFrameworkTables", "Error while adding businessEntityMeta. Error: " + e);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
Logger.logInfo(this.fileName, "insertParsedDataIntoFrameworkTables", "Adding structureMeta into FW DB");
|
|
86
|
+
const structureMetas = this.parser.getStructureMetas();
|
|
87
|
+
const insertStructureMetaQuery = `INSERT INTO StructureMeta (lid, timestamp, objectStatus, syncStatus, appName, beName, structureName, description, className, isHeader) VALUES ${structureMetas.map(meta => `('${meta.lid}', ${meta.timestamp}, ${meta.objectStatus}, ${meta.syncStatus}, '${meta.appName}', '${meta.beName}', '${meta.structureName}', '${meta.description}', '${meta.className}', ${meta.isHeader})`).join(', ')}`;
|
|
88
|
+
await this.databaseManager.executeStatement(DatabaseType.FrameworkDb, insertStructureMetaQuery);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
Logger.logError(this.fileName, "insertParsedDataIntoFrameworkTables", "Error while adding structureMeta. Error: " + e);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
Logger.logInfo(this.fileName, "insertParsedDataIntoFrameworkTables", "Adding fieldMeta into FW DB");
|
|
96
|
+
const fieldMetas = this.parser.getFieldMetas();
|
|
97
|
+
const insertFieldMetaQuery = `INSERT INTO FieldMeta (lid, timestamp, objectStatus, syncStatus, appName, beName, structureName, fieldName, description, length, mandatory, sqlType, isGid) VALUES ${fieldMetas.map(meta => `('${meta.lid}', ${meta.timestamp}, ${meta.objectStatus}, ${meta.syncStatus}, '${meta.appName}', '${meta.beName}', '${meta.structureName}', '${meta.fieldName}', '${meta.description.replace(/'/g, "''")}', '${meta.length}', '${meta.mandatory}', '${meta.sqlType}', ${meta.isGid})`).join(', ')}`;
|
|
98
|
+
await this.databaseManager.executeStatement(DatabaseType.FrameworkDb, insertFieldMetaQuery);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
Logger.logError(this.fileName, "insertParsedDataIntoFrameworkTables", "Error while adding fieldMeta. Error: " + e);
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async createAppTables(): Promise<boolean> {
|
|
107
|
+
const structureMetas = this.parser.getStructureMetas();
|
|
108
|
+
|
|
109
|
+
if (structureMetas.length === 0) {
|
|
110
|
+
Logger.logError("ApplicationManager", "createAppTables", "Invalid metadata.");
|
|
111
|
+
throw "Invalid metadata.";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const beMetaArray = this.parser.getBusinessEntityMetas();
|
|
115
|
+
const fieldMetaArray = this.parser.getFieldMetas();
|
|
116
|
+
|
|
117
|
+
const map: { [key: string]: any } = {
|
|
118
|
+
"structureMetas": structureMetas,
|
|
119
|
+
"beMetaArray": beMetaArray,
|
|
120
|
+
"fieldMetaArray": fieldMetaArray
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// const queries: string[] = await compute(appTableGenerator, map);
|
|
124
|
+
const queries: string[] = this.appTableGenerator(map);
|
|
125
|
+
|
|
126
|
+
for (const query of queries) {
|
|
127
|
+
if (query.length === 0) {
|
|
128
|
+
throw ("Invalid input json data");
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
Logger.logInfo("ApplicationManager", "createAppTables", "Executing query : " + query);
|
|
132
|
+
await this.databaseManager.executeStatement(DatabaseType.AppDb, query);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
Logger.logError("ApplicationManager", "createAppTables", "Error while creating tables. Error: " + e);
|
|
135
|
+
throw (e);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (const indexMeta of this.parser.getIndexMetas()) {
|
|
140
|
+
const queryString: string = this.prepareCreateIndexQuery(indexMeta.indexName, indexMeta.structureName, indexMeta.fieldName);
|
|
141
|
+
try {
|
|
142
|
+
Logger.logInfo("ApplicationManager", "createAppTables", "Executing query : " + queryString);
|
|
143
|
+
await this.databaseManager.executeStatement(DatabaseType.AppDb, queryString);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
Logger.logError("ApplicationManager", "createAppTables", "Error while creating Index. Error: " + e);
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
prepareCreateTableQuery(
|
|
154
|
+
tableName: string,
|
|
155
|
+
tableColumnNames: string[],
|
|
156
|
+
tableColumnTypes: any[],
|
|
157
|
+
primaryKeys: string[],
|
|
158
|
+
uniqueKeys: string[],
|
|
159
|
+
mandatoryFields: boolean[],
|
|
160
|
+
{ foreignKeys = [], foreignKeyTableName = "", foreignKeyTableKeys = [] }: {
|
|
161
|
+
foreignKeys?: string[],
|
|
162
|
+
foreignKeyTableName?: string,
|
|
163
|
+
foreignKeyTableKeys?: string[]
|
|
164
|
+
} = {}
|
|
165
|
+
): string {
|
|
166
|
+
let query: string = "";
|
|
167
|
+
const primaryKey: string = primaryKeys.join(", ");
|
|
168
|
+
const uniqueKey: string = uniqueKeys.join(", ");
|
|
169
|
+
let foreignKey: string = "";
|
|
170
|
+
let foreignKeyTableKey: string = "";
|
|
171
|
+
|
|
172
|
+
if (foreignKeyTableName.length > 0) {
|
|
173
|
+
foreignKey = foreignKeys.join(", ");
|
|
174
|
+
foreignKeyTableKey = foreignKeyTableKeys.join(", ");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const noOfColumns: number = tableColumnNames.length;
|
|
178
|
+
query += `CREATE TABLE IF NOT EXISTS ${tableName} (`;
|
|
179
|
+
|
|
180
|
+
for (let i = 0; i < noOfColumns; i++) {
|
|
181
|
+
if (i === 0) {
|
|
182
|
+
query += tableColumnNames[i];
|
|
183
|
+
} else {
|
|
184
|
+
query += `, ${tableColumnNames[i]}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (tableColumnTypes.length > 0) {
|
|
188
|
+
query += ` ${tableColumnTypes[i]}`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (mandatoryFields.length > 0) {
|
|
192
|
+
if (mandatoryFields[i]) {
|
|
193
|
+
query += " NOT NULL";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (primaryKey.length > 0) {
|
|
199
|
+
query += `, PRIMARY KEY(${primaryKey})`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (uniqueKey.length > 0) {
|
|
203
|
+
query += `, UNIQUE(${uniqueKey})`;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (foreignKeyTableName.length > 0) {
|
|
207
|
+
query += `, FOREIGN KEY (${foreignKey}) REFERENCES ${foreignKeyTableName}(${foreignKeyTableKey}) ON DELETE CASCADE`;
|
|
208
|
+
}
|
|
209
|
+
query += ")";
|
|
210
|
+
return query;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
prepareCreateIndexQuery(indexName: string, structureName: string, fieldNames: string[]): string {
|
|
214
|
+
let query: string = `CREATE INDEX ${indexName} ON ${structureName} (`;
|
|
215
|
+
query += fieldNames.join(", ");
|
|
216
|
+
query += ")";
|
|
217
|
+
return query;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
appTableGenerator(message: { [key: string]: any }) {
|
|
221
|
+
const queries: string[] = [];
|
|
222
|
+
const structureMetas = message['structureMetas'];
|
|
223
|
+
const beMetaArray = message['beMetaArray'];
|
|
224
|
+
const fieldMetaArray = message['fieldMetaArray'];
|
|
225
|
+
|
|
226
|
+
const noOfStructureMetas: number = structureMetas.length;
|
|
227
|
+
|
|
228
|
+
let structureMeta;
|
|
229
|
+
const foreignKeysForItemStructure: string[] = [FieldConstants.FieldFid];
|
|
230
|
+
const parentsForForeignKeysInHeaderStructure: string[] = [FieldConstants.FieldLid];
|
|
231
|
+
|
|
232
|
+
for (let i = 0; i < noOfStructureMetas; i++) {
|
|
233
|
+
structureMeta = structureMetas[i];
|
|
234
|
+
|
|
235
|
+
const beName: string = structureMeta.beName;
|
|
236
|
+
if (beName.length === 0) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const beMeta = beMetaArray.find((element: any) => element.beName === beName);
|
|
241
|
+
if (beMeta == null || beMeta.save !== "true") {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const fieldMetas = fieldMetaArray.filter((element: any) =>
|
|
246
|
+
element.appName === structureMeta.appName &&
|
|
247
|
+
element.beName === structureMeta.beName &&
|
|
248
|
+
element.structureName === structureMeta.structureName
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
if (fieldMetas.length === 0) {
|
|
252
|
+
throw "Invalid metadata.";
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const columnNames: string[] = [];
|
|
256
|
+
const columnTypes: any[] = [];
|
|
257
|
+
const mandatoryFields: boolean[] = [];
|
|
258
|
+
|
|
259
|
+
const gidsVector: string[] = [];
|
|
260
|
+
|
|
261
|
+
const primaryKeys: string[] = [FieldConstants.FieldLid];
|
|
262
|
+
const isStructureHeader: boolean = structureMeta.isHeader === "1";
|
|
263
|
+
|
|
264
|
+
columnNames.push(FieldConstants.FieldLid);
|
|
265
|
+
columnTypes.push(FieldConstants.FieldTypeLid);
|
|
266
|
+
mandatoryFields.push(true);
|
|
267
|
+
|
|
268
|
+
columnNames.push(FieldConstants.FieldTimestamp);
|
|
269
|
+
columnTypes.push(FieldConstants.FieldTypeTimestamp);
|
|
270
|
+
mandatoryFields.push(true);
|
|
271
|
+
|
|
272
|
+
columnNames.push(FieldConstants.FieldSyncStatus);
|
|
273
|
+
columnTypes.push(FieldConstants.FieldTypeSyncStatus);
|
|
274
|
+
mandatoryFields.push(true);
|
|
275
|
+
|
|
276
|
+
columnNames.push(FieldConstants.FieldObjectStatus);
|
|
277
|
+
columnTypes.push(FieldConstants.FieldTypeObjectStatus);
|
|
278
|
+
mandatoryFields.push(true);
|
|
279
|
+
|
|
280
|
+
if (isStructureHeader) {
|
|
281
|
+
columnNames.push(FieldConstants.FieldConflict);
|
|
282
|
+
columnTypes.push(FieldConstants.FieldTypeConflict);
|
|
283
|
+
mandatoryFields.push(false);
|
|
284
|
+
|
|
285
|
+
columnNames.push(FieldConstants.FieldInfoMsgCat);
|
|
286
|
+
columnTypes.push(FieldConstants.FieldTypeInfoMsgCat);
|
|
287
|
+
mandatoryFields.push(false);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!isStructureHeader) {
|
|
291
|
+
columnNames.push(FieldConstants.FieldFid);
|
|
292
|
+
columnTypes.push(FieldConstants.FieldTypeFid);
|
|
293
|
+
mandatoryFields.push(true);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let fieldMeta: any;
|
|
297
|
+
|
|
298
|
+
for (let j = 0; j < fieldMetas.length; j++) {
|
|
299
|
+
fieldMeta = fieldMetas[j];
|
|
300
|
+
|
|
301
|
+
const _columnName: string = fieldMeta.fieldName;
|
|
302
|
+
const _columnType: any = fieldMeta.sqlType;
|
|
303
|
+
|
|
304
|
+
columnNames.push(_columnName);
|
|
305
|
+
columnTypes.push(_columnType);
|
|
306
|
+
|
|
307
|
+
if (fieldMeta.isGid === "1") {
|
|
308
|
+
mandatoryFields.push(true);
|
|
309
|
+
gidsVector.push(fieldMeta.fieldName);
|
|
310
|
+
} else {
|
|
311
|
+
mandatoryFields.push(false);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const noOfGids: number = gidsVector.length;
|
|
316
|
+
const uniqueKeys: string[] = gidsVector;
|
|
317
|
+
|
|
318
|
+
if (isStructureHeader) {
|
|
319
|
+
const queryString: string = this.prepareCreateTableQuery(
|
|
320
|
+
structureMeta.structureName,
|
|
321
|
+
columnNames,
|
|
322
|
+
columnTypes,
|
|
323
|
+
primaryKeys,
|
|
324
|
+
uniqueKeys,
|
|
325
|
+
mandatoryFields
|
|
326
|
+
);
|
|
327
|
+
queries.push(queryString);
|
|
328
|
+
} else {
|
|
329
|
+
let headerName: string = structureMeta.beName + "_HEADER";
|
|
330
|
+
try {
|
|
331
|
+
const headerStructureMeta = structureMetas.find(
|
|
332
|
+
(element) =>
|
|
333
|
+
element.beName === structureMeta.beName &&
|
|
334
|
+
element.isHeader === "1"
|
|
335
|
+
);
|
|
336
|
+
if (headerStructureMeta) {
|
|
337
|
+
headerName = headerStructureMeta.structureName;
|
|
338
|
+
}
|
|
339
|
+
} catch (e) {}
|
|
340
|
+
const queryString: string = this.prepareCreateTableQuery(
|
|
341
|
+
structureMeta.structureName,
|
|
342
|
+
columnNames,
|
|
343
|
+
columnTypes,
|
|
344
|
+
primaryKeys,
|
|
345
|
+
uniqueKeys,
|
|
346
|
+
mandatoryFields,
|
|
347
|
+
{ foreignKeys: foreignKeysForItemStructure, foreignKeyTableName: headerName, foreignKeyTableKeys: parentsForForeignKeysInHeaderStructure }
|
|
348
|
+
);
|
|
349
|
+
queries.push(queryString);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return queries;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
// import { electron } from 'webpack';
|
|
3
|
+
import { Logger } from './logger';
|
|
4
|
+
import * as crypto from "crypto-js";
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
cordova: any; // This is defined from the cordova plugin
|
|
9
|
+
device: any; // This is defined from the cordova-plugin-device plugin
|
|
10
|
+
resolveLocalFileSystemURL: any;
|
|
11
|
+
UnviredDB: any; // This is defined from the cordova-plugin-unvired-db
|
|
12
|
+
FirebasePlugin: any; // This is defined from the cordova-plugin-firebasex plugin
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class FrameworkHelper {
|
|
17
|
+
static getPlatform(): string {
|
|
18
|
+
const platform = window.cordova.platformId//window.device.platform;
|
|
19
|
+
Logger.logInfo("FrameworkHelper", "getPlatform", "Platform: " + platform);
|
|
20
|
+
return platform.toLowerCase(); //"electron"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static getUUID(): string {
|
|
24
|
+
return uuidv4().replace(/-/g, '');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static getFrontendType() {
|
|
28
|
+
const platform = window.cordova.platformId;
|
|
29
|
+
const deviceModel = window.device.model;
|
|
30
|
+
Logger.logInfo("FrameworkHelper", "getFrontendType", "Platform: " + platform + " Device Model: " + deviceModel);
|
|
31
|
+
|
|
32
|
+
switch (platform) {
|
|
33
|
+
case "ios":
|
|
34
|
+
if (/iphone|ipod/i.test(deviceModel)) {
|
|
35
|
+
return 'IPHONE';
|
|
36
|
+
}
|
|
37
|
+
else if (/ipad/i.test(deviceModel)) {
|
|
38
|
+
return 'IPAD';
|
|
39
|
+
}
|
|
40
|
+
case "android":
|
|
41
|
+
if (/tablet/i.test(deviceModel)) {
|
|
42
|
+
return 'ANDROID_TABLET';
|
|
43
|
+
} else {
|
|
44
|
+
return 'ANDROID_PHONE';
|
|
45
|
+
}
|
|
46
|
+
case "browser":
|
|
47
|
+
return "BROWSER";
|
|
48
|
+
case "electron":
|
|
49
|
+
return "WINDOWS";
|
|
50
|
+
default:
|
|
51
|
+
return "IPHONE";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static getMD5String(str) {
|
|
56
|
+
if (str == null || str == undefined || str == "") {
|
|
57
|
+
return str;
|
|
58
|
+
}
|
|
59
|
+
const bytes = new TextEncoder().encode(str);
|
|
60
|
+
try {
|
|
61
|
+
var md5String = crypto.MD5(str).toString();
|
|
62
|
+
Logger.logInfo("FrameworkHelper", "getMD5String", `MD5 String: ${md5String}`);
|
|
63
|
+
return md5String;
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
Logger.logError("FrameworkHelper", "getMD5String", `Error: ${JSON.stringify(e)}`);
|
|
67
|
+
return str;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static getDocumentDirectory() {
|
|
72
|
+
return window.cordova.file.dataDirectory;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static async getFolderBasedOnUserId(userId: string): Promise<string> {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const userPath = this.getDocumentDirectory() + userId
|
|
78
|
+
window.resolveLocalFileSystemURL(userPath, (dir) => {
|
|
79
|
+
Logger.logInfo("FrameworkHelper", "getFolderBasedOnUserId", "Directory exists: " + dir.fullPath);
|
|
80
|
+
resolve(dir.nativeURL);
|
|
81
|
+
}, (error) => {
|
|
82
|
+
Logger.logInfo("FrameworkHelper", "getFolderBasedOnUserId", "Directory did not exist. Error: " + error);
|
|
83
|
+
// Directory did not exist, so creating it.
|
|
84
|
+
Logger.logInfo("FrameworkHelper", "getFolderBasedOnUserId", "Directory did not exist, so creating it: " + userPath);
|
|
85
|
+
window.resolveLocalFileSystemURL(this.getDocumentDirectory(), (parentDir) => {
|
|
86
|
+
const newDir = parentDir.getDirectory(userId, {create: true})
|
|
87
|
+
Logger.logInfo("FrameworkHelper", "getFolderBasedOnUserId", "Directory created: " + newDir.nativeURL);
|
|
88
|
+
resolve(newDir.nativeURL);
|
|
89
|
+
}, (error) => {
|
|
90
|
+
Logger.logError("FrameworkHelper", "getFolderBasedOnUserId", "Unable to get folder for userId: " + userId + ". Error: " + error);
|
|
91
|
+
resolve("");
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static async getAppDbPath(userId: string) {
|
|
98
|
+
const userDir = await this.getFolderBasedOnUserId(userId);
|
|
99
|
+
return userDir + "app.db";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static async getFrameworkDbPath(userId: string) {
|
|
103
|
+
const userDir = await this.getFolderBasedOnUserId(userId);
|
|
104
|
+
return userDir + "framework.db";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static deleteUserFolder(userId: string): Promise<void> {
|
|
108
|
+
return new Promise(async (resolve, reject) => {
|
|
109
|
+
const userPath = this.getDocumentDirectory() + userId
|
|
110
|
+
window.resolveLocalFileSystemURL(userPath, (dir) => {
|
|
111
|
+
Logger.logInfo("FrameworkHelper", "deleteUserFolder", "Directory exists: " + dir.fullPath);
|
|
112
|
+
dir.removeRecursively(() => {
|
|
113
|
+
Logger.logInfo("FrameworkHelper", "deleteUserFolder", "User folder removed");
|
|
114
|
+
resolve();
|
|
115
|
+
},
|
|
116
|
+
(error) => {
|
|
117
|
+
Logger.logError("FrameworkHelper", "deleteUserFolder", "Remove user folder error: " + error);
|
|
118
|
+
reject(error);
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
(error) => {
|
|
122
|
+
Logger.logError("FrameworkHelper", "deleteUserFolder", "Get user folder error: " + error);
|
|
123
|
+
reject(error);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|