-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added trimming whitespaces (eu-digital-green-certificates#53)
* Added trimming whitespaces * Update * Update * Update
- Loading branch information
1 parent
944d4bc
commit 4c8b7fc
Showing
7 changed files
with
171 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
decoder/src/main/java/dgca/verifier/app/decoder/cbor/DefaultGreenCertificateMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* ---license-start | ||
* eu-digital-green-certificates / dgca-verifier-app-android | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
* | ||
* Created by osarapulov on 7/28/21 1:23 PM | ||
*/ | ||
|
||
package dgca.verifier.app.decoder.cbor | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper | ||
import com.upokecenter.cbor.CBORObject | ||
import dgca.verifier.app.decoder.model.GreenCertificate | ||
|
||
class DefaultGreenCertificateMapper : GreenCertificateMapper, CBORMapper() { | ||
|
||
init { | ||
SimpleModule().apply { | ||
addDeserializer(String::class.java, object : JsonDeserializer<String>() { | ||
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): String? = p?.valueAsString?.trim() | ||
}) | ||
registerModule(this) | ||
} | ||
|
||
} | ||
|
||
override fun readValue(cborObject: CBORObject): GreenCertificate { | ||
val bytes = cborObject.EncodeToBytes() | ||
return readValue(bytes, GreenCertificate::class.java) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
decoder/src/main/java/dgca/verifier/app/decoder/cbor/GreenCertificateMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* ---license-start | ||
* eu-digital-green-certificates / dgca-verifier-app-android | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
* | ||
* Created by osarapulov on 7/28/21 1:19 PM | ||
*/ | ||
|
||
package dgca.verifier.app.decoder.cbor | ||
|
||
import com.upokecenter.cbor.CBORObject | ||
import dgca.verifier.app.decoder.model.GreenCertificate | ||
|
||
interface GreenCertificateMapper { | ||
fun readValue(cborObject: CBORObject): GreenCertificate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
decoder/src/test/java/dgca/verifier/app/decoder/cbor/DefaultGreenCertificateMapperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* ---license-start | ||
* eu-digital-green-certificates / dgca-verifier-app-android | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
* | ||
* Created by osarapulov on 7/28/21 1:32 PM | ||
*/ | ||
|
||
package dgca.verifier.app.decoder.cbor | ||
|
||
import com.upokecenter.cbor.CBORObject | ||
import dgca.verifier.app.decoder.model.GreenCertificate | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
internal class DefaultGreenCertificateMapperTest { | ||
val JSON = "{\n" + | ||
" \"t\": [\n" + | ||
" {\n" + | ||
" \"sc\": \" 2021-07-26T21:00:00Z \",\n" + | ||
" \"ma\": \" 1223 \",\n" + | ||
" \"tt\": \" LP217198-3 \",\n" + | ||
" \"tc\": \" Custom Testing Centre \",\n" + | ||
" \"co\": \" FR \",\n" + | ||
" \"ci\": \" URN:UVCI:V1:DE:O39BNVCVNHTRMKY0E9DYT4A43T \",\n" + | ||
" \"is\": \" Custom Issuer Certifcate \",\n" + | ||
" \"tg\": \" 840539006 \",\n" + | ||
" \"tr\": \" 260415000 \"\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"nam\": {\n" + | ||
" \"fnt\": \" STANDARDISEDFAMILY \"\n" + | ||
" },\n" + | ||
" \"ver\": \" 1.3.0 \",\n" + | ||
" \"dob\": \" \"\n" + | ||
"}" | ||
|
||
|
||
@Test | ||
fun test() { | ||
val greenCertificateMapper = DefaultGreenCertificateMapper() | ||
val cborObject = CBORObject.FromJSONString(JSON) | ||
val greenCertificate: GreenCertificate = | ||
greenCertificateMapper.readValue(cborObject) | ||
val testingCenter: String = greenCertificate.tests!!.first().testingCentre | ||
assertEquals(testingCenter.trim(), testingCenter) | ||
} | ||
} |