@regulaforensics/cordova-plugin-document-reader-api 8.1.122-nightly → 8.1.131-nightly

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,17 +1,11 @@
1
- //
2
- // JSONConstructor.kt
3
- // DocumentReader
4
- //
5
- // Created by Pavel Masiuk on 21.09.2023.
6
- // Copyright © 2023 Regula. All rights reserved.
7
- //
8
1
  @file:SuppressLint("MissingPermission")
2
+ @file:Suppress("unused")
9
3
 
10
- package cordova.plugin.documentreader
4
+ package com.regula.plugin.documentreader
11
5
 
12
6
  import android.annotation.SuppressLint
13
- import android.content.Context
14
7
  import android.graphics.Bitmap
8
+ import android.graphics.Matrix
15
9
  import android.graphics.Rect
16
10
  import android.graphics.Typeface
17
11
  import android.util.Pair
@@ -100,34 +94,22 @@ import com.regula.documentreader.api.results.rfid.SecurityObjectCertificates
100
94
  import com.regula.documentreader.api.results.rfid.SignerInfo
101
95
  import com.regula.documentreader.api.results.rfid.Validity
102
96
  import com.regula.documentreader.api.results.rfid.Value
103
- import cordova.plugin.documentreader.Convert.bitmapFromBase64
104
- import cordova.plugin.documentreader.Convert.bitmapToBase64
105
- import cordova.plugin.documentreader.Convert.byteArrayFromBase64
106
- import cordova.plugin.documentreader.Convert.generateByteArray
107
97
  import org.json.JSONArray
108
98
  import org.json.JSONObject
99
+ import com.regula.plugin.documentreader.Convert.toBase64
100
+ import com.regula.plugin.documentreader.Convert.toBitmap
101
+ import com.regula.plugin.documentreader.Convert.toByteArray
102
+
103
+ fun generateCompletion(action: Int, results: DocumentReaderResults?, error: RegulaException?) = mapOf(
104
+ "action" to action,
105
+ "results" to if (listOf(DocReaderAction.COMPLETE, DocReaderAction.MORE_PAGES_AVAILABLE, DocReaderAction.CANCEL, DocReaderAction.ERROR, DocReaderAction.TIMEOUT).contains(action)) generateDocumentReaderResults(results) else null,
106
+ "error" to generateRegulaException(error)
107
+ ).toJson()
109
108
 
110
- val weakReferencesHolder = mutableListOf<Any>()
111
-
112
- fun generateCompletion(action: Int, results: DocumentReaderResults?, error: RegulaException?, context: Context?) = object : JSONObject() { init {
113
- put("action", action)
114
- if (listOf(
115
- DocReaderAction.COMPLETE,
116
- DocReaderAction.MORE_PAGES_AVAILABLE,
117
- DocReaderAction.CANCEL,
118
- DocReaderAction.ERROR,
119
- DocReaderAction.TIMEOUT
120
- ).contains(action)
121
- ) put("results", generateDocumentReaderResults(results, context))
122
- put("error", generateRegulaException(error))
123
- }
124
- }
125
-
126
- fun generateSuccessCompletion(success: Boolean, error: RegulaException?) = object : JSONObject() { init {
127
- put("success", success)
128
- put("error", generateRegulaException(error))
129
- }
130
- }
109
+ fun generateSuccessCompletion(success: Boolean, error: RegulaException?) = mapOf(
110
+ "success" to success,
111
+ "error" to generateRegulaException(error)
112
+ ).toJson()
131
113
 
