@regulaforensics/cordova-plugin-document-reader-api 6.9.0 → 7.1.0

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.
@@ -1,1119 +0,0 @@
1
- package cordova.plugin.documentreader;
2
-
3
- import static cordova.plugin.documentreader.Helpers.*;
4
-
5
- import android.content.Context;
6
- import android.graphics.Bitmap;
7
- import android.graphics.Rect;
8
- import android.util.Base64;
9
-
10
- import com.regula.common.exception.RegulaException;
11
- import com.regula.documentreader.api.config.RecognizeConfig;
12
- import com.regula.documentreader.api.config.ScannerConfig;
13
- import com.regula.documentreader.api.enums.*;
14
- import com.regula.documentreader.api.params.*;
15
- import com.regula.documentreader.api.params.rfid.*;
16
- import com.regula.documentreader.api.params.rfid.authorization.*;
17
- import com.regula.documentreader.api.results.*;
18
- import com.regula.documentreader.api.results.authenticity.*;
19
- import com.regula.documentreader.api.results.rfid.*;
20
-
21
- import org.json.JSONArray;
22
- import org.json.JSONException;
23
- import org.json.JSONObject;
24
-
25
- import java.util.Arrays;
26
-
27
- @SuppressWarnings("deprecation")
28
- class JSONConstructor {
29
- static JSONObject generateVideoEncoderCompletion(String sessionId, java.io.File file) {
30
- JSONObject result = new JSONObject();
31
-
32
- try {
33
- result.put("sessionId", sessionId);
34
- result.put("filePath", file.getPath());
35
-
36
- } catch (JSONException e) {
37
- e.printStackTrace();
38
- }
39
-
40
- return result;
41
- }
42
-
43
- static JSONObject generateCompletion(int action, DocumentReaderResults results, RegulaException error, Context context) {
44
- JSONObject result = new JSONObject();
45
- try {
46
- if (Arrays.asList(
47
- DocReaderAction.COMPLETE,
48
- DocReaderAction.MORE_PAGES_AVAILABLE,
49
- DocReaderAction.CANCEL,
50
- DocReaderAction.ERROR,
51
- DocReaderAction.TIMEOUT
52
- ).contains(action))
53
- result.put("results", generateDocumentReaderResults(results, context));
54
- result.put("action", action);
55
- result.put("error", generateRegulaException(error));
56
- } catch (JSONException ignored) {
57
- }
58
- return result;
59
- }
60
-
61
- static JSONObject generateRegulaException(RegulaException input) {
62
- JSONObject result = new JSONObject();
63
- if (input == null) return null;
64
- try {
65
- result.put("errorCode", input.getErrorCode());
66
- result.put("message", input.getMessage());
67
- } catch (JSONException e) {
68
- e.printStackTrace();
69
- }
70
- return result;
71
- }
72
-
73
- static JSONObject generatePACertificateCompletion(byte[] serialNumber, PAResourcesIssuer issuer) {
74
- JSONObject result = new JSONObject();
75
- try {
76
- result.put("serialNumber", generateByteArray(serialNumber));
77
- result.put("issuer", generatePAResourcesIssuer(issuer));
78
- } catch (JSONException ignored) {
79
- }
80
-
81
- return result;
82
- }
83
-
84
- static TccParams TCCParamsFromJSON(JSONObject input) {
85
- TccParams result = new TccParams();
86
- try {
87
- if (input.has("serviceUrlTA"))
88
- result.setServiceUrlTA(input.getString("serviceUrlTA"));
89
- if (input.has("serviceUrlPA"))
90
- result.setServiceUrlPA(input.getString("serviceUrlPA"));
91
- if (input.has("pfxCertUrl"))
92
- result.setPfxCertUrl(input.getString("pfxCertUrl"));
93
- if (input.has("pfxPassPhrase"))
94
- result.setPfxPassPhrase(input.getString("pfxPassPhrase"));
95
- if (input.has("pfxCert"))
96
- result.setPfxCert(Base64.decode(input.getString("pfxCert"), Base64.DEFAULT));
97
- } catch (JSONException e) {
98
- e.printStackTrace();
99
- }
100
- return result;
101
- }
102
-
103
- static ImageInputData ImageInputDataFromJSON(JSONObject input) {
104
- if (input == null) return null;
105
- try {
106
- Bitmap image;
107
- int light = 6;
108
- int pageIndex = 0;
109
-
110
- if (input.has("image"))
111
- image = bitmapFromBase64(input.getString("image"));
112
- else return null;
113
- if (input.has("light"))
114
- pageIndex = input.getInt("light");
115
- if (input.has("pageIndex"))
116
- pageIndex = input.getInt("pageIndex");
117
- return new ImageInputData(image, light, pageIndex);
118
- } catch (JSONException e) {
119
- e.printStackTrace();
120
- }
121
-
122
- return null;
123
- }
124
-
125
- static DocReaderConfig DocReaderConfigFromJSON(JSONObject input) {
126
- DocReaderConfig result;
127
- byte[] license;
128
- try {
129
- if (input.has("license")) {
130
- license = Base64.decode(input.getString("license"), Base64.DEFAULT);
131
- result = new DocReaderConfig(license);
132
- } else return null;
133
- if (input.has("customDb"))
134
- result = new DocReaderConfig(license, Base64.decode(input.getString("customDb"), Base64.DEFAULT));
135
- if (input.has("licenseUpdate"))
136
- result.setLicenseUpdate(input.getBoolean("licenseUpdate"));
137
- if (input.has("delayedNNLoad"))
138
- result.setDelayedNNLoad(input.getBoolean("delayedNNLoad"));
139
- if (input.has("blackList"))
140
- result.setBlackList(input.getJSONObject("blackList"));
141
-
142
- return result;
143
- } catch (JSONException e) {
144
- e.printStackTrace();
145
- }
146
- return null;
147
- }
148
-
149
- static ScannerConfig ScannerConfigFromJSON(JSONObject input) {
150
- if (!input.has("scenario") && !input.has("onlineProcessingConfig")) return null;
151
- try {
152
- ScannerConfig.Builder builder;
153
- if (input.has("scenario"))
154
- builder = new ScannerConfig.Builder(input.getString("scenario"));
155
- else
156
- builder = new ScannerConfig.Builder(RegulaConfig.OnlineProcessingConfigFromJSON(input.getJSONObject("onlineProcessingConfig")));
157
- if (input.has("onlineProcessingConfig"))
158
- builder.setOnlineProcessingConfig(RegulaConfig.OnlineProcessingConfigFromJSON(input.getJSONObject("onlineProcessingConfig")));
159
- if (input.has("livePortrait"))
160
- builder.setLivePortrait(bitmapFromBase64(input.getString("livePortrait")));
161
- if (input.has("extPortrait"))
162
- builder.setExtPortrait(bitmapFromBase64(input.getString("extPortrait")));
163
- if (input.has("cameraId"))
164
- builder.setCameraId(input.getInt("cameraId"));
165
- return builder.build();
166
- } catch (JSONException e) {
167
- e.printStackTrace();
168
- }
169
- return null;
170
- }
171
-
172
- static RecognizeConfig RecognizeConfigFromJSON(JSONObject input) {
173
- if (!input.has("scenario") && !input.has("onlineProcessingConfig")) return null;
174
- if (!input.has("image") && !input.has("images") && !input.has("imageInputData")) return null;
175
- try {
176
- RecognizeConfig.Builder builder;
177
- if (input.has("scenario"))
178
- builder = new RecognizeConfig.Builder(input.getString("scenario"));
179
- else
180
- builder = new RecognizeConfig.Builder(RegulaConfig.OnlineProcessingConfigFromJSON(input.getJSONObject("onlineProcessingConfig")));
181
- if (input.has("livePortrait"))
182
- builder.setLivePortrait(bitmapFromBase64(input.getString("livePortrait")));
183
- if (input.has("extPortrait"))
184
- builder.setExtPortrait(bitmapFromBase64(input.getString("extPortrait")));
185
- if (input.has("image"))
186
- builder.setBitmap(bitmapFromBase64(input.getString("image")));
187
- if (input.has("oneShotIdentification"))
188
- builder.setOneShotIdentification(input.getBoolean("oneShotIdentification"));
189
- if (input.has("images")) {
190
- JSONArray base64Images = input.getJSONArray("images");
191
- Bitmap[] images = new Bitmap[base64Images.length()];
192
- for (int i = 0; i < images.length; i++)
193
- images[i] = bitmapFromBase64(base64Images.getString(i));
194
- builder.setBitmaps(images);
195
- }
196
- if (input.has("imageInputData")) {
197
- JSONArray base64InputData = input.getJSONArray("imageInputData");
198
- ImageInputData[] inputData = new ImageInputData[base64InputData.length()];
199
- for (int i = 0; i < inputData.length; i++)
200
- inputData[i] = ImageInputDataFromJSON(base64InputData.getJSONObject(i));
201
- builder.setImageInputData(inputData);
202
- }
203
- return builder.build();
204
- } catch (JSONException e) {
205
- e.printStackTrace();
206
- }
207
- return null;
208
- }
209
-
210
- static ImageQA ImageQAFromJSON(JSONObject input) {
211
- if (input == null) return null;
212
- ImageQA result = new ImageQA();
213
- try {
214
- if (input.has("dpiThreshold"))
215
- result.dpiThreshold = input.getInt("dpiThreshold");
216
- if (input.has("angleThreshold"))
217
- result.angleThreshold = input.getInt("angleThreshold");
218
- if (input.has("focusCheck"))
219
- result.focusCheck = input.getBoolean("focusCheck");
220
- if (input.has("glaresCheck"))
221
- result.glaresCheck = input.getBoolean("glaresCheck");
222
- if (input.has("colornessCheck"))
223
- result.colornessCheck = input.getBoolean("colornessCheck");
224
- if (input.has("moireCheck"))
225
- result.moireCheck = input.getBoolean("moireCheck");
226
- if (input.has("expectedPass"))
227
- result.expectedPass = intArrayFromJSON(input.getJSONArray("expectedPass"));
228
- if (input.has("documentPositionIndent"))
229
- result.documentPositionIndent = input.getInt("documentPositionIndent");
230
- if (input.has("glaresCheckParams"))
231
- result.glaresCheckParams = GlaresCheckParamsFromJSON(input.getJSONObject("glaresCheckParams"));
232
- } catch (JSONException e) {
233
- e.printStackTrace();
234
- }
235
-
236
- return result;
237
- }
238
-
239
- static ImageQA.GlaresCheckParams GlaresCheckParamsFromJSON(JSONObject input) {
240
- if (input == null) return null;
241
- ImageQA.GlaresCheckParams result = new ImageQA.GlaresCheckParams();
242
- try {
243
- if (input.has("imgMarginPart"))
244
- result.imgMarginPart = input.getDouble("imgMarginPart");
245
- if (input.has("maxGlaringPart"))
246
- result.maxGlaringPart = input.getDouble("maxGlaringPart");
247
- } catch (JSONException e) {
248
- e.printStackTrace();
249
- }
250
-
251
- return result;
252
- }
253
-
254
- static JSONObject generateImageQA(ImageQA input) {
255
- JSONObject result = new JSONObject();
256
- if (input == null) return null;
257
- try {
258
- result.put("dpiThreshold", input.dpiThreshold);
259
- result.put("angleThreshold", input.angleThreshold);
260
- result.put("focusCheck", input.focusCheck);
261
- result.put("glaresCheck", input.glaresCheck);
262
- result.put("colornessCheck", input.colornessCheck);
263
- result.put("moireCheck", input.moireCheck);
264
- result.put("documentPositionIndent", input.documentPositionIndent);
265
- result.put("expectedPass", generateIntArray(input.expectedPass));
266
- result.put("glaresCheckParams", generateGlaresCheckParams(input.glaresCheckParams));
267
- } catch (JSONException e) {
268
- e.printStackTrace();
269
- }
270
- return result;
271
- }
272
-
273
- static JSONObject generateGlaresCheckParams(ImageQA.GlaresCheckParams input) {
274
- JSONObject result = new JSONObject();
275
- if (input == null) return null;
276
- try {
277
- result.put("imgMarginPart", input.imgMarginPart);
278
- result.put("maxGlaringPart", input.maxGlaringPart);
279
- } catch (JSONException e) {
280
- e.printStackTrace();
281
- }
282
- return result;
283
- }
284
-
285
- // To JSON
286
-
287
- static JSONObject generateDocumentReaderScenario(DocumentReaderScenario input) {
288
- JSONObject result = new JSONObject();
289
- if (input == null) return null;
290
- try {
291
- result.put("name", input.name);
292
- result.put("caption", input.caption);
293
- result.put("description", input.description);
294
- result.put("multiPageOff", input.multiPageOff);
295
- result.put("frameKWHLandscape", input.frameKWHLandscape);
296
- result.put("frameKWHPortrait", input.frameKWHPortrait);
297
- result.put("frameKWHDoublePageSpreadPortrait", input.frameKWHDoublePageSpreadPortrait);
298
- result.put("frameKWHDoublePageSpreadLandscape", input.frameKWHDoublePageSpreadLandscape);
299
- result.put("frameOrientation", input.frameOrientation);
300
- result.put("uvTorch", input.uvTorch);
301
- result.put("faceExt", input.faceExt);
302
- result.put("seriesProcessMode", input.seriesProcessMode);
303
- result.put("manualCrop", input.manualCrop);
304
- } catch (JSONException e) {
305
- e.printStackTrace();
306
- }
307
- return result;
308
- }
309
-
310
- static JSONObject generateRect(Rect input) {
311
- JSONObject result = new JSONObject();
312
- if (input == null) return null;
313
- try {
314
- result.put("bottom", input.bottom);
315
- result.put("top", input.top);
316
- result.put("left", input.left);
317
- result.put("right", input.right);
318
- } catch (JSONException e) {
319
- e.printStackTrace();
320
- }
321
- return result;
322
- }
323
-
324
- static JSONObject generateDocReaderFieldRect(DocReaderFieldRect input) {
325
- JSONObject result = new JSONObject();
326
- if (input == null) return null;
327
- try {
328
- result.put("bottom", input.bottom);
329
- result.put("top", input.top);
330
- result.put("left", input.left);
331
- result.put("right", input.right);
332
- } catch (JSONException e) {
333
- e.printStackTrace();
334
- }
335
- return result;
336
- }
337
-
338
- static JSONObject generateDocumentReaderGraphicField(DocumentReaderGraphicField input, Context context) {
339
- JSONObject result = new JSONObject();
340
- if (input == null) return null;
341
- try {
342
- result.put("sourceType", input.sourceType);
343
- result.put("fieldType", input.fieldType);
344
- result.put("light", input.light);
345
- result.put("pageIndex", input.pageIndex);
346
- result.put("originalPageIndex", input.originalPageIndex);
347
- result.put("fieldName", eGraphicFieldType.getTranslation(context, input.fieldType));
348
- result.put("lightName", eRPRM_Lights.getTranslation(context, input.light));
349
- result.put("value", input.imageBase64());
350
- result.put("fieldRect", generateDocReaderFieldRect(input.boundRect));
351
- } catch (JSONException e) {
352
- e.printStackTrace();
353
- }
354
- return result;
355
- }
356
-
357
- static JSONObject generateDocumentReaderGraphicResult(DocumentReaderGraphicResult input, Context context) {
358
- JSONObject result = new JSONObject();
359
- if (input == null) return null;
360
- try {
361
- result.put("fields", generateList(input.fields, JSONConstructor::generateDocumentReaderGraphicField, context));
362
- } catch (JSONException e) {
363
- e.printStackTrace();
364
- }
365
- return result;
366
- }
367
-
368
- static JSONObject generateDocumentReaderValue(DocumentReaderValue input, Context context) {
369
- JSONObject result = new JSONObject();
370
- if (input == null) return null;
371
- try {
372
- result.put("pageIndex", input.pageIndex);
373
- result.put("sourceType", input.sourceType);
374
- result.put("validity", input.validity);
375
- result.put("probability", input.probability);
376
- result.put("value", input.value);
377
- result.put("originalValue", input.originalValue);
378
- result.put("boundRect", generateRect(input.boundRect));
379
- result.put("comparison", generateMap(input.comparison));
380
- result.put("originalSymbols", generateList(input.originalSymbols, JSONConstructor::generateDocumentReaderSymbol));
381
- result.put("rfidOrigin", generateDocumentReaderRfidOrigin(input.rfidOrigin));
382
- } catch (JSONException e) {
383
- e.printStackTrace();
384
- }
385
- return result;
386
- }
387
-
388
- static JSONObject generateDocumentReaderTextField(DocumentReaderTextField input, Context context) {
389
- JSONObject result = new JSONObject();
390
- if (input == null) return null;
391
- try {
392
- result.put("fieldType", input.fieldType);
393
- result.put("lcid", input.lcid);
394
- result.put("status", input.status);
395
- result.put("lcidName", input.getLcidName(context));
396
- result.put("fieldName", input.getFieldName(context));
397
- result.put("value", input.value);
398
- result.put("getValue", generateDocumentReaderValue(input.value(), context));
399
- result.put("values", generateList(input.values, JSONConstructor::generateDocumentReaderValue, context));
400
- result.put("comparisonList", generateList(input.comparisonList, JSONConstructor::generateDocumentReaderComparison));
401
- result.put("validityList", generateList(input.validityList, JSONConstructor::generateDocumentReaderValidity));
402
- result.put("comparisonStatus", input.comparisonStatus);
403
- result.put("validityStatus", input.validityStatus);
404
- } catch (JSONException e) {
405
- e.printStackTrace();
406
- }
407
- return result;
408
- }
409
-
410
- static JSONObject generateDocumentReaderTextResult(DocumentReaderTextResult input, Context context) {
411
- JSONObject result = new JSONObject();
412
- if (input == null) return null;
413
- try {
414
- result.put("status", input.status);
415
- result.put("comparisonStatus", input.comparisonStatus);
416
- result.put("validityStatus", input.validityStatus);
417
- result.put("availableSourceList", generateList(input.availableSourceList, JSONConstructor::generateDocumentReaderTextSource));
418
- result.put("fields", generateList(input.fields, JSONConstructor::generateDocumentReaderTextField, context));
419
- } catch (JSONException e) {
420
- e.printStackTrace();
421
- }
422
- return result;
423
- }
424
-
425
- static JSONObject generateCoordinate(Coordinate input) {
426
- JSONObject result = new JSONObject();
427
- if (input == null) return null;
428
- try {
429
- result.put("x", input.x);
430
- result.put("y", input.y);
431
- } catch (JSONException e) {
432
- e.printStackTrace();
433
- }
434
- return result;
435
- }
436
-
437
- static JSONObject generateElementPosition(ElementPosition input) {
438
- JSONObject result = new JSONObject();
439
- if (input == null) return null;
440
- try {
441
- result.put("docFormat", input.docFormat);
442
- result.put("width", input.width);
443
- result.put("height", input.height);
444
- result.put("dpi", input.dpi);
445
- result.put("pageIndex", input.pageIndex);
446
- result.put("inverse", input.inverse);
447
- result.put("perspectiveTr", input.perspectiveTr);
448
- result.put("objArea", input.objArea);
449
- result.put("objIntAngleDev", input.objIntAngleDev);
450
- result.put("resultStatus", input.resultStatus);
451
- result.put("angle", input.angle);
452
- result.put("center", generateCoordinate(input.center));
453
- result.put("leftTop", generateCoordinate(input.leftTop));
454
- result.put("leftBottom", generateCoordinate(input.leftBottom));
455
- result.put("rightTop", generateCoordinate(input.rightTop));
456
- result.put("rightBottom", generateCoordinate(input.rightBottom));
457
- } catch (JSONException e) {
458
- e.printStackTrace();
459
- }
460
- return result;
461
- }
462
-
463
- static JSONObject generateImageQuality(ImageQuality input) {
464
- JSONObject result = new JSONObject();
465
- if (input == null) return null;
466
- try {
467
- result.put("featureType", input.featureType);
468
- result.put("result", input.result);
469
- result.put("type", input.type);
470
- } catch (JSONException e) {
471
- e.printStackTrace();
472
- }
473
- return result;
474
- }
475
-
476
- static JSONObject generateImageQualityGroup(ImageQualityGroup input) {
477
- JSONObject result = new JSONObject();
478
- if (input == null) return null;
479
- try {
480
- result.put("count", input.count);
481
- result.put("result", input.result);
482
- result.put("imageQualityList", generateList(input.imageQualityList, JSONConstructor::generateImageQuality));
483
- result.put("pageIndex", input.pageIndex);
484
- } catch (JSONException e) {
485
- e.printStackTrace();
486
- }
487
- return result;
488
- }
489
-
490
- static JSONObject generateDocumentReaderDocumentType(DocumentReaderDocumentType input) {
491
- JSONObject result = new JSONObject();
492
- if (input == null) return null;
493
- try {
494
- result.put("pageIndex", input.pageIndex);
495
- result.put("documentID", input.documentID);
496
- result.put("dType", input.dType);
497
- result.put("dFormat", input.dFormat);
498
- result.put("dMRZ", input.dMRZ);
499
- result.put("isDeprecated", input.isDeprecated);
500
- result.put("name", input.name);
501
- result.put("ICAOCode", input.ICAOCode);
502
- result.put("dDescription", input.dDescription);
503
- result.put("dYear", input.dYear);
504
- result.put("dCountryName", input.dCountryName);
505
- result.put("FDSID", generateIntArray(input.FDSID));
506
- } catch (JSONException e) {
507
- e.printStackTrace();
508
- }
509
- return result;
510
- }
511
-
512
- static JSONObject generateDocumentReaderNotification(DocumentReaderNotification input) {
513
- JSONObject result = new JSONObject();
514
- if (input == null) return null;
515
- try {
516
- result.put("notificationCode", input.getNotificationCode());
517
- result.put("dataFileType", input.getDataFileType());
518
- result.put("progress", input.getProgress());
519
- } catch (JSONException e) {
520
- e.printStackTrace();
521
- }
522
- return result;
523
- }
524
-
525
- static JSONObject generateAccessControlProcedureType(AccessControlProcedureType input) {
526
- JSONObject result = new JSONObject();
527
- if (input == null) return null;
528
- try {
529
- result.put("activeOptionIdx", input.activeOptionIdx);
530
- result.put("type", input.type);
531
- result.put("status", input.status);
532
- result.put("notifications", generateList(input.notifications));
533
- } catch (JSONException e) {
534
- e.printStackTrace();
535
- }
536
- return result;
537
- }
538
-
539
- static JSONObject generateFileData(FileData input) {
540
- JSONObject result = new JSONObject();
541
- if (input == null) return null;
542
- try {
543
- result.put("length", input.length);
544
- result.put("type", input.type);
545
- result.put("status", input.status);
546
- result.put("data", input.data);
547
- } catch (JSONException e) {
548
- e.printStackTrace();
549
- }
550
- return result;
551
- }
552
-
553
- static JSONObject generateCertificateData(CertificateData input) {
554
- JSONObject result = new JSONObject();
555
- if (input == null) return null;
556
- try {
557
- result.put("length", input.length);
558
- result.put("data", input.data);
559
- } catch (JSONException e) {
560
- e.printStackTrace();
561
- }
562
- return result;
563
- }
564
-
565
- static JSONObject generateSecurityObjectCertificates(SecurityObjectCertificates input) {
566
- JSONObject result = new JSONObject();
567
- if (input == null) return null;
568
- try {
569
- result.put("securityObject", generateCertificateData(input.securityObject));
570
- } catch (JSONException e) {
571
- e.printStackTrace();
572
- }
573
- return result;
574
- }
575
-
576
- static JSONObject generateFile(File input) {
577
- JSONObject result = new JSONObject();
578
- if (input == null) return null;
579
- try {
580
- result.put("readingTime", input.readingTime);
581
- result.put("type", input.type);
582
- result.put("pAStatus", input.pAStatus);
583
- result.put("readingStatus", input.readingStatus);
584
- result.put("fileID", input.fileID);
585
- result.put("fileData", generateFileData(input.fileData));
586
- result.put("certificates", generateSecurityObjectCertificates(input.certificates));
587
- result.put("docFieldsText", generateList(input.docFieldsText));
588
- result.put("docFieldsGraphics", generateList(input.docFieldsGraphics));
589
- result.put("docFieldsOriginals", generateList(input.docFieldsOriginals));
590
- result.put("notifications", generateList(input.notifications));
591
- } catch (JSONException e) {
592
- e.printStackTrace();
593
- }
594
- return result;
595
- }
596
-
597
- static JSONObject generateApplication(Application input) {
598
- JSONObject result = new JSONObject();
599
- if (input == null) return null;
600
- try {
601
- result.put("type", input.type);
602
- result.put("status", input.status);
603
- result.put("applicationID", input.applicationID);
604
- result.put("dataHashAlgorithm", input.dataHashAlgorithm);
605
- result.put("unicodeVersion", input.unicodeVersion);
606
- result.put("version", input.version);
607
- result.put("files", generateList(input.files, JSONConstructor::generateFile));
608
- } catch (JSONException e) {
609
- e.printStackTrace();
610
- }
611
- return result;
612
- }
613
-
614
- static JSONObject generateValue(Value input) {
615
- JSONObject result = new JSONObject();
616
- if (input == null) return null;
617
- try {
618
- result.put("length", input.length);
619
- result.put("type", input.type);
620
- result.put("status", input.status);
621
- result.put("data", input.data);
622
- result.put("format", input.format);
623
- } catch (JSONException e) {
624
- e.printStackTrace();
625
- }
626
- return result;
627
- }
628
-
629
- static JSONObject generateAttribute(Attribute input) {
630
- JSONObject result = new JSONObject();
631
- if (input == null) return null;
632
- try {
633
- result.put("type", input.type);
634
- result.put("value", generateValue(input.value));
635
- } catch (JSONException e) {
636
- e.printStackTrace();
637
- }
638
- return result;
639
- }
640
-
641
- static JSONObject generateAuthority(Authority input) {
642
- JSONObject result = new JSONObject();
643
- if (input == null) return null;
644
- try {
645
- result.put("data", input.data);
646
- result.put("friendlyName", generateValue(input.friendlyName));
647
- result.put("attributes", generateList(input.attributes, JSONConstructor::generateAttribute));
648
- } catch (JSONException e) {
649
- e.printStackTrace();
650
- }
651
- return result;
652
- }
653
-
654
- static JSONObject generateExtension(Extension input) {
655
- JSONObject result = new JSONObject();
656
- if (input == null) return null;
657
- try {
658
- result.put("data", input.data);
659
- result.put("type", input.type);
660
- } catch (JSONException e) {
661
- e.printStackTrace();
662
- }
663
- return result;
664
- }
665
-
666
- static JSONObject generateValidity(Validity input) {
667
- JSONObject result = new JSONObject();
668
- if (input == null) return null;
669
- try {
670
- result.put("notAfter", generateValue(input.notAfter));
671
- result.put("notBefore", generateValue(input.notBefore));
672
- } catch (JSONException e) {
673
- e.printStackTrace();
674
- }
675
- return result;
676
- }
677
-
678
- static JSONObject generateCertificateChain(CertificateChain input) {
679
- JSONObject result = new JSONObject();
680
- if (input == null) return null;
681
- try {
682
- result.put("origin", input.origin);
683
- result.put("type", input.type);
684
- result.put("version", input.version);
685
- result.put("paStatus", input.paStatus);
686
- result.put("serialNumber", input.serialNumber);
687
- result.put("signatureAlgorithm", input.signatureAlgorithm);
688
- result.put("subjectPKAlgorithm", input.subjectPKAlgorithm);
689
- result.put("fileName", generateValue(input.fileName));
690
- result.put("validity", generateValidity(input.validity));
691
- result.put("issuer", generateAuthority(input.issuer));
692
- result.put("subject", generateAuthority(input.subject));
693
- result.put("notifications", generateList(input.notifications));
694
- result.put("extensions", generateList(input.extensions, JSONConstructor::generateExtension));
695
- } catch (JSONException e) {
696
- e.printStackTrace();
697
- }
698
- return result;
699
- }
700
-
701
- static JSONObject generateSignerInfo(SignerInfo input) {
702
- JSONObject result = new JSONObject();
703
- if (input == null) return null;
704
- try {
705
- result.put("version", input.version);
706
- result.put("paStatus", input.paStatus);
707
- result.put("dataToHash", input.dataToHash);
708
- result.put("digestAlgorithm", input.digestAlgorithm);
709
- result.put("signatureAlgorithm", input.signatureAlgorithm);
710
- result.put("serialNumber", generateValue(input.serialNumber));
711
- result.put("signature", generateValue(input.signature));
712
- result.put("subjectKeyIdentifier", generateValue(input.subjectKeyIdentifier));
713
- result.put("issuer", generateAuthority(input.issuer));
714
- result.put("notifications", generateList(input.notifications));
715
- result.put("signedAttributes", generateList(input.signedAttributes, JSONConstructor::generateExtension));
716
- result.put("certificateChain", generateList(input.certificateChain, JSONConstructor::generateCertificateChain));
717
- } catch (JSONException e) {
718
- e.printStackTrace();
719
- }
720
- return result;
721
- }
722
-
723
- static JSONObject generateSecurityObject(SecurityObject input) {
724
- JSONObject result = new JSONObject();
725
- if (input == null) return null;
726
- try {
727
- result.put("fileReference", input.fileReference);
728
- result.put("version", input.version);
729
- result.put("objectType", input.objectType);
730
- result.put("notifications", generateList(input.notifications));
731
- result.put("signerInfos", generateList(input.signerInfos, JSONConstructor::generateSignerInfo));
732
- } catch (JSONException e) {
733
- e.printStackTrace();
734
- }
735
- return result;
736
- }
737
-
738
- static JSONObject generateCardProperties(CardProperties input) {
739
- JSONObject result = new JSONObject();
740
- if (input == null) return null;
741
- try {
742
- result.put("aTQA", input.aTQA);
743
- result.put("bitRateR", input.bitRateR);
744
- result.put("bitRateS", input.bitRateS);
745
- result.put("chipTypeA", input.chipTypeA);
746
- result.put("mifareMemory", input.mifareMemory);
747
- result.put("rfidType", input.rfidType);
748
- result.put("sAK", input.sAK);
749
- result.put("support4", input.support4);
750
- result.put("supportMifare", input.supportMifare);
751
- result.put("aTQB", input.aTQB);
752
- result.put("aTR", input.aTR);
753
- result.put("baudrate1", input.baudrate1);
754
- result.put("baudrate2", input.baudrate2);
755
- result.put("uID", input.uID);
756
- } catch (JSONException e) {
757
- e.printStackTrace();
758
- }
759
- return result;
760
- }
761
-
762
- static JSONObject generateRFIDSessionData(RFIDSessionData input) {
763
- JSONObject result = new JSONObject();
764
- if (input == null) return null;
765
- try {
766
- result.put("totalBytesReceived", input.totalBytesReceived);
767
- result.put("totalBytesSent", input.totalBytesSent);
768
- result.put("status", input.status);
769
- result.put("extLeSupport", input.extLeSupport);
770
- result.put("processTime", input.processTime);
771
- result.put("cardProperties", generateCardProperties(input.cardProperties));
772
- result.put("accessControls", generateList(input.accessControls, JSONConstructor::generateAccessControlProcedureType));
773
- result.put("applications", generateList(input.applications, JSONConstructor::generateApplication));
774
- result.put("securityObjects", generateList(input.securityObjects, JSONConstructor::generateSecurityObject));
775
- result.put("dataGroups", generateIntArray(input.dataGroups));
776
- result.put("dataFields", generateList(input.dataFields, JSONConstructor::generateDataField));
777
- } catch (JSONException e) {
778
- e.printStackTrace();
779
- }
780
- return result;
781
- }
782
-
783
- static JSONObject generateDataField(DataField input) {
784
- JSONObject result = new JSONObject();
785
- if (input == null) return null;
786
- try {
787
- result.put("data", input.getData());
788
- result.put("fieldType", input.getFieldType());
789
- } catch (JSONException e) {
790
- e.printStackTrace();
791
- }
792
- return result;
793
- }
794
-
795
- static JSONObject generateDocumentReaderAuthenticityCheck(DocumentReaderAuthenticityCheck input, Context context) {
796
- JSONObject result = new JSONObject();
797
- if (input == null) return null;
798
- try {
799
- result.put("type", input.type);
800
- result.put("status", input.getStatus());
801
- result.put("typeName", input.getTypeName(context));
802
- result.put("pageIndex", input.pageIndex);
803
- result.put("elements", generateList(input.elements, JSONConstructor::generateDocumentReaderAuthenticityElement, context));
804
- } catch (JSONException e) {
805
- e.printStackTrace();
806
- }
807
- return result;
808
- }
809
-
810
- static JSONObject generatePDF417Info(PDF417Info input) {
811
- JSONObject result = new JSONObject();
812
- if (input == null) return null;
813
- try {
814
- result.put("errorLevel", input.errorLevel);
815
- result.put("columns", input.columns);
816
- result.put("rows", input.rows);
817
- } catch (JSONException e) {
818
- e.printStackTrace();
819
- }
820
- return result;
821
- }
822
-
823
- static JSONObject generateDocumentReaderBarcodeResult(DocumentReaderBarcodeResult input) {
824
- JSONObject result = new JSONObject();
825
- if (input == null) return null;
826
- try {
827
- result.put("fields", generateList(input.fields, JSONConstructor::generateDocumentReaderBarcodeField));
828
- } catch (JSONException e) {
829
- e.printStackTrace();
830
- }
831
- return result;
832
- }
833
-
834
- static JSONObject generateDocumentReaderBarcodeField(DocumentReaderBarcodeField input) {
835
- JSONObject result = new JSONObject();
836
- if (input == null) return null;
837
- try {
838
- result.put("barcodeType", input.barcodeType);
839
- result.put("status", input.status);
840
- result.put("pageIndex", input.pageIndex);
841
- result.put("pdf417Info", generatePDF417Info(input.pdf417Info));
842
- result.put("data", generateByteArray(input.data));
843
- } catch (JSONException e) {
844
- e.printStackTrace();
845
- }
846
- return result;
847
- }
848
-
849
- static JSONObject generateDocumentReaderAuthenticityResult(DocumentReaderAuthenticityResult input, Context context) {
850
- JSONObject result = new JSONObject();
851
- if (input == null) return null;
852
- try {
853
- result.put("status", input.getStatus());
854
- result.put("checks", generateList(input.checks, JSONConstructor::generateDocumentReaderAuthenticityCheck, context));
855
- } catch (JSONException e) {
856
- e.printStackTrace();
857
- }
858
- return result;
859
- }
860
-
861
- static JSONObject generateDocumentReaderAuthenticityElement(DocumentReaderAuthenticityElement input, Context context) {
862
- JSONObject result = new JSONObject();
863
- if (input == null) return null;
864
- try {
865
- result.put("status", input.status);
866
- result.put("elementType", input.elementType);
867
- result.put("elementDiagnose", input.elementDiagnose);
868
- result.put("elementTypeName", input.getElementTypeName(context));
869
- result.put("elementDiagnoseName", input.getElementDiagnoseName(context));
870
- } catch (JSONException e) {
871
- e.printStackTrace();
872
- }
873
- return result;
874
- }
875
-
876
- static JSONObject generatePAResourcesIssuer(PAResourcesIssuer input) {
877
- JSONObject result = new JSONObject();
878
- if (input == null) return null;
879
- try {
880
- result.put("data", generateByteArray(input.data));
881
- result.put("friendlyName", input.friendlyName);
882
- result.put("attributes", generateArray(input.attributes, JSONConstructor::generatePAAttribute));
883
- } catch (JSONException e) {
884
- e.printStackTrace();
885
- }
886
- return result;
887
- }
888
-
889
- static JSONObject generatePAAttribute(PAAttribute input) {
890
- JSONObject result = new JSONObject();
891
- if (input == null) return null;
892
- try {
893
- result.put("type", input.type);
894
- result.put("value", input.value);
895
- } catch (JSONException e) {
896
- e.printStackTrace();
897
- }
898
- return result;
899
- }
900
-
901
- static JSONObject generateTAChallenge(TAChallenge input) {
902
- JSONObject result = new JSONObject();
903
- if (input == null) return null;
904
- try {
905
- result.put("data", generateByteArray(input.data));
906
- result.put("auxPCD", input.auxPCD);
907
- result.put("challengePICC", input.challengePICC);
908
- result.put("hashPK", input.hashPK);
909
- result.put("idPICC", input.idPICC);
910
- } catch (JSONException e) {
911
- e.printStackTrace();
912
- }
913
- return result;
914
- }
915
-
916
- static JSONObject generateDocumentReaderResultsStatus(DocumentReaderResultsStatus input) {
917
- JSONObject result = new JSONObject();
918
- if (input == null) return null;
919
- try {
920
- result.put("overallStatus", input.getOverallStatus());
921
- result.put("optical", input.getOptical());
922
- result.put("detailsOptical", generateDetailsOptical(input.getDetailsOptical()));
923
- result.put("rfid", input.getRfid());
924
- result.put("detailsRFID", generateDetailsRFID(input.getDetailsRFID()));
925
- result.put("portrait", input.getPortrait());
926
- result.put("stopList", input.getStopList());
927
- } catch (JSONException e) {
928
- e.printStackTrace();
929
- }
930
- return result;
931
- }
932
-
933
- static JSONObject generateDetailsOptical(DocumentReaderResultsStatus.DetailsOptical input) {
934
- JSONObject result = new JSONObject();
935
- if (input == null) return null;
936
- try {
937
- result.put("overallStatus", input.getOverallStatus());
938
- result.put("mrz", input.getMrz());
939
- result.put("text", input.getText());
940
- result.put("docType", input.getDocType());
941
- result.put("security", input.getSecurity());
942
- result.put("imageQA", input.getImageQA());
943
- result.put("expiry", input.getExpiry());
944
- result.put("vds", input.getVds());
945
- result.put("pagesCount", input.getPagesCount());
946
- } catch (JSONException e) {
947
- e.printStackTrace();
948
- }
949
- return result;
950
- }
951
-
952
- static JSONObject generateDetailsRFID(DocumentReaderResultsStatus.DetailsRFID input) {
953
- JSONObject result = new JSONObject();
954
- if (input == null) return null;
955
- try {
956
- result.put("pa", input.getPA());
957
- result.put("ca", input.getCA());
958
- result.put("aa", input.getAA());
959
- result.put("ta", input.getTA());
960
- result.put("bac", input.getBAC());
961
- result.put("pace", input.getPACE());
962
- result.put("overallStatus", input.getOverallStatus());
963
- } catch (JSONException e) {
964
- e.printStackTrace();
965
- }
966
- return result;
967
- }
968
-
969
- static JSONObject generateVDSNCData(VDSNCData input) {
970
- JSONObject result = new JSONObject();
971
- if (input == null) return null;
972
- try {
973
- result.put("type", input.getType());
974
- result.put("version", input.getVersion());
975
- result.put("issuingCountry", input.getIssuingCountry());
976
- result.put("message", input.getMessage());
977
- result.put("signatureAlgorithm", input.getSignatureAlg());
978
- result.put("signature", generateBytesData(input.getSignature()));
979
- result.put("certificate", generateBytesData(input.getCertificate()));
980
- result.put("certificateChain", generateList(input.getCertificateChain(), JSONConstructor::generateCertificateChain));
981
- result.put("notifications", generateLongArray(input.getNotifications()));
982
- } catch (JSONException e) {
983
- e.printStackTrace();
984
- }
985
- return result;
986
- }
987
-
988
- static JSONObject generateBytesData(BytesData input) {
989
- JSONObject result = new JSONObject();
990
- if (input == null) return null;
991
- try {
992
- result.put("data", input.getData());
993
- result.put("length", input.getLength());
994
- result.put("status", input.getStatus());
995
- result.put("type", input.getType());
996
- } catch (JSONException e) {
997
- e.printStackTrace();
998
- }
999
- return result;
1000
- }
1001
-
1002
- static JSONObject generateDocReaderDocumentsDatabase(DocReaderDocumentsDatabase input) {
1003
- JSONObject result = new JSONObject();
1004
- if (input == null) return null;
1005
- try {
1006
- result.put("databaseID", input.databaseID);
1007
- result.put("version", input.version);
1008
- result.put("date", input.date);
1009
- result.put("databaseDescription", input.databaseDescription);
1010
- result.put("countriesNumber", input.countriesNumber);
1011
- result.put("documentsNumber", input.documentsNumber);
1012
- result.put("size", input.size);
1013
- } catch (JSONException e) {
1014
- e.printStackTrace();
1015
- }
1016
- return result;
1017
- }
1018
-
1019
- static JSONObject generateDocumentReaderComparison(DocumentReaderComparison input) {
1020
- JSONObject result = new JSONObject();
1021
- if (input == null) return null;
1022
- try {
1023
- result.put("sourceTypeLeft", input.sourceTypeLeft);
1024
- result.put("sourceTypeRight", input.sourceTypeRight);
1025
- result.put("status", input.status);
1026
- } catch (JSONException e) {
1027
- e.printStackTrace();
1028
- }
1029
- return result;
1030
- }
1031
-
1032
- static JSONObject generateDocumentReaderRfidOrigin(DocumentReaderRfidOrigin input) {
1033
- JSONObject result = new JSONObject();
1034
- if (input == null) return null;
1035
- try {
1036
- result.put("dg", input.dg);
1037
- result.put("dgTag", input.dgTag);
1038
- result.put("entryView", input.entryView);
1039
- result.put("tagEntry", input.tagEntry);
1040
- } catch (JSONException e) {
1041
- e.printStackTrace();
1042
- }
1043
- return result;
1044
- }
1045
-
1046
- static JSONObject generateDocumentReaderTextSource(DocumentReaderTextSource input) {
1047
- JSONObject result = new JSONObject();
1048
- if (input == null) return null;
1049
- try {
1050
- result.put("sourceType", input.sourceType);
1051
- result.put("source", input.source);
1052
- result.put("validityStatus", input.validityStatus);
1053
- } catch (JSONException e) {
1054
- e.printStackTrace();
1055
- }
1056
- return result;
1057
- }
1058
-
1059
- static JSONObject generateDocumentReaderSymbol(DocumentReaderSymbol input) {
1060
- JSONObject result = new JSONObject();
1061
- if (input == null) return null;
1062
- try {
1063
- result.put("code", input.code);
1064
- result.put("rect", generateRect(input.rect));
1065
- result.put("probability", input.probability);
1066
- } catch (JSONException e) {
1067
- e.printStackTrace();
1068
- }
1069
- return result;
1070
- }
1071
-
1072
- static JSONObject generateDocumentReaderValidity(DocumentReaderValidity input) {
1073
- JSONObject result = new JSONObject();
1074
- if (input == null) return null;
1075
- try {
1076
- result.put("sourceType", input.sourceType);
1077
- result.put("status", input.status);
1078
- } catch (JSONException e) {
1079
- e.printStackTrace();
1080
- }
1081
- return result;
1082
- }
1083
-
1084
- static JSONObject generateDocumentReaderResults(DocumentReaderResults input, Context context) {
1085
- JSONObject result = new JSONObject();
1086
- if (input == null) return null;
1087
- try {
1088
- result.put("videoCaptureSessionId", input.videoCaptureSessionId);
1089
- result.put("chipPage", input.chipPage);
1090
- result.put("irElapsedTime", input.irElapsedTime);
1091
- result.put("processingFinishedStatus", input.processingFinishedStatus);
1092
- result.put("elapsedTime", input.elapsedTime);
1093
- result.put("elapsedTimeRFID", input.elapsedTimeRFID);
1094
- result.put("morePagesAvailable", input.morePagesAvailable);
1095
- result.put("rfidResult", input.rfidResult);
1096
- result.put("highResolution", input.highResolution);
1097
- result.put("graphicResult", generateDocumentReaderGraphicResult(input.graphicResult, context));
1098
- result.put("textResult", generateDocumentReaderTextResult(input.textResult, context));
1099
- result.put("documentPosition", generateList(input.documentPosition, JSONConstructor::generateElementPosition));
1100
- result.put("barcodePosition", generateList(input.barcodePosition, JSONConstructor::generateElementPosition));
1101
- result.put("mrzPosition", generateList(input.mrzPosition, JSONConstructor::generateElementPosition));
1102
- result.put("imageQuality", generateList(input.imageQuality, JSONConstructor::generateImageQualityGroup));
1103
- result.put("rawResult", input.rawResult);
1104
- result.put("documentReaderNotification", generateDocumentReaderNotification(input.documentReaderNotification));
1105
- result.put("rfidSessionData", generateRFIDSessionData(input.rfidSessionData));
1106
- result.put("authenticityResult", generateDocumentReaderAuthenticityResult(input.authenticityResult, context));
1107
- result.put("barcodeResult", generateDocumentReaderBarcodeResult(input.barcodeResult));
1108
- result.put("ppmIn", input.ppmIn);
1109
- result.put("documentType", generateList(input.documentType, JSONConstructor::generateDocumentReaderDocumentType));
1110
- result.put("status", generateDocumentReaderResultsStatus(input.status));
1111
- result.put("vdsncData", generateVDSNCData(input.vdsncData));
1112
- } catch (JSONException e) {
1113
- e.printStackTrace();
1114
- }
1115
- return result;
1116
- }
1117
-
1118
- // From JSON
1119
- }