132
114
  fun prepareProgressFromJSON(it: JSONObject) = PrepareProgress(
133
115
  it.getInt("downloadedBytes"),
@@ -140,342 +122,280 @@ fun generatePrepareProgress(it: PrepareProgress) = mapOf(
140
122
  "progress" to it.progress
141
123
  ).toJson()
142
124
 
143
- fun generatePACertificateCompletion(serialNumber: ByteArray?, issuer: PAResourcesIssuer?) = object : JSONObject() { init {
144
- put("serialNumber", generateByteArray(serialNumber))
145
- put("issuer", generatePAResourcesIssuer(issuer))
146
- }
147
- }
148
-
149
- fun generateFinalizePackageCompletion(action: Int, info: TransactionInfo?, error: RegulaException?) = object : JSONObject() { init {
150
- put("action", action)
151
- put("info", generateTransactionInfo(info))
152
- put("error", generateRegulaException(error))
153
- }
154
- }
155
-
156
- fun regulaExceptionFromJSON(temp: JSONObject?) = temp?.let {
157
- val input: JSONObject = temp
125
+ fun generatePACertificateCompletion(serialNumber: ByteArray?, issuer: PAResourcesIssuer?) = mapOf(
126
+ "serialNumber" to serialNumber.toBase64(),
127
+ "issuer" to generatePAResourcesIssuer(issuer)
128
+ ).toJson()
158
129
 
159
- val code = input.optInt("code")
160
- val message = input.optString("message")
130
+ fun generateFinalizePackageCompletion(action: Int, info: TransactionInfo?, error: RegulaException?) = mapOf(
131
+ "action" to action,
132
+ "info" to generateTransactionInfo(info),
133
+ "error" to generateRegulaException(error)
134
+ ).toJson()
161
135
 
162
- RegulaException(code, message)
136
+ fun regulaExceptionFromJSON(input: JSONObject?) = input?.let {
137
+ RegulaException(
138
+ it.optInt("code"),
139
+ it.optString("message")
140
+ )
163
141
  }
164
142
 
165
- fun generateRegulaException(temp: RegulaException?): JSONObject? = temp?.let {
166
- object : JSONObject() { init {
167
- val input: RegulaException = it
168
- put("code", input.errorCode)
169
- put("message", input.message)
170
- }
171
- }
143
+ fun generateRegulaException(input: RegulaException?) = input?.let {
144
+ mapOf(
145
+ "code" to it.errorCode,
146
+ "message" to it.message
147
+ ).toJson()
172
148
  }
173
149
 
174
- fun transactionInfoFromJSON(temp: JSONObject?): TransactionInfo? {
175
- temp ?: return null
176
- val input: JSONObject = temp
150
+ fun transactionInfoFromJSON(input: JSONObject?) = input?.let {
177
151
  val result = TransactionInfo()
178
-
179
- if (input.has("transactionId")) result.transactionId = input.getString("transactionId")
180
- if (input.has("tag")) result.tag = input.getString("tag")
181
- if (input.has("sessionLogFolder")) result.sessionLogFolder = input.getString("sessionLogFolder")
182
-
183
- return result
152
+ result.transactionId = it.getStringOrNull("transactionId")
153
+ result.tag = it.getStringOrNull("tag")
154
+ result.sessionLogFolder = it.getStringOrNull("sessionLogFolder")
155
+ result
184
156
  }
185
157
 
186
- fun generateTransactionInfo(temp: TransactionInfo?): JSONObject? {
187
- val result = JSONObject()
188
- temp ?: return null
189
- val input: TransactionInfo = temp
190
-
191
- result.put("transactionId", input.transactionId)
192
- result.put("tag", input.tag)
193
- result.put("sessionLogFolder", input.sessionLogFolder)
194
-
195
- return result
158
+ fun generateTransactionInfo(input: TransactionInfo?) = input?.let {
159
+ mapOf(
160
+ "transactionId" to it.transactionId,
161
+ "tag" to it.tag,
162
+ "sessionLogFolder" to it.sessionLogFolder
163
+ ).toJson()
196
164
  }
197
165
 
198
- fun tccParamsFromJSON(input: JSONObject): TccParams {
166
+ fun tccParamsFromJSON(input: JSONObject) = input.let {
199
167
  val result = TccParams()
200
-
201
- if (input.has("serviceUrlTA")) result.serviceUrlTA = input.getString("serviceUrlTA")
202
- if (input.has("serviceUrlPA")) result.serviceUrlPA = input.getString("serviceUrlPA")
203
- if (input.has("pfxCertUrl")) result.pfxCertUrl = input.getString("pfxCertUrl")
204
- if (input.has("pfxPassPhrase")) result.pfxPassPhrase = input.getString("pfxPassPhrase")
205
- if (input.has("pfxCert")) result.pfxCert = byteArrayFromBase64(input.getString("pfxCert"))
206
-
207
- return result
208
- }
209
-
210
- fun generateTccParams(temp: TccParams?): JSONObject? {
211
- val result = JSONObject()
212
- temp ?: return null
213
- val input: TccParams = temp
214
-
215
- result.put("serviceUrlTA", input.serviceUrlTA)
216
- result.put("serviceUrlPA", input.serviceUrlPA)
217
- result.put("pfxCertUrl", input.pfxCertUrl)
218
- result.put("pfxPassPhrase", input.pfxPassPhrase)
219
- result.put("pfxCert", generateByteArray(input.pfxCert))
220
-
221
- return result
222
- }
223
-
224
- fun docReaderConfigFromJSON(input: JSONObject): DocReaderConfig {
225
- val license = byteArrayFromBase64(input.getString("license"))
226
- var result = DocReaderConfig(license!!)
227
-
228
- if (input.has("customDb")) result = DocReaderConfig(license, byteArrayFromBase64(input.getString("customDb"))!!)
229
- if (input.has("databasePath")) result = DocReaderConfig(license, input.getString("databasePath"))
230
- if (input.has("licenseUpdate")) result.setLicenseUpdate(input.getBoolean("licenseUpdate"))
231
- if (input.has("delayedNNLoad")) result.isDelayedNNLoad = input.getBoolean("delayedNNLoad")
232
- if (input.has("blackList")) result.blackList = input.getJSONObject("blackList")
233
-
234
- return result
235
- }
236
-
237
- fun generateDocReaderConfig(temp: DocReaderConfig?): JSONObject? {
238
- val result = JSONObject()
239
- temp ?: return null
240
- val input: DocReaderConfig = temp
241
-
242
- result.put("license", generateByteArray(input.license))
243
- result.put("customDb", generateByteArray(input.customDb))
244
- result.put("databasePath", input.customDbPath)
245
- result.put("licenseUpdate", input.isLicenseUpdate)
246
- result.put("delayedNNLoad", input.isDelayedNNLoad)
247
- result.put("blackList", input.blackList)
248
-
249
- return result
250
- }
251
-
252
- fun bleDeviceConfigFromJSON(input: JSONObject): BleDeviceConfig {
168
+ result.serviceUrlTA = it.getStringOrNull("serviceUrlTA")
169
+ result.serviceUrlPA = it.getStringOrNull("serviceUrlPA")
170
+ result.pfxCertUrl = it.getStringOrNull("pfxCertUrl")
171
+ result.pfxPassPhrase = it.getStringOrNull("pfxPassPhrase")
172
+ result.pfxCert = it.getStringOrNull("pfxCert").toByteArray()
173
+ result
174
+ }
175
+
176
+ fun generateTccParams(input: TccParams?) = input?.let {
177
+ mapOf(
178
+ "serviceUrlTA" to it.serviceUrlTA,
179
+ "serviceUrlPA" to it.serviceUrlPA,
180
+ "pfxCertUrl" to it.pfxCertUrl,
181
+ "pfxPassPhrase" to it.pfxPassPhrase,
182
+ "pfxCert" to it.pfxCert.toBase64()
183
+ ).toJson()
184
+ }
185
+
186
+ fun initConfigFromJSON(input: JSONObject) = input.let {
187
+ val license = it.getString("license").toByteArray()!!
188
+ var result = DocReaderConfig(license)
189
+ if (it.has("customDb")) result = DocReaderConfig(license, it.getString("customDb").toByteArray()!!)
190
+ if (it.has("databasePath")) result = DocReaderConfig(license, it.getString("databasePath"))
191
+
192
+ if (it.has("licenseUpdate")) result.setLicenseUpdate(it.getBoolean("licenseUpdate"))
193
+ if (it.has("delayedNNLoad")) result.isDelayedNNLoad = it.getBoolean("delayedNNLoad")
194
+ result.blackList = it.getJSONObjectOrNull("blackList")
195
+ result
196
+ }
197
+
198
+ fun generateInitConfig(input: DocReaderConfig?) = input?.let {
199
+ mapOf(
200
+ "license" to it.license.toBase64(),
201
+ "customDb" to it.customDb.toBase64(),
202
+ "databasePath" to it.customDbPath,
203
+ "licenseUpdate" to it.isLicenseUpdate,
204
+ "delayedNNLoad" to it.isDelayedNNLoad,
205
+ "blackList" to it.blackList
206
+ ).toJson()
207
+ }
208
+
209
+ fun initBleDeviceConfigFromJSON(input: JSONObject) = input.let {
253
210
  var result = BleDeviceConfig(bluetooth!!)
254
-
255
- if (input.has("customDb")) result = BleDeviceConfig(bluetooth!!, byteArrayFromBase64(input.getString("customDb")))
256
- if (input.has("licenseUpdate")) result.setLicenseUpdate(input.getBoolean("licenseUpdate"))
257
- if (input.has("delayedNNLoad")) result.isDelayedNNLoad = input.getBoolean("delayedNNLoad")
258
- if (input.has("blackList")) result.blackList = input.getJSONObject("blackList")
259
-
260
- return result
261
- }
262
-
263
- fun scannerConfigFromJSON(input: JSONObject): ScannerConfig {
264
- val builder = if (input.has("scenario")) ScannerConfig.Builder(input.getString("scenario"))
265
- else ScannerConfig.Builder(onlineProcessingConfigFromJSON(input.getJSONObject("onlineProcessingConfig"))!!)
266
-
267
- if (input.has("onlineProcessingConfig")) builder.setOnlineProcessingConfig(onlineProcessingConfigFromJSON(input.getJSONObject("onlineProcessingConfig")))
268
- if (input.has("livePortrait")) builder.setLivePortrait(bitmapFromBase64(input.getString("livePortrait"))!!)
269
- if (input.has("extPortrait")) builder.setExtPortrait(bitmapFromBase64(input.getString("extPortrait"))!!)
270
- if (input.has("cameraId")) builder.setCameraId(input.getInt("cameraId"))
271
-
272
- return builder.build()
273
- }
274
-
275
- fun generateScannerConfig(temp: ScannerConfig?): JSONObject? {
276
- val result = JSONObject()
277
- temp ?: return null
278
- val input: ScannerConfig = temp
279
-
280
- result.put("scenario", input.scenario)
281
- result.put("onlineProcessingConfig", generateOnlineProcessingConfig(input.onlineProcessingConfig))
282
- result.put("livePortrait", bitmapToBase64(input.livePortrait))
283
- result.put("extPortrait", bitmapToBase64(input.extPortrait))
284
- result.put("cameraId", input.cameraId)
285
-
286
- return result
287
- }
288
-
289
- fun recognizeConfigFromJSON(input: JSONObject): RecognizeConfig {
290
- val builder = if (input.has("scenario")) RecognizeConfig.Builder(input.getString("scenario"))
291
- else RecognizeConfig.Builder(onlineProcessingConfigFromJSON(input.getJSONObject("onlineProcessingConfig"))!!)
292
-
293
- if (input.has("oneShotIdentification")) builder.setOneShotIdentification(input.getBoolean("oneShotIdentification"))
294
- if (input.has("dtc")) builder.setDTC(byteArrayFromBase64(input.getString("dtc"))!!)
295
- if (input.has("livePortrait")) builder.setLivePortrait(bitmapFromBase64(input.getString("livePortrait"))!!)
296
- if (input.has("extPortrait")) builder.setExtPortrait(bitmapFromBase64(input.getString("extPortrait"))!!)
297
- if (input.has("image")) builder.setBitmap(bitmapFromBase64(input.getString("image"))!!)
298
- if (input.has("data")) builder.setData(byteArrayFromBase64(input.getString("data"))!!)
299
- if (input.has("images")) {
300
- val base64Images = input.getJSONArray("images")
211
+ if (it.has("customDb")) result = BleDeviceConfig(bluetooth!!, it.getString("customDb").toByteArray())
212
+
213
+ if (it.has("licenseUpdate")) result.setLicenseUpdate(it.getBoolean("licenseUpdate"))
214
+ if (it.has("delayedNNLoad")) result.isDelayedNNLoad = it.getBoolean("delayedNNLoad")
215
+ result.blackList = it.getJSONObjectOrNull("blackList")
216
+ result
217
+ }
218
+
219
+ fun scannerConfigFromJSON(input: JSONObject) = input.let {
220
+ val builder = if (it.has("scenario")) ScannerConfig.Builder(it.getString("scenario"))
221
+ else ScannerConfig.Builder(onlineProcessingConfigFromJSON(it.getJSONObject("onlineProcessingConfig"))!!)
222
+
223
+ if (it.has("onlineProcessingConfig")) builder.setOnlineProcessingConfig(onlineProcessingConfigFromJSON(it.getJSONObject("onlineProcessingConfig")))
224
+ if (it.has("livePortrait")) builder.setLivePortrait(it.getString("livePortrait").toBitmap()!!)
225
+ if (it.has("extPortrait")) builder.setExtPortrait(it.getString("extPortrait").toBitmap()!!)
226
+ if (it.has("cameraId")) builder.setCameraId(it.getInt("cameraId"))
227
+ builder.build()
228
+ }
229
+
230
+ fun generateScannerConfig(input: ScannerConfig?) = input?.let {
231
+ mapOf(
232
+ "scenario" to it.scenario,
233
+ "onlineProcessingConfig" to generateOnlineProcessingConfig(it.onlineProcessingConfig),
234
+ "livePortrait" to it.livePortrait.toBase64(),
235
+ "extPortrait" to it.extPortrait.toBase64(),
236
+ "cameraId" to it.cameraId
237
+ ).toJson()
238
+ }
239
+
240
+ fun recognizeConfigFromJSON(input: JSONObject) = input.let {
241
+ val builder = if (it.has("scenario")) RecognizeConfig.Builder(it.getString("scenario"))
242
+ else RecognizeConfig.Builder(onlineProcessingConfigFromJSON(it.getJSONObject("onlineProcessingConfig"))!!)
243
+
244
+ if (it.has("oneShotIdentification")) builder.setOneShotIdentification(it.getBoolean("oneShotIdentification"))
245
+ if (it.has("dtc")) builder.setDTC(it.getString("dtc").toByteArray()!!)
246
+ if (it.has("livePortrait")) builder.setLivePortrait(it.getString("livePortrait").toBitmap()!!)
247
+ if (it.has("extPortrait")) builder.setExtPortrait(it.getString("extPortrait").toBitmap()!!)
248
+ if (it.has("image")) builder.setBitmap(it.getString("image").toBitmap()!!)
249
+ if (it.has("data")) builder.setData(it.getString("data").toByteArray()!!)
250
+ if (it.has("images")) {
251
+ val base64Images = it.getJSONArray("images")
301
252
  val images = arrayOfNulls<Bitmap>(base64Images.length())
302
- for (i in images.indices) images[i] = bitmapFromBase64(base64Images.getString(i))
253
+ for (i in images.indices) images[i] = base64Images.getString(i).toBitmap()
303
254
  builder.setBitmaps(images)
304
255
  }
305
- if (input.has("imageInputData")) {
306
- val base64InputData = input.getJSONArray("imageInputData")
256
+ if (it.has("imageInputData")) {
257
+ val base64InputData = it.getJSONArray("imageInputData")
307
258
  val inputData = arrayOfNulls<ImageInputData>(base64InputData.length())
308
259
  for (i in inputData.indices) inputData[i] = imageInputDataFromJSON(base64InputData.getJSONObject(i))
309
260
  builder.setImageInputData(inputData)
310
261
  }
311
-
312
- return builder.build()
313
- }
314
-
315
- fun generateRecognizeConfig(temp: RecognizeConfig?): JSONObject? {
316
- val result = JSONObject()
317
- temp ?: return null
318
- val input: RecognizeConfig = temp
319
-
320
- result.put("scenario", input.scenario)
321
- result.put("onlineProcessingConfig", generateOnlineProcessingConfig(input.onlineProcessingConfig))
322
- result.put("oneShotIdentification", input.oneShotIdentification)
323
- result.put("dtc", generateByteArray(input.dtc))
324
- result.put("livePortrait", bitmapToBase64(input.livePortrait))
325
- result.put("extPortrait", bitmapToBase64(input.extPortrait))
326
- result.put("image", bitmapToBase64(input.bitmap))
327
- result.put("data", generateByteArray(input.data))
328
- if (input.bitmaps == null)
329
- result.put("images", null)
330
- else {
331
- val array = JSONArray()
332
- for (bitmap in input.bitmaps!!) array.put(bitmapToBase64(bitmap))
333
- result.put("images", array)
262
+ builder.build()
263
+ }
264
+
265
+ fun generateRecognizeConfig(input: RecognizeConfig?) = input?.let {
266
+ mapOf(
267
+ "scenario" to it.scenario,
268
+ "onlineProcessingConfig" to generateOnlineProcessingConfig(it.onlineProcessingConfig),
269
+ "oneShotIdentification" to it.oneShotIdentification,
270
+ "dtc" to it.dtc.toBase64(),
271
+ "livePortrait" to it.livePortrait.toBase64(),
272
+ "extPortrait" to it.extPortrait.toBase64(),
273
+ "image" to it.bitmap.toBase64(),
274
+ "data" to it.data.toBase64(),
275
+ "images" to
276
+ if (it.bitmaps == null) null
277
+ else {
278
+ val array = JSONArray()
279
+ for (bitmap in it.bitmaps!!) array.put(bitmap.toBase64())
280
+ array
281
+ },
282
+ "imageInputData" to it.imageInputData.toJson(::generateImageInputData)
283
+ ).toJson()
284
+ }
285
+
286
+ fun backendProcessingConfigFromJSON(input: JSONObject?) = input?.let {
287
+ val result = BackendProcessingConfig(it.getString("url"))
288
+ if (it.has("httpHeaders")) {
289
+ val httpHeaders: MutableMap<String, String> = HashMap()
290
+ it.getJSONObject("httpHeaders").forEach { key, value -> httpHeaders[key] = value as String }
291
+ result.httpHeaders = httpHeaders
334
292
  }
335
- result.put("imageInputData", generateArray(input.imageInputData, ::generateImageInputData))
336
-
337
- return result
293
+ result.rfidServerSideChipVerification = it.getBooleanOrNull("rfidServerSideChipVerification")
294
+ result.timeoutConnection = it.getDoubleOrNull("timeoutConnection")
295
+ result
338
296
  }
339
297
 
340
- fun backendProcessingConfigFromJSON(temp: JSONObject?): BackendProcessingConfig? {
341
- if (temp == null || !temp.has("url")) return null
342
- val input: JSONObject = temp
343
-
344
- val result = BackendProcessingConfig(input.getString("url"))
345
- if (input.has("httpHeaders")) result.httpHeaders = stringMapFromJson(input.getJSONObject("httpHeaders"))
346
- if (input.has("rfidServerSideChipVerification")) result.rfidServerSideChipVerification = input.getBoolean("rfidServerSideChipVerification")
347
- if (input.has("timeoutConnection")) result.timeoutConnection = input.getDouble("timeoutConnection")
348
-
349
- return result
298
+ fun generateBackendProcessingConfig(input: BackendProcessingConfig?) = input?.let {
299
+ mapOf(
300
+ "url" to it.url,
301
+ "rfidServerSideChipVerification" to it.rfidServerSideChipVerification,
302
+ "timeoutConnection" to it.timeoutConnection,
303
+ "httpHeaders" to if (it.httpHeaders == null) null else {
304
+ val httpHeaders = JSONObject()
305
+ for ((key, value) in it.httpHeaders!!) httpHeaders.put(key, value)
306
+ httpHeaders
307
+ }
308
+ ).toJson()
350
309
  }
351
310
 
352
- fun generateBackendProcessingConfig(temp: BackendProcessingConfig?): JSONObject? {
353
- val result = JSONObject()
354
- temp ?: return null
355
- val input: BackendProcessingConfig = temp
356
-
357
- result.put("url", input.url)
358
- result.put("httpHeaders", generateStringMap(input.httpHeaders))
359
- result.put("rfidServerSideChipVerification", input.rfidServerSideChipVerification)
360
- result.put("timeoutConnection", input.timeoutConnection)
361
-
362
- return result
363
- }
364
-
365
- fun onlineProcessingConfigFromJSON(temp: JSONObject?): OnlineProcessingConfig? {
366
- if (temp == null || !temp.has("mode")) return null
367
- val input: JSONObject = temp
368
- val builder = OnlineProcessingConfig.Builder(input.getInt("mode"))
369
-
370
- if (input.has("imageFormat")) builder.setImageFormat(input.getInt("imageFormat"))
371
- if (input.has("url")) builder.setUrl(input.getString("url"))
372
- if (input.has("imageCompressionQuality")) builder.setImageCompressionQuality(input.getDouble("imageCompressionQuality").toFloat())
373
- if (input.has("processParams")) builder.setProcessParams(processParamFromJSON(input.getJSONObject("processParams")))
374
- if (input.has("requestHeaders")) {
311
+ val weakReferencesHolder = mutableListOf<Any>()
312
+ fun onlineProcessingConfigFromJSON(input: JSONObject?) = input?.let {
313
+ val builder = OnlineProcessingConfig.Builder(it.getInt("mode"))
314
+
315
+ if (it.has("imageFormat")) builder.setImageFormat(it.getInt("imageFormat"))
316
+ if (it.has("url")) builder.setUrl(it.getString("url"))
317
+ if (it.has("imageCompressionQuality")) builder.setImageCompressionQuality(it.getDouble("imageCompressionQuality").toFloat())
318
+ if (it.has("processParams")) builder.setProcessParams(processParamFromJSON(it.getJSONObject("processParams")))
319
+ if (it.has("requestHeaders")) {
375
320
  val listener = NetworkInterceptorListener { input.getJSONObject("requestHeaders").forEach { k, v -> it.setRequestProperty(k, v as String) } }
376
321
  weakReferencesHolder.add(listener)
377
322
  builder.setNetworkInterceptorListener(listener)
378
323
  }
379
-
380
- return builder.build()
324
+ builder.build()
381
325
  }
382
326
 
383
- fun generateOnlineProcessingConfig(temp: OnlineProcessingConfig?): JSONObject? {
384
- val result = JSONObject()
385
- temp ?: return null
386
- val input: OnlineProcessingConfig = temp
387
-
388
- result.put("mode", input.mode)
389
- result.put("url", input.url)
390
- result.put("processParams", getProcessParams(input.processParam))
391
- result.put("imageFormat", input.imageFormat)
392
- result.put("imageCompressionQuality", input.imageCompressionQuality)
393
-
394
- return result
327
+ fun generateOnlineProcessingConfig(input: OnlineProcessingConfig?) = input?.let {
328
+ mapOf(
329
+ "mode" to it.mode,
330
+ "url" to it.url,
331
+ "processParams" to getProcessParams(it.processParam),
332
+ "imageFormat" to it.imageFormat,
333
+ "imageCompressionQuality" to it.imageCompressionQuality
334
+ ).toJson()
395
335
  }
396
336
 
397
- fun faceApiParamsFromJSON(temp: JSONObject?): FaceApiParams? {
337
+ fun faceApiParamsFromJSON(input: JSONObject?) = input?.let {
398
338
  val result = FaceApiParams()
399
- temp ?: return null
400
- val input: JSONObject = temp
401
-
402
- if (input.has("url") && !input.isNull("url")) result.url = input.getString("url")
403
- if (input.has("mode") && !input.isNull("mode")) result.mode = input.getString("mode")
404
- if (input.has("searchParams") && !input.isNull("searchParams")) result.search = faceApiSearchParamsFromJSON(input.getJSONObject("searchParams"))
405
- if (input.has("threshold") && !input.isNull("threshold")) result.threshold = input.getInt("threshold")
406
- if (input.has("serviceTimeout") && !input.isNull("serviceTimeout")) result.serviceTimeout = input.getInt("serviceTimeout")
407
- if (input.has("proxy") && !input.isNull("proxy")) result.proxy = input.getString("proxy")
408
- if (input.has("proxyPassword") && !input.isNull("proxyPassword")) result.proxyUserPwd = input.getString("proxyPassword")
409
- if (input.has("proxyType") && !input.isNull("proxyType")) result.proxyType = input.getInt("proxyType")
410
-
411
- return result
412
- }
413
339
 
414
- fun generateFaceApiParams(temp: FaceApiParams?): JSONObject? {
415
- val result = JSONObject()
416
- temp ?: return null
417
- val input: FaceApiParams = temp
340
+ if (it.has("url")) result.url = it.getString("url")
341
+ if (it.has("mode")) result.mode = it.getString("mode")
342
+ if (it.has("threshold") && !it.isNull("threshold")) result.threshold = it.getInt("threshold")
343
+ if (it.has("serviceTimeout") && !it.isNull("serviceTimeout")) result.serviceTimeout = it.getInt("serviceTimeout")
344
+ result.search = faceApiSearchParamsFromJSON(it.getJSONObjectOrNull("searchParams"))
345
+ result.proxy = it.getStringOrNull("proxy")
346
+ result.proxyUserPwd = it.getStringOrNull("proxyPassword")
347
+ result.proxyType = it.getIntOrNull("proxyType")
418
348
 
419
- result.put("url", input.url)
420
- result.put("mode", input.mode)
421
- result.put("searchParams", generateFaceApiSearchParams(input.search))
422
- result.put("threshold", input.threshold)
423
- result.put("serviceTimeout", input.serviceTimeout)
424
- result.put("proxy", input.proxy)
425
- result.put("proxyPassword", input.proxyUserPwd)
426
- result.put("proxyType", input.proxyType)
349
+ result
350
+ }
427
351
 
428
- return result
352
+ fun generateFaceApiParams(input: FaceApiParams?) = input?.let {
353
+ mapOf(
354
+ "url" to it.url,
355
+ "mode" to it.mode,
356
+ "searchParams" to generateFaceApiSearchParams(it.search),
357
+ "threshold" to it.threshold,
358
+ "serviceTimeout" to it.serviceTimeout,
359
+ "proxy" to it.proxy,
360
+ "proxyPassword" to it.proxyUserPwd,
361
+ "proxyType" to it.proxyType
362
+ ).toJson()
429
363
  }
430
364
 
431
- fun faceApiSearchParamsFromJSON(temp: JSONObject?): FaceApiParams.Search? {
365
+ fun faceApiSearchParamsFromJSON(input: JSONObject?) = input?.let {
432
366
  val result = FaceApiParams.Search()
433
- temp ?: return null
434
- val input: JSONObject = temp
435
367
 
436
- if (input.has("limit") && !input.isNull("limit")) result.limit = input.getInt("limit")
437
- if (input.has("threshold") && !input.isNull("threshold")) result.threshold = input.getDouble("threshold").toFloat()
438
- if (input.has("groupIds") && !input.isNull("groupIds")) {
439
- val jsonArrayGroupIds = input.getJSONArray("groupIds")
368
+ if (it.has("limit") && !it.isNull("limit")) result.limit = it.getInt("limit")
369
+ if (it.has("threshold") && !it.isNull("threshold")) result.threshold = it.getDouble("threshold").toFloat()
370
+ if (it.has("groupIds") && !it.isNull("groupIds")) {
371
+ val jsonArrayGroupIds = it.getJSONArray("groupIds")
440
372
  val groupIds = IntArray(jsonArrayGroupIds.length())
441
373
  for (i in 0 until jsonArrayGroupIds.length())
442
374
  groupIds[i] = jsonArrayGroupIds.getInt(i)
443
375
  result.groupIds = groupIds
444
376
  }
445
377
 
446
- return result
378
+ result
447
379
  }
448
380
 
449
- fun generateFaceApiSearchParams(temp: FaceApiParams.Search?): JSONObject? {
450
- val result = JSONObject()
451
- temp ?: return null
452
- val input: FaceApiParams.Search = temp
453
-
454
- result.put("limit", input.limit)
455
- result.put("threshold", input.threshold)
456
- result.put("groupIds", input.groupIds.generate())
457
-
458
- return result
381
+ fun generateFaceApiSearchParams(input: FaceApiParams.Search?) = input?.let {
382
+ mapOf(
383
+ "limit" to it.limit,
384
+ "threshold" to it.threshold,
385
+ "groupIds" to it.groupIds.toJson()
386
+ ).toJson()
459
387
  }
460
388
 
461
- fun rfidParamsFromJSON(temp: JSONObject?): RFIDParams? {
389
+ fun rfidParamsFromJSON(input: JSONObject?) = input?.let {
462
390
  val result = RFIDParams()
463
- temp ?: return null
464
- val input: JSONObject = temp
465
-
466
- if (input.has("paIgnoreNotificationCodes")) result.paIgnoreNotificationCodes = input.getJSONArray("paIgnoreNotificationCodes").toIntArray()
467
-
468
- return result
391
+ if (it.has("paIgnoreNotificationCodes")) result.paIgnoreNotificationCodes = it.getJSONArray("paIgnoreNotificationCodes").toIntArray()
392
+ result
469
393
  }
470
394
 
471
- fun generateRFIDParams(temp: RFIDParams?): JSONObject? {
472
- val result = JSONObject()
473
- temp ?: return null
474
- val input: RFIDParams = temp
475
-
476
- result.put("paIgnoreNotificationCodes", input.paIgnoreNotificationCodes.generate())
477
-
478
- return result
395
+ fun generateRFIDParams(input: RFIDParams?) = input?.let {
396
+ mapOf(
397
+ "paIgnoreNotificationCodes" to it.paIgnoreNotificationCodes.toJson()
398
+ ).toJson()
479
399
  }
480
400
 
481
401
  fun processParamFromJSON(input: JSONObject): ProcessParam {
@@ -550,9 +470,9 @@ fun rfidScenarioFromJSON(input: JSONObject): RfidScenario {
550
470
 
551
471
  fun generateRfidScenario(input: RfidScenario): JSONObject = getRfidScenario(input)
552
472
 
553
- fun customizationFromJSON(input: JSONObject, context: Context): ParamsCustomization {
473
+ fun customizationFromJSON(input: JSONObject): ParamsCustomization {
554
474
  val result = ParamsCustomization()
555
- setCustomization(result, input, context)
475
+ setCustomization(result, input)
556
476
  return result
557
477
  }
558
478
 
@@ -566,1662 +486,1293 @@ fun functionalityFromJSON(input: JSONObject): Functionality {
566
486
 
567
487
  fun generateFunctionality(input: Functionality): JSONObject = getFunctionality(input)
568
488
 
569
- fun glaresCheckParamsFromJSON(temp: JSONObject?): GlaresCheckParams? {
570
- temp ?: return null
571
- val input: JSONObject = temp
489
+ fun glaresCheckParamsFromJSON(input: JSONObject?) = input?.let {
572
490
  val result = GlaresCheckParams()
573
-
574
- if (input.has("imgMarginPart")) result.imgMarginPart = input.getDouble("imgMarginPart")
575
- if (input.has("maxGlaringPart")) result.maxGlaringPart = input.getDouble("maxGlaringPart")
576
-
577
- return result
491
+ if (it.has("imgMarginPart")) result.imgMarginPart = it.getDouble("imgMarginPart")
492
+ if (it.has("maxGlaringPart")) result.maxGlaringPart = it.getDouble("maxGlaringPart")
493
+ result
578
494
  }
579
495
 
580
- fun generateGlaresCheckParams(temp: GlaresCheckParams?): JSONObject? {
581
- val result = JSONObject()
582
- temp ?: return null
583
- val input: GlaresCheckParams = temp
584
-
585
- result.put("imgMarginPart", input.imgMarginPart)
586
- result.put("maxGlaringPart", input.maxGlaringPart)
587
-
588
- return result
589
- }
590
-
591
- fun typefaceFromJSON(input: JSONObject): Pair<Typeface, Int?> {
592
- val name = input.getString("name")
593
- val style = input.optInt("style", Typeface.NORMAL)
594
- val size = if (input.has("size")) input.getInt("size") else null
595
- return Pair(Typeface.create(name, style), size)
496
+ fun generateGlaresCheckParams(input: GlaresCheckParams?) = input?.let {
497
+ mapOf(
498
+ "imgMarginPart" to it.imgMarginPart,
499
+ "maxGlaringPart" to it.maxGlaringPart
500
+ ).toJson()
596
501
  }
597
502
 
598
- fun generateTypeface(temp: Typeface?, size: Int? = null): JSONObject? {
599
- val result = JSONObject()
600
- temp ?: return null
601
- val input: Typeface = temp
602
-
603
- result.put("name", "undefined")
604
- result.put("style", input.style)
605
- result.put("size", size)
503
+ fun typefaceFromJSON(it: JSONObject) = Pair(
504
+ Typeface.create(
505
+ it.getString("name"),
506
+ it.optInt("style", Typeface.NORMAL)
507
+ ),
508
+ if (it.has("size")) it.getInt("size") else null
509
+ )
606
510
 
607
- return result
511
+ fun generateTypeface(input: Typeface?, size: Int? = null) = input?.let {
512
+ mapOf(
513
+ "name" to "undefined",
514
+ "style" to it.style,
515
+ "size" to size
516
+ ).toJson()
608
517
  }
609
518
 
610
- fun imageInputDataFromJSON(temp: JSONObject?): ImageInputData? {
611
- if (temp == null || !temp.has("image")) return null
612
- val input: JSONObject = temp
613
-
614
- var light = 6
615
- var pageIndex = 0
616
- val image = bitmapFromBase64(input.getString("image"))!!
617
- if (input.has("light")) light = input.getInt("light")
618
- if (input.has("pageIndex")) pageIndex = input.getInt("pageIndex")
619
-
620
- return ImageInputData(image, light, pageIndex)
519
+ fun imageInputDataFromJSON(input: JSONObject?) = input?.let {
520
+ ImageInputData(
521
+ it.getString("image").toBitmap()!!,
522
+ it.getIntOrNull("light") ?: 6,
523
+ it.getIntOrNull("pageIndex") ?: 0
524
+ )
621
525
  }
622
526
 
623
- fun generateImageInputData(temp: ImageInputData?): JSONObject? {
624
- val result = JSONObject()
625
- temp ?: return null
626
- val input: ImageInputData = temp
627
-
628
- result.put("image", bitmapToBase64(input.bitmap))
629
- result.put("light", input.light)
630
- result.put("pageIndex", input.pageIndex)
631
-
632
- return result
527
+ fun generateImageInputData(input: ImageInputData?) = input?.let {
528
+ mapOf(
529
+ "image" to it.bitmap.toBase64(),
530
+ "light" to it.light,
531
+ "pageIndex" to it.pageIndex
532
+ ).toJson()
633
533
  }
634
534
 
635
- fun pkdCertificateFromJSON(temp: JSONObject?): PKDCertificate? {
636
- temp ?: return null
637
- val input: JSONObject = temp
535
+ fun pkdCertificateFromJSON(input: JSONObject?) = input?.let {
638
536
  var resourceType = 0
639
537
  var binaryData = ByteArray(0)
640
538
 
641
- if (input.has("resourceType")) resourceType = input.getInt("resourceType")
642
- if (input.has("binaryData")) binaryData = byteArrayFromBase64(input.getString("binaryData"))!!
643
- if (input.has("privateKey")) {
644
- val privateKey = byteArrayFromBase64(input.getString("privateKey"))
539
+ if (it.has("resourceType")) resourceType = it.getInt("resourceType")
540
+ if (it.has("binaryData")) binaryData = it.getString("binaryData").toByteArray()!!
541
+ if (it.has("privateKey")) {
542
+ val privateKey = it.getString("privateKey").toByteArray()
645
543
  return PKDCertificate(binaryData, resourceType, privateKey)
646
544
  }
647
- return PKDCertificate(binaryData, resourceType)
648
- }
649
-
650
- fun generatePKDCertificate(temp: PKDCertificate?): JSONObject? {
651
- val result = JSONObject()
652
- temp ?: return null
653
- val input: PKDCertificate = temp
654
-
655
- result.put("resourceType", input.resourceType)
656
- result.put("binaryData", generateByteArray(input.binaryData))
657
- result.put("privateKey", generateByteArray(input.privateKey))
658
-
659
- return result
660
- }
661
-
662
- fun documentReaderScenarioFromJSON(temp: JSONObject?): DocumentReaderScenario? {
663
- temp ?: return null
664
- val input: JSONObject = temp
665
-
666
- val name = input.optString("name")
667
- val caption = input.optString("caption")
668
- val description = input.optString("description")
669
- val multiPageOff = input.optBoolean("multiPageOff")
670
- val frameKWHLandscape = input.optDouble("frameKWHLandscape")
671
- val frameKWHPortrait = input.optDouble("frameKWHPortrait")
672
- val frameKWHDoublePageSpreadPortrait = input.optDouble("frameKWHDoublePageSpreadPortrait")
673
- val frameKWHDoublePageSpreadLandscape = input.optDouble("frameKWHDoublePageSpreadLandscape")
674
- val frameOrientation = input.optInt("frameOrientation")
675
- val uvTorch = input.optBoolean("uvTorch")
676
- val faceExt = input.optBoolean("faceExt")
677
- val seriesProcessMode = input.optBoolean("seriesProcessMode")
678
- val manualCrop = input.optBoolean("manualCrop")
679
-
680
- return DocumentReaderScenario(name, caption, description, if (multiPageOff) 1 else 0, frameKWHLandscape, frameKWHPortrait, frameKWHDoublePageSpreadPortrait, frameKWHDoublePageSpreadLandscape, frameOrientation, uvTorch, faceExt, seriesProcessMode, manualCrop, null)
681
- }
682
-
683
- fun generateDocumentReaderScenario(temp: DocumentReaderScenario?): JSONObject? {
684
- val result = JSONObject()
685
- temp ?: return null
686
- val input: DocumentReaderScenario = temp
687
-
688
- result.put("name", input.name)
689
- result.put("caption", input.caption)
690
- result.put("description", input.description)
691
- result.put("multiPageOff", input.multiPageOff)
692
- result.put("frameKWHLandscape", input.frameKWHLandscape)
693
- result.put("frameKWHPortrait", input.frameKWHPortrait)
694
- result.put("frameKWHDoublePageSpreadPortrait", input.frameKWHDoublePageSpreadPortrait)
695
- result.put("frameKWHDoublePageSpreadLandscape", input.frameKWHDoublePageSpreadLandscape)
696
- result.put("frameOrientation", input.frameOrientation)
697
- result.put("uvTorch", input.uvTorch)
698
- result.put("faceExt", input.faceExt)
699
- result.put("seriesProcessMode", input.seriesProcessMode)
700
- result.put("manualCrop", input.manualCrop)
701
-
702
- return result
703
- }
704
-
705
- fun rectFromJSON(temp: JSONObject?): Rect? {
706
- temp ?: return null
707
- val input: JSONObject = temp
545
+ PKDCertificate(binaryData, resourceType)
546
+ }
547
+
548
+ fun generatePKDCertificate(input: PKDCertificate?) = input?.let {
549
+ mapOf(
550
+ "resourceType" to it.resourceType,
551
+ "binaryData" to it.binaryData.toBase64(),
552
+ "privateKey" to it.privateKey.toBase64()
553
+ ).toJson()
554
+ }
555
+
556
+ fun documentReaderScenarioFromJSON(input: JSONObject?) = input?.let {
557
+ DocumentReaderScenario(
558
+ it.optString("name"),
559
+ it.optString("caption"),
560
+ it.optString("description"),
561
+ if (it.optBoolean("multiPageOff")) 1 else 0,
562
+ it.optDouble("frameKWHLandscape"),
563
+ it.optDouble("frameKWHPortrait"),
564
+ it.optDouble("frameKWHDoublePageSpreadPortrait"),
565
+ it.optDouble("frameKWHDoublePageSpreadLandscape"),
566
+ it.optInt("frameOrientation"),
567
+ it.optBoolean("uvTorch"),
568
+ it.optBoolean("faceExt"),
569
+ it.optBoolean("seriesProcessMode"),
570
+ it.optBoolean("manualCrop"),
571
+ null
572
+ )
573
+ }
574
+
575
+ fun generateDocumentReaderScenario(input: DocumentReaderScenario?) = input?.let {
576
+ mapOf(
577
+ "name" to it.name,
578
+ "caption" to it.caption,
579
+ "description" to it.description,
580
+ "multiPageOff" to it.multiPageOff,
581
+ "frameKWHLandscape" to it.frameKWHLandscape,
582
+ "frameKWHPortrait" to it.frameKWHPortrait,
583
+ "frameKWHDoublePageSpreadPortrait" to it.frameKWHDoublePageSpreadPortrait,
584
+ "frameKWHDoublePageSpreadLandscape" to it.frameKWHDoublePageSpreadLandscape,
585
+ "frameOrientation" to it.frameOrientation,
586
+ "uvTorch" to it.uvTorch,
587
+ "faceExt" to it.faceExt,
588
+ "seriesProcessMode" to it.seriesProcessMode,
589
+ "manualCrop" to it.manualCrop
590
+ ).toJson()
591
+ }
592
+
593
+ fun rectFromJSON(input: JSONObject?) = input?.let {
708
594
  val result = Rect()
709
595
 
710
- result.bottom = input.optInt("bottom")
711
- result.top = input.optInt("top")
712
- result.left = input.optInt("left")
713
- result.right = input.optInt("right")
596
+ result.bottom = it.optInt("bottom")
597
+ result.top = it.optInt("top")
598
+ result.left = it.optInt("left")
599
+ result.right = it.optInt("right")
714
600
 
715
- return result
601
+ result
716
602
  }
717
603
 
718
- fun generateRect(temp: Rect?): JSONObject? {
719
- val result = JSONObject()
720
- temp ?: return null
721
- val input: Rect = temp
722
-
723
- result.put("bottom", input.bottom)
724
- result.put("top", input.top)
725
- result.put("left", input.left)
726
- result.put("right", input.right)
727
-
728
- return result
604
+ fun generateRect(input: Rect?) = input?.let {
605
+ mapOf(
606
+ "bottom" to it.bottom,
607
+ "top" to it.top,
608
+ "left" to it.left,
609
+ "right" to it.right
610
+ ).toJson()
729
611
  }
730
612
 
731
- fun docReaderFieldRectFromJSON(temp: JSONObject?): DocReaderFieldRect? {
732
- temp ?: return null
733
- val input: JSONObject = temp
613
+ fun docReaderFieldRectFromJSON(input: JSONObject?) = input?.let {
734
614
  val result = DocReaderFieldRect()
735
615
 
736
- result.bottom = input.optInt("bottom")
737
- result.top = input.optInt("top")
738
- result.left = input.optInt("left")
739
- result.right = input.optInt("right")
616
+ result.bottom = it.optInt("bottom")
617
+ result.top = it.optInt("top")
618
+ result.left = it.optInt("left")
619
+ result.right = it.optInt("right")
740
620
 
741
- return result
621
+ result
742
622
  }
743
623
 
744
- fun generateDocReaderFieldRect(temp: DocReaderFieldRect?): JSONObject? {
745
- val result = JSONObject()
746
- temp ?: return null
747
- val input: DocReaderFieldRect = temp
748
-
749
- result.put("bottom", input.bottom)
750
- result.put("top", input.top)
751
- result.put("left", input.left)
752
- result.put("right", input.right)
753
-
754
- return result
624
+ fun generateDocReaderFieldRect(input: DocReaderFieldRect?) = input?.let {
625
+ mapOf(
626
+ "bottom" to it.bottom,
627
+ "top" to it.top,
628
+ "left" to it.left,
629
+ "right" to it.right
630
+ ).toJson()
755
631
  }
756
632
 
757
- fun documentReaderGraphicFieldFromJSON(temp: JSONObject?): DocumentReaderGraphicField? {
758
- temp ?: return null
759
- val input: JSONObject = temp
633
+ fun documentReaderGraphicFieldFromJSON(input: JSONObject?) = input?.let {
760
634
  val result = DocumentReaderGraphicField()
761
635
 
762
- input.remove("value")
763
- result.sourceType = input.optInt("sourceType")
764
- result.fieldType = input.optInt("fieldType")
765
- result.light = input.optInt("light")
766
- result.pageIndex = input.optInt("pageIndex")
767
- result.originalPageIndex = input.optInt("originalPageIndex")
768
- result.boundRect = docReaderFieldRectFromJSON(input.optJSONObject("fieldRect"))
636
+ it.remove("value")
637
+ result.sourceType = it.optInt("sourceType")
638
+ result.fieldType = it.optInt("fieldType")
639
+ result.light = it.optInt("light")
640
+ result.pageIndex = it.optInt("pageIndex")
641
+ result.originalPageIndex = it.optInt("originalPageIndex")
642
+ result.boundRect = docReaderFieldRectFromJSON(it.optJSONObject("fieldRect"))
769
643
 
770
- return result
644
+ result
771
645
  }
772
646
 
773
- fun generateDocumentReaderGraphicField(temp: DocumentReaderGraphicField?, context: Context?): JSONObject? {
774
- val result = JSONObject()
775
- temp ?: return null
776
- val input: DocumentReaderGraphicField = temp
777
-
778
- result.put("sourceType", input.sourceType)
779
- result.put("fieldType", input.fieldType)
780
- result.put("light", input.light)
781
- result.put("pageIndex", input.pageIndex)
782
- result.put("originalPageIndex", input.originalPageIndex)
783
- result.put("fieldName", eGraphicFieldType.getTranslation(context, input.fieldType))
784
- result.put("lightName", eRPRM_Lights.getTranslation(context, input.light))
785
- result.put("value", input.imageBase64())
786
- result.put("fieldRect", generateDocReaderFieldRect(input.boundRect))
787
-
788
- return result
647
+ fun generateDocumentReaderGraphicField(input: DocumentReaderGraphicField?) = input?.let {
648
+ mapOf(
649
+ "sourceType" to it.sourceType,
650
+ "fieldType" to it.fieldType,
651
+ "light" to it.light,
652
+ "pageIndex" to it.pageIndex,
653
+ "originalPageIndex" to it.originalPageIndex,
654
+ "fieldName" to eGraphicFieldType.getTranslation(context, it.fieldType),
655
+ "lightName" to eRPRM_Lights.getTranslation(context, it.light),
656
+ "value" to it.imageBase64(),
657
+ "fieldRect" to generateDocReaderFieldRect(it.boundRect)
658
+ ).toJson()
789
659
  }
790
660
 
791
- fun documentReaderGraphicResultFromJSON(temp: JSONObject?): DocumentReaderGraphicResult? {
792
- temp ?: return null
793
- val input: JSONObject = temp
661
+ fun documentReaderGraphicResultFromJSON(input: JSONObject?) = input?.let {
794
662
  val result = DocumentReaderGraphicResult()
795
-
796
- result.fields = listFromJSON(input.optJSONArray("fields"), ::documentReaderGraphicFieldFromJSON)!!
797
-
798
- return result
663
+ result.fields = it.optJSONArray("fields").toList(::documentReaderGraphicFieldFromJSON)!!
664
+ result
799
665
  }
800
666
 
801
- fun generateDocumentReaderGraphicResult(temp: DocumentReaderGraphicResult?, context: Context?): JSONObject? {
802
- val result = JSONObject()
803
- temp ?: return null
804
- val input: DocumentReaderGraphicResult = temp
805
-
806
- result.put("fields", generateList(input.fields, ::generateDocumentReaderGraphicField, context))
807
-
808
- return result
667
+ fun generateDocumentReaderGraphicResult(input: DocumentReaderGraphicResult?) = input?.let {
668
+ mapOf(
669
+ "fields" to it.fields.toJson(::generateDocumentReaderGraphicField)
670
+ ).toJson()
809
671
  }
810
672
 
811
- fun documentReaderValueFromJSON(temp: JSONObject?): DocumentReaderValue? {
812
- temp ?: return null
813
- val input: JSONObject = temp
673
+ fun documentReaderValueFromJSON(input: JSONObject?) = input?.let {
814
674
  val result = DocumentReaderValue()
815
675
 
816
- result.pageIndex = input.optInt("pageIndex")
817
- result.sourceType = input.optInt("sourceType")
818
- result.probability = input.optInt("probability")
819
- result.value = input.optString("value")
820
- result.originalValue = input.optString("originalValue")
821
- result.boundRect = rectFromJSON(input.optJSONObject("boundRect"))
822
- result.originalSymbols = listFromJSON(input.optJSONArray("originalSymbols"), ::documentReaderSymbolFromJSON)!!
823
- result.rfidOrigin = documentReaderRFIDOriginFromJSON(input.optJSONObject("rfidOrigin"))
676
+ result.pageIndex = it.optInt("pageIndex")
677
+ result.sourceType = it.optInt("sourceType")
678
+ result.probability = it.optInt("probability")
679
+ result.value = it.optString("value")
680
+ result.originalValue = it.optString("originalValue")
681
+ result.boundRect = rectFromJSON(it.optJSONObject("boundRect"))
682
+ result.originalSymbols = it.optJSONArray("originalSymbols").toList(::documentReaderSymbolFromJSON)!!
683
+ result.rfidOrigin = documentReaderRFIDOriginFromJSON(it.optJSONObject("rfidOrigin"))
824
684
 
825
- return result
685
+ result
826
686
  }
827
687
 
828
- fun generateDocumentReaderValue(temp: DocumentReaderValue?): JSONObject? {
829
- val result = JSONObject()
830
- temp ?: return null
831
- val input: DocumentReaderValue = temp
832
-
833
- result.put("pageIndex", input.pageIndex)
834
- result.put("sourceType", input.sourceType)
835
- result.put("probability", input.probability)
836
- result.put("value", input.value)
837
- result.put("originalValue", input.originalValue)
838
- result.put("boundRect", generateRect(input.boundRect))
839
- result.put("originalSymbols", generateList(input.originalSymbols, ::generateDocumentReaderSymbol))
840
- result.put("rfidOrigin", generateDocumentReaderRFIDOrigin(input.rfidOrigin))
841
-
842
- return result
688
+ fun generateDocumentReaderValue(input: DocumentReaderValue?) = input?.let {
689
+ mapOf(
690
+ "pageIndex" to it.pageIndex,
691
+ "sourceType" to it.sourceType,
692
+ "probability" to it.probability,
693
+ "value" to it.value,
694
+ "originalValue" to it.originalValue,
695
+ "boundRect" to generateRect(it.boundRect),
696
+ "originalSymbols" to it.originalSymbols.toJson(::generateDocumentReaderSymbol),
697
+ "rfidOrigin" to generateDocumentReaderRFIDOrigin(it.rfidOrigin)
698
+ ).toJson()
843
699
  }
844
700
 
845
- fun documentReaderTextFieldFromJSON(temp: JSONObject?): DocumentReaderTextField? {
846
- temp ?: return null
847
- val input: JSONObject = temp
701
+ fun documentReaderTextFieldFromJSON(input: JSONObject?) = input?.let {
848
702
  val result = DocumentReaderTextField()
849
703
 
850
- input.remove("getValue")
851
- result.fieldType = input.optInt("fieldType")
852
- result.lcid = input.optInt("lcid")
853
- result.status = input.optInt("status")
854
- result.value = input.optString("value")
855
- result.values = listFromJSON(input.optJSONArray("values"), ::documentReaderValueFromJSON)!!
856
- result.comparisonList = listFromJSON(input.optJSONArray("comparisonList"), ::documentReaderComparisonFromJSON)!!
857
- result.validityList = listFromJSON(input.optJSONArray("validityList"), ::documentReaderValidityFromJSON)!!
858
- result.comparisonStatus = input.optInt("comparisonStatus")
859
- result.validityStatus = input.optInt("validityStatus")
860
-
861
- return result
862
- }
863
-
864
- fun generateDocumentReaderTextField(temp: DocumentReaderTextField?, context: Context?): JSONObject? {
865
- val result = JSONObject()
866
- temp ?: return null
867
- val input: DocumentReaderTextField = temp
868
-
869
- result.put("fieldType", input.fieldType)
870
- result.put("lcid", input.lcid)
871
- result.put("status", input.status)
872
- result.put("lcidName", input.getLcidName(context!!))
873
- result.put("fieldName", input.getFieldName(context))
874
- result.put("value", input.value)
875
- result.put("getValue", generateDocumentReaderValue(input.value()))
876
- result.put("values", generateList(input.values, ::generateDocumentReaderValue))
877
- result.put("comparisonList", generateList(input.comparisonList, ::generateDocumentReaderComparison))
878
- result.put("validityList", generateList(input.validityList, ::generateDocumentReaderValidity))
879
- result.put("comparisonStatus", input.comparisonStatus)
880
- result.put("validityStatus", input.validityStatus)
881
-
882
- return result
883
- }
884
-
885
- fun documentReaderTextResultFromJSON(temp: JSONObject?): DocumentReaderTextResult? {
886
- temp ?: return null
887
- val input: JSONObject = temp
704
+ it.remove("getValue")
705
+ result.fieldType = it.optInt("fieldType")
706
+ result.lcid = it.optInt("lcid")
707
+ result.status = it.optInt("status")
708
+ result.value = it.optString("value")
709
+ result.values = it.optJSONArray("values").toList(::documentReaderValueFromJSON)!!
710
+ result.comparisonList = it.optJSONArray("comparisonList").toList(::documentReaderComparisonFromJSON)!!
711
+ result.validityList = it.optJSONArray("validityList").toList(::documentReaderValidityFromJSON)!!
712
+ result.comparisonStatus = it.optInt("comparisonStatus")
713
+ result.validityStatus = it.optInt("validityStatus")
714
+
715
+ result
716
+ }
717
+
718
+ fun generateDocumentReaderTextField(input: DocumentReaderTextField?) = input?.let {
719
+ mapOf(
720
+ "fieldType" to it.fieldType,
721
+ "lcid" to it.lcid,
722
+ "status" to it.status,
723
+ "lcidName" to it.getLcidName(context),
724
+ "fieldName" to it.getFieldName(context),
725
+ "value" to it.value,
726
+ "getValue" to generateDocumentReaderValue(it.value()),
727
+ "values" to it.values.toJson(::generateDocumentReaderValue),
728
+ "comparisonList" to it.comparisonList.toJson(::generateDocumentReaderComparison),
729
+ "validityList" to it.validityList.toJson(::generateDocumentReaderValidity),
730
+ "comparisonStatus" to it.comparisonStatus,
731
+ "validityStatus" to it.validityStatus
732
+ ).toJson()
733
+ }
734
+
735
+ fun documentReaderTextResultFromJSON(input: JSONObject?) = input?.let {
888
736
  val result = DocumentReaderTextResult()
889
737
 
890
- result.status = input.optInt("status")
891
- result.comparisonStatus = input.optInt("comparisonStatus")
892
- result.validityStatus = input.optInt("validityStatus")
893
- result.availableSourceList = listFromJSON(input.optJSONArray("availableSourceList"), ::documentReaderTextSourceFromJSON)!!
894
- result.fields = listFromJSON(input.optJSONArray("fields"), ::documentReaderTextFieldFromJSON)!!
738
+ result.status = it.optInt("status")
739
+ result.comparisonStatus = it.optInt("comparisonStatus")
740
+ result.validityStatus = it.optInt("validityStatus")
741
+ result.availableSourceList = it.optJSONArray("availableSourceList").toList(::documentReaderTextSourceFromJSON)!!
742
+ result.fields = it.optJSONArray("fields").toList(::documentReaderTextFieldFromJSON)!!
895
743
 
896
- return result
744
+ result
897
745
  }
898
746
 
899
- fun generateDocumentReaderTextResult(temp: DocumentReaderTextResult?, context: Context?): JSONObject? {
900
- val result = JSONObject()
901
- temp ?: return null
902
- val input: DocumentReaderTextResult = temp
903
-
904
- result.put("status", input.status)
905
- result.put("comparisonStatus", input.comparisonStatus)
906
- result.put("validityStatus", input.validityStatus)
907
- result.put("availableSourceList", generateList(input.availableSourceList, ::generateDocumentReaderTextSource))
908
- result.put("fields", generateList(input.fields, ::generateDocumentReaderTextField, context))
909
-
910
- return result
747
+ fun generateDocumentReaderTextResult(input: DocumentReaderTextResult?) = input?.let {
748
+ mapOf(
749
+ "status" to it.status,
750
+ "comparisonStatus" to it.comparisonStatus,
751
+ "validityStatus" to it.validityStatus,
752
+ "availableSourceList" to it.availableSourceList.toJson(::generateDocumentReaderTextSource),
753
+ "fields" to it.fields.toJson(::generateDocumentReaderTextField)
754
+ ).toJson()
911
755
  }
912
756
 
913
- fun coordinateFromJSON(temp: JSONObject?): Coordinate? {
914
- temp ?: return null
915
- val input: JSONObject = temp
757
+ fun coordinateFromJSON(input: JSONObject?) = input?.let {
916
758
  val result = Coordinate()
917
-
918
- result.x = input.optInt("x")
919
- result.y = input.optInt("y")
920
-
921
- return result
759
+ result.x = it.optInt("x")
760
+ result.y = it.optInt("y")
761
+ result
922
762
  }
923
763
 
924
- fun generateCoordinate(temp: Coordinate?): JSONObject? {
925
- val result = JSONObject()
926
- temp ?: return null
927
- val input: Coordinate = temp
928
-
929
- result.put("x", input.x)
930
- result.put("y", input.y)
931
-
932
- return result
764
+ fun generateCoordinate(input: Coordinate?) = input?.let {
765
+ mapOf(
766
+ "x" to it.x,
767
+ "y" to it.y
768
+ ).toJson()
933
769
  }
934
770
 
935
- fun elementPositionFromJSON(temp: JSONObject?): ElementPosition? {
936
- temp ?: return null
937
- val input: JSONObject = temp
771
+ fun elementPositionFromJSON(input: JSONObject?) = input?.let {
938
772
  val result = ElementPosition()
939
773
 
940
- result.docFormat = input.optInt("docFormat")
941
- result.width = input.optInt("width")
942
- result.height = input.optInt("height")
943
- result.dpi = input.optInt("dpi")
944
- result.pageIndex = input.optInt("pageIndex")
945
- result.inverse = input.optInt("inverse")
946
- result.perspectiveTr = input.optInt("perspectiveTr")
947
- result.objArea = input.optInt("objArea")
948
- result.objIntAngleDev = input.optInt("objIntAngleDev")
949
- result.resultStatus = input.optInt("resultStatus")
950
- result.angle = input.optDouble("angle")
951
- result.center = coordinateFromJSON(input.optJSONObject("center"))
952
- result.leftTop = coordinateFromJSON(input.optJSONObject("leftTop"))
953
- result.leftBottom = coordinateFromJSON(input.optJSONObject("leftBottom"))
954
- result.rightTop = coordinateFromJSON(input.optJSONObject("rightTop"))
955
- result.rightBottom = coordinateFromJSON(input.optJSONObject("rightBottom"))
956
-
957
- return result
958
- }
959
-
960
- fun generateElementPosition(temp: ElementPosition?): JSONObject? {
961
- val result = JSONObject()
962
- temp ?: return null
963
- val input: ElementPosition = temp
964
-
965
- result.put("docFormat", input.docFormat)
966
- result.put("width", input.width)
967
- result.put("height", input.height)
968
- result.put("dpi", input.dpi)
969
- result.put("pageIndex", input.pageIndex)
970
- result.put("inverse", input.inverse)
971
- result.put("perspectiveTr", input.perspectiveTr)
972
- result.put("objArea", input.objArea)
973
- result.put("objIntAngleDev", input.objIntAngleDev)
974
- result.put("resultStatus", input.resultStatus)
975
- result.put("angle", input.angle)
976
- result.put("center", generateCoordinate(input.center))
977
- result.put("leftTop", generateCoordinate(input.leftTop))
978
- result.put("leftBottom", generateCoordinate(input.leftBottom))
979
- result.put("rightTop", generateCoordinate(input.rightTop))
980
- result.put("rightBottom", generateCoordinate(input.rightBottom))
981
-
982
- return result
983
- }
984
-
985
- fun imageQualityFromJSON(temp: JSONObject?): ImageQuality? {
986
- temp ?: return null
987
- val input: JSONObject = temp
774
+ result.docFormat = it.optInt("docFormat")
775
+ result.width = it.optInt("width")
776
+ result.height = it.optInt("height")
777
+ result.dpi = it.optInt("dpi")
778
+ result.pageIndex = it.optInt("pageIndex")
779
+ result.inverse = it.optInt("inverse")
780
+ result.perspectiveTr = it.optInt("perspectiveTr")
781
+ result.objArea = it.optInt("objArea")
782
+ result.objIntAngleDev = it.optInt("objIntAngleDev")
783
+ result.resultStatus = it.optInt("resultStatus")
784
+ result.angle = it.optDouble("angle")
785
+ result.center = coordinateFromJSON(it.optJSONObject("center"))
786
+ result.leftTop = coordinateFromJSON(it.optJSONObject("leftTop"))
787
+ result.leftBottom = coordinateFromJSON(it.optJSONObject("leftBottom"))
788
+ result.rightTop = coordinateFromJSON(it.optJSONObject("rightTop"))
789
+ result.rightBottom = coordinateFromJSON(it.optJSONObject("rightBottom"))
790
+
791
+ result
792
+ }
793
+
794
+ fun generateElementPosition(input: ElementPosition?) = input?.let {
795
+ mapOf(
796
+ "docFormat" to it.docFormat,
797
+ "width" to it.width,
798
+ "height" to it.height,
799
+ "dpi" to it.dpi,
800
+ "pageIndex" to it.pageIndex,
801
+ "inverse" to it.inverse,
802
+ "perspectiveTr" to it.perspectiveTr,
803
+ "objArea" to it.objArea,
804
+ "objIntAngleDev" to it.objIntAngleDev,
805
+ "resultStatus" to it.resultStatus,
806
+ "angle" to it.angle,
807
+ "center" to generateCoordinate(it.center),
808
+ "leftTop" to generateCoordinate(it.leftTop),
809
+ "leftBottom" to generateCoordinate(it.leftBottom),
810
+ "rightTop" to generateCoordinate(it.rightTop),
811
+ "rightBottom" to generateCoordinate(it.rightBottom)
812
+ ).toJson()
813
+ }
814
+
815
+ fun imageQualityFromJSON(input: JSONObject?) = input?.let {
988
816
  val result = ImageQuality()
989
817
 
990
- result.featureType = input.optInt("featureType")
991
- result.result = input.optInt("result")
992
- result.type = input.optInt("type")
993
- result.boundRects = listFromJSON(input.optJSONArray("boundRects"), ::docReaderFieldRectFromJSON)!!
818
+ result.featureType = it.optInt("featureType")
819
+ result.result = it.optInt("result")
820
+ result.type = it.optInt("type")
821
+ result.boundRects = it.optJSONArray("boundRects").toList(::docReaderFieldRectFromJSON)!!
994
822
 
995
- return result
823
+ result
996
824
  }
997
825
 
998
- fun generateImageQuality(temp: ImageQuality?): JSONObject? {
999
- val result = JSONObject()
1000
- temp ?: return null
1001
- val input: ImageQuality = temp
1002
-
1003
- result.put("featureType", input.featureType)
1004
- result.put("result", input.result)
1005
- result.put("type", input.type)
1006
- result.put("boundRects", generateList(input.boundRects, ::generateDocReaderFieldRect))
1007
-
1008
- return result
826
+ fun generateImageQuality(input: ImageQuality?) = input?.let {
827
+ mapOf(
828
+ "featureType" to it.featureType,
829
+ "result" to it.result,
830
+ "type" to it.type,
831
+ "boundRects" to it.boundRects.toJson(::generateDocReaderFieldRect)
832
+ ).toJson()
1009
833
  }
1010
834
 
1011
- fun imageQualityGroupFromJSON(temp: JSONObject?): ImageQualityGroup? {
1012
- temp ?: return null
1013
- val input: JSONObject = temp
835
+ fun imageQualityGroupFromJSON(input: JSONObject?) = input?.let {
1014
836
  val result = ImageQualityGroup()
1015
837
 
1016
- result.count = input.optInt("count")
1017
- result.result = input.optInt("result")
1018
- result.pageIndex = input.optInt("pageIndex")
1019
- result.imageQualityList = listFromJSON(input.optJSONArray("imageQualityList"), ::imageQualityFromJSON)!!
838
+ result.count = it.optInt("count")
839
+ result.result = it.optInt("result")
840
+ result.pageIndex = it.optInt("pageIndex")
841
+ result.imageQualityList = it.optJSONArray("imageQualityList").toList(::imageQualityFromJSON)!!
1020
842
 
1021
- return result
843
+ result
1022
844
  }
1023
845
 
1024
- fun generateImageQualityGroup(temp: ImageQualityGroup?): JSONObject? {
1025
- val result = JSONObject()
1026
- temp ?: return null
1027
- val input: ImageQualityGroup = temp
1028
-
1029
- result.put("count", input.count)
1030
- result.put("result", input.result)
1031
- result.put("imageQualityList", generateList(input.imageQualityList, ::generateImageQuality))
1032
- result.put("pageIndex", input.pageIndex)
1033
-
1034
- return result
846
+ fun generateImageQualityGroup(input: ImageQualityGroup?) = input?.let {
847
+ mapOf(
848
+ "count" to it.count,
849
+ "result" to it.result,
850
+ "imageQualityList" to it.imageQualityList.toJson(::generateImageQuality),
851
+ "pageIndex" to it.pageIndex
852
+ ).toJson()
1035
853
  }
1036
854
 
1037
- fun cameraSizeFromJSON(input: JSONObject): Pair<Int, Int> {
1038
- val width = input.getInt("width")
1039
- val height = input.getInt("height")
1040
- return Pair(width, height)
855
+ fun cameraSizeFromJSON(input: JSONObject) = input.let {
856
+ val width = it.getInt("width")
857
+ val height = it.getInt("height")
858
+ Pair(width, height)
1041
859
  }
1042
860
 
1043
861
  fun generateCameraSize(width: Int?, height: Int?): JSONObject? {
1044
862
  width ?: return null
1045
863
  height ?: return null
1046
- val result = JSONObject()
1047
- result.put("width", width)
1048
- result.put("height", height)
1049
- return result
864
+ return mapOf(
865
+ "width" to width,
866
+ "height" to height
867
+ ).toJson()
1050
868
  }
1051
869
 
1052
- fun documentReaderDocumentTypeFromJSON(temp: JSONObject?): DocumentReaderDocumentType? {
1053
- temp ?: return null
1054
- val input: JSONObject = temp
870
+ fun documentReaderDocumentTypeFromJSON(input: JSONObject?) = input?.let {
1055
871
  val result = DocumentReaderDocumentType()
1056
872
 
1057
- result.pageIndex = input.optInt("pageIndex")
1058
- result.documentID = input.optInt("documentID")
1059
- result.dType = input.optInt("dType")
1060
- result.dFormat = input.optInt("dFormat")
1061
- result.dMRZ = input.optBoolean("dMRZ")
1062
- result.isDeprecated = input.optBoolean("isDeprecated")
1063
- result.name = input.optString("name")
1064
- result.ICAOCode = input.optString("ICAOCode")
1065
- result.dDescription = input.optString("dDescription")
1066
- result.dCountryName = input.optString("dCountryName")
1067
- result.dYear = input.optString("dYear")
1068
- result.FDSID = input.optJSONArray("FDSID").toIntArray()
1069
-
1070
- return result
1071
- }
1072
-
1073
- fun generateDocumentReaderDocumentType(temp: DocumentReaderDocumentType?): JSONObject? {
1074
- val result = JSONObject()
1075
- temp ?: return null
1076
- val input: DocumentReaderDocumentType = temp
1077
-
1078
- result.put("pageIndex", input.pageIndex)
1079
- result.put("documentID", input.documentID)
1080
- result.put("dType", input.dType)
1081
- result.put("dFormat", input.dFormat)
1082
- result.put("dMRZ", input.dMRZ)
1083
- result.put("isDeprecated", input.isDeprecated)
1084
- result.put("name", input.name)
1085
- result.put("ICAOCode", input.ICAOCode)
1086
- result.put("dDescription", input.dDescription)
1087
- result.put("dYear", input.dYear)
1088
- result.put("dCountryName", input.dCountryName)
1089
- result.put("FDSID", input.FDSID.generate())
1090
-
1091
- return result
1092
- }
1093
-
1094
- fun generateDocumentReaderNotification(temp: DocumentReaderNotification?): JSONObject? {
1095
- val result = JSONObject()
1096
- temp ?: return null
1097
- val input: DocumentReaderNotification = temp
1098
-
1099
- result.put("notificationCode", input.notificationCode)
1100
- result.put("dataFileType", input.dataFileType)
1101
- result.put("progress", input.progress)
1102
-
1103
- return result
1104
- }
1105
-
1106
- fun accessControlProcedureTypeFromJSON(temp: JSONObject?): AccessControlProcedureType? {
1107
- temp ?: return null
1108
- val input: JSONObject = temp
873
+ result.pageIndex = it.optInt("pageIndex")
874
+ result.documentID = it.optInt("documentID")
875
+ result.dType = it.optInt("dType")
876
+ result.dFormat = it.optInt("dFormat")
877
+ result.dMRZ = it.optBoolean("dMRZ")
878
+ result.isDeprecated = it.optBoolean("isDeprecated")
879
+ result.name = it.optString("name")
880
+ result.ICAOCode = it.optString("ICAOCode")
881
+ result.dDescription = it.optString("dDescription")
882
+ result.dCountryName = it.optString("dCountryName")
883
+ result.dYear = it.optString("dYear")
884
+ result.FDSID = it.optJSONArray("FDSID").toIntArray()
885
+
886
+ result
887
+ }
888
+
889
+ fun generateDocumentReaderDocumentType(input: DocumentReaderDocumentType?) = input?.let {
890
+ mapOf(
891
+ "pageIndex" to it.pageIndex,
892
+ "documentID" to it.documentID,
893
+ "dType" to it.dType,
894
+ "dFormat" to it.dFormat,
895
+ "dMRZ" to it.dMRZ,
896
+ "isDeprecated" to it.isDeprecated,
897
+ "name" to it.name,
898
+ "ICAOCode" to it.ICAOCode,
899
+ "dDescription" to it.dDescription,
900
+ "dYear" to it.dYear,
901
+ "dCountryName" to it.dCountryName,
902
+ "FDSID" to it.FDSID.toJson()
903
+ ).toJson()
904
+ }
905
+
906
+ fun generateDocumentReaderNotification(input: DocumentReaderNotification?) = input?.let {
907
+ mapOf(
908
+ "notificationCode" to it.notificationCode,
909
+ "dataFileType" to it.dataFileType,
910
+ "progress" to it.progress
911
+ ).toJson()
912
+ }
913
+
914
+ fun accessControlProcedureTypeFromJSON(input: JSONObject?) = input?.let {
1109
915
  val result = AccessControlProcedureType()
1110
916
 
1111
- result.activeOptionIdx = input.optInt("activeOptionIdx")
1112
- result.type = input.optInt("type")
1113
- result.status = input.optInt("status").toLong()
1114
- result.notifications = listFromJSON(input.optJSONArray("notifications")!!)
917
+ result.activeOptionIdx = it.optInt("activeOptionIdx")
918
+ result.type = it.optInt("type")
919
+ result.status = it.optInt("status").toLong()
920
+ result.notifications = it.optJSONArray("notifications")!!.toList()
1115
921
 
1116
- return result
922
+ result
1117
923
  }
1118
924
 
1119
- fun generateAccessControlProcedureType(temp: AccessControlProcedureType?): JSONObject? {
1120
- val result = JSONObject()
1121
- temp ?: return null
1122
- val input: AccessControlProcedureType = temp
1123
-
1124
- result.put("activeOptionIdx", input.activeOptionIdx)
1125
- result.put("type", input.type)
1126
- result.put("status", input.status)
1127
- result.put("notifications", generateList(input.notifications))
1128
-
1129
- return result
925
+ fun generateAccessControlProcedureType(input: AccessControlProcedureType?) = input?.let {
926
+ mapOf(
927
+ "activeOptionIdx" to it.activeOptionIdx,
928
+ "type" to it.type,
929
+ "status" to it.status,
930
+ "notifications" to it.notifications.toJson()
931
+ ).toJson()
1130
932
  }
1131
933
 
1132
- fun fileDataFromJSON(temp: JSONObject?): FileData? {
1133
- temp ?: return null
1134
- val input: JSONObject = temp
934
+ fun fileDataFromJSON(input: JSONObject?) = input?.let {
1135
935
  val result = FileData()
1136
936
 
1137
- result.length = input.optInt("length")
1138
- result.type = input.optInt("type")
1139
- result.status = input.optInt("status").toLong()
1140
- result.data = input.optString("data")
937
+ result.length = it.optInt("length")
938
+ result.type = it.optInt("type")
939
+ result.status = it.optInt("status").toLong()
940
+ result.data = it.optString("data")
1141
941
 
1142
- return result
942
+ result
1143
943
  }
1144
944
 
1145
- fun generateFileData(temp: FileData?): JSONObject? {
1146
- val result = JSONObject()
1147
- temp ?: return null
1148
- val input: FileData = temp
1149
-
1150
- result.put("length", input.length)
1151
- result.put("type", input.type)
1152
- result.put("status", input.status)
1153
- result.put("data", input.data)
1154
-
1155
- return result
945
+ fun generateFileData(input: FileData?) = input?.let {
946
+ mapOf(
947
+ "length" to it.length,
948
+ "type" to it.type,
949
+ "status" to it.status,
950
+ "data" to it.data
951
+ ).toJson()
1156
952
  }
1157
953
 
1158
- fun certificateDataFromJSON(temp: JSONObject?): CertificateData? {
1159
- temp ?: return null
1160
- val input: JSONObject = temp
954
+ fun certificateDataFromJSON(input: JSONObject?) = input?.let {
1161
955
  val result = CertificateData()
1162
-
1163
- result.length = input.optInt("length")
1164
- result.data = input.optString("data")
1165
-
1166
- return result
956
+ result.length = it.optInt("length")
957
+ result.data = it.optString("data")
958
+ result
1167
959
  }
1168
960
 
1169
- fun generateCertificateData(temp: CertificateData?): JSONObject? {
1170
- val result = JSONObject()
1171
- temp ?: return null
1172
- val input: CertificateData = temp
1173
-
1174
- result.put("length", input.length)
1175
- result.put("data", input.data)
1176
-
1177
- return result
961
+ fun generateCertificateData(input: CertificateData?) = input?.let {
962
+ mapOf(
963
+ "length" to it.length,
964
+ "data" to it.data
965
+ ).toJson()
1178
966
  }
1179
967
 
1180
- fun securityObjectCertificatesFromJSON(temp: JSONObject?): SecurityObjectCertificates? {
1181
- temp ?: return null
1182
- val input: JSONObject = temp
968
+ fun securityObjectCertificatesFromJSON(input: JSONObject?) = input?.let {
1183
969
  val result = SecurityObjectCertificates()
1184
-
1185
- result.securityObject = certificateDataFromJSON(input.optJSONObject("securityObject"))
1186
-
1187
- return result
970
+ result.securityObject = certificateDataFromJSON(it.optJSONObject("securityObject"))
971
+ result
1188
972
  }
1189
973
 
1190
- fun generateSecurityObjectCertificates(temp: SecurityObjectCertificates?): JSONObject? {
1191
- val result = JSONObject()
1192
- temp ?: return null
1193
- val input: SecurityObjectCertificates = temp
1194
-
1195
- result.put("securityObject", generateCertificateData(input.securityObject))
1196
-
1197
- return result
974
+ fun generateSecurityObjectCertificates(input: SecurityObjectCertificates?) = input?.let {
975
+ mapOf(
976
+ "securityObject" to generateCertificateData(it.securityObject)
977
+ ).toJson()
1198
978
  }
1199
979
 
1200
- fun fileFromJSON(temp: JSONObject?): File? {
1201
- temp ?: return null
1202
- val input: JSONObject = temp
980
+ fun fileFromJSON(input: JSONObject?) = input?.let {
1203
981
  val result = File()
1204
982
 
1205
- result.readingTime = input.optInt("readingTime")
1206
- result.type = input.optInt("type")
1207
- result.pAStatus = input.optLong("pAStatus")
1208
- result.readingStatus = input.optInt("readingStatus").toLong()
1209
- result.fileID = input.optString("fileID")
1210
- result.fileData = fileDataFromJSON(input.optJSONObject("fileData"))
1211
- result.certificates = securityObjectCertificatesFromJSON(input.optJSONObject("certificates"))
1212
- result.docFieldsText = listFromJSON(input.optJSONArray("docFieldsText")!!)
1213
- result.docFieldsGraphics = listFromJSON(input.optJSONArray("docFieldsGraphics")!!)
1214
- result.docFieldsOriginals = listFromJSON(input.optJSONArray("docFieldsOriginals")!!)
1215
- result.notifications = listFromJSON(input.optJSONArray("notifications")!!)
1216
-
1217
- return result
1218
- }
1219
-
1220
- fun generateFile(temp: File?, context: Context?): JSONObject? {
1221
- val result = JSONObject()
1222
- temp ?: return null
1223
- val input: File = temp
1224
-
1225
- result.put("readingTime", input.readingTime)
1226
- result.put("type", input.type)
1227
- result.put("typeName", eRFID_DataFile_Type.getTranslation(context, input.type))
1228
- result.put("pAStatus", input.pAStatus)
1229
- result.put("readingStatus", input.readingStatus)
1230
- result.put("fileID", input.fileID)
1231
- result.put("fileData", generateFileData(input.fileData))
1232
- result.put("certificates", generateSecurityObjectCertificates(input.certificates))
1233
- result.put("docFieldsText", generateList(input.docFieldsText))
1234
- result.put("docFieldsGraphics", generateList(input.docFieldsGraphics))
1235
- result.put("docFieldsOriginals", generateList(input.docFieldsOriginals))
1236
- result.put("notifications", generateList(input.notifications))
1237
-
1238
- return result
1239
- }
1240
-
1241
- fun applicationFromJSON(temp: JSONObject?): Application? {
1242
- temp ?: return null
1243
- val input: JSONObject = temp
983
+ result.readingTime = it.optInt("readingTime")
984
+ result.type = it.optInt("type")
985
+ result.pAStatus = it.optLong("pAStatus")
986
+ result.readingStatus = it.optInt("readingStatus").toLong()
987
+ result.fileID = it.optString("fileID")
988
+ result.fileData = fileDataFromJSON(it.optJSONObject("fileData"))
989
+ result.certificates = securityObjectCertificatesFromJSON(it.optJSONObject("certificates"))
990
+ result.docFieldsText = it.optJSONArray("docFieldsText")!!.toList()
991
+ result.docFieldsGraphics = it.optJSONArray("docFieldsGraphics")!!.toList()
992
+ result.docFieldsOriginals = it.optJSONArray("docFieldsOriginals")!!.toList()
993
+ result.notifications = it.optJSONArray("notifications")!!.toList()
994
+
995
+ result
996
+ }
997
+
998
+ fun generateFile(input: File?) = input?.let {
999
+ mapOf(
1000
+ "readingTime" to it.readingTime,
1001
+ "type" to it.type,
1002
+ "typeName" to eRFID_DataFile_Type.getTranslation(context, it.type),
1003
+ "pAStatus" to it.pAStatus,
1004
+ "readingStatus" to it.readingStatus,
1005
+ "fileID" to it.fileID,
1006
+ "fileData" to generateFileData(it.fileData),
1007
+ "certificates" to generateSecurityObjectCertificates(it.certificates),
1008
+ "docFieldsText" to it.docFieldsText.toJson(),
1009
+ "docFieldsGraphics" to it.docFieldsGraphics.toJson(),
1010
+ "docFieldsOriginals" to it.docFieldsOriginals.toJson(),
1011
+ "notifications" to it.notifications.toJson()
1012
+ ).toJson()
1013
+ }
1014
+
1015
+ fun applicationFromJSON(input: JSONObject?) = input?.let {
1244
1016
  val result = Application()
1245
1017
 
1246
- result.type = input.optInt("type")
1247
- result.status = input.optInt("status")
1248
- result.applicationID = input.optString("applicationID")
1249
- result.dataHashAlgorithm = input.optString("dataHashAlgorithm")
1250
- result.unicodeVersion = input.optString("unicodeVersion")
1251
- result.version = input.optString("version")
1252
- result.files = listFromJSON(input.optJSONArray("files"), ::fileFromJSON)!!
1018
+ result.type = it.optInt("type")
1019
+ result.status = it.optInt("status")
1020
+ result.applicationID = it.optString("applicationID")
1021
+ result.dataHashAlgorithm = it.optString("dataHashAlgorithm")
1022
+ result.unicodeVersion = it.optString("unicodeVersion")
1023
+ result.version = it.optString("version")
1024
+ result.files = it.optJSONArray("files").toList(::fileFromJSON)!!
1253
1025
 
1254
- return result
1026
+ result
1255
1027
  }
1256
1028
 
1257
- fun generateApplication(temp: Application?, context: Context?): JSONObject? {
1258
- val result = JSONObject()
1259
- temp ?: return null
1260
- val input: Application = temp
1261
-
1262
- result.put("type", input.type)
1263
- result.put("status", input.status)
1264
- result.put("applicationID", input.applicationID)
1265
- result.put("dataHashAlgorithm", input.dataHashAlgorithm)
1266
- result.put("unicodeVersion", input.unicodeVersion)
1267
- result.put("version", input.version)
1268
- result.put("files", generateList(input.files, ::generateFile, context))
1269
-
1270
- return result
1029
+ fun generateApplication(input: Application?) = input?.let {
1030
+ mapOf(
1031
+ "type" to it.type,
1032
+ "status" to it.status,
1033
+ "applicationID" to it.applicationID,
1034
+ "dataHashAlgorithm" to it.dataHashAlgorithm,
1035
+ "unicodeVersion" to it.unicodeVersion,
1036
+ "version" to it.version,
1037
+ "files" to it.files.toJson(::generateFile)
1038
+ ).toJson()
1271
1039
  }
1272
1040
 
1273
- fun valueFromJSON(temp: JSONObject?): Value? {
1274
- temp ?: return null
1275
- val input: JSONObject = temp
1041
+ fun valueFromJSON(input: JSONObject?) = input?.let {
1276
1042
  val result = Value()
1277
1043
 
1278
- result.length = input.optInt("length")
1279
- result.type = input.optInt("type")
1280
- result.status = input.optInt("status").toLong()
1281
- result.data = input.optString("data")
1282
- result.format = input.optString("format")
1044
+ result.length = it.optInt("length")
1045
+ result.type = it.optInt("type")
1046
+ result.status = it.optInt("status").toLong()
1047
+ result.data = it.optString("data")
1048
+ result.format = it.optString("format")
1283
1049
 
1284
- return result
1050
+ result
1285
1051
  }
1286
1052
 
1287
- fun generateValue(temp: Value?): JSONObject? {
1288
- val result = JSONObject()
1289
- temp ?: return null
1290
- val input: Value = temp
1291
-
1292
- result.put("length", input.length)
1293
- result.put("type", input.type)
1294
- result.put("status", input.status)
1295
- result.put("data", input.data)
1296
- result.put("format", input.format)
1297
-
1298
- return result
1053
+ fun generateValue(input: Value?) = input?.let {
1054
+ mapOf(
1055
+ "length" to it.length,
1056
+ "type" to it.type,
1057
+ "status" to it.status,
1058
+ "data" to it.data,
1059
+ "format" to it.format
1060
+ ).toJson()
1299
1061
  }
1300
1062
 
1301
- fun attributeFromJSON(temp: JSONObject?): Attribute? {
1302
- temp ?: return null
1303
- val input: JSONObject = temp
1063
+ fun attributeFromJSON(input: JSONObject?) = input?.let {
1304
1064
  val result = Attribute()
1305
-
1306
- result.type = input.optString("type")
1307
- result.value = valueFromJSON(input.optJSONObject("value"))
1308
-
1309
- return result
1065
+ result.type = it.optString("type")
1066
+ result.value = valueFromJSON(it.optJSONObject("value"))
1067
+ result
1310
1068
  }
1311
1069
 
1312
- fun generateAttribute(temp: Attribute?): JSONObject? {
1313
- val result = JSONObject()
1314
- temp ?: return null
1315
- val input: Attribute = temp
1316
-
1317
- result.put("type", input.type)
1318
- result.put("value", generateValue(input.value))
1319
-
1320
- return result
1070
+ fun generateAttribute(input: Attribute?) = input?.let {
1071
+ mapOf(
1072
+ "type" to it.type,
1073
+ "value" to generateValue(it.value)
1074
+ ).toJson()
1321
1075
  }
1322
1076
 
1323
- fun authorityFromJSON(temp: JSONObject?): Authority? {
1324
- temp ?: return null
1325
- val input: JSONObject = temp
1077
+ fun authorityFromJSON(input: JSONObject?) = input?.let {
1326
1078
  val result = Authority()
1327
-
1328
- result.data = input.optString("data")
1329
- result.friendlyName = valueFromJSON(input.optJSONObject("friendlyName"))
1330
- result.attributes = listFromJSON(input.optJSONArray("attributes"), ::attributeFromJSON)!!
1331
-
1332
- return result
1079
+ result.data = it.optString("data")
1080
+ result.friendlyName = valueFromJSON(it.optJSONObject("friendlyName"))
1081
+ result.attributes = it.optJSONArray("attributes").toList(::attributeFromJSON)!!
1082
+ result
1333
1083
  }
1334
1084
 
1335
- fun generateAuthority(temp: Authority?): JSONObject? {
1336
- val result = JSONObject()
1337
- temp ?: return null
1338
- val input: Authority = temp
1339
-
1340
- result.put("data", input.data)
1341
- result.put("friendlyName", generateValue(input.friendlyName))
1342
- result.put("attributes", generateList(input.attributes, ::generateAttribute))
1343
-
1344
- return result
1085
+ fun generateAuthority(input: Authority?) = input?.let {
1086
+ mapOf(
1087
+ "data" to it.data,
1088
+ "friendlyName" to generateValue(it.friendlyName),
1089
+ "attributes" to it.attributes.toJson(::generateAttribute)
1090
+ ).toJson()
1345
1091
  }
1346
1092
 
1347
- fun extensionFromJSON(temp: JSONObject?): Extension? {
1348
- temp ?: return null
1349
- val input: JSONObject = temp
1093
+ fun extensionFromJSON(input: JSONObject?) = input?.let {
1350
1094
  val result = Extension()
1351
-
1352
- result.data = input.optString("data")
1353
- result.type = input.optString("type")
1354
-
1355
- return result
1095
+ result.data = it.optString("data")
1096
+ result.type = it.optString("type")
1097
+ result
1356
1098
  }
1357
1099
 
1358
- fun generateExtension(temp: Extension?): JSONObject? {
1359
- val result = JSONObject()
1360
- temp ?: return null
1361
- val input: Extension = temp
1362
-
1363
- result.put("data", input.data)
1364
- result.put("type", input.type)
1365
-
1366
- return result
1100
+ fun generateExtension(input: Extension?) = input?.let {
1101
+ mapOf(
1102
+ "data" to it.data,
1103
+ "type" to it.type
1104
+ ).toJson()
1367
1105
  }
1368
1106
 
1369
- fun validityFromJSON(temp: JSONObject?): Validity? {
1370
- temp ?: return null
1371
- val input: JSONObject = temp
1107
+ fun validityFromJSON(input: JSONObject?) = input?.let {
1372
1108
  val result = Validity()
1373
-
1374
- result.notAfter = valueFromJSON(input.optJSONObject("notAfter"))
1375
- result.notBefore = valueFromJSON(input.optJSONObject("notBefore"))
1376
-
1377
- return result
1109
+ result.notAfter = valueFromJSON(it.optJSONObject("notAfter"))
1110
+ result.notBefore = valueFromJSON(it.optJSONObject("notBefore"))
1111
+ result
1378
1112
  }
1379
1113
 
1380
- fun generateValidity(temp: Validity?): JSONObject? {
1381
- val result = JSONObject()
1382
- temp ?: return null
1383
- val input: Validity = temp
1384
-
1385
- result.put("notAfter", generateValue(input.notAfter))
1386
- result.put("notBefore", generateValue(input.notBefore))
1387
-
1388
- return result
1114
+ fun generateValidity(input: Validity?) = input?.let {
1115
+ mapOf(
1116
+ "notAfter" to generateValue(it.notAfter),
1117
+ "notBefore" to generateValue(it.notBefore)
1118
+ ).toJson()
1389
1119
  }
1390
1120
 
1391
- fun certificateChainFromJSON(temp: JSONObject?): CertificateChain? {
1392
- temp ?: return null
1393
- val input: JSONObject = temp
1121
+ fun certificateChainFromJSON(input: JSONObject?) = input?.let {
1394
1122
  val result = CertificateChain()
1395
1123
 
1396
- result.origin = input.optInt("origin")
1397
- result.type = input.optInt("type")
1398
- result.version = input.optInt("version")
1399
- result.paStatus = input.optInt("paStatus").toLong()
1400
- result.serialNumber = input.optString("serialNumber")
1401
- result.signatureAlgorithm = input.optString("signatureAlgorithm")
1402
- result.subjectPKAlgorithm = input.optString("subjectPKAlgorithm")
1403
- result.fileName = valueFromJSON(input.optJSONObject("fileName"))
1404
- result.validity = validityFromJSON(input.optJSONObject("validity"))
1405
- result.issuer = authorityFromJSON(input.optJSONObject("issuer"))
1406
- result.subject = authorityFromJSON(input.optJSONObject("subject"))
1407
- result.notifications = listFromJSON(input.optJSONArray("notifications")!!)
1408
- result.extensions = listFromJSON(input.optJSONArray("extensions"), ::extensionFromJSON)!!
1409
-
1410
- return result
1411
- }
1412
-
1413
- fun generateCertificateChain(temp: CertificateChain?): JSONObject? {
1414
- val result = JSONObject()
1415
- temp ?: return null
1416
- val input: CertificateChain = temp
1417
-
1418
- result.put("origin", input.origin)
1419
- result.put("type", input.type)
1420
- result.put("version", input.version)
1421
- result.put("paStatus", input.paStatus)
1422
- result.put("serialNumber", input.serialNumber)
1423
- result.put("signatureAlgorithm", input.signatureAlgorithm)
1424
- result.put("subjectPKAlgorithm", input.subjectPKAlgorithm)
1425
- result.put("fileName", generateValue(input.fileName))
1426
- result.put("validity", generateValidity(input.validity))
1427
- result.put("issuer", generateAuthority(input.issuer))
1428
- result.put("subject", generateAuthority(input.subject))
1429
- result.put("notifications", generateList(input.notifications))
1430
- result.put("extensions", generateList(input.extensions, ::generateExtension))
1431
-
1432
- return result
1433
- }
1434
-
1435
- fun signerInfoFromJSON(temp: JSONObject?): SignerInfo? {
1436
- temp ?: return null
1437
- val input: JSONObject = temp
1124
+ result.origin = it.optInt("origin")
1125
+ result.type = it.optInt("type")
1126
+ result.version = it.optInt("version")
1127
+ result.paStatus = it.optInt("paStatus").toLong()
1128
+ result.serialNumber = it.optString("serialNumber")
1129
+ result.signatureAlgorithm = it.optString("signatureAlgorithm")
1130
+ result.subjectPKAlgorithm = it.optString("subjectPKAlgorithm")
1131
+ result.fileName = valueFromJSON(it.optJSONObject("fileName"))
1132
+ result.validity = validityFromJSON(it.optJSONObject("validity"))
1133
+ result.issuer = authorityFromJSON(it.optJSONObject("issuer"))
1134
+ result.subject = authorityFromJSON(it.optJSONObject("subject"))
1135
+ result.notifications = it.optJSONArray("notifications")!!.toList()
1136
+ result.extensions = it.optJSONArray("extensions").toList(::extensionFromJSON)!!
1137
+
1138
+ result
1139
+ }
1140
+
1141
+ fun generateCertificateChain(input: CertificateChain?) = input?.let {
1142
+ mapOf(
1143
+ "origin" to it.origin,
1144
+ "type" to it.type,
1145
+ "version" to it.version,
1146
+ "paStatus" to it.paStatus,
1147
+ "serialNumber" to it.serialNumber,
1148
+ "signatureAlgorithm" to it.signatureAlgorithm,
1149
+ "subjectPKAlgorithm" to it.subjectPKAlgorithm,
1150
+ "fileName" to generateValue(it.fileName),
1151
+ "validity" to generateValidity(it.validity),
1152
+ "issuer" to generateAuthority(it.issuer),
1153
+ "subject" to generateAuthority(it.subject),
1154
+ "notifications" to it.notifications.toJson(),
1155
+ "extensions" to it.extensions.toJson(::generateExtension)
1156
+ ).toJson()
1157
+ }
1158
+
1159
+ fun signerInfoFromJSON(input: JSONObject?) = input?.let {
1438
1160
  val result = SignerInfo()
1439
1161
 
1440
- result.version = input.optInt("version")
1441
- result.paStatus = input.optInt("paStatus").toLong()
1442
- result.dataToHash = input.optString("dataToHash")
1443
- result.digestAlgorithm = input.optString("digestAlgorithm")
1444
- result.signatureAlgorithm = input.optString("signatureAlgorithm")
1445
- result.serialNumber = valueFromJSON(input.optJSONObject("serialNumber"))
1446
- result.signature = valueFromJSON(input.optJSONObject("signature"))
1447
- result.subjectKeyIdentifier = valueFromJSON(input.optJSONObject("subjectKeyIdentifier"))
1448
- result.issuer = authorityFromJSON(input.optJSONObject("issuer"))
1449
- result.notifications = listFromJSON(input.optJSONArray("notifications")!!)
1450
- result.signedAttributes = listFromJSON(input.optJSONArray("signedAttributes"), ::extensionFromJSON)!!
1451
- result.certificateChain = listFromJSON(input.optJSONArray("certificateChain"), ::certificateChainFromJSON)!!
1452
-
1453
- return result
1454
- }
1455
-
1456
- fun generateSignerInfo(temp: SignerInfo?): JSONObject? {
1457
- val result = JSONObject()
1458
- temp ?: return null
1459
- val input: SignerInfo = temp
1460
-
1461
- result.put("version", input.version)
1462
- result.put("paStatus", input.paStatus)
1463
- result.put("dataToHash", input.dataToHash)
1464
- result.put("digestAlgorithm", input.digestAlgorithm)
1465
- result.put("signatureAlgorithm", input.signatureAlgorithm)
1466
- result.put("serialNumber", generateValue(input.serialNumber))
1467
- result.put("signature", generateValue(input.signature))
1468
- result.put("subjectKeyIdentifier", generateValue(input.subjectKeyIdentifier))
1469
- result.put("issuer", generateAuthority(input.issuer))
1470
- result.put("notifications", generateList(input.notifications))
1471
- result.put("signedAttributes", generateList(input.signedAttributes, ::generateExtension))
1472
- result.put("certificateChain", generateList(input.certificateChain, ::generateCertificateChain))
1473
-
1474
- return result
1475
- }
1476
-
1477
- fun securityObjectFromJSON(temp: JSONObject?): SecurityObject? {
1478
- temp ?: return null
1479
- val input: JSONObject = temp
1162
+ result.version = it.optInt("version")
1163
+ result.paStatus = it.optInt("paStatus").toLong()
1164
+ result.dataToHash = it.optString("dataToHash")
1165
+ result.digestAlgorithm = it.optString("digestAlgorithm")
1166
+ result.signatureAlgorithm = it.optString("signatureAlgorithm")
1167
+ result.serialNumber = valueFromJSON(it.optJSONObject("serialNumber"))
1168
+ result.signature = valueFromJSON(it.optJSONObject("signature"))
1169
+ result.subjectKeyIdentifier = valueFromJSON(it.optJSONObject("subjectKeyIdentifier"))
1170
+ result.issuer = authorityFromJSON(it.optJSONObject("issuer"))
1171
+ result.notifications = it.optJSONArray("notifications")!!.toList()
1172
+ result.signedAttributes = it.optJSONArray("signedAttributes").toList(::extensionFromJSON)!!
1173
+ result.certificateChain = it.optJSONArray("certificateChain").toList(::certificateChainFromJSON)!!
1174
+
1175
+ result
1176
+ }
1177
+
1178
+ fun generateSignerInfo(input: SignerInfo?) = input?.let {
1179
+ mapOf(
1180
+ "version" to it.version,
1181
+ "paStatus" to it.paStatus,
1182
+ "dataToHash" to it.dataToHash,
1183
+ "digestAlgorithm" to it.digestAlgorithm,
1184
+ "signatureAlgorithm" to it.signatureAlgorithm,
1185
+ "serialNumber" to generateValue(it.serialNumber),
1186
+ "signature" to generateValue(it.signature),
1187
+ "subjectKeyIdentifier" to generateValue(it.subjectKeyIdentifier),
1188
+ "issuer" to generateAuthority(it.issuer),
1189
+ "notifications" to it.notifications.toJson(),
1190
+ "signedAttributes" to it.signedAttributes.toJson(::generateExtension),
1191
+ "certificateChain" to it.certificateChain.toJson(::generateCertificateChain)
1192
+ ).toJson()
1193
+ }
1194
+
1195
+ fun securityObjectFromJSON(input: JSONObject?) = input?.let {
1480
1196
  val result = SecurityObject()
1481
1197
 
1482
- result.fileReference = input.optInt("fileReference")
1483
- result.version = input.optInt("version")
1484
- result.objectType = input.optString("objectType")
1485
- result.notifications = listFromJSON(input.optJSONArray("notifications")!!)
1486
- result.signerInfos = listFromJSON(input.optJSONArray("signerInfos"), ::signerInfoFromJSON)!!
1198
+ result.fileReference = it.optInt("fileReference")
1199
+ result.version = it.optInt("version")
1200
+ result.objectType = it.optString("objectType")
1201
+ result.notifications = it.optJSONArray("notifications")!!.toList()
1202
+ result.signerInfos = it.optJSONArray("signerInfos").toList(::signerInfoFromJSON)!!
1487
1203
 
1488
- return result
1204
+ result
1489
1205
  }
1490
1206
 
1491
- fun generateSecurityObject(temp: SecurityObject?): JSONObject? {
1492
- val result = JSONObject()
1493
- temp ?: return null
1494
- val input: SecurityObject = temp
1495
-
1496
- result.put("fileReference", input.fileReference)
1497
- result.put("version", input.version)
1498
- result.put("objectType", input.objectType)
1499
- result.put("notifications", generateList(input.notifications))
1500
- result.put("signerInfos", generateList(input.signerInfos, ::generateSignerInfo))
1501
-
1502
- return result
1207
+ fun generateSecurityObject(input: SecurityObject?) = input?.let {
1208
+ mapOf(
1209
+ "fileReference" to it.fileReference,
1210
+ "version" to it.version,
1211
+ "objectType" to it.objectType,
1212
+ "notifications" to it.notifications.toJson(),
1213
+ "signerInfos" to it.signerInfos.toJson(::generateSignerInfo)
1214
+ ).toJson()
1503
1215
  }
1504
1216
 
1505
- fun cardPropertiesFromJSON(temp: JSONObject?): CardProperties? {
1506
- temp ?: return null
1507
- val input: JSONObject = temp
1217
+ fun cardPropertiesFromJSON(input: JSONObject?) = input?.let {
1508
1218
  val result = CardProperties()
1509
1219
 
1510
- result.aTQA = input.optInt("aTQA")
1511
- result.bitRateR = input.optInt("bitRateR")
1512
- result.bitRateS = input.optInt("bitRateS")
1513
- result.chipTypeA = input.optInt("chipTypeA")
1514
- result.mifareMemory = input.optInt("mifareMemory")
1515
- result.rfidType = input.optInt("rfidType")
1516
- result.sAK = input.optInt("sAK")
1517
- result.support4 = input.optBoolean("support4")
1518
- result.supportMifare = input.optBoolean("supportMifare")
1519
- result.aTQB = input.optString("aTQB")
1520
- result.aTR = input.optString("aTR")
1521
- result.baudrate1 = input.optString("baudrate1")
1522
- result.baudrate2 = input.optString("baudrate2")
1523
- result.uID = input.optString("uID")
1524
-
1525
- return result
1526
- }
1527
-
1528
- fun generateCardProperties(temp: CardProperties?): JSONObject? {
1529
- val result = JSONObject()
1530
- temp ?: return null
1531
- val input: CardProperties = temp
1532
-
1533
- result.put("aTQA", input.aTQA)
1534
- result.put("bitRateR", input.bitRateR)
1535
- result.put("bitRateS", input.bitRateS)
1536
- result.put("chipTypeA", input.chipTypeA)
1537
- result.put("mifareMemory", input.mifareMemory)
1538
- result.put("rfidType", input.rfidType)
1539
- result.put("sAK", input.sAK)
1540
- result.put("support4", input.support4)
1541
- result.put("supportMifare", input.supportMifare)
1542
- result.put("aTQB", input.aTQB)
1543
- result.put("aTR", input.aTR)
1544
- result.put("baudrate1", input.baudrate1)
1545
- result.put("baudrate2", input.baudrate2)
1546
- result.put("uID", input.uID)
1547
-
1548
- return result
1549
- }
1550
-
1551
- fun rfidSessionDataFromJSON(temp: JSONObject?): RFIDSessionData? {
1552
- temp ?: return null
1553
- val input: JSONObject = temp
1220
+ result.aTQA = it.optInt("aTQA")
1221
+ result.bitRateR = it.optInt("bitRateR")
1222
+ result.bitRateS = it.optInt("bitRateS")
1223
+ result.chipTypeA = it.optInt("chipTypeA")
1224
+ result.mifareMemory = it.optInt("mifareMemory")
1225
+ result.rfidType = it.optInt("rfidType")
1226
+ result.sAK = it.optInt("sAK")
1227
+ result.support4 = it.optBoolean("support4")
1228
+ result.supportMifare = it.optBoolean("supportMifare")
1229
+ result.aTQB = it.optString("aTQB")
1230
+ result.aTR = it.optString("aTR")
1231
+ result.baudrate1 = it.optString("baudrate1")
1232
+ result.baudrate2 = it.optString("baudrate2")
1233
+ result.uID = it.optString("uID")
1234
+
1235
+ result
1236
+ }
1237
+
1238
+ fun generateCardProperties(input: CardProperties?) = input?.let {
1239
+ mapOf(
1240
+ "aTQA" to it.aTQA,
1241
+ "bitRateR" to it.bitRateR,
1242
+ "bitRateS" to it.bitRateS,
1243
+ "chipTypeA" to it.chipTypeA,
1244
+ "mifareMemory" to it.mifareMemory,
1245
+ "rfidType" to it.rfidType,
1246
+ "sAK" to it.sAK,
1247
+ "support4" to it.support4,
1248
+ "supportMifare" to it.supportMifare,
1249
+ "aTQB" to it.aTQB,
1250
+ "aTR" to it.aTR,
1251
+ "baudrate1" to it.baudrate1,
1252
+ "baudrate2" to it.baudrate2,
1253
+ "uID" to it.uID
1254
+ ).toJson()
1255
+ }
1256
+
1257
+ fun rfidSessionDataFromJSON(input: JSONObject?) = input?.let {
1554
1258
  val result = RFIDSessionData()
1555
1259
 
1556
- result.totalBytesReceived = input.optInt("totalBytesReceived")
1557
- result.totalBytesSent = input.optInt("totalBytesSent")
1558
- result.status = input.optInt("status").toLong()
1559
- result.extLeSupport = input.optLong("extLeSupport")
1560
- result.processTime = input.optLong("processTime")
1561
- result.cardProperties = cardPropertiesFromJSON(input.optJSONObject("cardProperties"))
1562
- result.accessControls = listFromJSON(input.optJSONArray("accessControls"), ::accessControlProcedureTypeFromJSON)!!
1563
- result.applications = listFromJSON(input.optJSONArray("applications"), ::applicationFromJSON)!!
1564
- result.securityObjects = listFromJSON(input.optJSONArray("securityObjects"), ::securityObjectFromJSON)!!
1565
- result.dataFields = listFromJSON(input.optJSONArray("dataFields"), ::dataFieldFromJSON)!!
1566
- result.dataGroups = input.optJSONArray("dataGroups").toIntArray()
1567
-
1568
- return result
1569
- }
1570
-
1571
- fun generateRFIDSessionData(temp: RFIDSessionData?, context: Context?): JSONObject? {
1572
- val result = JSONObject()
1573
- temp ?: return null
1574
- val input: RFIDSessionData = temp
1575
-
1576
- result.put("totalBytesReceived", input.totalBytesReceived)
1577
- result.put("totalBytesSent", input.totalBytesSent)
1578
- result.put("status", input.status)
1579
- result.put("extLeSupport", input.extLeSupport)
1580
- result.put("processTime", input.processTime)
1581
- result.put("cardProperties", generateCardProperties(input.cardProperties))
1582
- result.put("accessControls", generateList(input.accessControls, ::generateAccessControlProcedureType))
1583
- result.put("applications", generateList(input.applications, ::generateApplication, context))
1584
- result.put("securityObjects", generateList(input.securityObjects, ::generateSecurityObject))
1585
- result.put("dataGroups", input.dataGroups.generate())
1586
- result.put("dataFields", generateList(input.dataFields, ::generateDataField))
1587
-
1588
- return result
1589
- }
1590
-
1591
- fun dataFieldFromJSON(temp: JSONObject?): DataField? {
1592
- temp ?: return null
1593
- val input: JSONObject = temp
1260
+ result.totalBytesReceived = it.optInt("totalBytesReceived")
1261
+ result.totalBytesSent = it.optInt("totalBytesSent")
1262
+ result.status = it.optInt("status").toLong()
1263
+ result.extLeSupport = it.optLong("extLeSupport")
1264
+ result.processTime = it.optLong("processTime")
1265
+ result.cardProperties = cardPropertiesFromJSON(it.optJSONObject("cardProperties"))
1266
+ result.accessControls = it.optJSONArray("accessControls").toList(::accessControlProcedureTypeFromJSON)!!
1267
+ result.applications = it.optJSONArray("applications").toList(::applicationFromJSON)!!
1268
+ result.securityObjects = it.optJSONArray("securityObjects").toList(::securityObjectFromJSON)!!
1269
+ result.dataFields = it.optJSONArray("dataFields").toList(::dataFieldFromJSON)!!
1270
+ result.dataGroups = it.optJSONArray("dataGroups").toIntArray()
1271
+
1272
+ result
1273
+ }
1274
+
1275
+ fun generateRFIDSessionData(input: RFIDSessionData?) = input?.let {
1276
+ mapOf(
1277
+ "totalBytesReceived" to it.totalBytesReceived,
1278
+ "totalBytesSent" to it.totalBytesSent,
1279
+ "status" to it.status,
1280
+ "extLeSupport" to it.extLeSupport,
1281
+ "processTime" to it.processTime,
1282
+ "cardProperties" to generateCardProperties(it.cardProperties),
1283
+ "accessControls" to it.accessControls.toJson(::generateAccessControlProcedureType),
1284
+ "applications" to it.applications.toJson(::generateApplication),
1285
+ "securityObjects" to it.securityObjects.toJson(::generateSecurityObject),
1286
+ "dataGroups" to it.dataGroups.toJson(),
1287
+ "dataFields" to it.dataFields.toJson(::generateDataField)
1288
+ ).toJson()
1289
+ }
1290
+
1291
+ fun dataFieldFromJSON(input: JSONObject?) = input?.let {
1594
1292
  val result = DataField()
1595
-
1596
- result.data = input.optString("data")
1597
- result.fieldType = input.optInt("fieldType")
1598
-
1599
- return result
1293
+ result.data = it.optString("data")
1294
+ result.fieldType = it.optInt("fieldType")
1295
+ result
1600
1296
  }
1601
1297
 
1602
- fun generateDataField(temp: DataField?): JSONObject? {
1603
- val result = JSONObject()
1604
- temp ?: return null
1605
- val input: DataField = temp
1606
-
1607
- result.put("data", input.data)
1608
- result.put("fieldType", input.fieldType)
1609
-
1610
- return result
1298
+ fun generateDataField(input: DataField?) = input?.let {
1299
+ mapOf(
1300
+ "data" to it.data,
1301
+ "fieldType" to it.fieldType
1302
+ ).toJson()
1611
1303
  }
1612
1304
 
1613
- fun documentReaderAuthenticityCheckFromJSON(temp: JSONObject?): DocumentReaderAuthenticityCheck? {
1614
- temp ?: return null
1615
- val input: JSONObject = temp
1305
+ fun documentReaderAuthenticityCheckFromJSON(input: JSONObject?) = input?.let {
1616
1306
  val result = DocumentReaderAuthenticityCheck()
1617
-
1618
- result.type = input.optInt("type")
1619
- result.pageIndex = input.optInt("pageIndex")
1620
- result.elements = listFromJSON(input.optJSONArray("elements"), ::documentReaderAuthenticityElementFromJSON)!!
1621
-
1622
- return result
1307
+ result.type = it.optInt("type")
1308
+ result.pageIndex = it.optInt("pageIndex")
1309
+ result.elements = it.optJSONArray("elements").toList(::documentReaderAuthenticityElementFromJSON)!!
1310
+ result
1623
1311
  }
1624
1312
 
1625
- fun generateDocumentReaderAuthenticityCheck(temp: DocumentReaderAuthenticityCheck?, context: Context?): JSONObject? {
1626
- val result = JSONObject()
1627
- temp ?: return null
1628
- val input: DocumentReaderAuthenticityCheck = temp
1629
-
1630
- result.put("type", input.type)
1631
- result.put("status", input.status)
1632
- result.put("typeName", input.getTypeName(context))
1633
- result.put("pageIndex", input.pageIndex)
1634
- result.put("elements", generateList(input.elements, ::generateDocumentReaderAuthenticityElement, context))
1635
-
1636
- return result
1313
+ fun generateDocumentReaderAuthenticityCheck(input: DocumentReaderAuthenticityCheck?) = input?.let {
1314
+ mapOf(
1315
+ "type" to it.type,
1316
+ "status" to it.status,
1317
+ "typeName" to it.getTypeName(context),
1318
+ "pageIndex" to it.pageIndex,
1319
+ "elements" to it.elements.toJson(::generateDocumentReaderAuthenticityElement)
1320
+ ).toJson()
1637
1321
  }
1638
1322
 
1639
- fun pdf417InfoFromJSON(temp: JSONObject?): PDF417Info? {
1640
- temp ?: return null
1641
- val input: JSONObject = temp
1323
+ fun pdf417InfoFromJSON(input: JSONObject?) = input?.let {
1642
1324
  val result = PDF417Info()
1643
-
1644
- result.errorLevel = input.optInt("errorLevel")
1645
- result.columns = input.optInt("columns")
1646
- result.rows = input.optInt("rows")
1647
-
1648
- return result
1325
+ result.errorLevel = it.optInt("errorLevel")
1326
+ result.columns = it.optInt("columns")
1327
+ result.rows = it.optInt("rows")
1328
+ result
1649
1329
  }
1650
1330
 
1651
- fun generatePDF417Info(temp: PDF417Info?): JSONObject? {
1652
- val result = JSONObject()
1653
- temp ?: return null
1654
- val input: PDF417Info = temp
1655
-
1656
- result.put("errorLevel", input.errorLevel)
1657
- result.put("columns", input.columns)
1658
- result.put("rows", input.rows)
1659
-
1660
- return result
1331
+ fun generatePDF417Info(input: PDF417Info?) = input?.let {
1332
+ mapOf(
1333
+ "errorLevel" to it.errorLevel,
1334
+ "columns" to it.columns,
1335
+ "rows" to it.rows
1336
+ ).toJson()
1661
1337
  }
1662
1338
 
1663
- fun documentReaderBarcodeResultFromJSON(temp: JSONObject?): DocumentReaderBarcodeResult? {
1664
- temp ?: return null
1665
- val input: JSONObject = temp
1339
+ fun documentReaderBarcodeResultFromJSON(input: JSONObject?) = input?.let {
1666
1340
  val result = DocumentReaderBarcodeResult()
1667
-
1668
- result.fields = listFromJSON(input.optJSONArray("fields"), ::documentReaderBarcodeFieldFromJSON)!!
1669
-
1670
- return result
1341
+ result.fields = it.optJSONArray("fields").toList(::documentReaderBarcodeFieldFromJSON)!!
1342
+ result
1671
1343
  }
1672
1344
 
1673
- fun generateDocumentReaderBarcodeResult(temp: DocumentReaderBarcodeResult?): JSONObject? {
1674
- val result = JSONObject()
1675
- temp ?: return null
1676
- val input: DocumentReaderBarcodeResult = temp
1677
-
1678
- result.put("fields", generateList(input.fields, ::generateDocumentReaderBarcodeField))
1679
-
1680
- return result
1345
+ fun generateDocumentReaderBarcodeResult(input: DocumentReaderBarcodeResult?) = input?.let {
1346
+ mapOf(
1347
+ "fields" to it.fields.toJson(::generateDocumentReaderBarcodeField)
1348
+ ).toJson()
1681
1349
  }
1682
1350
 
1683
- fun documentReaderBarcodeFieldFromJSON(temp: JSONObject?): DocumentReaderBarcodeField? {
1684
- temp ?: return null
1685
- val input: JSONObject = temp
1351
+ fun documentReaderBarcodeFieldFromJSON(input: JSONObject?) = input?.let {
1686
1352
  val result = DocumentReaderBarcodeField()
1687
1353
 
1688
- result.barcodeType = input.optInt("barcodeType")
1689
- result.status = input.optInt("status")
1690
- result.pageIndex = input.optInt("pageIndex")
1691
- result.pdf417Info = pdf417InfoFromJSON(input.optJSONObject("pdf417Info"))
1692
- result.data = byteArrayFromBase64(input.optString("data"))
1354
+ result.barcodeType = it.optInt("barcodeType")
1355
+ result.status = it.optInt("status")
1356
+ result.pageIndex = it.optInt("pageIndex")
1357
+ result.pdf417Info = pdf417InfoFromJSON(it.optJSONObject("pdf417Info"))
1358
+ result.data = it.optString("data").toByteArray()
1693
1359
 
1694
- return result
1360
+ result
1695
1361
  }
1696
1362
 
1697
- fun generateDocumentReaderBarcodeField(temp: DocumentReaderBarcodeField?): JSONObject? {
1698
- val result = JSONObject()
1699
- temp ?: return null
1700
- val input: DocumentReaderBarcodeField = temp
1701
-
1702
- result.put("barcodeType", input.barcodeType)
1703
- result.put("status", input.status)
1704
- result.put("pageIndex", input.pageIndex)
1705
- result.put("pdf417Info", generatePDF417Info(input.pdf417Info))
1706
- result.put("data", generateByteArray(input.data))
1707
-
1708
- return result
1363
+ fun generateDocumentReaderBarcodeField(input: DocumentReaderBarcodeField?) = input?.let {
1364
+ mapOf(
1365
+ "barcodeType" to it.barcodeType,
1366
+ "status" to it.status,
1367
+ "pageIndex" to it.pageIndex,
1368
+ "pdf417Info" to generatePDF417Info(it.pdf417Info),
1369
+ "data" to it.data.toBase64()
1370
+ ).toJson()
1709
1371
  }
1710
1372
 
1711
- fun documentReaderAuthenticityResultFromJSON(temp: JSONObject?): DocumentReaderAuthenticityResult? {
1712
- temp ?: return null
1713
- val input: JSONObject = temp
1373
+ fun documentReaderAuthenticityResultFromJSON(input: JSONObject?) = input?.let {
1714
1374
  val result = DocumentReaderAuthenticityResult()
1715
-
1716
- result.checks = listFromJSON(input.optJSONArray("checks"), ::documentReaderAuthenticityCheckFromJSON)!!
1717
-
1718
- return result
1375
+ result.checks = it.optJSONArray("checks").toList(::documentReaderAuthenticityCheckFromJSON)!!
1376
+ result
1719
1377
  }
1720
1378
 
1721
- fun generateDocumentReaderAuthenticityResult(temp: DocumentReaderAuthenticityResult?, context: Context?): JSONObject? {
1722
- val result = JSONObject()
1723
- temp ?: return null
1724
- val input: DocumentReaderAuthenticityResult = temp
1725
-
1726
- @Suppress("DEPRECATION")
1727
- result.put("status", input.status)
1728
- result.put("checks", generateList(input.checks, ::generateDocumentReaderAuthenticityCheck, context))
1729
-
1730
- return result
1379
+ @Suppress("DEPRECATION")
1380
+ fun generateDocumentReaderAuthenticityResult(input: DocumentReaderAuthenticityResult?) = input?.let {
1381
+ mapOf(
1382
+ "status" to it.status,
1383
+ "checks" to it.checks.toJson(::generateDocumentReaderAuthenticityCheck)
1384
+ ).toJson()
1731
1385
  }
1732
1386
 
1733
- fun documentReaderAuthenticityElementFromJSON(temp: JSONObject?): DocumentReaderAuthenticityElement? {
1734
- temp ?: return null
1735
- val input: JSONObject = temp
1387
+ fun documentReaderAuthenticityElementFromJSON(input: JSONObject?) = input?.let {
1736
1388
  val result = DocumentReaderAuthenticityElement()
1737
-
1738
- result.status = input.optInt("status")
1739
- result.elementType = input.optInt("elementType")
1740
- result.elementDiagnose = input.optInt("elementDiagnose")
1741
-
1742
- return result
1389
+ result.status = it.optInt("status")
1390
+ result.elementType = it.optInt("elementType")
1391
+ result.elementDiagnose = it.optInt("elementDiagnose")
1392
+ result
1743
1393
  }
1744
1394
 
1745
- fun generateDocumentReaderAuthenticityElement(temp: DocumentReaderAuthenticityElement?, context: Context?): JSONObject? {
1746
- val result = JSONObject()
1747
- temp ?: return null
1748
- val input: DocumentReaderAuthenticityElement = temp
1749
-
1750
- result.put("status", input.status)
1751
- result.put("elementType", input.elementType)
1752
- result.put("elementDiagnose", input.elementDiagnose)
1753
- result.put("elementTypeName", input.getElementTypeName(context))
1754
- result.put("elementDiagnoseName", input.getElementDiagnoseName(context))
1755
-
1756
- return result
1395
+ fun generateDocumentReaderAuthenticityElement(input: DocumentReaderAuthenticityElement?) = input?.let {
1396
+ mapOf(
1397
+ "status" to it.status,
1398
+ "elementType" to it.elementType,
1399
+ "elementDiagnose" to it.elementDiagnose,
1400
+ "elementTypeName" to it.getElementTypeName(context),
1401
+ "elementDiagnoseName" to it.getElementDiagnoseName(context)
1402
+ ).toJson()
1757
1403
  }
1758
1404
 
1759
- fun paResourcesIssuerFromJSON(temp: JSONObject?): PAResourcesIssuer? {
1760
- temp ?: return null
1761
- val input: JSONObject = temp
1405
+ fun paResourcesIssuerFromJSON(input: JSONObject?) = input?.let {
1762
1406
  val result = PAResourcesIssuer()
1763
-
1764
- result.data = byteArrayFromBase64(input.optString("data"))
1765
- result.friendlyName = input.optString("friendlyName")
1766
- result.attributes = arrayFromJSON(input.optJSONArray("attributes"), ::paAttributeFromJSON, arrayOfNulls(input.optJSONArray("attributes")?.length() ?: 0))
1767
-
1768
- return result
1407
+ result.data = it.optString("data").toByteArray()
1408
+ result.friendlyName = it.optString("friendlyName")
1409
+ result.attributes = it.optJSONArray("attributes").toArray(::paAttributeFromJSON)
1410
+ result
1769
1411
  }
1770
1412
 
1771
- fun generatePAResourcesIssuer(temp: PAResourcesIssuer?): JSONObject? {
1772
- val result = JSONObject()
1773
- temp ?: return null
1774
- val input: PAResourcesIssuer = temp
1775
-
1776
- result.put("data", generateByteArray(input.data))
1777
- result.put("friendlyName", input.friendlyName)
1778
- result.put("attributes", generateArray(input.attributes, ::generatePAAttribute))
1779
-
1780
- return result
1413
+ fun generatePAResourcesIssuer(input: PAResourcesIssuer?) = input?.let {
1414
+ mapOf(
1415
+ "data" to it.data.toBase64(),
1416
+ "friendlyName" to it.friendlyName,
1417
+ "attributes" to it.attributes.toJson(::generatePAAttribute)
1418
+ ).toJson()
1781
1419
  }
1782
1420
 
1783
- fun paAttributeFromJSON(temp: JSONObject?): PAAttribute? {
1784
- temp ?: return null
1785
- val input: JSONObject = temp
1421
+ fun paAttributeFromJSON(input: JSONObject?) = input?.let {
1786
1422
  val result = PAAttribute()
1787
-
1788
- result.type = input.optString("type")
1789
- result.value = input.optString("value")
1790
-
1791
- return result
1423
+ result.type = it.optString("type")
1424
+ result.value = it.optString("value")
1425
+ result
1792
1426
  }
1793
1427
 
1794
- fun generatePAAttribute(temp: PAAttribute?): JSONObject? {
1795
- val result = JSONObject()
1796
- temp ?: return null
1797
- val input: PAAttribute = temp
1798
-
1799
- result.put("type", input.type)
1800
- result.put("value", input.value)
1801
-
1802
- return result
1428
+ fun generatePAAttribute(input: PAAttribute?) = input?.let {
1429
+ mapOf(
1430
+ "type" to it.type,
1431
+ "value" to it.value
1432
+ ).toJson()
1803
1433
  }
1804
1434
 
1805
- fun taChallengeFromJSON(temp: JSONObject?): TAChallenge? {
1806
- temp ?: return null
1807
- val input: JSONObject = temp
1435
+ fun taChallengeFromJSON(input: JSONObject?) = input?.let {
1808
1436
  val result = TAChallenge()
1809
1437
 
1810
- result.data = byteArrayFromBase64(input.optString("data"))
1811
- result.auxPCD = input.optString("auxPCD")
1812
- result.challengePICC = input.optString("challengePICC")
1813
- result.hashPK = input.optString("hashPK")
1814
- result.idPICC = input.optString("idPICC")
1815
-
1816
- return result
1817
- }
1818
-
1819
- fun generateTAChallenge(temp: TAChallenge?): JSONObject? {
1820
- val result = JSONObject()
1821
- temp ?: return null
1822
- val input: TAChallenge = temp
1823
-
1824
- result.put("data", generateByteArray(input.data))
1825
- result.put("auxPCD", input.auxPCD)
1826
- result.put("challengePICC", input.challengePICC)
1827
- result.put("hashPK", input.hashPK)
1828
- result.put("idPICC", input.idPICC)
1829
-
1830
- return result
1831
- }
1832
-
1833
- fun documentReaderResultsStatusFromJSON(temp: JSONObject?): DocumentReaderResultsStatus? {
1834
- temp ?: return null
1835
- val input: JSONObject = temp
1836
-
1837
- input.remove("detailsRFID")
1838
-
1839
- return DocumentReaderResultsStatus.fromJson(input)
1840
- }
1841
-
1842
- fun generateDocumentReaderResultsStatus(temp: DocumentReaderResultsStatus?): JSONObject? {
1843
- val result = JSONObject()
1844
- temp ?: return null
1845
- val input: DocumentReaderResultsStatus = temp
1846
-
1847
- result.put("overallStatus", input.overallStatus)
1848
- result.put("optical", input.optical)
1849
- result.put("detailsOptical", generateDetailsOptical(input.detailsOptical))
1850
- result.put("rfid", input.rfid)
1851
- result.put("detailsRFID", generateDetailsRFID(input.detailsRFID))
1852
- result.put("portrait", input.portrait)
1853
- result.put("stopList", input.stopList)
1854
-
1855
- return result
1856
- }
1857
-
1858
- fun generateDetailsOptical(temp: DetailsOptical?): JSONObject? {
1859
- val result = JSONObject()
1860
- temp ?: return null
1861
- val input: DetailsOptical = temp
1862
-
1863
- result.put("overallStatus", input.overallStatus)
1864
- result.put("mrz", input.mrz)
1865
- result.put("text", input.text)
1866
- result.put("docType", input.docType)
1867
- result.put("security", input.security)
1868
- result.put("imageQA", input.imageQA)
1869
- result.put("expiry", input.expiry)
1870
- result.put("vds", input.vds)
1871
- result.put("pagesCount", input.pagesCount)
1872
-
1873
- return result
1874
- }
1875
-
1876
- fun generateDetailsRFID(temp: DetailsRFID?): JSONObject? {
1877
- val result = JSONObject()
1878
- temp ?: return null
1879
- val input: DetailsRFID = temp
1880
-
1881
- result.put("pa", input.pa)
1882
- result.put("ca", input.ca)
1883
- result.put("aa", input.aa)
1884
- result.put("ta", input.ta)
1885
- result.put("bac", input.bac)
1886
- result.put("pace", input.pace)
1887
- result.put("overallStatus", input.overallStatus)
1888
-
1889
- return result
1890
- }
1891
-
1892
- fun vdsncDataDictionaryFromJSON(input: JSONObject): JSONObject {
1893
- val temp = JSONObject(input.toString())
1894
-
1895
- temp.put("Type", input.optString("type"))
1896
- temp.put("Version", input.optInt("version"))
1897
- temp.put("IssuingCountry", input.optString("issuingCountry"))
1898
- temp.put("Message", input.optJSONObject("message"))
1899
- temp.put("SignatureAlg", input.optString("signatureAlgorithm"))
1900
- temp.put("Signature", bytesDataDictionaryFromJSON(input.optJSONObject("signature")))
1901
- temp.put("Certificate", bytesDataDictionaryFromJSON(input.optJSONObject("certificate")))
1902
- temp.put("CertificateChain", input.optJSONArray("certificateChain"))
1903
- temp.put("Notifications", input.optJSONArray("notifications"))
1904
-
1905
- return temp
1438
+ result.data = it.optString("data").toByteArray()
1439
+ result.auxPCD = it.optString("auxPCD")
1440
+ result.challengePICC = it.optString("challengePICC")
1441
+ result.hashPK = it.optString("hashPK")
1442
+ result.idPICC = it.optString("idPICC")
1443
+
1444
+ result
1445
+ }
1446
+
1447
+ fun generateTAChallenge(input: TAChallenge?) = input?.let {
1448
+ mapOf(
1449
+ "data" to it.data.toBase64(),
1450
+ "auxPCD" to it.auxPCD,
1451
+ "challengePICC" to it.challengePICC,
1452
+ "hashPK" to it.hashPK,
1453
+ "idPICC" to it.idPICC
1454
+ ).toJson()
1455
+ }
1456
+
1457
+ fun documentReaderResultsStatusFromJSON(input: JSONObject?) = input?.let {
1458
+ it.remove("detailsRFID")
1459
+ DocumentReaderResultsStatus.fromJson(input)
1460
+ }
1461
+
1462
+ fun generateDocumentReaderResultsStatus(input: DocumentReaderResultsStatus?) = input?.let {
1463
+ mapOf(
1464
+ "overallStatus" to it.overallStatus,
1465
+ "optical" to it.optical,
1466
+ "detailsOptical" to generateDetailsOptical(it.detailsOptical),
1467
+ "rfid" to it.rfid,
1468
+ "detailsRFID" to generateDetailsRFID(it.detailsRFID),
1469
+ "portrait" to it.portrait,
1470
+ "stopList" to it.stopList
1471
+ ).toJson()
1472
+ }
1473
+
1474
+ fun generateDetailsOptical(input: DetailsOptical?) = input?.let {
1475
+ mapOf(
1476
+ "overallStatus" to it.overallStatus,
1477
+ "mrz" to it.mrz,
1478
+ "text" to it.text,
1479
+ "docType" to it.docType,
1480
+ "security" to it.security,
1481
+ "imageQA" to it.imageQA,
1482
+ "expiry" to it.expiry,
1483
+ "vds" to it.vds,
1484
+ "pagesCount" to it.pagesCount
1485
+ ).toJson()
1486
+ }
1487
+
1488
+ fun generateDetailsRFID(input: DetailsRFID?) = input?.let {
1489
+ mapOf(
1490
+ "pa" to it.pa,
1491
+ "ca" to it.ca,
1492
+ "aa" to it.aa,
1493
+ "ta" to it.ta,
1494
+ "bac" to it.bac,
1495
+ "pace" to it.pace,
1496
+ "overallStatus" to it.overallStatus
1497
+ ).toJson()
1498
+ }
1499
+
1500
+ fun vdsncDataDictionaryFromJSON(input: JSONObject) = input.let {
1501
+ val result = JSONObject(it.toString())
1502
+
1503
+ result.put("Type", it.optString("type"))
1504
+ result.put("Version", it.optInt("version"))
1505
+ result.put("IssuingCountry", it.optString("issuingCountry"))
1506
+ result.put("Message", it.optJSONObject("message"))
1507
+ result.put("SignatureAlg", it.optString("signatureAlgorithm"))
1508
+ result.put("Signature", bytesDataDictionaryFromJSON(it.optJSONObject("signature")))
1509
+ result.put("Certificate", bytesDataDictionaryFromJSON(it.optJSONObject("certificate")))
1510
+ result.put("CertificateChain", it.optJSONArray("certificateChain"))
1511
+ result.put("Notifications", it.optJSONArray("notifications"))
1512
+
1513
+ result
1906
1514
  }
1907
1515
 
1908
1516
  fun vdsncDataFromJSON(input: JSONObject) = VDSNCData.fromJson(vdsncDataDictionaryFromJSON(input))
1909
1517
 
1910
- fun generateVDSNCData(temp: VDSNCData?): JSONObject? {
1911
- val result = JSONObject()
1912
- temp ?: return null
1913
- val input: VDSNCData = temp
1914
-
1915
- result.put("type", input.type)
1916
- result.put("version", input.version)
1917
- result.put("issuingCountry", input.issuingCountry)
1918
- result.put("message", input.message)
1919
- result.put("signatureAlgorithm", input.signatureAlg)
1920
- result.put("signature", generateBytesData(input.signature))
1921
- result.put("certificate", generateBytesData(input.certificate))
1922
- result.put("certificateChain", generateList(input.certificateChain, ::generateCertificateChain))
1923
- result.put("notifications", generateLongArray(input.notifications))
1924
-
1925
- return result
1518
+ fun generateVDSNCData(input: VDSNCData?) = input?.let {
1519
+ mapOf(
1520
+ "type" to it.type,
1521
+ "version" to it.version,
1522
+ "issuingCountry" to it.issuingCountry,
1523
+ "message" to it.message,
1524
+ "signatureAlgorithm" to it.signatureAlg,
1525
+ "signature" to generateBytesData(it.signature),
1526
+ "certificate" to generateBytesData(it.certificate),
1527
+ "certificateChain" to it.certificateChain.toJson(::generateCertificateChain),
1528
+ "notifications" to if (it.notifications == null) null else {
1529
+ val notifications = JSONArray()
1530
+ for (i in it.notifications!!.indices) notifications.put(i, it.notifications!![i])
1531
+ notifications
1532
+ }
1533
+ ).toJson()
1926
1534
  }
1927
1535
 
1928
- fun bytesDataDictionaryFromJSON(input: JSONObject?): JSONObject? {
1929
- input ?: return null
1930
- val temp = JSONObject(input.toString())
1536
+ fun bytesDataDictionaryFromJSON(input: JSONObject?) = input?.let {
1537
+ val result = JSONObject(input.toString())
1931
1538
 
1932
- temp.put("Data", input.optString("data"))
1933
- temp.put("Length", input.optInt("length"))
1934
- temp.put("Status", input.optLong("status"))
1935
- temp.put("Type", input.optInt("type"))
1539
+ result.put("Data", input.optString("data"))
1540
+ result.put("Length", input.optInt("length"))
1541
+ result.put("Status", input.optLong("status"))
1542
+ result.put("Type", input.optInt("type"))
1936
1543
 
1937
- return temp
1544
+ result
1938
1545
  }
1939
1546
 
1940
1547
  fun bytesDataFromJSON(input: JSONObject?) = BytesData.fromJson(bytesDataDictionaryFromJSON(input))
1941
1548
 
1942
- fun generateBytesData(temp: BytesData?): JSONObject? {
1943
- val result = JSONObject()
1944
- temp ?: return null
1945
- val input: BytesData = temp
1946
-
1947
- result.put("data", input.data)
1948
- result.put("length", input.length)
1949
- result.put("status", input.status)
1950
- result.put("type", input.type)
1951
-
1952
- return result
1953
- }
1954
-
1955
- fun generateLicense(temp: License?): JSONObject? {
1956
- val result = JSONObject()
1957
- temp ?: return null
1958
- val input: License = temp
1959
-
1960
- result.put("expiryDate", input.expiryDate?.toString())
1961
- result.put("countryFilter", generateList(input.countryFilter))
1962
- result.put("isRfidAvailable", input.isRfidAvailable)
1963
-
1964
- return result
1965
- }
1966
-
1967
- fun generateDocReaderVersion(temp: DocReaderVersion?): JSONObject? {
1968
- val result = JSONObject()
1969
- temp ?: return null
1970
- val input: DocReaderVersion = temp
1971
-
1972
- result.put("api", input.api)
1973
- result.put("core", input.core)
1974
- result.put("coreMode", input.coreMode)
1975
- result.put("database", generateDocReaderDocumentsDatabase(input.database))
1976
-
1977
- return result
1978
- }
1979
-
1980
- fun docReaderDocumentsDatabaseFromJSON(input: JSONObject?): DocReaderDocumentsDatabase? {
1981
- input ?: return null
1982
- val temp = JSONObject(input.toString())
1983
-
1984
- temp.put("id", input.optString("databaseID"))
1985
- temp.put("export_date", input.optString("date"))
1986
- temp.put("description", input.optString("databaseDescription"))
1987
-
1988
- return DocReaderDocumentsDatabase.fromJson(temp)
1989
- }
1990
-
1991
- fun generateDocReaderDocumentsDatabase(temp: DocReaderDocumentsDatabase?): JSONObject? {
1992
- val result = JSONObject()
1993
- temp ?: return null
1994
- val input: DocReaderDocumentsDatabase = temp
1995
-
1996
- result.put("databaseID", input.databaseID)
1997
- result.put("version", input.version)
1998
- result.put("date", input.date)
1999
- result.put("databaseDescription", input.databaseDescription)
2000
- result.put("countriesNumber", input.countriesNumber)
2001
- result.put("documentsNumber", input.documentsNumber)
2002
- result.put("size", input.size)
2003
-
2004
- return result
2005
- }
2006
-
2007
- fun documentReaderComparisonFromJSON(temp: JSONObject?): DocumentReaderComparison? {
2008
- temp ?: return null
2009
- val input: JSONObject = temp
1549
+ fun generateBytesData(input: BytesData?) = input?.let {
1550
+ mapOf(
1551
+ "data" to it.data,
1552
+ "length" to it.length,
1553
+ "status" to it.status,
1554
+ "type" to it.type
1555
+ ).toJson()
1556
+ }
1557
+
1558
+ fun generateLicense(input: License?) = input?.let {
1559
+ mapOf(
1560
+ "expiryDate" to it.expiryDate?.toString(),
1561
+ "countryFilter" to it.countryFilter?.toJson(),
1562
+ "isRfidAvailable" to it.isRfidAvailable
1563
+ ).toJson()
1564
+ }
1565
+
1566
+ fun generateDocReaderVersion(input: DocReaderVersion?) = input?.let {
1567
+ mapOf(
1568
+ "api" to it.api,
1569
+ "core" to it.core,
1570
+ "coreMode" to it.coreMode,
1571
+ "database" to generateDocReaderDocumentsDatabase(it.database)
1572
+ ).toJson()
1573
+ }
1574
+
1575
+ fun docReaderDocumentsDatabaseFromJSON(input: JSONObject?) = input?.let {
1576
+ val result = JSONObject(it.toString())
1577
+ result.put("id", it.optString("databaseID"))
1578
+ result.put("export_date", it.optString("date"))
1579
+ result.put("description", it.optString("databaseDescription"))
1580
+ DocReaderDocumentsDatabase.fromJson(result)
1581
+ }
1582
+
1583
+ fun generateDocReaderDocumentsDatabase(input: DocReaderDocumentsDatabase?) = input?.let {
1584
+ mapOf(
1585
+ "databaseID" to it.databaseID,
1586
+ "version" to it.version,
1587
+ "date" to it.date,
1588
+ "databaseDescription" to it.databaseDescription,
1589
+ "countriesNumber" to it.countriesNumber,
1590
+ "documentsNumber" to it.documentsNumber,
1591
+ "size" to it.size
1592
+ ).toJson()
1593
+ }
1594
+
1595
+ fun documentReaderComparisonFromJSON(input: JSONObject?) = input?.let {
2010
1596
  val result = DocumentReaderComparison()
2011
-
2012
- result.sourceTypeLeft = input.optInt("sourceTypeLeft")
2013
- result.sourceTypeRight = input.optInt("sourceTypeRight")
2014
- result.status = input.optInt("status")
2015
-
2016
- return result
1597
+ result.sourceTypeLeft = it.optInt("sourceTypeLeft")
1598
+ result.sourceTypeRight = it.optInt("sourceTypeRight")
1599
+ result.status = it.optInt("status")
1600
+ result
2017
1601
  }
2018
1602
 
2019
- fun generateDocumentReaderComparison(temp: DocumentReaderComparison?): JSONObject? {
2020
- val result = JSONObject()
2021
- temp ?: return null
2022
- val input: DocumentReaderComparison = temp
2023
-
2024
- result.put("sourceTypeLeft", input.sourceTypeLeft)
2025
- result.put("sourceTypeRight", input.sourceTypeRight)
2026
- result.put("status", input.status)
2027
-
2028
- return result
1603
+ fun generateDocumentReaderComparison(input: DocumentReaderComparison?) = input?.let {
1604
+ mapOf(
1605
+ "sourceTypeLeft" to it.sourceTypeLeft,
1606
+ "sourceTypeRight" to it.sourceTypeRight,
1607
+ "status" to it.status
1608
+ ).toJson()
2029
1609
  }
2030
1610
 
2031
- fun documentReaderRFIDOriginFromJSON(temp: JSONObject?): DocumentReaderRfidOrigin? {
2032
- temp ?: return null
2033
- val input: JSONObject = temp
1611
+ fun documentReaderRFIDOriginFromJSON(input: JSONObject?) = input?.let {
2034
1612
  val result = DocumentReaderRfidOrigin()
2035
1613
 
2036
- result.dg = input.optInt("dg")
2037
- result.dgTag = input.optInt("dgTag")
2038
- result.entryView = input.optInt("entryView")
2039
- result.tagEntry = input.optInt("tagEntry")
1614
+ result.dg = it.optInt("dg")
1615
+ result.dgTag = it.optInt("dgTag")
1616
+ result.entryView = it.optInt("entryView")
1617
+ result.tagEntry = it.optInt("tagEntry")
2040
1618
 
2041
- return result
1619
+ result
2042
1620
  }
2043
1621
 
2044
- fun generateDocumentReaderRFIDOrigin(temp: DocumentReaderRfidOrigin?): JSONObject? {
2045
- val result = JSONObject()
2046
- temp ?: return null
2047
- val input: DocumentReaderRfidOrigin = temp
2048
-
2049
- result.put("dg", input.dg)
2050
- result.put("dgTag", input.dgTag)
2051
- result.put("entryView", input.entryView)
2052
- result.put("tagEntry", input.tagEntry)
2053
-
2054
- return result
1622
+ fun generateDocumentReaderRFIDOrigin(input: DocumentReaderRfidOrigin?) = input?.let {
1623
+ mapOf(
1624
+ "dg" to it.dg,
1625
+ "dgTag" to it.dgTag,
1626
+ "entryView" to it.entryView,
1627
+ "tagEntry" to it.tagEntry
1628
+ ).toJson()
2055
1629
  }
2056
1630
 
2057
- fun documentReaderTextSourceFromJSON(temp: JSONObject?): DocumentReaderTextSource? {
2058
- temp ?: return null
2059
- val input: JSONObject = temp
1631
+ fun documentReaderTextSourceFromJSON(input: JSONObject?) = input?.let {
2060
1632
  val result = DocumentReaderTextSource()
2061
-
2062
- result.sourceType = input.optInt("sourceType")
2063
- result.source = input.optString("source")
2064
- result.validityStatus = input.optInt("validityStatus")
2065
-
2066
- return result
1633
+ result.sourceType = it.optInt("sourceType")
1634
+ result.source = it.optString("source")
1635
+ result.validityStatus = it.optInt("validityStatus")
1636
+ result
2067
1637
  }
2068
1638
 
2069
- fun generateDocumentReaderTextSource(temp: DocumentReaderTextSource?): JSONObject? {
2070
- val result = JSONObject()
2071
- temp ?: return null
2072
- val input: DocumentReaderTextSource = temp
2073
-
2074
- result.put("sourceType", input.sourceType)
2075
- result.put("source", input.source)
2076
- result.put("validityStatus", input.validityStatus)
2077
-
2078
- return result
1639
+ fun generateDocumentReaderTextSource(input: DocumentReaderTextSource?) = input?.let {
1640
+ mapOf(
1641
+ "sourceType" to it.sourceType,
1642
+ "source" to it.source,
1643
+ "validityStatus" to it.validityStatus
1644
+ ).toJson()
2079
1645
  }
2080
1646
 
2081
- fun documentReaderSymbolFromJSON(temp: JSONObject?): DocumentReaderSymbol? {
2082
- temp ?: return null
2083
- val input: JSONObject = temp
1647
+ fun documentReaderSymbolFromJSON(input: JSONObject?) = input?.let {
2084
1648
  val result = DocumentReaderSymbol()
2085
-
2086
- result.code = input.optInt("code")
2087
- result.probability = input.optInt("probability")
2088
- result.rect = rectFromJSON(input.optJSONObject("rect"))
2089
-
2090
- return result
1649
+ result.code = it.optInt("code")
1650
+ result.probability = it.optInt("probability")
1651
+ result.rect = rectFromJSON(it.optJSONObject("rect"))
1652
+ result
2091
1653
  }
2092
1654
 
2093
- fun generateDocumentReaderSymbol(temp: DocumentReaderSymbol?): JSONObject? {
2094
- val result = JSONObject()
2095
- temp ?: return null
2096
- val input: DocumentReaderSymbol = temp
2097
-
2098
- result.put("code", input.code)
2099
- result.put("rect", generateRect(input.rect))
2100
- result.put("probability", input.probability)
2101
-
2102
- return result
1655
+ fun generateDocumentReaderSymbol(input: DocumentReaderSymbol?) = input?.let {
1656
+ mapOf(
1657
+ "code" to it.code,
1658
+ "rect" to generateRect(it.rect),
1659
+ "probability" to it.probability
1660
+ ).toJson()
2103
1661
  }
2104
1662
 
2105
- fun documentReaderValidityFromJSON(temp: JSONObject?): DocumentReaderValidity? {
2106
- temp ?: return null
2107
- val input: JSONObject = temp
1663
+ fun documentReaderValidityFromJSON(input: JSONObject?) = input?.let {
2108
1664
  val result = DocumentReaderValidity()
2109
-
2110
- result.sourceType = input.optInt("sourceType")
2111
- result.status = input.optInt("status")
2112
-
2113
- return result
1665
+ result.sourceType = it.optInt("sourceType")
1666
+ result.status = it.optInt("status")
1667
+ result
2114
1668
  }
2115
1669
 
2116
- fun generateDocumentReaderValidity(temp: DocumentReaderValidity?): JSONObject? {
2117
- val result = JSONObject()
2118
- temp ?: return null
2119
- val input: DocumentReaderValidity = temp
2120
-
2121
- result.put("sourceType", input.sourceType)
2122
- result.put("status", input.status)
2123
-
2124
- return result
1670
+ fun generateDocumentReaderValidity(input: DocumentReaderValidity?) = input?.let {
1671
+ mapOf(
1672
+ "sourceType" to it.sourceType,
1673
+ "status" to it.status
1674
+ ).toJson()
2125
1675
  }
2126
1676
 
2127
- fun barcodeTypeArrayFromJson(temp: JSONArray?): Array<String?>? {
2128
- temp ?: return null
2129
- val input: JSONArray = temp
2130
-
2131
- val result = arrayOfNulls<String>(input.length())
2132
- for (i in 0 until input.length()) result[i] = BarcodeType.valueOf(input.getInt(i))
2133
-
2134
- return result
1677
+ fun barcodeTypeArrayFromJson(input: JSONArray?) = input?.let {
1678
+ val result = arrayOfNulls<String>(it.length())
1679
+ for (i in 0 until it.length()) result[i] = BarcodeType.valueOf(it.getInt(i))
1680
+ result
2135
1681
  }
2136
1682
 
2137
- fun generateBarcodeTypeArray(temp: Array<String?>?): JSONArray? {
2138
- temp ?: return null
2139
- val input: Array<String?> = temp
1683
+ fun generateBarcodeTypeArray(input: Array<String?>?) = input?.let {
2140
1684
  val result = JSONArray()
2141
-
2142
- for (s in input) result.put(generateBarcodeType(s))
2143
-
2144
- return result
2145
- }
2146
-
2147
- fun generateBarcodeType(input: String?) = when (input) {
2148
- "bct_Code128" -> 1
2149
- "bct_Code39" -> 2
2150
- "bct_EAN8" -> 3
2151
- "bct_ITF" -> 4
2152
- "bct_PDF417" -> 5
2153
- "bct_STF" -> 6
2154
- "bct_MTF" -> 7
2155
- "bct_IATA" -> 8
2156
- "bct_CODABAR" -> 9
2157
- "bct_UPCA" -> 10
2158
- "bct_CODE93" -> 11
2159
- "bct_UPCE" -> 12
2160
- "bct_EAN13" -> 13
2161
- "bct_QRCODE" -> 14
2162
- "bct_AZTEC" -> 15
2163
- "bct_DATAMATRIX" -> 16
2164
- "bct_ALL_1D" -> 17
2165
- "bct_Code11" -> 18
2166
- "bct_JABCODE" -> 19
2167
- else -> 0
2168
- }
2169
-
2170
- fun documentReaderResultsFromJSON(temp: JSONObject?): DocumentReaderResults? {
2171
- temp ?: return null
2172
- val input: JSONObject = temp
1685
+ for (s in it) result.put(
1686
+ when (s) {
1687
+ "bct_Code128" -> 1
1688
+ "bct_Code39" -> 2
1689
+ "bct_EAN8" -> 3
1690
+ "bct_ITF" -> 4
1691
+ "bct_PDF417" -> 5
1692
+ "bct_STF" -> 6
1693
+ "bct_MTF" -> 7
1694
+ "bct_IATA" -> 8
1695
+ "bct_CODABAR" -> 9
1696
+ "bct_UPCA" -> 10
1697
+ "bct_CODE93" -> 11
1698
+ "bct_UPCE" -> 12
1699
+ "bct_EAN13" -> 13
1700
+ "bct_QRCODE" -> 14
1701
+ "bct_AZTEC" -> 15
1702
+ "bct_DATAMATRIX" -> 16
1703
+ "bct_ALL_1D" -> 17
1704
+ "bct_Code11" -> 18
1705
+ "bct_JABCODE" -> 19
1706
+ else -> 0
1707
+ }
1708
+ )
1709
+ result
1710
+ }
1711
+
1712
+ fun documentReaderResultsFromJSON(input: JSONObject?) = input?.let {
2173
1713
  val result = DocumentReaderResults()
2174
1714
 
2175
- result.chipPage = input.optInt("chipPage")
2176
- result.processingFinishedStatus = input.optInt("processingFinishedStatus")
2177
- result.elapsedTime = input.optInt("elapsedTime")
2178
- result.elapsedTimeRFID = input.optInt("elapsedTimeRFID")
2179
- result.morePagesAvailable = input.optInt("morePagesAvailable")
2180
- result.graphicResult = documentReaderGraphicResultFromJSON(input.optJSONObject("graphicResult"))
2181
- result.textResult = documentReaderTextResultFromJSON(input.optJSONObject("textResult"))
2182
- result.documentPosition = listFromJSON(input.optJSONArray("documentPosition"), ::elementPositionFromJSON)!!
2183
- result.barcodePosition = listFromJSON(input.optJSONArray("barcodePosition"), ::elementPositionFromJSON)!!
2184
- result.mrzPosition = listFromJSON(input.optJSONArray("mrzPosition"), ::elementPositionFromJSON)!!
2185
- result.imageQuality = listFromJSON(input.optJSONArray("imageQuality"), ::imageQualityGroupFromJSON)!!
2186
- result.rawResult = input.optString("rawResult")
2187
- result.rfidSessionData = rfidSessionDataFromJSON(input.optJSONObject("rfidSessionData"))
2188
- result.authenticityResult = documentReaderAuthenticityResultFromJSON(input.optJSONObject("authenticityResult"))
2189
- result.barcodeResult = documentReaderBarcodeResultFromJSON(input.optJSONObject("barcodeResult"))
2190
- result.rfidSessionData = rfidSessionDataFromJSON(input.optJSONObject("rfidSessionData"))
2191
- result.documentType = listFromJSON(input.optJSONArray("documentType"), ::documentReaderDocumentTypeFromJSON)!!
2192
- result.status = documentReaderResultsStatusFromJSON(input.optJSONObject("status"))!!
2193
- result.vdsncData = vdsncDataFromJSON(input.optJSONObject("vdsncData")!!)
2194
- result.dtcData = input.getString("dtcData")
2195
- result.transactionInfo = transactionInfoFromJSON(input.optJSONObject("transactionInfo"))!!
2196
-
2197
- return result
1715
+ result.chipPage = it.optInt("chipPage")
1716
+ result.processingFinishedStatus = it.optInt("processingFinishedStatus")
1717
+ result.elapsedTime = it.optInt("elapsedTime")
1718
+ result.elapsedTimeRFID = it.optInt("elapsedTimeRFID")
1719
+ result.morePagesAvailable = it.optInt("morePagesAvailable")
1720
+ result.graphicResult = documentReaderGraphicResultFromJSON(it.optJSONObject("graphicResult"))
1721
+ result.textResult = documentReaderTextResultFromJSON(it.optJSONObject("textResult"))
1722
+ result.documentPosition = it.optJSONArray("documentPosition").toList(::elementPositionFromJSON)!!
1723
+ result.barcodePosition = it.optJSONArray("barcodePosition").toList(::elementPositionFromJSON)!!
1724
+ result.mrzPosition = it.optJSONArray("mrzPosition").toList(::elementPositionFromJSON)!!
1725
+ result.imageQuality = it.optJSONArray("imageQuality").toList(::imageQualityGroupFromJSON)!!
1726
+ result.rawResult = it.optString("rawResult")
1727
+ result.rfidSessionData = rfidSessionDataFromJSON(it.optJSONObject("rfidSessionData"))
1728
+ result.authenticityResult = documentReaderAuthenticityResultFromJSON(it.optJSONObject("authenticityResult"))
1729
+ result.barcodeResult = documentReaderBarcodeResultFromJSON(it.optJSONObject("barcodeResult"))
1730
+ result.rfidSessionData = rfidSessionDataFromJSON(it.optJSONObject("rfidSessionData"))
1731
+ result.documentType = it.optJSONArray("documentType").toList(::documentReaderDocumentTypeFromJSON)!!
1732
+ result.status = documentReaderResultsStatusFromJSON(it.optJSONObject("status"))!!
1733
+ result.vdsncData = vdsncDataFromJSON(it.optJSONObject("vdsncData")!!)
1734
+ result.dtcData = it.getString("dtcData")
1735
+ result.transactionInfo = transactionInfoFromJSON(it.optJSONObject("transactionInfo"))!!
1736
+ result
1737
+ }
1738
+
1739
+ fun generateDocumentReaderResults(input: DocumentReaderResults?) = input?.let {
1740
+ mapOf(
1741
+ "chipPage" to it.chipPage,
1742
+ "processingFinishedStatus" to it.processingFinishedStatus,
1743
+ "elapsedTime" to it.elapsedTime,
1744
+ "elapsedTimeRFID" to it.elapsedTimeRFID,
1745
+ "morePagesAvailable" to it.morePagesAvailable,
1746
+ "graphicResult" to generateDocumentReaderGraphicResult(it.graphicResult),
1747
+ "textResult" to generateDocumentReaderTextResult(it.textResult),
1748
+ "documentPosition" to it.documentPosition.toJson(::generateElementPosition),
1749
+ "barcodePosition" to it.barcodePosition.toJson(::generateElementPosition),
1750
+ "mrzPosition" to it.mrzPosition.toJson(::generateElementPosition),
1751
+ "imageQuality" to it.imageQuality.toJson(::generateImageQualityGroup),
1752
+ "rawResult" to it.rawResult,
1753
+ "rfidSessionData" to generateRFIDSessionData(it.rfidSessionData),
1754
+ "authenticityResult" to generateDocumentReaderAuthenticityResult(it.authenticityResult),
1755
+ "barcodeResult" to generateDocumentReaderBarcodeResult(it.barcodeResult),
1756
+ "documentType" to it.documentType.toJson(::generateDocumentReaderDocumentType),
1757
+ "status" to generateDocumentReaderResultsStatus(it.status),
1758
+ "vdsncData" to generateVDSNCData(it.vdsncData),
1759
+ "dtcData" to it.dtcData,
1760
+ "transactionInfo" to generateTransactionInfo(it.transactionInfo)
1761
+ ).toJson()
1762
+ }
1763
+
1764
+ fun matrixFromJSON(input: JSONArray?) = input?.let {
1765
+ val matrix = Matrix()
1766
+ val result = FloatArray(it.length())
1767
+ for (i in 0 until it.length()) result[i] = it.getDouble(i).toFloat()
1768
+ matrix.setValues(result)
1769
+ matrix
1770
+ }
1771
+
1772
+ fun generateMatrix(input: Matrix?) = input?.let {
1773
+ val floats = FloatArray(9)
1774
+ it.getValues(floats)
1775
+ val result = JSONArray()
1776
+ for (f in floats) result.put(java.lang.Float.valueOf(f))
1777
+ result
2198
1778
  }
2199
-
2200
- fun generateDocumentReaderResults(temp: DocumentReaderResults?, context: Context?): JSONObject? {
2201
- val result = JSONObject()
2202
- temp ?: return null
2203
- val input: DocumentReaderResults = temp
2204
-
2205
- result.put("chipPage", input.chipPage)
2206
- result.put("processingFinishedStatus", input.processingFinishedStatus)
2207
- result.put("elapsedTime", input.elapsedTime)
2208
- result.put("elapsedTimeRFID", input.elapsedTimeRFID)
2209
- result.put("morePagesAvailable", input.morePagesAvailable)
2210
- result.put("graphicResult", generateDocumentReaderGraphicResult(input.graphicResult, context))
2211
- result.put("textResult", generateDocumentReaderTextResult(input.textResult, context))
2212
- result.put("documentPosition", generateList(input.documentPosition, ::generateElementPosition))
2213
- result.put("barcodePosition", generateList(input.barcodePosition, ::generateElementPosition))
2214
- result.put("mrzPosition", generateList(input.mrzPosition, ::generateElementPosition))
2215
- result.put("imageQuality", generateList(input.imageQuality, ::generateImageQualityGroup))
2216
- result.put("rawResult", input.rawResult)
2217
- result.put("rfidSessionData", generateRFIDSessionData(input.rfidSessionData, context))
2218
- result.put("authenticityResult", generateDocumentReaderAuthenticityResult(input.authenticityResult, context))
2219
- result.put("barcodeResult", generateDocumentReaderBarcodeResult(input.barcodeResult))
2220
- result.put("documentType", generateList(input.documentType, ::generateDocumentReaderDocumentType))
2221
- result.put("status", generateDocumentReaderResultsStatus(input.status))
2222
- result.put("vdsncData", generateVDSNCData(input.vdsncData))
2223
- result.put("dtcData", input.dtcData)
2224
- result.put("transactionInfo", generateTransactionInfo(input.transactionInfo))
2225
-
2226
- return result
2227
- }